Cbc  2.9.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinMessageHandler.hpp
Go to the documentation of this file.
1 /* $Id: CoinMessageHandler.hpp 1514 2011-12-10 23:35:23Z lou $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CoinMessageHandler_H
7 #define CoinMessageHandler_H
8 
9 #include "CoinUtilsConfig.h"
10 #include "CoinPragma.hpp"
11 
12 #include <iostream>
13 #include <cstdio>
14 #include <string>
15 #include <vector>
16 
31 /*
32  I (jjf) am strongly in favo(u)r of language support for an open
33  source project, but I have tried to make it as lightweight as
34  possible in the sense that only a subset of messages need to be
35  defined - the rest default to US English. There will be different
36  sets of messages for each component - so at present there is a
37  Clp component and a Coin component.
38 
39  Because messages are only used in a controlled environment and have no
40  impact on code and are tested by other tests I have included tests such
41  as language and derivation in other unit tests.
42 */
43 /*
44  Where there are derived classes I (jjf) have started message numbers at 1001.
45 */
46 
47 
59 
60 public:
67  const char * message);
75 
78  void replaceMessage(const char * message);
81 
85  inline int externalNumber() const
86  {return externalNumber_;}
92  inline void setExternalNumber(int number)
93  {externalNumber_=number;}
95  inline char severity() const
96  {return severity_;}
98  inline void setDetail(int level)
99  {detail_=static_cast<char> (level);}
101  inline int detail() const
102  {return detail_;}
104  inline char * message() const
105  {return message_;}
107 
110  int externalNumber_;
113  char detail_;
115  char severity_;
117  mutable char message_[400];
119 };
120 
129 
130 public:
136  enum Language {
137  us_en = 0,
140  };
141 
145  CoinMessages(int numberMessages=0);
147  ~CoinMessages();
149  CoinMessages(const CoinMessages&);
153 
161  void addMessage(int messageNumber, const CoinOneMessage & message);
167  void replaceMessage(int messageNumber, const char * message);
169  inline Language language() const
170  {return language_;}
172  void setLanguage(Language newlanguage)
173  {language_ = newlanguage;}
175  void setDetailMessage(int newLevel, int messageNumber);
183  void setDetailMessages(int newLevel, int numberMessages,
184  int * messageNumbers);
186  void setDetailMessages(int newLevel, int low, int high);
187 
189  inline int getClass() const
190  { return class_;}
192  void toCompact();
194  void fromCompact();
196 
199  int numberMessages_;
204  char source_[5];
206  int class_;
214 };
215 
216 // for convenience eol
220 };
221 
328 
329 friend bool CoinMessageHandlerUnitTest () ;
330 
331 public:
336  virtual int print() ;
339  virtual void checkSeverity() ;
341 
347  CoinMessageHandler(FILE *fp);
349  virtual ~CoinMessageHandler();
355  virtual CoinMessageHandler * clone() const;
357 
359  inline int detail(int messageNumber, const CoinMessages &normalMessage) const
361  { return normalMessage.message_[messageNumber]->detail();}
363  inline int logLevel() const
364  { return logLevel_;}
382  void setLogLevel(int value);
384  inline int logLevel(int which) const
385  { return logLevels_[which];}
390  void setLogLevel(int which, int value);
391 
393  void setPrecision(unsigned int new_precision);
395  inline int precision() { return (g_precision_) ; }
396 
398  void setPrefix(bool yesNo);
400  bool prefix() const;
406  inline double doubleValue(int position) const
407  { return doubleValue_[position];}
412  inline int numberDoubleFields() const
413  {return static_cast<int>(doubleValue_.size());}
419  inline int intValue(int position) const
420  { return longValue_[position];}
425  inline int numberIntFields() const
426  {return static_cast<int>(longValue_.size());}
432  inline char charValue(int position) const
433  { return charValue_[position];}
438  inline int numberCharFields() const
439  {return static_cast<int>(charValue_.size());}
445  inline std::string stringValue(int position) const
446  { return stringValue_[position];}
451  inline int numberStringFields() const
452  {return static_cast<int>(stringValue_.size());}
453 
456  {return currentMessage_;}
458  inline std::string currentSource() const
459  {return source_;}
461  inline const char * messageBuffer() const
462  {return messageBuffer_;}
464  inline int highestNumber() const
465  {return highestNumber_;}
467  inline FILE * filePointer() const
468  { return fp_;}
470  inline void setFilePointer(FILE * fp)
471  { fp_ = fp;}
473 
482  CoinMessageHandler &message(int messageNumber,
483  const CoinMessages &messages) ;
484 
498  CoinMessageHandler & message(int detail = -1) ;
499 
512  CoinMessageHandler &message(int externalNumber, const char *source,
513  const char *msg,
514  char severity, int detail = -1) ;
515 
520  CoinMessageHandler & operator<< (int intvalue);
521 #if COIN_BIG_INDEX==1
522 
526  CoinMessageHandler & operator<< (long longvalue);
527 #endif
528 #if COIN_BIG_INDEX==2
529 
533  CoinMessageHandler & operator<< (long long longvalue);
534 #endif
535 
539  CoinMessageHandler & operator<< (double doublevalue);
544  CoinMessageHandler & operator<< (const std::string& stringvalue);
549  CoinMessageHandler & operator<< (char charvalue);
554  CoinMessageHandler & operator<< (const char *stringvalue);
564  int finish();
574  CoinMessageHandler & printing(bool onOff);
575 
577 
586 #define COIN_NUM_LOG 4
587 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
589 protected:
592  std::vector<double> doubleValue_;
594  std::vector<int> longValue_;
595  std::vector<char> charValue_;
596  std::vector<std::string> stringValue_;
602  int prefix_;
608  char * format_;
612  char * messageOut_;
614  std::string source_;
627  FILE * fp_;
629  char g_format_[8];
633 
634 private:
635 
637  void gutsOfCopy(const CoinMessageHandler &rhs) ;
638 
643  char *nextPerCent(char *start, const bool initial = false) ;
644 
649  int internalPrint() ;
650 
652  void calcPrintStatus(int msglvl, int msgclass) ;
653 
654 
655 };
656 
657 //#############################################################################
663 bool
665 
666 #endif
CoinMessageMarker
char source_[5]
Source (null-terminated string, maximum 4 characters).
FILE * filePointer() const
Get current file pointer.
virtual ~CoinMessageHandler()
Destructor.
std::string source_
Current source of message.
void setExternalNumber(int number)
Set message ID number.
char * format_
Format string for message (remainder)
void replaceMessage(const char *message)
Replace message text (e.g., text in a different language)
int internalNumber_
Internal number for use with enums.
int internalPrint()
Internal printing function.
int finish()
Finish (and print) the message.
#define COIN_NUM_LOG
Log levels will be by type and will then use type given in CoinMessage::class_.
void gutsOfCopy(const CoinMessageHandler &rhs)
The body of the copy constructor and the assignment operator.
void setPrefix(bool yesNo)
Switch message prefix on or off.
std::vector< double > doubleValue_
values in message
int printStatus_
0 - Normal.
CoinOneMessage & operator=(const CoinOneMessage &)
assignment operator.
CoinMessageHandler & operator<<(int intvalue)
Process an integer parameter value.
virtual CoinMessageHandler * clone() const
Clone.
int externalNumber_
number to print out (also determines severity)
int class_
Class - see later on before CoinMessageHandler.
Base class for message handling.
std::vector< char > charValue_
void setDetail(int level)
Set detail level.
int lengthMessages_
Length of fake CoinOneMessage array.
~CoinMessages()
Destructor.
void setLanguage(Language newlanguage)
Set language.
char severity_
Severity.
bool prefix() const
Current setting for printing message prefix.
std::vector< std::string > stringValue_
double doubleValue(int position) const
Values of double fields already processed.
CoinMessageHandler()
Constructor.
int logLevel() const
Get current log (detail) level.
CoinMessageHandler & operator=(const CoinMessageHandler &)
Assignment operator.
std::string stringValue(int position) const
Values of string fields already processed.
CoinMessages(int numberMessages=0)
Constructor with number of messages.
int numberIntFields() const
Number of integer fields already processed.
FILE * fp_
File pointer.
Language language_
Language.
void fromCompact()
Moves from compact format.
int externalNumber() const
Get message ID number.
int numberDoubleFields() const
Number of double fields already processed.
char message_[400]
Messages (in correct language) (not all 400 may exist)
void setPrecision(unsigned int new_precision)
Set the number of significant digits for printing floating point numbers.
int numberCharFields() const
Number of char fields already processed.
CoinOneMessage currentMessage_
Current message.
void setDetailMessages(int newLevel, int numberMessages, int *messageNumbers)
Change detail level for several messages.
void setDetailMessage(int newLevel, int messageNumber)
Change detail level for one message.
CoinOneMessage currentMessage() const
Current message.
CoinOneMessage ** message_
Messages.
char * nextPerCent(char *start, const bool initial=false)
Internal function to locate next format code.
void calcPrintStatus(int msglvl, int msgclass)
Decide if this message should print.
int numberStringFields() const
Number of string fields already processed.
virtual int print()
Print message, return 0 normally.
char severity() const
Severity.
int highestNumber_
Highest message number (indicates any errors)
std::string currentSource() const
Source of current message.
std::vector< int > longValue_
int g_precision_
Current number of significant digits for floating point numbers.
bool CoinMessageHandlerUnitTest()
A function that tests the methods in the CoinMessageHandler class.
virtual void checkSeverity()
Check message severity - if too bad then abort.
CoinMessageHandler & message(int messageNumber, const CoinMessages &messages)
Start a message.
int getClass() const
Returns class.
int highestNumber() const
Highest message number (indicates any errors)
int intValue(int position) const
Values of integer fields already processed.
Language
Supported languages.
char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE]
Output buffer.
void replaceMessage(int messageNumber, const char *message)
Replaces the text of the specified message.
int detail() const
Get detail level.
Language language() const
Language.
CoinMessageHandler & printing(bool onOff)
Enable or disable printing of an optional portion of a message.
int logLevel(int which) const
Get alternative log level.
void addMessage(int messageNumber, const CoinOneMessage &message)
Installs a new message in the specified index position.
char * message() const
Return the message text.
char detail_
Will only print if detail matches.
char charValue(int position) const
Values of char fields already processed.
CoinOneMessage()
Default constructor.
int numberMessages_
Number of messages.
void toCompact()
Moves to compact format.
char g_format_[8]
Current format for floating point numbers.
int detail(int messageNumber, const CoinMessages &normalMessage) const
Get detail level of a message.
friend bool CoinMessageHandlerUnitTest()
A function that tests the methods in the CoinMessageHandler class.
~CoinOneMessage()
Destructor.
const char * messageBuffer() const
Output buffer.
int logLevels_[COIN_NUM_LOG]
Log levels.
int prefix_
Whether we want prefix (may get more subtle so is int)
char * messageOut_
Position in output buffer.
CoinMessages & operator=(const CoinMessages &)
assignment operator.
Class to hold and manipulate an array of massaged messages.
Class for one massaged message.
void setLogLevel(int value)
Set current log (detail) level.
void setFilePointer(FILE *fp)
Set new file pointer.
#define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE
Maximum length of constructed message (characters)
int precision()
Current number of significant digits for printing floating point numbers.