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

- File List
- File Members

# /home/coin/svn-release/Alps-1.5.2/CoinUtils/src/CoinMessageHandler.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinMessageHandler.hpp 1514 2011-12-10 23:35:23Z lou $ */
    00002 // Copyright (C) 2002, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00005
    00006 #ifndef CoinMessageHandler_H
    00007 #define CoinMessageHandler_H
    00008
    00009 #include "CoinUtilsConfig.h"
    00010 #include "CoinPragma.hpp"
    00011
    00012 #include <iostream>
    00013 #include <cstdio>
    00014 #include <string>
    00015 #include <vector>
    00016
    00031 /*
    00032  I (jjf) am strongly in favo(u)r of language support for an open
    00033  source project, but I have tried to make it as lightweight as
    00034  possible in the sense that only a subset of messages need to be
    00035  defined - the rest default to US English.  There will be different
    00036  sets of messages for each component - so at present there is a
    00037  Clp component and a Coin component.
    00038
    00039  Because messages are only used in a controlled environment and have no
    00040  impact on code and are tested by other tests I have included tests such
    00041  as language and derivation in other unit tests.
    00042 */
    00043 /*
    00044   Where there are derived classes I (jjf) have started message numbers at 1001.
    00045 */
    00046
    00047
    00058 class CoinOneMessage {
    00059
    00060 public:
    00064   CoinOneMessage();
    00066   CoinOneMessage(int externalNumber, char detail,
    00067                 const char * message);
    00069   ~CoinOneMessage();
    00071   CoinOneMessage(const CoinOneMessage&);
    00073   CoinOneMessage& operator=(const CoinOneMessage&);
    00075
    00078
    00079   void replaceMessage(const char * message);
    00081
    00085   inline int externalNumber() const
    00086   {return externalNumber_;}
    00092   inline void setExternalNumber(int number)
    00093   {externalNumber_=number;}
    00095   inline char severity() const
    00096   {return severity_;}
    00098   inline void setDetail(int level)
    00099   {detail_=static_cast<char> (level);}
    00101   inline int detail() const
    00102   {return detail_;}
    00104   inline char * message() const
    00105   {return message_;}
    00107
    00110
    00111     int externalNumber_;
    00113     char detail_;
    00115     char severity_;
    00117   mutable char message_[400];
    00119 };
    00120
    00128 class CoinMessages {
    00129
    00130 public:
    00136   enum Language {
    00137     us_en = 0,
    00138     uk_en,
    00139     it
    00140   };
    00141
    00145   CoinMessages(int numberMessages=0);
    00147   ~CoinMessages();
    00149   CoinMessages(const CoinMessages&);
    00151   CoinMessages& operator=(const CoinMessages&);
    00153
    00161   void addMessage(int messageNumber, const CoinOneMessage & message);
    00167   void replaceMessage(int messageNumber, const char * message);
    00169   inline Language language() const
    00170   {return language_;}
    00172   void setLanguage(Language newlanguage)
    00173   {language_ = newlanguage;}
    00175   void setDetailMessage(int newLevel, int messageNumber);
    00183   void setDetailMessages(int newLevel, int numberMessages,
    00184                          int * messageNumbers);
    00186   void setDetailMessages(int newLevel, int low, int high);
    00187
    00189   inline int getClass() const
    00190   { return class_;}
    00192   void toCompact();
    00194   void fromCompact();
    00196
    00199
    00200   int numberMessages_;
    00202   Language language_;
    00204   char source_[5];
    00206   int class_;
    00210   int lengthMessages_;
    00212   CoinOneMessage ** message_;
    00214 };
    00215
    00216 // for convenience eol
    00217 enum CoinMessageMarker {
    00218   CoinMessageEol = 0,
    00219   CoinMessageNewline = 1
    00220 };
    00221
    00327 class CoinMessageHandler  {
    00328
    00329 friend bool CoinMessageHandlerUnitTest () ;
    00330
    00331 public:
    00336   virtual int print() ;
    00339   virtual void checkSeverity() ;
    00341
    00344
    00345   CoinMessageHandler();
    00347   CoinMessageHandler(FILE *fp);
    00349   virtual ~CoinMessageHandler();
    00351   CoinMessageHandler(const CoinMessageHandler&);
    00353   CoinMessageHandler& operator=(const CoinMessageHandler&);
    00355   virtual CoinMessageHandler * clone() const;
    00357
    00359
    00360   inline int detail(int messageNumber, const CoinMessages &normalMessage) const
    00361   { return normalMessage.message_[messageNumber]->detail();}
    00363   inline int logLevel() const
    00364           { return logLevel_;}
    00382   void setLogLevel(int value);
    00384   inline int logLevel(int which) const
    00385   { return logLevels_[which];}
    00390   void setLogLevel(int which, int value);
    00391
    00393   void setPrecision(unsigned int new_precision);
    00395   inline int precision() { return (g_precision_) ; }
    00396
    00398   void setPrefix(bool yesNo);
    00400   bool  prefix() const;
    00406   inline double doubleValue(int position) const
    00407   { return doubleValue_[position];}
    00412   inline int numberDoubleFields() const
    00413   {return static_cast<int>(doubleValue_.size());}
    00419   inline int intValue(int position) const
    00420   { return longValue_[position];}
    00425   inline int numberIntFields() const
    00426   {return static_cast<int>(longValue_.size());}
    00432   inline char charValue(int position) const
    00433   { return charValue_[position];}
    00438   inline int numberCharFields() const
    00439   {return static_cast<int>(charValue_.size());}
    00445   inline std::string stringValue(int position) const
    00446   { return stringValue_[position];}
    00451   inline int numberStringFields() const
    00452   {return static_cast<int>(stringValue_.size());}
    00453
    00455   inline CoinOneMessage  currentMessage() const
    00456   {return currentMessage_;}
    00458   inline std::string currentSource() const
    00459   {return source_;}
    00461   inline const char * messageBuffer() const
    00462   {return messageBuffer_;}
    00464   inline int highestNumber() const
    00465   {return highestNumber_;}
    00467   inline FILE * filePointer() const
    00468   { return fp_;}
    00470   inline void setFilePointer(FILE * fp)
    00471   { fp_ = fp;}
    00473
    00482   CoinMessageHandler &message(int messageNumber,
    00483                               const CoinMessages &messages) ;
    00484
    00498   CoinMessageHandler & message(int detail = -1) ;
    00499
    00512   CoinMessageHandler &message(int externalNumber, const char *source,
    00513                               const char *msg,
    00514                               char severity, int detail = -1) ;
    00515
    00520   CoinMessageHandler & operator<< (int intvalue);
    00521 #if COIN_BIG_INDEX==1
    00522
    00526   CoinMessageHandler & operator<< (long longvalue);
    00527 #endif
    00528 #if COIN_BIG_INDEX==2
    00529
    00533   CoinMessageHandler & operator<< (long long longvalue);
    00534 #endif
    00535
    00539   CoinMessageHandler & operator<< (double doublevalue);
    00544   CoinMessageHandler & operator<< (const std::string& stringvalue);
    00549   CoinMessageHandler & operator<< (char charvalue);
    00554   CoinMessageHandler & operator<< (const char *stringvalue);
    00559   CoinMessageHandler & operator<< (CoinMessageMarker);
    00564   int finish();
    00574   CoinMessageHandler & printing(bool onOff);
    00575
    00577
    00586 #define COIN_NUM_LOG 4
    00588 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
    00589 protected:
    00592
    00593   std::vector<double> doubleValue_;
    00594   std::vector<int> longValue_;
    00595   std::vector<char> charValue_;
    00596   std::vector<std::string> stringValue_;
    00598   int logLevel_;
    00600   int logLevels_[COIN_NUM_LOG];
    00602   int prefix_;
    00604   CoinOneMessage  currentMessage_;
    00606   int internalNumber_;
    00608   char * format_;
    00610   char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
    00612   char * messageOut_;
    00614   std::string source_;
    00623   int printStatus_;
    00625   int highestNumber_;
    00627   FILE * fp_;
    00629   char g_format_[8];
    00631   int g_precision_ ;
    00633
    00634 private:
    00635
    00637   void gutsOfCopy(const CoinMessageHandler &rhs) ;
    00638
    00643   char *nextPerCent(char *start, const bool initial = false) ;
    00644
    00649   int internalPrint() ;
    00650
    00652   void calcPrintStatus(int msglvl, int msgclass) ;
    00653
    00654
    00655 };
    00656
    00657 //#############################################################################
    00663 bool
    00664 CoinMessageHandlerUnitTest();
    00665
    00666 #endif