- Main Page
- Namespaces
- Classes
- Files
- Directories

- Search for |

- File List
- File Members

# CoinMessageHandler.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinMessageHandler.hpp 1448 2011-06-19 15:34:41Z stefan $ */
    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 include tests such
    00041  as language and derivation in other unit tests.
    00042 */
    00043
    00054 class CoinOneMessage {
    00055
    00056 public:
    00060   CoinOneMessage();
    00062   CoinOneMessage(int externalNumber, char detail,
    00063                 const char * message);
    00065   ~CoinOneMessage();
    00067   CoinOneMessage(const CoinOneMessage&);
    00069   CoinOneMessage& operator=(const CoinOneMessage&);
    00071
    00074
    00075   void replaceMessage(const char * message);
    00077
    00081   inline int externalNumber() const
    00082   {return externalNumber_;}
    00088   inline void setExternalNumber(int number)
    00089   {externalNumber_=number;}
    00091   inline char severity() const
    00092   {return severity_;}
    00094   inline void setDetail(int level)
    00095   {detail_=static_cast<char> (level);}
    00097   inline int detail() const
    00098   {return detail_;}
    00100   inline char * message() const
    00101   {return message_;}
    00103
    00106
    00107     int externalNumber_;
    00109     char detail_;
    00111     char severity_;
    00113   mutable char message_[400];
    00115 };
    00116
    00124 class CoinMessages {
    00125
    00126 public:
    00132   enum Language {
    00133     us_en = 0,
    00134     uk_en,
    00135     it
    00136   };
    00137
    00141   CoinMessages(int numberMessages=0);
    00143   ~CoinMessages();
    00145   CoinMessages(const CoinMessages&);
    00147   CoinMessages& operator=(const CoinMessages&);
    00149
    00157   void addMessage(int messageNumber, const CoinOneMessage & message);
    00163   void replaceMessage(int messageNumber, const char * message);
    00165   inline Language language() const
    00166   {return language_;}
    00168   void setLanguage(Language newlanguage)
    00169   {language_ = newlanguage;}
    00171   void setDetailMessage(int newLevel, int messageNumber);
    00179   void setDetailMessages(int newLevel, int numberMessages,
    00180                          int * messageNumbers);
    00182   void setDetailMessages(int newLevel, int low, int high);
    00183
    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);
    00381
    00383   void setPrecision(unsigned int new_precision);
    00385   inline int precision() { return (g_precision_) ; }
    00386
    00388   void setPrefix(bool yesNo);
    00390   bool  prefix() const;
    00396   inline double doubleValue(int position) const
    00397   { return doubleValue_[position];}
    00402   inline int numberDoubleFields() const
    00403   {return static_cast<int>(doubleValue_.size());}
    00409   inline int intValue(int position) const
    00410   { return longValue_[position];}
    00415   inline int numberIntFields() const
    00416   {return static_cast<int>(longValue_.size());}
    00422   inline char charValue(int position) const
    00423   { return charValue_[position];}
    00428   inline int numberCharFields() const
    00429   {return static_cast<int>(charValue_.size());}
    00435   inline std::string stringValue(int position) const
    00436   { return stringValue_[position];}
    00441   inline int numberStringFields() const
    00442   {return static_cast<int>(stringValue_.size());}
    00443
    00445   inline CoinOneMessage  currentMessage() const
    00446   {return currentMessage_;}
    00448   inline std::string currentSource() const
    00449   {return source_;}
    00451   inline const char * messageBuffer() const
    00452   {return messageBuffer_;}
    00454   inline int highestNumber() const
    00455   {return highestNumber_;}
    00457   inline FILE * filePointer() const
    00458   { return fp_;}
    00460   inline void setFilePointer(FILE * fp)
    00461   { fp_ = fp;}
    00463
    00472   CoinMessageHandler & message(int messageNumber,
    00473                               const CoinMessages & messages);
    00481   CoinMessageHandler & message();
    00488   CoinMessageHandler & message(int externalNumber,const char * header,
    00489                               const char * msg,char severity);
    00494   CoinMessageHandler & operator<< (int intvalue);
    00495 #if COIN_BIG_INDEX==1
    00496
    00500   CoinMessageHandler & operator<< (long longvalue);
    00501 #endif
    00502 #if COIN_BIG_INDEX==2
    00503
    00507   CoinMessageHandler & operator<< (long long longvalue);
    00508 #endif
    00509
    00513   CoinMessageHandler & operator<< (double doublevalue);
    00518   CoinMessageHandler & operator<< (const std::string& stringvalue);
    00523   CoinMessageHandler & operator<< (char charvalue);
    00528   CoinMessageHandler & operator<< (const char *stringvalue);
    00533   CoinMessageHandler & operator<< (CoinMessageMarker);
    00538   int finish();
    00548   CoinMessageHandler & printing(bool onOff);
    00549
    00554   char * nextPerCent(char * start , const bool initial=false);
    00559   int internalPrint();
    00561
    00570 #define COIN_NUM_LOG 4
    00572 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
    00573 protected:
    00576
    00577   std::vector<double> doubleValue_;
    00578   std::vector<int> longValue_;
    00579   std::vector<char> charValue_;
    00580   std::vector<std::string> stringValue_;
    00582   int logLevel_;
    00584   int logLevels_[COIN_NUM_LOG];
    00586   int prefix_;
    00588   CoinOneMessage  currentMessage_;
    00590   int internalNumber_;
    00592   char * format_;
    00594   char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
    00596   char * messageOut_;
    00598   std::string source_;
    00604   int printStatus_;
    00606   int highestNumber_;
    00608   FILE * fp_;
    00610   char g_format_[8];
    00612   int g_precision_ ;
    00614
    00615 };
    00616
    00617 //#############################################################################
    00623 bool
    00624 CoinMessageHandlerUnitTest();
    00625
    00626 #endif