50 #ifndef OPENMESH_MOSTREAM_HH
51 #define OPENMESH_MOSTREAM_HH
56 #include <OpenMesh/Core/System/config.h>
58 #if defined( OM_CC_GCC ) && OM_CC_VERSION < 30000
59 # include <streambuf.h>
68 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
76 #ifndef DOXY_IGNORE_THIS
82 class basic_multiplex_target
85 virtual ~basic_multiplex_target() {}
86 virtual void operator<<(
const std::string& _s) = 0;
91 class multiplex_target :
public basic_multiplex_target
94 explicit multiplex_target(T& _t) : target_(_t) {}
95 virtual void operator<<(
const std::string& _s)
override { target_ << _s; }
105 #if defined( OM_CC_GCC ) && OM_CC_VERSION < 30000
106 # define STREAMBUF streambuf
107 # define INT_TYPE int
110 # define STREAMBUF std::basic_streambuf<char>
113 class multiplex_streambuf :
public STREAMBUF
117 typedef STREAMBUF base_type;
118 #if defined( OM_CC_GCC ) && OM_CC_VERSION < 30000
119 typedef int int_type;
122 static int_type eof() {
return -1; }
123 static char to_char_type(int_type c) {
return char(c); }
126 typedef base_type::int_type int_type;
127 typedef base_type::traits_type traits_type;
131 multiplex_streambuf() : enabled_(true) { buffer_.reserve(100); }
134 ~multiplex_streambuf()
136 tmap_iter t_it(target_map_.begin()), t_end(target_map_.end());
137 for (; t_it!=t_end; ++t_it)
143 bool is_enabled()
const {
return enabled_; }
144 void enable() { enabled_ =
true; }
145 void disable() { enabled_ =
false; }
149 template <
class T>
bool connect(T& _target)
151 void* key = (
void*) &_target;
153 if (target_map_.find(key) != target_map_.end())
156 target_type* mtarget =
new multiplex_target<T>(_target);
157 target_map_[key] = mtarget;
165 template <
class T>
bool disconnect(T& _target)
167 void* key = (
void*) &_target;
168 tmap_iter t_it = target_map_.find(key);
170 if (t_it != target_map_.end())
172 __disconnect(t_it->second);
173 target_map_.erase(t_it);
187 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
188 std::lock_guard<std::mutex> lck (serializer_);
191 if (!buffer_.empty())
193 if (enabled_) multiplex();
194 #if defined( OM_CC_GCC ) && OM_CC_VERSION < 30000
200 return base_type::sync();
207 int_type overflow(int_type _c = multiplex_streambuf::traits_type::eof())
209 char c = traits_type::to_char_type(_c);
212 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
214 std::lock_guard<std::mutex> lck (serializer_);
215 buffer_.push_back(c);
218 buffer_.push_back(c);
221 if (c ==
'\n') sync();
228 typedef basic_multiplex_target target_type;
229 typedef std::vector<target_type*> target_list;
230 typedef target_list::iterator tlist_iter;
231 typedef std::map<void*, target_type*> target_map;
232 typedef target_map::iterator tmap_iter;
236 void __connect(target_type* _target) { targets_.push_back(_target); }
240 void __disconnect(target_type* _target) {
241 targets_.erase(std::find(targets_.begin(), targets_.end(), _target));
248 tlist_iter t_it(targets_.begin()), t_end(targets_.end());
249 for (; t_it!=t_end; ++t_it)
256 target_list targets_;
257 target_map target_map_;
262 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined( __GXX_EXPERIMENTAL_CXX0X__ )
263 std::mutex serializer_;
283 class mostream :
public std::ostream
288 explicit mostream() : std::ostream(nullptr) { init(&streambuffer_); }
292 template <
class T>
bool connect(T& _target)
294 return streambuffer_.connect(_target);
299 template <
class T>
bool disconnect(T& _target)
301 return streambuffer_.disconnect(_target);
306 bool is_enabled()
const {
return streambuffer_.is_enabled(); }
309 void enable() { streambuffer_.enable(); }
312 void disable() { streambuffer_.disable(); }
316 multiplex_streambuf streambuffer_;
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
auto operator<<(std::ostream &os, const VectorT< Scalar, DIM > &_vec) -> typename std::enable_if< sizeof(decltype(os<< _vec[0])) >=0
output a vector by printing its space-separated compontens