Clp 1.17.6

- 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 2083 2019-01-06 19:38:09Z unxusr $ */
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 #include "CoinTypes.hpp"
12
13 #include <iostream>
14 #include <cstdio>
15 #include <string>
16 #include <vector>
17
32 /*
33 I (jjf) am strongly in favo(u)r of language support for an open
34 source project, but I have tried to make it as lightweight as
35 possible in the sense that only a subset of messages need to be
36 defined - the rest default to US English. There will be different
37 sets of messages for each component - so at present there is a
38 Clp component and a Coin component.
39
40 Because messages are only used in a controlled environment and have no
41 impact on code and are tested by other tests I have included tests such
42 as language and derivation in other unit tests.
43 */
44 /*
45 Where there are derived classes I (jjf) have started message numbers at 1001.
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 {
87 return externalNumber_;
88 }
94 inline void setExternalNumber(int number)
95 {
96 externalNumber_ = number;
97 }
99 inline char severity() const
100 {
101 return severity_;
102 }
104 inline void setDetail(int level)
105 {
106 detail_ = static_cast< char >(level);
107 }
109 inline int detail() const
110 {
111 return detail_;
112 }
114 inline char *message() const
115 {
116 return message_;
117 }
119
122 int externalNumber_;
125 char detail_;
127 char severity_;
129 mutable char message_[400];
131 };
132
140 class CoinMessages {
141
142 public:
148 enum Language {
149 us_en = 0,
150 uk_en,
151 it
152 };
153
157 CoinMessages(int numberMessages = 0);
159 ~CoinMessages();
161 CoinMessages(const CoinMessages &);
163 CoinMessages &operator=(const CoinMessages &);
165
173 void addMessage(int messageNumber, const CoinOneMessage &message);
179 void replaceMessage(int messageNumber, const char *message);
181 inline Language language() const
182 {
183 return language_;
184 }
186 void setLanguage(Language newlanguage)
187 {
188 language_ = newlanguage;
189 }
191 void setDetailMessage(int newLevel, int messageNumber);
199 void setDetailMessages(int newLevel, int numberMessages,
200 int *messageNumbers);
202 void setDetailMessages(int newLevel, int low, int high);
203
205 inline int getClass() const
206 {
207 return class_;
208 }
210 void toCompact();
212 void fromCompact();
214
217 int numberMessages_;
220 Language language_;
222 char source_[5];
224 int class_;
228 int lengthMessages_;
230 CoinOneMessage **message_;
232 };
233
234 // for convenience eol
235 enum CoinMessageMarker {
236 CoinMessageEol = 0,
237 CoinMessageNewline = 1
238 };
239
345 class CoinMessageHandler {
346
347 friend bool CoinMessageHandlerUnitTest();
348
349 public:
354 virtual int print();
357 virtual void checkSeverity();
359
362 CoinMessageHandler();
365 CoinMessageHandler(FILE *fp);
367 virtual ~CoinMessageHandler();
369 CoinMessageHandler(const CoinMessageHandler &);
371 CoinMessageHandler &operator=(const CoinMessageHandler &);
373 virtual CoinMessageHandler *clone() const;
375
377 inline int detail(int messageNumber, const CoinMessages &normalMessage) const
379 {
380 return normalMessage.message_[messageNumber]->detail();
381 }
383 inline int logLevel() const
384 {
385 return logLevel_;
386 }
404 void setLogLevel(int value);
406 inline int logLevel(int which) const
407 {
408 return logLevels_[which];
409 }
414 void setLogLevel(int which, int value);
415
417 void setPrecision(unsigned int new_precision);
419 inline int precision() { return (g_precision_); }
420
422 void setPrefix(bool yesNo);
424 bool prefix() const;
430 inline double doubleValue(int position) const
431 {
432 return doubleValue_[position];
433 }
438 inline int numberDoubleFields() const
439 {
440 return static_cast< int >(doubleValue_.size());
441 }
447 inline CoinBigIndex intValue(int position) const
448 {
449 return longValue_[position];
450 }
455 inline int numberIntFields() const
456 {
457 return static_cast< int >(longValue_.size());
458 }
464 inline char charValue(int position) const
465 {
466 return charValue_[position];
467 }
472 inline int numberCharFields() const
473 {
474 return static_cast< int >(charValue_.size());
475 }
481 inline std::string stringValue(int position) const
482 {
483 return stringValue_[position];
484 }
489 inline int numberStringFields() const
490 {
491 return static_cast< int >(stringValue_.size());
492 }
493
495 inline CoinOneMessage currentMessage() const
496 {
497 return currentMessage_;
498 }
500 inline std::string currentSource() const
501 {
502 return source_;
503 }
505 inline const char *messageBuffer() const
506 {
507 return messageBuffer_;
508 }
510 inline int highestNumber() const
511 {
512 return highestNumber_;
513 }
515 inline FILE *filePointer() const
516 {
517 return fp_;
518 }
520 inline void setFilePointer(FILE *fp)
521 {
522 fp_ = fp;
523 }
525
534 CoinMessageHandler &message(int messageNumber,
535 const CoinMessages &messages);
536
550 CoinMessageHandler &message(int detail = -1);
551
564 CoinMessageHandler &message(int externalNumber, const char *source,
565 const char *msg,
566 char severity, int detail = -1);
567
572 CoinMessageHandler &operator<<(int intvalue);
573 #if COIN_BIG_INDEX == 1
574
578 CoinMessageHandler &operator<<(long longvalue);
579 #endif
580 #if COIN_BIG_INDEX == 2
581
585 CoinMessageHandler &operator<<(long long longvalue);
586 #endif
587
591 CoinMessageHandler &operator<<(double doublevalue);
596 CoinMessageHandler &operator<<(const std::string &stringvalue);
601 CoinMessageHandler &operator<<(char charvalue);
606 CoinMessageHandler &operator<<(const char *stringvalue);
611 CoinMessageHandler &operator<<(CoinMessageMarker);
616 int finish();
626 CoinMessageHandler &printing(bool onOff);
627
629
638 #define COIN_NUM_LOG 4
639 #define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE 1000
641 protected:
644 std::vector< double > doubleValue_;
646 std::vector< CoinBigIndex > longValue_;
647 std::vector< char > charValue_;
648 std::vector< std::string > stringValue_;
650 int logLevel_;
652 int logLevels_[COIN_NUM_LOG];
654 int prefix_;
656 CoinOneMessage currentMessage_;
658 int internalNumber_;
660 char *format_;
662 char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE];
664 char *messageOut_;
666 std::string source_;
675 int printStatus_;
677 int highestNumber_;
679 FILE *fp_;
681 char g_format_[8];
683 int g_precision_;
685
686 private:
688 void gutsOfCopy(const CoinMessageHandler &rhs);
689
694 char *nextPerCent(char *start, const bool initial = false);
695
700 int internalPrint();
701
703 void calcPrintStatus(int msglvl, int msgclass);
704 };
705
706 //#############################################################################
712 bool CoinMessageHandlerUnitTest();
713
714 #endif
715
716 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
717 */
CoinMessageMarker
CoinMessageMarker
Definition: CoinMessageHandler.hpp:235
CoinMessages::source_
char source_[5]
Source (null-terminated string, maximum 4 characters).
Definition: CoinMessageHandler.hpp:222
CoinMessageHandler::filePointer
FILE * filePointer() const
Get current file pointer.
Definition: CoinMessageHandler.hpp:515
CoinMessageHandler::intValue
CoinBigIndex intValue(int position) const
Values of integer fields already processed.
Definition: CoinMessageHandler.hpp:447
CoinMessageHandler::~CoinMessageHandler
virtual ~CoinMessageHandler()
Destructor.
CoinMessageHandler::source_
std::string source_
Current source of message.
Definition: CoinMessageHandler.hpp:666
CoinOneMessage::setExternalNumber
void setExternalNumber(int number)
Set message ID number.
Definition: CoinMessageHandler.hpp:94
CoinMessageHandler::format_
char * format_
Format string for message (remainder)
Definition: CoinMessageHandler.hpp:660
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:658
CoinMessageHandler::internalPrint
int internalPrint()
Internal printing function.
CoinMessageHandler::finish
int finish()
Finish (and print) the message.
CoinTypes.hpp
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:638
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::printStatus_
int printStatus_
0 - Normal.
Definition: CoinMessageHandler.hpp:675
CoinMessageHandler::logLevel_
int logLevel_
Log level.
Definition: CoinMessageHandler.hpp:650
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:123
CoinMessages::class_
int class_
Class - see later on before CoinMessageHandler.
Definition: CoinMessageHandler.hpp:224
CoinMessageHandler
Base class for message handling.
Definition: CoinMessageHandler.hpp:345
CoinOneMessage::setDetail
void setDetail(int level)
Set detail level.
Definition: CoinMessageHandler.hpp:104
CoinMessages::lengthMessages_
int lengthMessages_
Length of fake CoinOneMessage array.
Definition: CoinMessageHandler.hpp:228
CoinMessages::~CoinMessages
~CoinMessages()
Destructor.
CoinMessageHandler::charValue_
std::vector< char > charValue_
Definition: CoinMessageHandler.hpp:647
CoinMessages::uk_en
Definition: CoinMessageHandler.hpp:150
CoinMessages::setLanguage
void setLanguage(Language newlanguage)
Set language.
Definition: CoinMessageHandler.hpp:186
CoinOneMessage::severity_
char severity_
Severity.
Definition: CoinMessageHandler.hpp:127
CoinMessageHandler::prefix
bool prefix() const
Current setting for printing message prefix.
CoinMessageHandler::doubleValue
double doubleValue(int position) const
Values of double fields already processed.
Definition: CoinMessageHandler.hpp:430
CoinMessageHandler::CoinMessageHandler
CoinMessageHandler()
Constructor.
CoinMessageHandler::logLevel
int logLevel() const
Get current log (detail) level.
Definition: CoinMessageHandler.hpp:383
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:481
CoinMessageEol
Definition: CoinMessageHandler.hpp:236
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:455
CoinMessageHandler::fp_
FILE * fp_
File pointer.
Definition: CoinMessageHandler.hpp:679
CoinMessages::language_
Language language_
Language.
Definition: CoinMessageHandler.hpp:220
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:438
CoinPragma.hpp
CoinOneMessage::message_
char message_[400]
Messages (in correct language) (not all 400 may exist)
Definition: CoinMessageHandler.hpp:129
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:472
CoinMessageHandler::currentMessage_
CoinOneMessage currentMessage_
Current message.
Definition: CoinMessageHandler.hpp:656
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:495
CoinMessageHandler::longValue_
std::vector< CoinBigIndex > longValue_
Definition: CoinMessageHandler.hpp:646
CoinMessages::message_
CoinOneMessage ** message_
Messages.
Definition: CoinMessageHandler.hpp:230
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:489
CoinMessageHandler::print
virtual int print()
Print message, return 0 normally.
CoinOneMessage::severity
char severity() const
Severity.
Definition: CoinMessageHandler.hpp:99
CoinMessageHandler::highestNumber_
int highestNumber_
Highest message number (indicates any errors)
Definition: CoinMessageHandler.hpp:677
CoinMessageHandler::currentSource
std::string currentSource() const
Source of current message.
Definition: CoinMessageHandler.hpp:500
CoinMessageHandler::g_precision_
int g_precision_
Current number of significant digits for floating point numbers.
Definition: CoinMessageHandler.hpp:683
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:205
CoinMessageHandler::highestNumber
int highestNumber() const
Highest message number (indicates any errors)
Definition: CoinMessageHandler.hpp:510
CoinMessages::Language
Language
Supported languages.
Definition: CoinMessageHandler.hpp:148
CoinMessageHandler::messageBuffer_
char messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE]
Output buffer.
Definition: CoinMessageHandler.hpp:662
CoinBigIndex
int CoinBigIndex
Definition: Coin_C_defines.h:136
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:109
CoinMessages::language
Language language() const
Language.
Definition: CoinMessageHandler.hpp:181
CoinMessages::us_en
Definition: CoinMessageHandler.hpp:149
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:406
CoinMessageHandler::doubleValue_
std::vector< double > doubleValue_
values in message
Definition: CoinMessageHandler.hpp:645
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:114
CoinOneMessage::detail_
char detail_
Will only print if detail matches.
Definition: CoinMessageHandler.hpp:125
CoinMessageHandler::charValue
char charValue(int position) const
Values of char fields already processed.
Definition: CoinMessageHandler.hpp:464
CoinMessageNewline
Definition: CoinMessageHandler.hpp:237
CoinOneMessage::CoinOneMessage
CoinOneMessage()
Default constructor.
CoinMessages::numberMessages_
int numberMessages_
Number of messages.
Definition: CoinMessageHandler.hpp:218
CoinMessages::toCompact
void toCompact()
Moves to compact format.
CoinMessageHandler::g_format_
char g_format_[8]
Current format for floating point numbers.
Definition: CoinMessageHandler.hpp:681
CoinMessageHandler::detail
int detail(int messageNumber, const CoinMessages &normalMessage) const
Get detail level of a message.
Definition: CoinMessageHandler.hpp:378
CoinMessageHandler::CoinMessageHandlerUnitTest
friend bool CoinMessageHandlerUnitTest()
A function that tests the methods in the CoinMessageHandler class.
CoinOneMessage::~CoinOneMessage
~CoinOneMessage()
Destructor.
CoinMessages::it
Definition: CoinMessageHandler.hpp:151
CoinMessageHandler::messageBuffer
const char * messageBuffer() const
Output buffer.
Definition: CoinMessageHandler.hpp:505
CoinMessageHandler::logLevels_
int logLevels_[COIN_NUM_LOG]
Log levels.
Definition: CoinMessageHandler.hpp:652
CoinMessageHandler::prefix_
int prefix_
Whether we want prefix (may get more subtle so is int)
Definition: CoinMessageHandler.hpp:654
CoinUtilsConfig.h
CoinMessageHandler::messageOut_
char * messageOut_
Position in output buffer.
Definition: CoinMessageHandler.hpp:664
CoinMessages::operator=
CoinMessages & operator=(const CoinMessages &)
assignment operator.
CoinMessages
Class to hold and manipulate an array of massaged messages.
Definition: CoinMessageHandler.hpp:140
CoinMessageHandler::stringValue_
std::vector< std::string > stringValue_
Definition: CoinMessageHandler.hpp:648
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:520
COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE
#define COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE
Maximum length of constructed message (characters)
Definition: CoinMessageHandler.hpp:640
CoinMessageHandler::precision
int precision()
Current number of significant digits for printing floating point numbers.
Definition: CoinMessageHandler.hpp:419