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  This file is part of the elastix software.
4 
5  Copyright (c) University Medical Center Utrecht. All rights reserved.
6  See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for
7  details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notices for more information.
12 
13 ======================================================================*/
14 #ifndef __xoutbase_h
15 #define __xoutbase_h
16 
18 #ifdef _MSC_VER
19 #pragma warning ( disable : 4786 )
20 #pragma warning ( disable : 4503 )
21 #endif
22 
23 #include <iostream>
24 #include <ostream>
25 #include <map>
26 #include <string>
27 
28 namespace xoutlibrary
29 {
30 using namespace std;
31 
42 template< class charT, class traits = char_traits< charT > >
43 class xoutbase
44 {
45 public:
46 
48  typedef xoutbase Self;
49 
50  typedef traits traits_type;
51  typedef charT char_type;
52  typedef typename traits::int_type int_type;
53  typedef typename traits::pos_type pos_type;
54  typedef typename traits::off_type off_type;
55  typedef basic_ostream< charT, traits > ostream_type;
56  typedef basic_ios< charT, traits > ios_type;
57 
58  typedef std::map< std::string, ostream_type * > CStreamMapType;
59  typedef std::map< std::string, Self * > XStreamMapType;
60  typedef typename CStreamMapType::iterator CStreamMapIteratorType;
61  typedef typename XStreamMapType::iterator XStreamMapIteratorType;
62  typedef typename CStreamMapType::value_type CStreamMapEntryType;
63  typedef typename XStreamMapType::value_type XStreamMapEntryType;
64 
66  xoutbase();
67 
69  virtual ~xoutbase();
70 
73  inline Self & operator[]( const char * cellname );
74 
89  template< class T >
90  Self & operator<<( const T & _arg )
91  {
92  return this->SendToTargets( _arg );
93  }
94 
95 
97  {
98  return this->SendToTargets( pf );
99  }
100 
101 
102  Self & operator<<( ios_type & (* pf)( ios_type & ) )
103  {
104  return this->SendToTargets( pf );
105  }
106 
107 
108  Self & operator<<( ios_base & (* pf)( ios_base & ) )
109  {
110  return this->SendToTargets( pf );
111  }
112 
113 
114  virtual void WriteBufferedData( void );
115 
119  virtual int AddTargetCell( const char * name, ostream_type * cell );
120 
121  virtual int AddTargetCell( const char * name, Self * cell );
122 
123  virtual int AddTargetCell( const char * ){ return 1; }
124  virtual int RemoveTargetCell( const char * name );
125 
126  virtual void SetTargetCells( const CStreamMapType & cellmap );
127 
128  virtual void SetTargetCells( const XStreamMapType & cellmap );
129 
131  virtual int AddOutput( const char * name, ostream_type * output );
132 
133  virtual int AddOutput( const char * name, Self * output );
134 
135  virtual int RemoveOutput( const char * name );
136 
137  virtual void SetOutputs( const CStreamMapType & outputmap );
138 
139  virtual void SetOutputs( const XStreamMapType & outputmap );
140 
142  virtual const CStreamMapType & GetCOutputs( void );
143 
144  virtual const XStreamMapType & GetXOutputs( void );
145 
146 protected:
147 
149  virtual Self & SelectXCell( const char * name );
150 
154 
159 
162  bool m_Call;
163 
165  virtual void Callback( void ){}
166 
167  template< class T >
168  Self & SendToTargets( const T & _arg )
169  {
170  Send< T >::ToTargets( const_cast< T & >( _arg ), m_CTargetCells, m_XTargetCells );
172  if( m_Call )
173  {
174  this->Callback();
175  }
176  return *this;
177  } // end SendToTargets
178 
179 
180 private:
181 
182  template< class T >
183  class Send
184  {
185 public:
186 
187  static void ToTargets( T & _arg, CStreamMapType & CTargetCells, XStreamMapType & XTargetCells )
188  {
190  for( CStreamMapIteratorType cit = CTargetCells.begin();
191  cit != CTargetCells.end(); ++cit )
192  {
193  *( cit->second ) << _arg;
194  }
195 
197  for( XStreamMapIteratorType xit = XTargetCells.begin();
198  xit != XTargetCells.end(); ++xit )
199  {
200  *( xit->second ) << _arg;
201  }
202 
203  } // end ToTargets
204 
205 
206  };
207 
208 };
209 
210 } // end namespace xoutlibrary
211 
212 #include "xoutbase.hxx"
213 
214 #endif // end #ifndef __xoutbase_h
CStreamMapType m_COutputs
Definition: xoutbase.h:152
XStreamMapType::value_type XStreamMapEntryType
Definition: xoutbase.h:63
virtual void Callback(void)
Definition: xoutbase.h:165
XStreamMapType m_XOutputs
Definition: xoutbase.h:153
basic_ostream< charT, traits > ostream_type
Definition: xoutbase.h:55
CStreamMapType::value_type CStreamMapEntryType
Definition: xoutbase.h:62
Self & operator<<(const T &_arg)
Definition: xoutbase.h:90
Self & SendToTargets(const T &_arg)
Definition: xoutbase.h:168
XStreamMapType m_XTargetCells
Definition: xoutbase.h:158
virtual int AddTargetCell(const char *)
Definition: xoutbase.h:123
Self & operator<<(ostream_type &(*pf)(ostream_type &))
Definition: xoutbase.h:96
traits::pos_type pos_type
Definition: xoutbase.h:53
XStreamMapType::iterator XStreamMapIteratorType
Definition: xoutbase.h:61
Base class for xout.
Definition: xoutbase.h:43
traits::int_type int_type
Definition: xoutbase.h:52
CStreamMapType m_CTargetCells
Definition: xoutbase.h:157
std::map< std::string, Self * > XStreamMapType
Definition: xoutbase.h:59
Self & operator<<(ios_base &(*pf)(ios_base &))
Definition: xoutbase.h:108
std::map< std::string, ostream_type * > CStreamMapType
Definition: xoutbase.h:58
traits::off_type off_type
Definition: xoutbase.h:54
Self & operator<<(ios_type &(*pf)(ios_type &))
Definition: xoutbase.h:102
CStreamMapType::iterator CStreamMapIteratorType
Definition: xoutbase.h:60
basic_ios< charT, traits > ios_type
Definition: xoutbase.h:56


Generated on 11-03-2014 for elastix by doxygen 1.8.6 elastix logo