CoinUtils 2.10.15

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinMessageHandler.hpp
Go to the documentation of this file.
1 /* $Id: CoinMessageHandler.hpp 1514 2011-12-10 23:35:23Z lou $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5
6 #ifndef CoinMessageHandler_H
7 #define CoinMessageHandler_H
8
9 #include "CoinUtilsConfig.h"
10 #include "CoinPragma.hpp"
11
12 #include <iostream>
13 #include <cstdio>
14 #include <string>
15 #include <vector>
16
31 /*
32 I (jjf) am strongly in favo(u)r of language support for an open
33 source project, but I have tried to make it as lightweight as
34 possible in the sense that only a subset of messages need to be
35 defined - the rest default to US English. There will be different
36 sets of messages for each component - so at present there is a
37 Clp component and a Coin component.
38
39 Because messages are only used in a controlled environment and have no
40 impact on code and are tested by other tests I have included tests such
41 as language and derivation in other unit tests.
42 */
43 /*
44 Where there are derived classes I (jjf) have started message numbers at 1001.
45 */
46
47
58 class CoinOneMessage {
59
60 public:
64 CoinOneMessage();
66 CoinOneMessage(int externalNumber, char detail,
67 const char * message);
69 ~CoinOneMessage();
71 CoinOneMessage(const CoinOneMessage&);
73 CoinOneMessage& operator=(const CoinOneMessage&);
75
78 void replaceMessage(const char * message);
81
85 inline int externalNumber() const
86 {return externalNumber_;}
92 inline void setExternalNumber(int number)
93 {externalNumber_=number;}
95 inline char severity() const
96 {return severity_;}
98 inline void setDetail(int level)
99 {detail_=static_cast<char> (level);}
101 inline int detail() const
102 {return detail_;}
104 inline char * message() const
105 {return message_;}
107
110 int externalNumber_;
113 char detail_;
115 char severity_;
117 mutable char message_[400];
119 };
120
128 class CoinMessages {
129
130 public:
136 enum Language {
137 us_en = 0,
138 uk_en,
139 it
140 };
141
145 CoinMessages(int numberMessages=0);
147 ~CoinMessages();
149 CoinMessages(const CoinMessages&);
151 CoinMessages& operator=(const CoinMessages&);
153
161 void addMessage(int messageNumber, const CoinOneMessage & message);
167 void replaceMessage(int messageNumber, const char * message);
169 inline Language language() const
170 {return language_;}
172 void setLanguage(Language newlanguage)
173 {language_ = newlanguage;}
175 void setDetailMessage(int newLevel, int messageNumber);
183 void setDetailMessages(int newLevel, int numberMessages,
184 int * messageNumbers);
186 void setDetailMessages(int newLevel, int low, int high);
187
189 inline int getClass() const
190 { return class_;}
192 void toCompact();
194 void fromCompact();
196
199 int numberMessages_;
202 Language language_;
204 char source_[5];
206 int class_;
210 int lengthMessages_;
212 CoinOneMessage ** message_;
214 };
215
216 // for convenience eol
217 enum CoinMessageMarker {
218 CoinMessageEol = 0,
219 CoinMessageNewline = 1
220 };
221
327 class CoinMessageHandler {
328
329 friend bool CoinMessageHandlerUnitTest () ;
330
331 public:
336 virtual int print() ;
339 virtual void checkSeverity() ;
341
344 CoinMessageHandler();
347 CoinMessageHandler(FILE *fp);
349 virtual ~CoinMessageHandler();
351 CoinMessageHandler(const CoinMessageHandler&);
353 CoinMessageHandler& operator=(const CoinMessageHandler&);
355 virtual CoinMessageHandler * clone() const;
357
359 inline int detail(int messageNumber, const CoinMessages &normalMessage) const
361 { return normalMessage.message_[messageNumber]->detail();}
363 inline int logLevel() const
364 { return logLevel_;}
382 void setLogLevel(int value);
384 inline int logLevel(int which) const
385 { return logLevels_[which];}
390 void setLogLevel(int which, int value);
391
393 void setPrecision(unsigned int new_precision);
395 inline int precision() { return (g_precision_) ; }
396
398 void setPrefix(bool yesNo);
400 bool prefix() const;
406 inline double doubleValue(int position) const
407 { return doubleValue_[position];}
412 inline int numberDoubleFields() const
413 {return static_cast<int>(doubleValue_.size());}
419 inline int intValue(int position) const
420 { return longValue_[position];}
425 inline int numberIntFields() const
426 {return static_cast<int>(longValue_.size());}
432 inline char charValue(int position) const
433 { return charValue_[position];}
438 inline int numberCharFields() const
439 {return static_cast<int>(charValue_.size());}
445 inline std::string stringValue(int position) const
446 { return stringValue_[position];}
451 inline int numberStringFields() const
452 {return static_cast<int>(stringValue_.size());}
453
455 inline CoinOneMessage currentMessage() const
456 {return currentMessage_;}
458 inline std::string currentSource() const
459 {return source_;}
461 inline const char * messageBuffer() const
462 {return messageBuffer_;}
464 inline int highestNumber() const
465 {return highestNumber_;}
467 inline FILE * filePointer() const
468 { return fp_;}
470 inline void setFilePointer(FILE * fp)
471 { fp_ = fp;}
473
482 CoinMessageHandler &message(int messageNumber,
483 const CoinMessages &messages) ;
484
498 CoinMessageHandler & message(int detail = -1) ;
499
512 CoinMessageHandler &message(int externalNumber, const char *source,
513 const char *msg,
514 char severity, int detail = -1) ;
515
520 CoinMessageHandler & operator<< (int intvalue);
521 #if COIN_BIG_INDEX==1
522
526 CoinMessageHandler & operator<< (long longvalue);
527 #endif
528 #if COIN_BIG_INDEX==2
529
533 CoinMessageHandler & operator<< (long long longvalue);
534 #endif
535
539 CoinMessageHandler & operator<< (double doublevalue);
544 CoinMessageHandler & operator<< (const std::string& stringvalue);
549 CoinMessageHandler & operator<< (char charvalue);
554 CoinMessageHandler & operator<< (const char *stringvalue);
559 CoinMessageHandler & operator<< (CoinMessageMarker);
564 int finish();
574 CoinMessageHandler & printing(bool onOff);
575
577
586 #define COIN_NUM_LOG 4
587 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
589 protected:
592 std::vector<double> doubleValue_;
594 std::vector<int> longValue_;
595 std::vector<char> charValue_;
596 std::vector<std::string> stringValue_;
598 int logLevel_;
600 int logLevels_[COIN_NUM_LOG];
602 int prefix_;
604 CoinOneMessage currentMessage_;
606 int internalNumber_;
608 char * format_;
610 char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
612 char * messageOut_;
614 std::string source_;
623 int printStatus_;
625 int highestNumber_;
627 FILE * fp_;
629 char g_format_[8];
631 int g_precision_ ;
633
634 private:
635
637 void gutsOfCopy(const CoinMessageHandler &rhs) ;
638
643 char *nextPerCent(char *start, const bool initial = false) ;
644
649 int internalPrint() ;
650
652 void calcPrintStatus(int msglvl, int msgclass) ;
653
654
655 };
656
657 //#############################################################################
663 bool
664 CoinMessageHandlerUnitTest();
665
666 #endif
CoinMessageMarker
CoinMessageMarker
Definition: CoinMessageHandler.hpp:217
CoinMessages::source_
char source_[5]
Source (null-terminated string, maximum 4 characters).
Definition: CoinMessageHandler.hpp:204
CoinMessageHandler::filePointer
FILE * filePointer() const
Get current file pointer.
Definition: CoinMessageHandler.hpp:467
CoinMessageHandler::~CoinMessageHandler
virtual ~CoinMessageHandler()
Destructor.
CoinMessageHandler::source_
std::string source_
Current source of message.
Definition: CoinMessageHandler.hpp:614
CoinOneMessage::setExternalNumber
void setExternalNumber(int number)
Set message ID number.
Definition: CoinMessageHandler.hpp:92
CoinMessageHandler::format_
char * format_
Format string for message (remainder)
Definition: CoinMessageHandler.hpp:608
CoinOneMessage::replaceMessage
void replaceMessage(const char *message)
Replace message text (e.g., text in a different language)
CoinMessageHandler::internalNumber_
int internalNumber_
Internal number for use with enums.
Definition: CoinMessageHandler.hpp:606
CoinMessageHandler::internalPrint
int internalPrint()
Internal printing function.
CoinMessageHandler::finish
int finish()
Finish (and print) the message.
COIN_NUM_LOG
#define COIN_NUM_LOG
Log levels will be by type and will then use type given in CoinMessage::class_.
Definition: CoinMessageHandler.hpp:586
CoinMessageHandler::gutsOfCopy
void gutsOfCopy(const CoinMessageHandler &rhs)
The body of the copy constructor and the assignment operator.
CoinMessageHandler::setPrefix
void setPrefix(bool yesNo)
Switch message prefix on or off.
CoinMessageHandler::doubleValue_
std::vector< double > doubleValue_
values in message
Definition: CoinMessageHandler.hpp:593
CoinMessageHandler::printStatus_
int printStatus_
0 - Normal.
Definition: CoinMessageHandler.hpp:623
CoinMessageHandler::logLevel_
int logLevel_
Log level.
Definition: CoinMessageHandler.hpp:598
CoinOneMessage::operator=
CoinOneMessage & operator=(const CoinOneMessage &)
assignment operator.
CoinMessageHandler::operator<<
CoinMessageHandler & operator<<(int intvalue)
Process an integer parameter value.
CoinMessageHandler::clone
virtual CoinMessageHandler * clone() const
Clone.
CoinOneMessage::externalNumber_
int externalNumber_
number to print out (also determines severity)
Definition: CoinMessageHandler.hpp:111
CoinMessages::class_
int class_
Class - see later on before CoinMessageHandler.
Definition: CoinMessageHandler.hpp:206
CoinMessageHandler
Base class for message handling.
Definition: CoinMessageHandler.hpp:327
CoinMessageHandler::charValue_
std::vector< char > charValue_
Definition: CoinMessageHandler.hpp:595
CoinOneMessage::setDetail
void setDetail(int level)
Set detail level.
Definition: CoinMessageHandler.hpp:98
CoinMessages::lengthMessages_
int lengthMessages_
Length of fake CoinOneMessage array.
Definition: CoinMessageHandler.hpp:210
CoinMessages::~CoinMessages
~CoinMessages()
Destructor.
CoinMessages::uk_en
Definition: CoinMessageHandler.hpp:138
CoinMessages::setLanguage
void setLanguage(Language newlanguage)
Set language.
Definition: CoinMessageHandler.hpp:172
CoinOneMessage::severity_
char severity_
Severity.
Definition: CoinMessageHandler.hpp:115
CoinMessageHandler::prefix
bool prefix() const
Current setting for printing message prefix.
CoinMessageHandler::stringValue_
std::vector< std::string > stringValue_
Definition: CoinMessageHandler.hpp:596
CoinMessageHandler::doubleValue
double doubleValue(int position) const
Values of double fields already processed.
Definition: CoinMessageHandler.hpp:406
CoinMessageHandler::CoinMessageHandler
CoinMessageHandler()
Constructor.
CoinMessageHandler::logLevel
int logLevel() const
Get current log (detail) level.
Definition: CoinMessageHandler.hpp:363
CoinMessageHandler::operator=
CoinMessageHandler & operator=(const CoinMessageHandler &)
Assignment operator.
CoinMessageHandler::stringValue
std::string stringValue(int position) const
Values of string fields already processed.
Definition: CoinMessageHandler.hpp:445
CoinMessageEol
Definition: CoinMessageHandler.hpp:218
CoinMessages::CoinMessages
CoinMessages(int numberMessages=0)
Constructor with number of messages.
CoinMessageHandler::numberIntFields
int numberIntFields() const
Number of integer fields already processed.
Definition: CoinMessageHandler.hpp:425
CoinMessageHandler::fp_
FILE * fp_
File pointer.
Definition: CoinMessageHandler.hpp:627
CoinMessages::language_
Language language_
Language.
Definition: CoinMessageHandler.hpp:202
CoinMessages::fromCompact
void fromCompact()
Moves from compact format.
CoinOneMessage::externalNumber
int externalNumber() const
Get message ID number.
Definition: CoinMessageHandler.hpp:85
CoinMessageHandler::numberDoubleFields
int numberDoubleFields() const
Number of double fields already processed.
Definition: CoinMessageHandler.hpp:412
CoinPragma.hpp
CoinOneMessage::message_
char message_[400]
Messages (in correct language) (not all 400 may exist)
Definition: CoinMessageHandler.hpp:117
CoinMessageHandler::setPrecision
void setPrecision(unsigned int new_precision)
Set the number of significant digits for printing floating point numbers.
CoinMessageHandler::numberCharFields
int numberCharFields() const
Number of char fields already processed.
Definition: CoinMessageHandler.hpp:438
CoinMessageHandler::currentMessage_
CoinOneMessage currentMessage_
Current message.
Definition: CoinMessageHandler.hpp:604
CoinMessages::setDetailMessages
void setDetailMessages(int newLevel, int numberMessages, int *messageNumbers)
Change detail level for several messages.
CoinMessages::setDetailMessage
void setDetailMessage(int newLevel, int messageNumber)
Change detail level for one message.
CoinMessageHandler::currentMessage
CoinOneMessage currentMessage() const
Current message.
Definition: CoinMessageHandler.hpp:455
CoinMessages::message_
CoinOneMessage ** message_
Messages.
Definition: CoinMessageHandler.hpp:212
CoinMessageHandler::nextPerCent
char * nextPerCent(char *start, const bool initial=false)
Internal function to locate next format code.
CoinMessageHandler::calcPrintStatus
void calcPrintStatus(int msglvl, int msgclass)
Decide if this message should print.
CoinMessageHandler::numberStringFields
int numberStringFields() const
Number of string fields already processed.
Definition: CoinMessageHandler.hpp:451
CoinMessageHandler::print
virtual int print()
Print message, return 0 normally.
CoinOneMessage::severity
char severity() const
Severity.
Definition: CoinMessageHandler.hpp:95
CoinMessageHandler::highestNumber_
int highestNumber_
Highest message number (indicates any errors)
Definition: CoinMessageHandler.hpp:625
CoinMessageHandler::currentSource
std::string currentSource() const
Source of current message.
Definition: CoinMessageHandler.hpp:458
CoinMessageHandler::longValue_
std::vector< int > longValue_
Definition: CoinMessageHandler.hpp:594
CoinMessageHandler::g_precision_
int g_precision_
Current number of significant digits for floating point numbers.
Definition: CoinMessageHandler.hpp:631
CoinMessageHandlerUnitTest
bool CoinMessageHandlerUnitTest()
A function that tests the methods in the CoinMessageHandler class.
CoinMessageHandler::checkSeverity
virtual void checkSeverity()
Check message severity - if too bad then abort.
CoinMessageHandler::message
CoinMessageHandler & message(int messageNumber, const CoinMessages &messages)
Start a message.
CoinMessages::getClass
int getClass() const
Returns class.
Definition: CoinMessageHandler.hpp:189
CoinMessageHandler::highestNumber
int highestNumber() const
Highest message number (indicates any errors)
Definition: CoinMessageHandler.hpp:464
CoinMessageHandler::intValue
int intValue(int position) const
Values of integer fields already processed.
Definition: CoinMessageHandler.hpp:419
CoinMessages::Language
Language
Supported languages.
Definition: CoinMessageHandler.hpp:136
CoinMessageHandler::messageBuffer_
char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE]
Output buffer.
Definition: CoinMessageHandler.hpp:610
CoinMessages::replaceMessage
void replaceMessage(int messageNumber, const char *message)
Replaces the text of the specified message.
CoinOneMessage::detail
int detail() const
Get detail level.
Definition: CoinMessageHandler.hpp:101
CoinMessages::language
Language language() const
Language.
Definition: CoinMessageHandler.hpp:169
CoinMessages::us_en
Definition: CoinMessageHandler.hpp:137
CoinMessageHandler::printing
CoinMessageHandler & printing(bool onOff)
Enable or disable printing of an optional portion of a message.
CoinMessageHandler::logLevel
int logLevel(int which) const
Get alternative log level.
Definition: CoinMessageHandler.hpp:384
CoinMessages::addMessage
void addMessage(int messageNumber, const CoinOneMessage &message)
Installs a new message in the specified index position.
CoinOneMessage::message
char * message() const
Return the message text.
Definition: CoinMessageHandler.hpp:104
CoinOneMessage::detail_
char detail_
Will only print if detail matches.
Definition: CoinMessageHandler.hpp:113
CoinMessageHandler::charValue
char charValue(int position) const
Values of char fields already processed.
Definition: CoinMessageHandler.hpp:432
CoinMessageNewline
Definition: CoinMessageHandler.hpp:219
CoinOneMessage::CoinOneMessage
CoinOneMessage()
Default constructor.
CoinMessages::numberMessages_
int numberMessages_
Number of messages.
Definition: CoinMessageHandler.hpp:200
CoinMessages::toCompact
void toCompact()
Moves to compact format.
CoinMessageHandler::g_format_
char g_format_[8]
Current format for floating point numbers.
Definition: CoinMessageHandler.hpp:629
CoinMessageHandler::detail
int detail(int messageNumber, const CoinMessages &normalMessage) const
Get detail level of a message.
Definition: CoinMessageHandler.hpp:360
CoinMessageHandler::CoinMessageHandlerUnitTest
friend bool CoinMessageHandlerUnitTest()
A function that tests the methods in the CoinMessageHandler class.
CoinOneMessage::~CoinOneMessage
~CoinOneMessage()
Destructor.
CoinMessages::it
Definition: CoinMessageHandler.hpp:139
CoinMessageHandler::messageBuffer
const char * messageBuffer() const
Output buffer.
Definition: CoinMessageHandler.hpp:461
CoinMessageHandler::logLevels_
int logLevels_[COIN_NUM_LOG]
Log levels.
Definition: CoinMessageHandler.hpp:600
CoinMessageHandler::prefix_
int prefix_
Whether we want prefix (may get more subtle so is int)
Definition: CoinMessageHandler.hpp:602
CoinUtilsConfig.h
CoinMessageHandler::messageOut_
char * messageOut_
Position in output buffer.
Definition: CoinMessageHandler.hpp:612
CoinMessages::operator=
CoinMessages & operator=(const CoinMessages &)
assignment operator.
CoinMessages
Class to hold and manipulate an array of massaged messages.
Definition: CoinMessageHandler.hpp:128
CoinOneMessage
Class for one massaged message.
Definition: CoinMessageHandler.hpp:58
CoinMessageHandler::setLogLevel
void setLogLevel(int value)
Set current log (detail) level.
CoinMessageHandler::setFilePointer
void setFilePointer(FILE *fp)
Set new file pointer.
Definition: CoinMessageHandler.hpp:470
COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE
#define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE
Maximum length of constructed message (characters)
Definition: CoinMessageHandler.hpp:588
CoinMessageHandler::precision
int precision()
Current number of significant digits for printing floating point numbers.
Definition: CoinMessageHandler.hpp:395