Scopira 20080306

output.h

00001 
00002 /*
00003  *  Copyright (c) 2004-2008    National Research Council
00004  *
00005  *  All rights reserved.
00006  *
00007  *  This material is confidential and proprietary information of
00008  *  National Research Council Canada ("Confidential Information").
00009  *  This Confidential Information may only be used and reproduced
00010  *  in accordance with the terms of the license agreement.
00011  *
00012  */
00013 
00014 #ifndef __INCLUDED_SCOPIRA_TOOL_OUTPUT_H__
00015 #define __INCLUDED_SCOPIRA_TOOL_OUTPUT_H__
00016 
00017 // we'll include this as a convinience to users that include output.h
00018 #include <scopira/tool/flow.h>
00019 #include <scopira/tool/export.h>
00020 
00021 namespace scopira
00022 {
00023   namespace tool
00024   {
00029     typedef scopira::tool::oflow_i& (*output_func)(void);
00030 
00043     SCOPIRA_EXPORT extern scopira::tool::output_func gm_tool_output;
00044 
00054     scopira::tool::oflow_i& tool_output(void);
00055 
00064     SCOPIRA_EXPORT extern scopira::tool::oflow_i *gm_tool_output_stream;
00065 
00066     class output_stack;
00067   }
00068 }
00069 
00070 #ifndef OUTPUT
00071 #define OUTPUT (scopira::tool::gm_tool_output())
00072 #endif
00073 
00080 class scopira::tool::output_stack
00081 {
00082   private:
00083     output_func dm_oldfunc;
00084     oflow_i *dm_oldflow;
00085   public:
00092     output_stack(oflow_i *newflow)
00093       : dm_oldfunc(gm_tool_output), dm_oldflow(gm_tool_output_stream) {
00094       gm_tool_output = tool_output;
00095       gm_tool_output_stream = newflow;
00096     }
00097 
00104     output_stack(output_func newfunc)
00105       : dm_oldfunc(gm_tool_output), dm_oldflow(gm_tool_output_stream) {
00106       gm_tool_output = newfunc;
00107       gm_tool_output_stream = 0;
00108     }
00109 
00110     // dtor does a stack pop, that is, restores the old values
00111     ~output_stack() {
00112       gm_tool_output = dm_oldfunc;
00113       gm_tool_output_stream = dm_oldflow;
00114     }
00115 };
00116 
00137 #endif
00138