- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Bcps-0.91.0/CoinUtils/src/CoinMessageHandler.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2002, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef CoinMessageHandler_H
    00004 #define CoinMessageHandler_H
    00005
    00006 #if defined(_MSC_VER)
    00007 // Turn off compiler warning about long names
    00008 #  pragma warning(disable:4786)
    00009 #endif
    00010
    00011
    00012 #include <iostream>
    00013 #include <cstdio>
    00014 #include <string>
    00015 #include <vector>
    00016 #include "CoinFinite.hpp"
    00017
    00032 /*
    00033  I (jjf) am strongly in favo(u)r of language support for an open
    00034  source project, but I have tried to make it as lightweight as
    00035  possible in the sense that only a subset of messages need to be
    00036  defined - the rest default to US English.  There will be different
    00037  sets of messages for each component - so at present there is a
    00038  Clp component and a Coin component.
    00039
    00040  Because messages are only used in a controlled environment and have no
    00041  impact on code and are tested by other tests I have include tests such
    00042  as language and derivation in other unit tests.
    00043 */
    00044
    00055 class CoinOneMessage {
    00056
    00057 public:
    00061   CoinOneMessage();
    00063   CoinOneMessage(int externalNumber, char detail,
    00064                 const char * message);
    00066   ~CoinOneMessage();
    00068   CoinOneMessage(const CoinOneMessage&);
    00070   CoinOneMessage& operator=(const CoinOneMessage&);
    00072
    00075
    00076   void replaceMessage(const char * message);
    00078
    00082   inline int externalNumber() const
    00083   {return externalNumber_;}
    00089   inline void setExternalNumber(int number)
    00090   {externalNumber_=number;}
    00092   inline char severity() const
    00093   {return severity_;}
    00095   inline void setDetail(int level)
    00096   {detail_=static_cast<char> (level);}
    00098   inline int detail() const
    00099   {return detail_;}
    00101   inline char * message() const
    00102   {return message_;}
    00104
    00107
    00108     int externalNumber_;
    00110     char detail_;
    00112     char severity_;
    00114   mutable char message_[400];
    00116 };
    00117
    00125 class CoinMessages {
    00126
    00127 public:
    00133   enum Language {
    00134     us_en = 0,
    00135     uk_en,
    00136     it
    00137   };
    00138
    00142   CoinMessages(int numberMessages=0);
    00144   ~CoinMessages();
    00146   CoinMessages(const CoinMessages&);
    00148   CoinMessages& operator=(const CoinMessages&);
    00150
    00158   void addMessage(int messageNumber, const CoinOneMessage & message);
    00164   void replaceMessage(int messageNumber, const char * message);
    00166   inline Language language() const
    00167   {return language_;}
    00169   void setLanguage(Language language)
    00170   {language_ = language;}
    00172   void setDetailMessage(int newLevel, int messageNumber);
    00180   void setDetailMessages(int newLevel, int numberMessages,
    00181                          int * messageNumbers);
    00183   void setDetailMessages(int newLevel, int low, int high);
    00185   inline int getClass() const
    00186   { return class_;}
    00188   void toCompact();
    00190   void fromCompact();
    00192
    00195
    00196   int numberMessages_;
    00198   Language language_;
    00200   char source_[5];
    00202   int class_;
    00206   int lengthMessages_;
    00208   CoinOneMessage ** message_;
    00210 };
    00211
    00212 // for convenience eol
    00213 enum CoinMessageMarker {
    00214   CoinMessageEol = 0,
    00215   CoinMessageNewline = 1
    00216 };
    00217
    00309 /*
    00310   Where there are derived classes I (jjf) have started message numbers at 1001.
    00311 */
    00312
    00313 class CoinMessageHandler  {
    00314
    00315 friend bool CoinMessageHandlerUnitTest () ;
    00316
    00317 private:
    00319   void gutsOfCopy(const CoinMessageHandler& rhs);
    00320
    00321 public:
    00326   virtual int print() ;
    00329   virtual void checkSeverity() ;
    00331
    00334
    00335   CoinMessageHandler();
    00337   CoinMessageHandler(FILE *fp);
    00339   virtual ~CoinMessageHandler();
    00341   CoinMessageHandler(const CoinMessageHandler&);
    00343   CoinMessageHandler& operator=(const CoinMessageHandler&);
    00345   virtual CoinMessageHandler * clone() const;
    00347
    00349
    00350   inline int detail(int messageNumber, const CoinMessages &normalMessage) const
    00351   { return normalMessage.message_[messageNumber]->detail();}
    00353   inline int logLevel() const
    00354           { return logLevel_;}
    00372   void setLogLevel(int value);
    00374   inline int logLevel(int which) const
    00375   { return logLevels_[which];}
    00380   void setLogLevel(int which, int value);
    00382   void setPrefix(bool yesNo);
    00384   bool  prefix() const;
    00390   inline double doubleValue(int position) const
    00391   { return doubleValue_[position];}
    00396   inline int numberDoubleFields() const
    00397   {return static_cast<int>(doubleValue_.size());}
    00403   inline int intValue(int position) const
    00404   { return longValue_[position];}
    00409   inline int numberIntFields() const
    00410   {return static_cast<int>(longValue_.size());}
    00416   inline char charValue(int position) const
    00417   { return charValue_[position];}
    00422   inline int numberCharFields() const
    00423   {return static_cast<int>(charValue_.size());}
    00429   inline std::string stringValue(int position) const
    00430   { return stringValue_[position];}
    00435   inline int numberStringFields() const
    00436   {return static_cast<int>(stringValue_.size());}
    00437
    00439   inline CoinOneMessage  currentMessage() const
    00440   {return currentMessage_;}
    00442   inline std::string currentSource() const
    00443   {return source_;}
    00445   inline const char * messageBuffer() const
    00446   {return messageBuffer_;}
    00448   inline int highestNumber() const
    00449   {return highestNumber_;}
    00451   inline FILE * filePointer() const
    00452   { return fp_;}
    00454   inline void setFilePointer(FILE * fp)
    00455   { fp_ = fp;}
    00457
    00466   CoinMessageHandler & message(int messageNumber,
    00467                               const CoinMessages & messages);
    00475   CoinMessageHandler & message();
    00482   CoinMessageHandler & message(int externalNumber,const char * header,
    00483                               const char * msg,char severity);
    00488   CoinMessageHandler & operator<< (int intvalue);
    00489 #if COIN_BIG_INDEX==1
    00490
    00494   CoinMessageHandler & operator<< (long longvalue);
    00495 #endif
    00496 #if COIN_BIG_INDEX==2
    00497
    00501   CoinMessageHandler & operator<< (long long longvalue);
    00502 #endif
    00503
    00507   CoinMessageHandler & operator<< (double doublevalue);
    00512   CoinMessageHandler & operator<< (const std::string& stringvalue);
    00517   CoinMessageHandler & operator<< (char charvalue);
    00522   CoinMessageHandler & operator<< (const char *stringvalue);
    00527   CoinMessageHandler & operator<< (CoinMessageMarker);
    00532   int finish();
    00542   CoinMessageHandler & printing(bool onOff);
    00543
    00548   char * nextPerCent(char * start , const bool initial=false);
    00553   int internalPrint();
    00555
    00565 #define COIN_NUM_LOG 4
    00566 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
    00567 protected:
    00570
    00571   std::vector<double> doubleValue_;
    00572   std::vector<long> longValue_;
    00573   std::vector<char> charValue_;
    00574   std::vector<std::string> stringValue_;
    00576   int logLevel_;
    00578   int logLevels_[COIN_NUM_LOG];
    00580   int prefix_;
    00582   CoinOneMessage  currentMessage_;
    00584   int internalNumber_;
    00586   char * format_;
    00588   char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
    00590   char * messageOut_;
    00592   std::string source_;
    00598   int printStatus_;
    00600   int highestNumber_;
    00602   FILE * fp_;
    00604 };
    00605
    00606 //#############################################################################
    00612 bool
    00613 CoinMessageHandlerUnitTest();
    00614
    00615 #endif