COPASI API  4.16.103
CCopasiMessage.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 /**
16  * CCopasiMessage class.
17  * New Class for COPASI message handling. (C) Stefan Hoops 2001.
18  */
19 
20 #ifndef COPASI_CCopasiMessage
21 #define COPASI_CCopasiMessage
22 
23 #include <string>
24 #include <deque>
25 
26 typedef struct MESSAGES {size_t No; const char * Text;}
27 Message;
28 
29 #define MCopasiBase 5000
30 #define MCReadConfig MCopasiBase + 100
31 #define MCWriteConfig MCopasiBase + 200
32 #define MCRange MCopasiBase + 300
33 #define MCKinFunction MCopasiBase + 400
34 #define MCCopasiVector MCopasiBase + 500
35 #define MCFunctionParameters MCopasiBase + 600
36 #define MCMassAction MCopasiBase + 700
37 #define MCCopasiMethod MCopasiBase + 800
38 #define MCReaction MCopasiBase + 900
39 #define MCParameter MCopasiBase + 1000
40 #define MCChemEq MCopasiBase + 1100
41 #define MCTrajectoryMethod MCopasiBase + 1200
42 #define MCXML MCopasiBase + 1300
43 #define MCCopasiMessage MCopasiBase + 1400
44 #define MCConfiguration MCopasiBase + 1500
45 #define MCOptimization MCopasiBase + 1600
46 #define MCSBML MCopasiBase + 1700
47 #define MCTrajectoryProblem MCopasiBase + 2800
48 #define MCDirEntry MCopasiBase + 2900
49 #define MCFunction MCopasiBase + 3000
50 #define MCMathML MCopasiBase + 3100
51 #define MCEvaluationNodeObject MCopasiBase + 3200
52 #define MCCopasiTask MCopasiBase + 3300
53 #define MCSteadyState MCopasiBase + 3400
54 #define MCFitting MCopasiBase + 3500
55 #define MCObject MCopasiBase + 3600
56 #define MCLyap MCopasiBase + 3700
57 #define MCODEExporter MCopasiBase + 3800
58 #define MCRegistration MCopasiBase + 3900
59 #define MCTSSAMethod MCopasiBase + 4000
60 #define MCTSSAProblem MCopasiBase + 4100
61 #define MCEigen MCopasiBase + 4200
62 #define MCAnnotation MCopasiBase + 4300
63 #define MCMathModel MCopasiBase + 4400
64 #define MCModelMerging MCopasiBase + 4500
65 #define MCModelExpansion MCopasiBase + 4600
66 #define MCEFMAnalysis MCopasiBase + 4700
67 #define MCLayout MCopasiBase + 4800
68 #define MCScan MCopasiBase + 4900
69 #define MCSEDML MCopasiBase + 5000
70 #define MCMCA MCopasiBase + 5100
71 /**
72  * This throws an exception with information where the error occurred.
73  */
74 #define fatalError() {CCopasiMessage(CCopasiMessage::EXCEPTION, \
75  "%s (%d) compiled: %s %s", \
76  __FILE__, __LINE__, __DATE__, __TIME__);}
77 
79 {
80 public:
81  enum Type
82  {
83  RAW = 0,
84  TRACE = 1,
86  WARNING = 3,
87  // In the case that ERROR is defined we have to remove its definition
88  // temporarily.
89 #ifdef ERROR
90 # undef ERROR
91 #endif
92  ERROR = 4,
93  EXCEPTION = 5,
94  RAW_FILTERED = 128,
100  };
101 
102  // Attributes
103 
104 private:
105  /**
106  * Message text.
107  */
108  std::string mText;
109 
110  /**
111  * Message type.
112  */
114 
115  /**
116  * Message Number
117  */
118  size_t mNumber;
119 
120 #ifndef WIN32
121  /**
122  * The stack of messages. Each message created with one of
123  * the specific constructors is automatically added to the stack.
124  */
125  static std::deque< CCopasiMessage > mMessageDeque;
126 #endif // not WIN32
127 
128  /**
129  * A flag indicating whether the COPASI is running as commandline or
130  * GUI
131  */
132  static bool IsGUI;
133 
134  // Operations
135 
136 public:
137  /**
138  * This function peeks at the first message created in COPASI.
139  * If no more messages are in the dequeue the message
140  * (MCCopasiMessage + 1, "Message (1): No more messages." is returned.
141  * @return const CCopasiMessage & message
142  */
143  static const CCopasiMessage & peekFirstMessage();
144 
145  /**
146  * This function peeks at the last message created in COPASI.
147  * If no more messages are in the dequeue the message
148  * (MCCopasiMessage + 1, "Message (1): No more messages." is returned.
149  * @return const CCopasiMessage & message
150  */
151  static const CCopasiMessage & peekLastMessage();
152 
153  /**
154  * This function retrieves the first message created in COPASI.
155  * Consecutive calls allow for the retrieval of all generated
156  * messages in chronological order. If no more messages are in
157  * the dequeue the message (MCCopasiMessage + 1, "Message (1):
158  * No more messages." is returned.
159  * @return CCopasiMessage message
160  */
162 
163  /**
164  * This function retrieves the last message created in COPASI.
165  * Consecutive calls allow for the retrieval of all generated
166  * messages in reverse chronological order. If no more messages
167  * are in the dequeue the message (MCCopasiMessage + 1, "Message
168  * (1): No more messages." is returned.
169  * @return CCopasiMessage message
170  */
172 
173  /**
174  * Retrieve the text of all messages in the dequeue in chronological
175  * or reverse chronological order. If more than on message is in
176  * the dequeue the messages are separated by an empty line.
177  * @return std::string messageTexts
178  */
179  static std::string getAllMessageText(const bool & chronological = true);
180 
181  /**
182  * This function clears the message stack.
183  */
184  static void clearDeque();
185 
186  /**
187  * Retrieve the size of the dequeue
188  * @return size_t size
189  */
190  static size_t size();
191 
192  /**
193  * Retrieve highest severity of the messages in the dequeue.
194  * @return const CCopasiMessage::Type & highestSeverity
195  */
197 
198  /**
199  * Check whether a message with the given number is in the dequeue
200  * @param const size_t & number
201  * @return bool found
202  */
203  static bool checkForMessage(const size_t & number);
204 
205  /**
206  * Set whether the messages are created from COPASI as GUI or commandline.
207  * This method is called from CCopasiRootContainer::init and there should be
208  * no need to call it otherwise.
209  * @param const bool & isGUI
210  */
211  static void setIsGUI(const bool & isGUI);
212 
213  /**
214  * Default constructor.
215  * This creates a default error messages, which actually does nothing.
216  */
217  CCopasiMessage();
218 
219  /**
220  * Copy constructor.
221  * @param const CCopasiMessage & src
222  */
223  CCopasiMessage(const CCopasiMessage & src);
224 
225  /**
226  * Specified constructor.
227  * This creates a formated message.
228  * @param CCopasiMessage::Type type (RAW|TRACE|WARNING|ERROR)
229  * @param const char * format (printf like format string)
230  * @param ... arguments like in printf
231  */
232  CCopasiMessage(Type type, const char *format, ...);
233 
234  /**
235  * Specified constructor.
236  * This creates a formated message.
237  * @param CCopasiMessage::Type type (RAW|TRACE|WARNING|ERROR)
238  * @param size_t number (message number see message.h)
239  * @param ... arguments like in printf
240  */
241  CCopasiMessage(Type type, size_t number, ...);
242 
243  /**
244  * Destructor.
245  */
246  ~CCopasiMessage();
247 
248  /**
249  * Assignment operator.
250  */
252 
253  /**
254  * Retrieves the text of the message.
255  * @return "const string &" mMessage
256  */
257  const std::string & getText() const;
258 
259  /**
260  * Retrieves the type of the message.
261  * @return "const CCopasiMessage::Type &" mType
262  */
263  const CCopasiMessage::Type & getType() const;
264 
265  /**
266  * Retrieves the number of the message.
267  * @return "const size_t &" mNumber
268  */
269  const size_t & getNumber() const;
270 
271 private:
272  /**
273  * The actual constructor of a message.
274  * @param const bool & throw (default: false)
275  * @param text message text
276  */
277  void handler(const bool & _throw = false);
278 
279  /**
280  * Inserts line breaks in the message text.
281  */
282  void lineBreak();
283 };
284 
285 #endif // COPASI_CCopasiMessage
const char * Text
static const CCopasiMessage & peekLastMessage()
static bool IsGUI
const std::string & getText() const
static std::string getAllMessageText(const bool &chronological=true)
const size_t & getNumber() const
static CCopasiMessage getFirstMessage()
static void setIsGUI(const bool &isGUI)
CCopasiMessage::Type mType
static void clearDeque()
void handler(const bool &_throw=false)
static std::deque< CCopasiMessage > mMessageDeque
static const CCopasiMessage & peekFirstMessage()
size_t No
const CCopasiMessage::Type & getType() const
struct MESSAGES Message
static size_t size()
CCopasiMessage & operator=(const CCopasiMessage &RHS)
std::string mText
static bool checkForMessage(const size_t &number)
static CCopasiMessage getLastMessage()
static CCopasiMessage::Type getHighestSeverity()