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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.2.1/CoinUtils/src/CoinMessageHandler.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinMessageHandler.hpp 1362 2010-12-19 16:56:55Z stefan $ */
    00002 // Copyright (C) 2002, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 #ifndef CoinMessageHandler_H
    00005 #define CoinMessageHandler_H
    00006
    00007 #if defined(_MSC_VER)
    00008 // Turn off compiler warning about long names
    00009 #  pragma warning(disable:4786)
    00010 #endif
    00011
    00012
    00013 #include <iostream>
    00014 #include <cstdio>
    00015 #include <string>
    00016 #include <vector>
    00017 #include "CoinFinite.hpp"
    00018
    00033 /*
    00034  I (jjf) am strongly in favo(u)r of language support for an open
    00035  source project, but I have tried to make it as lightweight as
    00036  possible in the sense that only a subset of messages need to be
    00037  defined - the rest default to US English.  There will be different
    00038  sets of messages for each component - so at present there is a
    00039  Clp component and a Coin component.
    00040
    00041  Because messages are only used in a controlled environment and have no
    00042  impact on code and are tested by other tests I have include tests such
    00043  as language and derivation in other unit tests.
    00044 */
    00045
    00056 class CoinOneMessage {
    00057
    00058 public:
    00062   CoinOneMessage();
    00064   CoinOneMessage(int externalNumber, char detail,
    00065                 const char * message);
    00067   ~CoinOneMessage();
    00069   CoinOneMessage(const CoinOneMessage&);
    00071   CoinOneMessage& operator=(const CoinOneMessage&);
    00073
    00076
    00077   void replaceMessage(const char * message);
    00079
    00083   inline int externalNumber() const
    00084   {return externalNumber_;}
    00090   inline void setExternalNumber(int number)
    00091   {externalNumber_=number;}
    00093   inline char severity() const
    00094   {return severity_;}
    00096   inline void setDetail(int level)
    00097   {detail_=static_cast<char> (level);}
    00099   inline int detail() const
    00100   {return detail_;}
    00102   inline char * message() const
    00103   {return message_;}
    00105
    00108
    00109     int externalNumber_;
    00111     char detail_;
    00113     char severity_;
    00115   mutable char message_[400];
    00117 };
    00118
    00126 class CoinMessages {
    00127
    00128 public:
    00134   enum Language {
    00135     us_en = 0,
    00136     uk_en,
    00137     it
    00138   };
    00139
    00143   CoinMessages(int numberMessages=0);
    00145   ~CoinMessages();
    00147   CoinMessages(const CoinMessages&);
    00149   CoinMessages& operator=(const CoinMessages&);
    00151
    00159   void addMessage(int messageNumber, const CoinOneMessage & message);
    00165   void replaceMessage(int messageNumber, const char * message);
    00167   inline Language language() const
    00168   {return language_;}
    00170   void setLanguage(Language newlanguage)
    00171   {language_ = newlanguage;}
    00173   void setDetailMessage(int newLevel, int messageNumber);
    00181   void setDetailMessages(int newLevel, int numberMessages,
    00182                          int * messageNumbers);
    00184   void setDetailMessages(int newLevel, int low, int high);
    00185
    00187   inline int getClass() const
    00188   { return class_;}
    00190   void toCompact();
    00192   void fromCompact();
    00194
    00197
    00198   int numberMessages_;
    00200   Language language_;
    00202   char source_[5];
    00204   int class_;
    00208   int lengthMessages_;
    00210   CoinOneMessage ** message_;
    00212 };
    00213
    00214 // for convenience eol
    00215 enum CoinMessageMarker {
    00216   CoinMessageEol = 0,
    00217   CoinMessageNewline = 1
    00218 };
    00219
    00311 /*
    00312   Where there are derived classes I (jjf) have started message numbers at 1001.
    00313 */
    00314
    00315 class CoinMessageHandler  {
    00316
    00317 friend bool CoinMessageHandlerUnitTest () ;
    00318
    00319 private:
    00321   void gutsOfCopy(const CoinMessageHandler& rhs);
    00322
    00323 public:
    00328   virtual int print() ;
    00331   virtual void checkSeverity() ;
    00333
    00336
    00337   CoinMessageHandler();
    00339   CoinMessageHandler(FILE *fp);
    00341   virtual ~CoinMessageHandler();
    00343   CoinMessageHandler(const CoinMessageHandler&);
    00345   CoinMessageHandler& operator=(const CoinMessageHandler&);
    00347   virtual CoinMessageHandler * clone() const;
    00349
    00351
    00352   inline int detail(int messageNumber, const CoinMessages &normalMessage) const
    00353   { return normalMessage.message_[messageNumber]->detail();}
    00355   inline int logLevel() const
    00356           { return logLevel_;}
    00374   void setLogLevel(int value);
    00376   inline int logLevel(int which) const
    00377   { return logLevels_[which];}
    00382   void setLogLevel(int which, int value);
    00383
    00385   void setPrecision(unsigned int new_precision);
    00387   inline int precision() { return (g_precision_) ; }
    00388
    00390   void setPrefix(bool yesNo);
    00392   bool  prefix() const;
    00398   inline double doubleValue(int position) const
    00399   { return doubleValue_[position];}
    00404   inline int numberDoubleFields() const
    00405   {return static_cast<int>(doubleValue_.size());}
    00411   inline int intValue(int position) const
    00412   { return longValue_[position];}
    00417   inline int numberIntFields() const
    00418   {return static_cast<int>(longValue_.size());}
    00424   inline char charValue(int position) const
    00425   { return charValue_[position];}
    00430   inline int numberCharFields() const
    00431   {return static_cast<int>(charValue_.size());}
    00437   inline std::string stringValue(int position) const
    00438   { return stringValue_[position];}
    00443   inline int numberStringFields() const
    00444   {return static_cast<int>(stringValue_.size());}
    00445
    00447   inline CoinOneMessage  currentMessage() const
    00448   {return currentMessage_;}
    00450   inline std::string currentSource() const
    00451   {return source_;}
    00453   inline const char * messageBuffer() const
    00454   {return messageBuffer_;}
    00456   inline int highestNumber() const
    00457   {return highestNumber_;}
    00459   inline FILE * filePointer() const
    00460   { return fp_;}
    00462   inline void setFilePointer(FILE * fp)
    00463   { fp_ = fp;}
    00465
    00474   CoinMessageHandler & message(int messageNumber,
    00475                               const CoinMessages & messages);
    00483   CoinMessageHandler & message();
    00490   CoinMessageHandler & message(int externalNumber,const char * header,
    00491                               const char * msg,char severity);
    00496   CoinMessageHandler & operator<< (int intvalue);
    00497 #if COIN_BIG_INDEX==1
    00498
    00502   CoinMessageHandler & operator<< (long longvalue);
    00503 #endif
    00504 #if COIN_BIG_INDEX==2
    00505
    00509   CoinMessageHandler & operator<< (long long longvalue);
    00510 #endif
    00511
    00515   CoinMessageHandler & operator<< (double doublevalue);
    00520   CoinMessageHandler & operator<< (const std::string& stringvalue);
    00525   CoinMessageHandler & operator<< (char charvalue);
    00530   CoinMessageHandler & operator<< (const char *stringvalue);
    00535   CoinMessageHandler & operator<< (CoinMessageMarker);
    00540   int finish();
    00550   CoinMessageHandler & printing(bool onOff);
    00551
    00556   char * nextPerCent(char * start , const bool initial=false);
    00561   int internalPrint();
    00563
    00572 #define COIN_NUM_LOG 4
    00574 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
    00575 protected:
    00578
    00579   std::vector<double> doubleValue_;
    00580   std::vector<int> longValue_;
    00581   std::vector<char> charValue_;
    00582   std::vector<std::string> stringValue_;
    00584   int logLevel_;
    00586   int logLevels_[COIN_NUM_LOG];
    00588   int prefix_;
    00590   CoinOneMessage  currentMessage_;
    00592   int internalNumber_;
    00594   char * format_;
    00596   char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
    00598   char * messageOut_;
    00600   std::string source_;
    00606   int printStatus_;
    00608   int highestNumber_;
    00610   FILE * fp_;
    00612   char g_format_[8];
    00614   int g_precision_ ;
    00616
    00617 };
    00618
    00619 //#############################################################################
    00625 bool
    00626 CoinMessageHandlerUnitTest();
    00627
    00628 #endif