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

- File List
- File Members

# /home/coin/SVN-release/Vol-1.2.0/CoinUtils/src/CoinMessageHandler.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinMessageHandler.hpp 1235 2009-12-04 14:28:29Z forrest $ */
    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);
    00186   inline int getClass() const
    00187   { return class_;}
    00189   void toCompact();
    00191   void fromCompact();
    00193
    00196
    00197   int numberMessages_;
    00199   Language language_;
    00201   char source_[5];
    00203   int class_;
    00207   int lengthMessages_;
    00209   CoinOneMessage ** message_;
    00211 };
    00212
    00213 // for convenience eol
    00214 enum CoinMessageMarker {
    00215   CoinMessageEol = 0,
    00216   CoinMessageNewline = 1
    00217 };
    00218
    00310 /*
    00311   Where there are derived classes I (jjf) have started message numbers at 1001.
    00312 */
    00313
    00314 class CoinMessageHandler  {
    00315
    00316 friend bool CoinMessageHandlerUnitTest () ;
    00317
    00318 private:
    00320   void gutsOfCopy(const CoinMessageHandler& rhs);
    00321
    00322 public:
    00327   virtual int print() ;
    00330   virtual void checkSeverity() ;
    00332
    00335
    00336   CoinMessageHandler();
    00338   CoinMessageHandler(FILE *fp);
    00340   virtual ~CoinMessageHandler();
    00342   CoinMessageHandler(const CoinMessageHandler&);
    00344   CoinMessageHandler& operator=(const CoinMessageHandler&);
    00346   virtual CoinMessageHandler * clone() const;
    00348
    00350
    00351   inline int detail(int messageNumber, const CoinMessages &normalMessage) const
    00352   { return normalMessage.message_[messageNumber]->detail();}
    00354   inline int logLevel() const
    00355           { return logLevel_;}
    00373   void setLogLevel(int value);
    00375   inline int logLevel(int which) const
    00376   { return logLevels_[which];}
    00381   void setLogLevel(int which, int value);
    00383   void setPrefix(bool yesNo);
    00385   bool  prefix() const;
    00391   inline double doubleValue(int position) const
    00392   { return doubleValue_[position];}
    00397   inline int numberDoubleFields() const
    00398   {return static_cast<int>(doubleValue_.size());}
    00404   inline int intValue(int position) const
    00405   { return longValue_[position];}
    00410   inline int numberIntFields() const
    00411   {return static_cast<int>(longValue_.size());}
    00417   inline char charValue(int position) const
    00418   { return charValue_[position];}
    00423   inline int numberCharFields() const
    00424   {return static_cast<int>(charValue_.size());}
    00430   inline std::string stringValue(int position) const
    00431   { return stringValue_[position];}
    00436   inline int numberStringFields() const
    00437   {return static_cast<int>(stringValue_.size());}
    00438
    00440   inline CoinOneMessage  currentMessage() const
    00441   {return currentMessage_;}
    00443   inline std::string currentSource() const
    00444   {return source_;}
    00446   inline const char * messageBuffer() const
    00447   {return messageBuffer_;}
    00449   inline int highestNumber() const
    00450   {return highestNumber_;}
    00452   inline FILE * filePointer() const
    00453   { return fp_;}
    00455   inline void setFilePointer(FILE * fp)
    00456   { fp_ = fp;}
    00458
    00467   CoinMessageHandler & message(int messageNumber,
    00468                               const CoinMessages & messages);
    00476   CoinMessageHandler & message();
    00483   CoinMessageHandler & message(int externalNumber,const char * header,
    00484                               const char * msg,char severity);
    00489   CoinMessageHandler & operator<< (int intvalue);
    00490 #if COIN_BIG_INDEX==1
    00491
    00495   CoinMessageHandler & operator<< (long longvalue);
    00496 #endif
    00497 #if COIN_BIG_INDEX==2
    00498
    00502   CoinMessageHandler & operator<< (long long longvalue);
    00503 #endif
    00504
    00508   CoinMessageHandler & operator<< (double doublevalue);
    00513   CoinMessageHandler & operator<< (const std::string& stringvalue);
    00518   CoinMessageHandler & operator<< (char charvalue);
    00523   CoinMessageHandler & operator<< (const char *stringvalue);
    00528   CoinMessageHandler & operator<< (CoinMessageMarker);
    00533   int finish();
    00543   CoinMessageHandler & printing(bool onOff);
    00544
    00549   char * nextPerCent(char * start , const bool initial=false);
    00554   int internalPrint();
    00556
    00566 #define COIN_NUM_LOG 4
    00567 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
    00568 protected:
    00571
    00572   std::vector<double> doubleValue_;
    00573   std::vector<int> longValue_;
    00574   std::vector<char> charValue_;
    00575   std::vector<std::string> stringValue_;
    00577   int logLevel_;
    00579   int logLevels_[COIN_NUM_LOG];
    00581   int prefix_;
    00583   CoinOneMessage  currentMessage_;
    00585   int internalNumber_;
    00587   char * format_;
    00589   char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
    00591   char * messageOut_;
    00593   std::string source_;
    00599   int printStatus_;
    00601   int highestNumber_;
    00603   FILE * fp_;
    00605 };
    00606
    00607 //#############################################################################
    00613 bool
    00614 CoinMessageHandlerUnitTest();
    00615
    00616 #endif