All Classes Namespaces Functions Typedefs Enumerations Pages
atom.h
1 #ifndef _FMATVEC_ATOM_H
2 #define _FMATVEC_ATOM_H
3 
4 #include <ostream>
5 #include <iostream>
6 #include <boost/shared_ptr.hpp>
7 #include <boost/make_shared.hpp>
8 #include <boost/array.hpp>
9 #include <boost/static_assert.hpp>
10 
11 namespace fmatvec {
12 
20 class Atom {
21  public:
22 
24  // When adding new message type a stream and a initial active flag must be provided in atom.cc (see NEW TYPES HERE)
25  enum MsgType {
26  Info, // Informational messages
27  Warn, // Warning messages
28  Debug, // Debugging messages
29  SIZE // Must be the last enum in this list
30  };
31  #define FMATVEC_ATOM_MSGTYPE_SIZE 3
32 #ifndef SWIG // swig can not parse this however it is not needed for swig
33  BOOST_STATIC_ASSERT_MSG(SIZE==FMATVEC_ATOM_MSGTYPE_SIZE, "The proprocessor define FMATVEC_ATOM_MSGTYPE_SIZE must be equal Atom::SIZE.");
34 #endif
35 
36  protected:
38  Atom();
40  Atom(const Atom &src);
41  public:
43  virtual ~Atom();
44 #ifndef SWIG // no assignment operator for swig
45  Atom& operator=(const Atom &);
47 #endif
48 
54  static void setCurrentMessageStream(MsgType type,
55  const boost::shared_ptr<bool> &a=boost::make_shared<bool>(true),
56  const boost::shared_ptr<std::ostream> &s=boost::make_shared<std::ostream>(std::cout.rdbuf()));
57 
59  void setMessageStreamActive(MsgType type, bool active);
60 
62  void getMessageStream(MsgType type,
63  boost::shared_ptr<bool> &a,
64  boost::shared_ptr<std::ostream> &s);
65 
69  void adoptMessageStreams(const Atom *src=NULL);
70 
74  std::ostream &msg(MsgType type) {
75  return *_msg[type];
76  }
80  bool msgAct(MsgType type) {
81  return *_msgAct[type];
82  }
83 
86  static std::ostream &msgStatic(MsgType type) {
87  return *_msgStatic[type];
88  }
91  static bool msgActStatic(MsgType type) {
92  return *_msgActStatic[type];
93  }
94 
95  private:
96 
97  // A stream which prints to null.
98  static boost::shared_ptr<std::ostream> _nullStream;
99 
100  // Static pointer arrays of streams and active flags which were used for newly created objects.
101  // These can be changed using setCurrentMessageStream(...)
102  static boost::array<boost::shared_ptr<bool >, SIZE> _msgActStatic;
103  static boost::array<boost::shared_ptr<std::ostream>, SIZE> _msgSavedStatic;
104  static boost::array<boost::shared_ptr<std::ostream>, SIZE> _msgStatic;
105 
106  // Pointer arrays to streams and active flags this object uses.
107  // (these have a life-time at least as long as the object itself, ensured by reference counting)
108  boost::array<boost::shared_ptr<bool >, SIZE> _msgAct;
109  boost::array<boost::shared_ptr<std::ostream>, SIZE> _msgSaved;
110  boost::array<boost::shared_ptr<std::ostream>, SIZE> _msg;
111 };
112 
113 }
114 
115 #endif
void getMessageStream(MsgType type, boost::shared_ptr< bool > &a, boost::shared_ptr< std::ostream > &s)
Get the shared message stream active flag and the shared message stream of this object.
Definition: atom.cc:76
static std::ostream & msgStatic(MsgType type)
Definition: atom.h:86
Definition: atom.h:20
static void setCurrentMessageStream(MsgType type, const boost::shared_ptr< bool > &a=boost::make_shared< bool >(true), const boost::shared_ptr< std::ostream > &s=boost::make_shared< std::ostream >(std::cout.rdbuf()))
Definition: atom.cc:65
std::ostream & msg(MsgType type)
Definition: atom.h:74
Atom()
When a Atom is default constructed use the current statically set message streams.
Definition: atom.cc:46
void setMessageStreamActive(MsgType type, bool active)
Set the active flag of this object and all objects which were created using the same message stream a...
Definition: atom.cc:71
static bool msgActStatic(MsgType type)
Definition: atom.h:91
bool msgAct(MsgType type)
Definition: atom.h:80
void adoptMessageStreams(const Atom *src=NULL)
Definition: atom.cc:83
virtual ~Atom()
dtor.
Definition: atom.cc:58
MsgType
Messages can be printed to different message types named here.
Definition: atom.h:25
Atom & operator=(const Atom &)
When a Atom is assinged do not change the messsage streams since we always use the message streams be...
Definition: atom.cc:61

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML