go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
xoutbase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright UMC Utrecht and contributors
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __xoutbase_h
19 #define __xoutbase_h
20 
22 #ifdef _MSC_VER
23 #pragma warning ( disable : 4786 )
24 #pragma warning ( disable : 4503 )
25 #endif
26 
27 #include <iostream>
28 #include <ostream>
29 #include <map>
30 #include <string>
31 
32 namespace xoutlibrary
33 {
34 using namespace std;
35 
46 template< class charT, class traits = char_traits< charT > >
47 class xoutbase
48 {
49 public:
50 
52  typedef xoutbase Self;
53 
54  typedef traits traits_type;
55  typedef charT char_type;
56  typedef typename traits::int_type int_type;
57  typedef typename traits::pos_type pos_type;
58  typedef typename traits::off_type off_type;
59  typedef basic_ostream< charT, traits > ostream_type;
60  typedef basic_ios< charT, traits > ios_type;
61 
62  typedef std::map< std::string, ostream_type * > CStreamMapType;
63  typedef std::map< std::string, Self * > XStreamMapType;
64  typedef typename CStreamMapType::iterator CStreamMapIteratorType;
65  typedef typename XStreamMapType::iterator XStreamMapIteratorType;
66  typedef typename CStreamMapType::value_type CStreamMapEntryType;
67  typedef typename XStreamMapType::value_type XStreamMapEntryType;
68 
70  xoutbase();
71 
73  virtual ~xoutbase();
74 
77  inline Self & operator[]( const char * cellname );
78 
93  template< class T >
94  Self & operator<<( const T & _arg )
95  {
96  return this->SendToTargets( _arg );
97  }
98 
99 
100  Self & operator<<( ostream_type & (* pf)( ostream_type & ) )
101  {
102  return this->SendToTargets( pf );
103  }
104 
105 
106  Self & operator<<( ios_type & (* pf)( ios_type & ) )
107  {
108  return this->SendToTargets( pf );
109  }
110 
111 
112  Self & operator<<( ios_base & (* pf)( ios_base & ) )
113  {
114  return this->SendToTargets( pf );
115  }
116 
117 
118  virtual void WriteBufferedData( void );
119 
123  virtual int AddTargetCell( const char * name, ostream_type * cell );
124 
125  virtual int AddTargetCell( const char * name, Self * cell );
126 
127  virtual int AddTargetCell( const char * ){ return 1; }
128  virtual int RemoveTargetCell( const char * name );
129 
130  virtual void SetTargetCells( const CStreamMapType & cellmap );
131 
132  virtual void SetTargetCells( const XStreamMapType & cellmap );
133 
135  virtual int AddOutput( const char * name, ostream_type * output );
136 
137  virtual int AddOutput( const char * name, Self * output );
138 
139  virtual int RemoveOutput( const char * name );
140 
141  virtual void SetOutputs( const CStreamMapType & outputmap );
142 
143  virtual void SetOutputs( const XStreamMapType & outputmap );
144 
146  virtual const CStreamMapType & GetCOutputs( void );
147 
148  virtual const XStreamMapType & GetXOutputs( void );
149 
150 protected:
151 
153  virtual Self & SelectXCell( const char * name );
154 
156  CStreamMapType m_COutputs;
157  XStreamMapType m_XOutputs;
158 
161  CStreamMapType m_CTargetCells;
162  XStreamMapType m_XTargetCells;
163 
166  bool m_Call;
167 
169  virtual void Callback( void ){}
170 
171  template< class T >
172  Self & SendToTargets( const T & _arg )
173  {
174  Send< T >::ToTargets( const_cast< T & >( _arg ), m_CTargetCells, m_XTargetCells );
176  if( m_Call )
177  {
178  this->Callback();
179  }
180  return *this;
181  } // end SendToTargets
182 
183 
184 private:
185 
186  template< class T >
187  class Send
188  {
189 public:
190 
191  static void ToTargets( T & _arg, CStreamMapType & CTargetCells, XStreamMapType & XTargetCells )
192  {
194  for( CStreamMapIteratorType cit = CTargetCells.begin();
195  cit != CTargetCells.end(); ++cit )
196  {
197  *( cit->second ) << _arg;
198  }
199 
201  for( XStreamMapIteratorType xit = XTargetCells.begin();
202  xit != XTargetCells.end(); ++xit )
203  {
204  *( xit->second ) << _arg;
205  }
206 
207  } // end ToTargets
208 
209 
210  };
211 
212 };
213 
214 } // end namespace xoutlibrary
215 
216 #include "xoutbase.hxx"
217 
218 #endif // end #ifndef __xoutbase_h
CStreamMapType m_COutputs
Definition: xoutbase.h:156
XStreamMapType::value_type XStreamMapEntryType
Definition: xoutbase.h:67
virtual void Callback(void)
Definition: xoutbase.h:169
XStreamMapType m_XOutputs
Definition: xoutbase.h:157
basic_ostream< charT, traits > ostream_type
Definition: xoutbase.h:59
CStreamMapType::value_type CStreamMapEntryType
Definition: xoutbase.h:66
Self & operator<<(const T &_arg)
Definition: xoutbase.h:94
Self & SendToTargets(const T &_arg)
Definition: xoutbase.h:172
XStreamMapType m_XTargetCells
Definition: xoutbase.h:162
virtual int AddTargetCell(const char *)
Definition: xoutbase.h:127
Self & operator<<(ostream_type &(*pf)(ostream_type &))
Definition: xoutbase.h:100
traits::pos_type pos_type
Definition: xoutbase.h:57
XStreamMapType::iterator XStreamMapIteratorType
Definition: xoutbase.h:65
Base class for xout.
Definition: xoutbase.h:47
traits::int_type int_type
Definition: xoutbase.h:56
CStreamMapType m_CTargetCells
Definition: xoutbase.h:161
std::map< std::string, Self * > XStreamMapType
Definition: xoutbase.h:63
Self & operator<<(ios_base &(*pf)(ios_base &))
Definition: xoutbase.h:112
std::map< std::string, ostream_type * > CStreamMapType
Definition: xoutbase.h:62
traits::off_type off_type
Definition: xoutbase.h:58
Self & operator<<(ios_type &(*pf)(ios_type &))
Definition: xoutbase.h:106
CStreamMapType::iterator CStreamMapIteratorType
Definition: xoutbase.h:64
basic_ios< charT, traits > ios_type
Definition: xoutbase.h:60


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo