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

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# CoinMessageHandler Class Reference

Base class for message handling. More...

`#include <CoinMessageHandler.hpp>`

Inheritance diagram for CoinMessageHandler:

[legend]
Collaboration diagram for CoinMessageHandler:

[legend]
List of all members.

## Public Member Functions
Virtual methods that the derived classes may provide
virtual int | print ()
| Print message, return 0 normally.
virtual void | checkSeverity ()
| Check message severity - if too bad then abort.
Constructors etc
| CoinMessageHandler ()
| Constructor.
| CoinMessageHandler (FILE *fp)
| Constructor to put to file pointer (won't be closed).
virtual | ~CoinMessageHandler ()
| Destructor.
| CoinMessageHandler (const CoinMessageHandler &)
| The copy constructor.
CoinMessageHandler & | operator= (const CoinMessageHandler &)
| Assignment operator.
virtual CoinMessageHandler * | clone () const
| Clone.
Get and set methods
int | detail (int messageNumber, const CoinMessages &normalMessage) const
| Get detail level of a message.
int | logLevel () const
| Get current log (detail) level.
void | setLogLevel (int value)
| Set current log (detail) level.
int | logLevel (int which) const
| Get alternative log level.
void | setLogLevel (int which, int value)
| Set alternative log level value.
void | setPrecision (unsigned int new_precision)
| Set the number of significant digits for printing floating point numbers.
int | precision ()
| Current number of significant digits for printing floating point numbers.
void | setPrefix (bool yesNo)
| Switch message prefix on or off.
bool | prefix () const
| Current setting for printing message prefix.
double | doubleValue (int position) const
| Values of double fields already processed.
int | numberDoubleFields () const
| Number of double fields already processed.
int | intValue (int position) const
| Values of integer fields already processed.
int | numberIntFields () const
| Number of integer fields already processed.
char | charValue (int position) const
| Values of char fields already processed.
int | numberCharFields () const
| Number of char fields already processed.
std::string | stringValue (int position) const
| Values of string fields already processed.
int | numberStringFields () const
| Number of string fields already processed.
CoinOneMessage | currentMessage () const
| Current message.
std::string | currentSource () const
| Source of current message.
const char * | messageBuffer () const
| Output buffer.
int | highestNumber () const
| Highest message number (indicates any errors).
FILE * | filePointer () const
| Get current file pointer.
void | setFilePointer (FILE *fp)
| Set new file pointer.
Actions to create a message
CoinMessageHandler & | message (int messageNumber, const CoinMessages &messages)
| Start a message.
CoinMessageHandler & | message ()
| Start or continue a message.
CoinMessageHandler & | message (int externalNumber, const char *header, const char *msg, char severity)
| Generate a standard prefix and append `msg` `as is'.
CoinMessageHandler & | operator<< (int intvalue)
| Process an integer parameter value.
CoinMessageHandler & | operator<< (double doublevalue)
| Process a double parameter value.
CoinMessageHandler & | operator<< (const std::string &stringvalue)
| Process a STL string parameter value.
CoinMessageHandler & | operator<< (char charvalue)
| Process a char parameter value.
CoinMessageHandler & | operator<< (const char *stringvalue)
| Process a C-style string parameter value.
CoinMessageHandler & | operator<< (CoinMessageMarker)
| Process a marker.
int | finish ()
| Finish (and print) the message.
CoinMessageHandler & | printing (bool onOff)
| Enable or disable printing of an optional portion of a message.
char * | nextPerCent (char *start, const bool initial=false)
| Internal function to locate next format code.
int | internalPrint ()
| Internal printing function.
## Protected Attributes
Protected member data
std::vector< double > | doubleValue_
| values in message
std::vector< int > | longValue_
| values in message
std::vector< char > | charValue_
| values in message
std::vector< std::string > | stringValue_
| values in message
int | logLevel_
| Log level.
int | logLevels_ [COIN_NUM_LOG]
| Log levels.
int | prefix_
| Whether we want prefix (may get more subtle so is int).
CoinOneMessage | currentMessage_
| Current message.
int | internalNumber_
| Internal number for use with enums.
char * | format_
| Format string for message (remainder).
char | messageBuffer_ [COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE]
| Output buffer.
char * | messageOut_
| Position in output buffer.
std::string | source_
| Current source of message.
int | printStatus_
| 0 - normal, 1 - put in values, move along format, no print 2 - put in values, no print 3 - skip message
int | highestNumber_
| Highest message number (indicates any errors).
FILE * | fp_
| File pointer.
char | g_format_ [8]
| Current format for floating point numbers.
int | g_precision_
| Current number of significant digits for floating point numbers.
## Private Member Functions
void | gutsOfCopy (const CoinMessageHandler &rhs)
| The body of the copy constructor and the assignment operator.
## Friends
bool | CoinMessageHandlerUnitTest ()
| A function that tests the methods in the CoinMessageHandler class.

## Detailed Description

Base class for message handling.

The default behavior is described here: messages are printed, and (if the severity is sufficiently high) execution will be aborted. Inherit and redefine the methods print and checkSeverity to augment the behaviour.

Messages can be printed with or without a prefix; the prefix will consist of a source string, the external ID number, and a letter code, e.g., Clp6024W. A prefix makes the messages look less nimble but is very useful for "grep" etc.

### Usage

The general approach to using the COIN messaging facility is as follows:

- Define your messages. For each message, you must supply an external ID number, a log (detail) level, and a format string. Typically, you define a convenience structure for this, something that's easy to use to create an array of initialised message definitions at compile time.
- Create a CoinMessages object, sized to accommodate the number of messages you've defined. (Incremental growth will happen if necessary as messages are loaded, but it's inefficient.)
- Load the messages into the CoinMessages object. Typically this entails creating a CoinOneMessage object for each message and passing it as a parameter to CoinMessages::addMessage(). You specify the message's internal ID as the other parameter to addMessage.
- Create and use a CoinMessageHandler object to print messages.

See, for example, CoinMessage.hpp and CoinMessage.cpp for an example of the first three steps. `Format codes' below has a simple example of printing a message.

### External ID numbers and severity

CoinMessageHandler assumes the following relationship between the external ID number of a message and the severity of the message:

- <3000 are informational ('I')
- <6000 warnings ('W')
- <9000 non-fatal errors ('E')
- >=9000 aborts the program (after printing the message) ('S')

### Format codes

CoinMessageHandler can print integers (normal, long, and long long), doubles, characters, and strings. See the descriptions of the various << operators.

When processing a standard message with a format string, the formatting codes specified in the format string will be passed to the sprintf function, along with the argument. When generating a message with no format string, each << operator uses a simple format code appropriate for its argument. Consult the documentation for the standard printf facility for further information on format codes.

The special format code `%?' provides a hook to enable or disable printing. For each `%?' code, there must be a corresponding call to printing(bool). This provides a way to define optional parts in messages, delineated by the code `%?' in the format string. Printing can be suppressed for these optional parts, but any operands must still be supplied. For example, given the message string

        "A message with%? an optional integer %d and%? a double %g."

installed in CoinMessages `exampleMsgs` with index 5, and `CoinMessageHandler` `hdl`, the code

        hdl.message(5,exampleMsgs) ;
        hdl.printing(true) << 42 ;
        hdl.printing(true) << 53.5 << CoinMessageEol ;

will print

        A message with an optional integer 42 and a double 53.5.

while

        hdl.message(5,exampleMsgs) ;
        hdl.printing(false) << 42 ;
        hdl.printing(true) << 53.5 << CoinMessageEol ;

will print

        A message with a double 53.5.

For additional examples of usage, see CoinMessageHandlerUnitTest in CoinMessageHandlerTest.cpp.

Definition at line 315 of file CoinMessageHandler.hpp.

## Constructor & Destructor Documentation

CoinMessageHandler::CoinMessageHandler | ( |  | ) |

Constructor.

CoinMessageHandler::CoinMessageHandler | ( | FILE * | fp | ) |

Constructor to put to file pointer (won't be closed).

virtual CoinMessageHandler::~CoinMessageHandler | ( |  | ) | `[virtual]`

Destructor.

CoinMessageHandler::CoinMessageHandler | ( | const CoinMessageHandler & |  | ) |

The copy constructor.

## Member Function Documentation

void CoinMessageHandler::gutsOfCopy | ( | const CoinMessageHandler & | rhs | ) | `[private]`

The body of the copy constructor and the assignment operator.

virtual int CoinMessageHandler::print | ( |  | ) | `[virtual]`

Print message, return 0 normally.

Reimplemented in MyMessageHandler.

virtual void CoinMessageHandler::checkSeverity | ( |  | ) | `[virtual]`

Check message severity - if too bad then abort.

CoinMessageHandler& CoinMessageHandler::operator= | ( | const CoinMessageHandler & |  | ) |

Assignment operator.

virtual CoinMessageHandler* CoinMessageHandler::clone | ( |  | ) | const`[virtual]`

Clone.

Reimplemented in MyMessageHandler.

int CoinMessageHandler::detail | ( | int | messageNumber,
|  | const CoinMessages & | normalMessage |
| ) |  |  | const`[inline]`

Get detail level of a message.

Definition at line 352 of file CoinMessageHandler.hpp.

References CoinOneMessage::detail(), and CoinMessages::message_.

int CoinMessageHandler::logLevel | ( |  | ) | const`[inline]`

Get current log (detail) level.

Definition at line 355 of file CoinMessageHandler.hpp.

References logLevel_.

void CoinMessageHandler::setLogLevel | ( | int | value | ) |

Set current log (detail) level.

If the log level is equal or greater than the detail level of a message, the message will be printed. A rough convention for the amount of output expected is

- 0 - none
- 1 - minimal
- 2 - normal low
- 3 - normal high
- 4 - verbose

Please assign log levels to messages accordingly. Log levels of 8 and above (8,16,32, etc.) are intended for selective debugging. The logical AND of the log level specified in the message and the current log level is used to determine if the message is printed. (In other words, you're using individual bits to determine which messages are printed.)

Referenced by AbcModel::init(), LAP::CglLandPSimplex::setLogLevel(), and CglLandP::setLogLevel().

int CoinMessageHandler::logLevel | ( | int | which | ) | const`[inline]`

Get alternative log level.

Definition at line 376 of file CoinMessageHandler.hpp.

References logLevels_.

void CoinMessageHandler::setLogLevel | ( | int | which,
|  | int | value |
| ) |  |  |

Set alternative log level value.

Can be used to store alternative log level information within the handler.

void CoinMessageHandler::setPrecision | ( | unsigned int | new_precision | ) |

Set the number of significant digits for printing floating point numbers.

int CoinMessageHandler::precision | ( |  | ) | `[inline]`

Current number of significant digits for printing floating point numbers.

Definition at line 387 of file CoinMessageHandler.hpp.

References g_precision_.

void CoinMessageHandler::setPrefix | ( | bool | yesNo | ) |

Switch message prefix on or off.

bool CoinMessageHandler::prefix | ( |  | ) | const

Current setting for printing message prefix.

double CoinMessageHandler::doubleValue | ( | int | position | ) | const`[inline]`

Values of double fields already processed.

As the parameter for a double field is processed, the value is saved and can be retrieved using this function.

Definition at line 398 of file CoinMessageHandler.hpp.

References doubleValue_.

int CoinMessageHandler::numberDoubleFields | ( |  | ) | const`[inline]`

Number of double fields already processed.

Incremented each time a field of type double is processed.

Definition at line 404 of file CoinMessageHandler.hpp.

References doubleValue_.

int CoinMessageHandler::intValue | ( | int | position | ) | const`[inline]`

Values of integer fields already processed.

As the parameter for a integer field is processed, the value is saved and can be retrieved using this function.

Definition at line 411 of file CoinMessageHandler.hpp.

References longValue_.

int CoinMessageHandler::numberIntFields | ( |  | ) | const`[inline]`

Number of integer fields already processed.

Incremented each time a field of type integer is processed.

Definition at line 417 of file CoinMessageHandler.hpp.

References longValue_.

char CoinMessageHandler::charValue | ( | int | position | ) | const`[inline]`

Values of char fields already processed.

As the parameter for a char field is processed, the value is saved and can be retrieved using this function.

Definition at line 424 of file CoinMessageHandler.hpp.

References charValue_.

int CoinMessageHandler::numberCharFields | ( |  | ) | const`[inline]`

Number of char fields already processed.

Incremented each time a field of type char is processed.

Definition at line 430 of file CoinMessageHandler.hpp.

References charValue_.

std::string CoinMessageHandler::stringValue | ( | int | position | ) | const`[inline]`

Values of string fields already processed.

As the parameter for a string field is processed, the value is saved and can be retrieved using this function.

Definition at line 437 of file CoinMessageHandler.hpp.

References stringValue_.

int CoinMessageHandler::numberStringFields | ( |  | ) | const`[inline]`

Number of string fields already processed.

Incremented each time a field of type string is processed.

Definition at line 443 of file CoinMessageHandler.hpp.

References stringValue_.

CoinOneMessage CoinMessageHandler::currentMessage | ( |  | ) | const`[inline]`

Current message.

Definition at line 447 of file CoinMessageHandler.hpp.

References currentMessage_.

std::string CoinMessageHandler::currentSource | ( |  | ) | const`[inline]`

Source of current message.

Definition at line 450 of file CoinMessageHandler.hpp.

References source_.

const char* CoinMessageHandler::messageBuffer | ( |  | ) | const`[inline]`

Output buffer.

Definition at line 453 of file CoinMessageHandler.hpp.

References messageBuffer_.

int CoinMessageHandler::highestNumber | ( |  | ) | const`[inline]`

Highest message number (indicates any errors).

Definition at line 456 of file CoinMessageHandler.hpp.

References highestNumber_.

FILE* CoinMessageHandler::filePointer | ( |  | ) | const`[inline]`

Get current file pointer.

Definition at line 459 of file CoinMessageHandler.hpp.

References fp_.

void CoinMessageHandler::setFilePointer | ( | FILE * | fp | ) | `[inline]`

Set new file pointer.

Definition at line 462 of file CoinMessageHandler.hpp.

References fp_.

CoinMessageHandler& CoinMessageHandler::message | ( | int | messageNumber,
|  | const CoinMessages & | messages |
| ) |  |  |

Start a message.

Look up the specified message. A prefix will be generated if enabled. The message will be printed if the current log level is equal or greater than the log level of the message.

Referenced by LAP::CglLandPSimplex::outPivInfo().

CoinMessageHandler& CoinMessageHandler::message | ( |  | ) |

Start or continue a message.

Does nothing except return a reference to the handler. This can be used with any of the << operators. One use is to start a message which will be constructed entirely from scratch. Another use is continuation of a message after code that interrupts the usual sequence of << operators.

CoinMessageHandler& CoinMessageHandler::message | ( | int | externalNumber,
|  | const char * | header,
|  | const char * | msg,
|  | char | severity |
| ) |  |  |

Generate a standard prefix and append `msg` `as is'.

Intended as a transition mechanism. The standard prefix is generated (if enabled), and `msg` is appended. Only the operator<<(CoinMessageMarker) operator can be used with a message started with this call.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | int | intvalue | ) |

Process an integer parameter value.

The default format code is `d'.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | double | doublevalue | ) |

Process a double parameter value.

The default format code is `d'.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | const std::string & | stringvalue | ) |

Process a STL string parameter value.

The default format code is `g'.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | char | charvalue | ) |

Process a char parameter value.

The default format code is `s'.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | const char * | stringvalue | ) |

Process a C-style string parameter value.

The default format code is `c'.

CoinMessageHandler& CoinMessageHandler::operator<< | ( | CoinMessageMarker |  | ) |

Process a marker.

The default format code is `s'.

int CoinMessageHandler::finish | ( |  | ) |

Finish (and print) the message.

Equivalent to using the CoinMessageEol marker.

CoinMessageHandler& CoinMessageHandler::printing | ( | bool | onOff | ) |

Enable or disable printing of an optional portion of a message.

Optional portions of a message are delimited by `%?' markers, and printing processes one %? marker. If `onOff` is true, the subsequent portion of the message (to the next %? marker or the end of the format string) will be printed. If `onOff` is false, printing is suppressed. Parameters must still be supplied, whether printing is suppressed or not. See the class documentation for an example.

char* CoinMessageHandler::nextPerCent | ( | char * | start,
|  | const bool | initial = `false` |
| ) |  |  |

Internal function to locate next format code.

Intended for internal use. Side effects modify the format string.

int CoinMessageHandler::internalPrint | ( |  | ) |

Internal printing function.

Makes it easier to split up print into clean, print and check severity

## Friends And Related Function Documentation

bool CoinMessageHandlerUnitTest | ( |  | ) | `[friend]`

A function that tests the methods in the CoinMessageHandler class.

The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging.

## Member Data Documentation

std::vector<double> CoinMessageHandler::doubleValue_`[protected]`

values in message

Definition at line 579 of file CoinMessageHandler.hpp.

Referenced by doubleValue(), and numberDoubleFields().

std::vector<int> CoinMessageHandler::longValue_`[protected]`

values in message

Definition at line 580 of file CoinMessageHandler.hpp.

Referenced by intValue(), and numberIntFields().

std::vector<char> CoinMessageHandler::charValue_`[protected]`

values in message

Definition at line 581 of file CoinMessageHandler.hpp.

Referenced by charValue(), and numberCharFields().

std::vector<std::string> CoinMessageHandler::stringValue_`[protected]`

values in message

Definition at line 582 of file CoinMessageHandler.hpp.

Referenced by numberStringFields(), and stringValue().

int CoinMessageHandler::logLevel_`[protected]`

Log level.

Definition at line 584 of file CoinMessageHandler.hpp.

Referenced by logLevel().

int CoinMessageHandler::logLevels_[COIN_NUM_LOG]`[protected]`

Log levels.

Definition at line 586 of file CoinMessageHandler.hpp.

Referenced by logLevel().

int CoinMessageHandler::prefix_`[protected]`

Whether we want prefix (may get more subtle so is int).

Definition at line 588 of file CoinMessageHandler.hpp.

CoinOneMessage CoinMessageHandler::currentMessage_`[protected]`

Current message.

Definition at line 590 of file CoinMessageHandler.hpp.

Referenced by currentMessage().

int CoinMessageHandler::internalNumber_`[protected]`

Internal number for use with enums.

Definition at line 592 of file CoinMessageHandler.hpp.

char* CoinMessageHandler::format_`[protected]`

Format string for message (remainder).

Definition at line 594 of file CoinMessageHandler.hpp.

char CoinMessageHandler::messageBuffer_[COIN_MESSAGE_HANDLER_MAX_BUFFER_SIZE]`[protected]`

Output buffer.

Definition at line 596 of file CoinMessageHandler.hpp.

Referenced by messageBuffer().

char* CoinMessageHandler::messageOut_`[protected]`

Position in output buffer.

Definition at line 598 of file CoinMessageHandler.hpp.

std::string CoinMessageHandler::source_`[protected]`

Current source of message.

Definition at line 600 of file CoinMessageHandler.hpp.

Referenced by currentSource().

int CoinMessageHandler::printStatus_`[protected]`

0 - normal, 1 - put in values, move along format, no print 2 - put in values, no print 3 - skip message

Definition at line 606 of file CoinMessageHandler.hpp.

int CoinMessageHandler::highestNumber_`[protected]`

Highest message number (indicates any errors).

Definition at line 608 of file CoinMessageHandler.hpp.

Referenced by highestNumber().

FILE* CoinMessageHandler::fp_`[protected]`

File pointer.

Definition at line 610 of file CoinMessageHandler.hpp.

Referenced by filePointer(), and setFilePointer().

char CoinMessageHandler::g_format_[8]`[protected]`

Current format for floating point numbers.

Definition at line 612 of file CoinMessageHandler.hpp.

int CoinMessageHandler::g_precision_`[protected]`

Current number of significant digits for floating point numbers.

Definition at line 614 of file CoinMessageHandler.hpp.

Referenced by precision().

The documentation for this class was generated from the following file:

- /home/coin/SVN-release/Alps-1.2.1/CoinUtils/src/CoinMessageHandler.hpp