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

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML