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 
15 #ifndef __xoutbase_h
16 #define __xoutbase_h
17 
19 #ifdef _MSC_VER
20 #pragma warning ( disable : 4786 )
21 #pragma warning ( disable : 4503 )
22 #endif
23 
24 
25 #include <iostream>
26 #include <ostream>
27 #include <map>
28 #include <string>
29 
30 
31 namespace xoutlibrary
32 {
33  using namespace std;
34 
45  template<class charT, class traits = char_traits<charT> >
46  class xoutbase
47  {
48  public:
49 
51  typedef xoutbase Self;
52 
53  typedef traits traits_type;
54  typedef charT char_type;
55  typedef typename traits::int_type int_type;
56  typedef typename traits::pos_type pos_type;
57  typedef typename traits::off_type off_type;
58  typedef basic_ostream<charT, traits> ostream_type;
59  typedef basic_ios<charT, traits> ios_type;
60 
61  typedef std::map< std::string, ostream_type * > CStreamMapType;
62  typedef std::map< std::string, Self * > XStreamMapType;
63  typedef typename CStreamMapType::iterator CStreamMapIteratorType;
64  typedef typename XStreamMapType::iterator XStreamMapIteratorType;
65  typedef typename CStreamMapType::value_type CStreamMapEntryType;
66  typedef typename XStreamMapType::value_type XStreamMapEntryType;
67 
69  xoutbase();
70 
72  virtual ~xoutbase();
73 
76  inline Self & operator[]( const char * cellname );
77 
92  template <class T>
93  Self & operator<<( const T& _arg )
94  {
95  return this->SendToTargets( _arg );
96  }
97 
99  {
100  return this->SendToTargets( pf );
101  }
102 
104  {
105  return this->SendToTargets( pf );
106  }
107 
108  Self & operator<<( ios_base & (*pf)(ios_base &) )
109  {
110  return this->SendToTargets( pf );
111  }
112 
113  virtual void WriteBufferedData(void);
114 
118  virtual int AddTargetCell( const char * name, ostream_type * cell );
119  virtual int AddTargetCell( const char * name, Self * cell );
120  virtual int AddTargetCell( const char * ){ return 1; }
121  virtual int RemoveTargetCell( const char * name );
122 
123  virtual void SetTargetCells( const CStreamMapType & cellmap );
124  virtual void SetTargetCells( const XStreamMapType & cellmap );
125 
127  virtual int AddOutput( const char * name, ostream_type * output );
128  virtual int AddOutput( const char * name, Self * output );
129  virtual int RemoveOutput( const char * name );
130 
131  virtual void SetOutputs( const CStreamMapType & outputmap );
132  virtual void SetOutputs( const XStreamMapType & outputmap );
133 
135  virtual const CStreamMapType & GetCOutputs( void );
136  virtual const XStreamMapType & GetXOutputs( void );
137 
138  protected:
139 
141  virtual Self & SelectXCell( const char * name );
142 
146 
151 
154  bool m_Call;
155 
157  virtual void Callback(void){};
158 
159  template<class T>
160  Self & SendToTargets( const T & _arg )
161  {
162  Send<T>::ToTargets( const_cast<T &>(_arg), m_CTargetCells, m_XTargetCells );
164  if ( m_Call )
165  {
166  this->Callback();
167  }
168  return *this;
169  } // end SendToTargets
170 
171  private:
172 
173  template <class T>
174  class Send
175  {
176  public:
177  static void ToTargets( T & _arg, CStreamMapType & CTargetCells, XStreamMapType & XTargetCells )
178  {
180  for ( CStreamMapIteratorType cit = CTargetCells.begin();
181  cit != CTargetCells.end(); ++cit )
182  {
183  *(cit->second) << _arg;
184  }
185 
187  for ( XStreamMapIteratorType xit = XTargetCells.begin();
188  xit != XTargetCells.end(); ++xit )
189  {
190  *(xit->second) << _arg;
191  }
192 
193  } // end ToTargets
194 
195  }; // end class Send
196 
197 
198  }; // end class xoutbase
199 
200 
201 
202 } // end namespace xoutlibrary
203 
204 
205 #include "xoutbase.hxx"
206 
207 #endif // end #ifndef __xoutbase_h
208 
CStreamMapType m_COutputs
Definition: xoutbase.h:144
XStreamMapType::value_type XStreamMapEntryType
Definition: xoutbase.h:66
basic_ios< charT, traits > ios_type
Definition: xoutbase.h:59
virtual void Callback(void)
Definition: xoutbase.h:157
XStreamMapType m_XOutputs
Definition: xoutbase.h:145
CStreamMapType::value_type CStreamMapEntryType
Definition: xoutbase.h:65
basic_ostream< charT, traits > ostream_type
Definition: xoutbase.h:58
Self & operator<<(const T &_arg)
Definition: xoutbase.h:93
Self & SendToTargets(const T &_arg)
Definition: xoutbase.h:160
XStreamMapType m_XTargetCells
Definition: xoutbase.h:150
virtual int AddTargetCell(const char *)
Definition: xoutbase.h:120
Self & operator<<(ostream_type &(*pf)(ostream_type &))
Definition: xoutbase.h:98
traits::pos_type pos_type
Definition: xoutbase.h:56
XStreamMapType::iterator XStreamMapIteratorType
Definition: xoutbase.h:64
Base class for xout.
Definition: xoutbase.h:46
traits::int_type int_type
Definition: xoutbase.h:55
CStreamMapType m_CTargetCells
Definition: xoutbase.h:149
std::map< std::string, Self * > XStreamMapType
Definition: xoutbase.h:62
Self & operator<<(ios_base &(*pf)(ios_base &))
Definition: xoutbase.h:108
std::map< std::string, ostream_type * > CStreamMapType
Definition: xoutbase.h:61
traits::off_type off_type
Definition: xoutbase.h:57
Self & operator<<(ios_type &(*pf)(ios_type &))
Definition: xoutbase.h:103
CStreamMapType::iterator CStreamMapIteratorType
Definition: xoutbase.h:63


Generated on 04-01-2014 for elastix by doxygen 1.8.5 elastix logo