Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __xoutbase_h
00016 #define __xoutbase_h
00017
00019 #ifdef _MSC_VER
00020 #pragma warning ( disable : 4786 )
00021 #pragma warning ( disable : 4503 )
00022 #endif
00023
00024
00025 #include <iostream>
00026 #include <ostream>
00027 #include <map>
00028 #include <string>
00029
00030
00031 namespace xoutlibrary
00032 {
00033 using namespace std;
00034
00045 template<class charT, class traits = char_traits<charT> >
00046 class xoutbase
00047 {
00048 public:
00049
00051 typedef xoutbase Self;
00052
00053 typedef traits traits_type;
00054 typedef charT char_type;
00055 typedef typename traits::int_type int_type;
00056 typedef typename traits::pos_type pos_type;
00057 typedef typename traits::off_type off_type;
00058 typedef basic_ostream<charT, traits> ostream_type;
00059 typedef basic_ios<charT, traits> ios_type;
00060
00061 typedef std::map< std::string, ostream_type * > CStreamMapType;
00062 typedef std::map< std::string, Self * > XStreamMapType;
00063 typedef typename CStreamMapType::iterator CStreamMapIteratorType;
00064 typedef typename XStreamMapType::iterator XStreamMapIteratorType;
00065 typedef typename CStreamMapType::value_type CStreamMapEntryType;
00066 typedef typename XStreamMapType::value_type XStreamMapEntryType;
00067
00069 xoutbase();
00070
00072 virtual ~xoutbase();
00073
00076 inline Self & operator[]( const char * cellname );
00077
00092 template <class T>
00093 Self & operator<<( const T& _arg )
00094 {
00095 return this->SendToTargets( _arg );
00096 }
00097
00098 Self & operator<<( ostream_type & (*pf)(ostream_type &) )
00099 {
00100 return this->SendToTargets( pf );
00101 }
00102
00103 Self & operator<<( ios_type & (*pf)(ios_type &) )
00104 {
00105 return this->SendToTargets( pf );
00106 }
00107
00108 Self & operator<<( ios_base & (*pf)(ios_base &) )
00109 {
00110 return this->SendToTargets( pf );
00111 }
00112
00113 virtual void WriteBufferedData(void);
00114
00118 virtual int AddTargetCell( const char * name, ostream_type * cell );
00119 virtual int AddTargetCell( const char * name, Self * cell );
00120 virtual int AddTargetCell( const char * ){ return 1; }
00121 virtual int RemoveTargetCell( const char * name );
00122
00123 virtual void SetTargetCells( const CStreamMapType & cellmap );
00124 virtual void SetTargetCells( const XStreamMapType & cellmap );
00125
00127 virtual int AddOutput( const char * name, ostream_type * output );
00128 virtual int AddOutput( const char * name, Self * output );
00129 virtual int RemoveOutput( const char * name );
00130
00131 virtual void SetOutputs( const CStreamMapType & outputmap );
00132 virtual void SetOutputs( const XStreamMapType & outputmap );
00133
00135 virtual const CStreamMapType & GetCOutputs( void );
00136 virtual const XStreamMapType & GetXOutputs( void );
00137
00138 protected:
00139
00141 virtual Self & SelectXCell( const char * name );
00142
00144 CStreamMapType m_COutputs;
00145 XStreamMapType m_XOutputs;
00146
00149 CStreamMapType m_CTargetCells;
00150 XStreamMapType m_XTargetCells;
00151
00154 bool m_Call;
00155
00157 virtual void Callback(void){};
00158
00159 template<class T>
00160 Self & SendToTargets( const T & _arg )
00161 {
00162 Send<T>::ToTargets( const_cast<T &>(_arg), m_CTargetCells, m_XTargetCells );
00164 if ( m_Call )
00165 {
00166 this->Callback();
00167 }
00168 return *this;
00169 }
00170
00171 private:
00172
00173 template <class T>
00174 class Send
00175 {
00176 public:
00177 static void ToTargets( T & _arg, CStreamMapType & CTargetCells, XStreamMapType & XTargetCells )
00178 {
00180 for ( CStreamMapIteratorType cit = CTargetCells.begin();
00181 cit != CTargetCells.end(); ++cit )
00182 {
00183 *(cit->second) << _arg;
00184 }
00185
00187 for ( XStreamMapIteratorType xit = XTargetCells.begin();
00188 xit != XTargetCells.end(); ++xit )
00189 {
00190 *(xit->second) << _arg;
00191 }
00192
00193 }
00194
00195 };
00196
00197
00198 };
00199
00200
00201
00202 }
00203
00204
00205 #include "xoutbase.hxx"
00206
00207 #endif // end #ifndef __xoutbase_h
00208