MINT2
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes | List of all members
MessageSerivce Class Reference

#include <MessageService.h>

Public Types

enum  ErrorType {
  WELCOME, ERROR, INFO, VERBOSE,
  GOODBYE
}
 Define the possible error types. More...
 
typedef std::basic_ostream< char, std::char_traits< char > > CoutType
 
typedef CoutType &(* StandardEndLine) (CoutType &)
 

Public Member Functions

void printErrorCount ()
 
template<class T >
MessageSerivceoperator<< (const T &v)
 
MessageSerivceoperator<< (StandardEndLine manip)
 
 ~MessageSerivce ()
 

Static Public Member Functions

static MessageSerivcegetMessageService (ErrorType errorType)
 
static MessageSerivcegetMessageService ()
 

Public Attributes

std::ostream & _stream
 the output stream - by default this is std:cout More...
 
std::map< ErrorType, bool > _outputOptions
 
std::map< ErrorType, TString > _outputHeaders
 
bool _endlCalled
 
bool _printOrNot
 
ErrorType _errorType
 
long int _errorCount
 

Private Member Functions

 MessageSerivce ()
 

Static Private Attributes

static MessageSerivces_messageService = 0
 static variable that holds the singleton object More...
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

This is used to print all of the output from HyperPlot to a chosen output stream (by default std::cout). Access to this class is done through the precompiler definitions.

WELCOME_LOG - A welcome message in the constructor of each class ERROR_LOG - Use to print error messages to the screen INFO_LOG - Use to print useful information to the screen VERBOSE_LOG - Use for verbose information GOODBYE_LOG - A goodbye message in the destructor of each class

ERROR_COUNT - Print out how many error messages have been shown. This is useful to call at the end of the main function

Definition at line 33 of file MessageService.h.

Member Typedef Documentation

◆ CoutType

typedef std::basic_ostream<char, std::char_traits<char> > MessageSerivce::CoutType

this is the type of std::cout

Definition at line 131 of file MessageService.h.

◆ StandardEndLine

typedef CoutType&(* MessageSerivce::StandardEndLine) (CoutType &)

this is the function signature of std::endl

Definition at line 135 of file MessageService.h.

Member Enumeration Documentation

◆ ErrorType

Define the possible error types.

Enumerator
WELCOME 
ERROR 
INFO 
VERBOSE 
GOODBYE 

Definition at line 45 of file MessageService.h.

Constructor & Destructor Documentation

◆ MessageSerivce()

MessageSerivce::MessageSerivce ( )
private

constuctor

Definition at line 55 of file MessageService.cpp.

55  :
56  _stream(std::cout),
57  _endlCalled(true),
58  _errorCount(0)
59 {
60 
61  _outputOptions[WELCOME] = false;
62  _outputOptions[ERROR ] = true ;
63  _outputOptions[INFO ] = true ;
64  _outputOptions[VERBOSE] = false;
65  _outputOptions[GOODBYE] = false;
66 
67  _outputHeaders[WELCOME] = "HyperPlot Welcome : ";
68  _outputHeaders[ERROR ] = "\033[31mHyperPlot Error : ";
69  _outputHeaders[INFO ] = "\033[32mHyperPlot Info : ";
70  _outputHeaders[VERBOSE] = "HyperPlot Verbose : ";
71  _outputHeaders[GOODBYE] = "HyperPlot Goodbye : ";
72 
73 }
std::ostream & _stream
the output stream - by default this is std:cout
std::map< ErrorType, TString > _outputHeaders
std::map< ErrorType, bool > _outputOptions
long int _errorCount

◆ ~MessageSerivce()

MessageSerivce::~MessageSerivce ( )

destuctor

Definition at line 88 of file MessageService.cpp.

88  {
89 
90  //turns out that it never gets destructed so this doesn't work. Bit of a shame
91  if (_errorCount != 0){
92  _errorCount--;
93  getMessageService(ERROR) << "There was " << _errorCount << " errors during runtime" << std::endl;
94  }
95 
96 }
static MessageSerivce & getMessageService()
long int _errorCount

Member Function Documentation

◆ getMessageService() [1/2]

MessageSerivce & MessageSerivce::getMessageService ( ErrorType  errorType)
static

Static function to retrive the MessageSerivce singleton. At the same time, also change the state of the MessageSerivce.

Definition at line 8 of file MessageService.cpp.

8  {
9 
10  //if the singleton doesn't exist, return make it
11  if (s_messageService == 0){
13  }
14 
15  //See if we should be printing the error type given.
16  //Set the _printOrNot variable accordingly
18 
19 
20 
21  //Set the error type to the one given
23 
24  //if the message type has changed, and no endl was called, then
25  //force a new line.
26  if (s_messageService->_errorType != errorType && s_messageService->_endlCalled == 0){
27  *s_messageService << std::endl;
28  }
29 
30  s_messageService->_errorType = errorType;
31  }
32 
33  //return the singleton
34  return *s_messageService;
35 
36 }
static MessageSerivce * s_messageService
static variable that holds the singleton object
ErrorType _errorType
std::map< ErrorType, bool > _outputOptions

◆ getMessageService() [2/2]

MessageSerivce & MessageSerivce::getMessageService ( )
static

Static function to retrive the MessageSerivce singleton without altering its message state

Definition at line 40 of file MessageService.cpp.

40  {
41 
42  //if the singleton doesn't exist, return make it
43  if (s_messageService == 0){
45  }
46 
47  //return the singleton
48  return *s_messageService;
49 
50 }
static MessageSerivce * s_messageService
static variable that holds the singleton object

◆ operator<<() [1/2]

template<class T >
MessageSerivce& MessageSerivce::operator<< ( const T &  v)
inline

This makes is possible the do messageSerivce <<

Definition at line 83 of file MessageService.h.

84  {
85 
86  if (_printOrNot) {
87  if (_endlCalled){
89  if (_errorType == ERROR) _errorCount++;
90  _endlCalled = 0;
91  }
92  _stream << v;
93  }
94  return *this;
95  }
std::ostream & _stream
the output stream - by default this is std:cout
ErrorType _errorType
std::map< ErrorType, TString > _outputHeaders
long int _errorCount

◆ operator<<() [2/2]

MessageSerivce& MessageSerivce::operator<< ( StandardEndLine  manip)
inline

define an operator<< to take in std::endl

Definition at line 139 of file MessageService.h.

140  {
141  //SAM -> I'm assuming that when this gets called it's
142  //always endl - I imagine this isn't always the case.
143  if (_printOrNot){
144  _endlCalled = true;
145 
146  // call the function, but we cannot return it's value
147  _stream << "\033[0m";
148  manip(_stream);
149 
150  }
151  return *this;
152  }
std::ostream & _stream
the output stream - by default this is std:cout

◆ printErrorCount()

void MessageSerivce::printErrorCount ( )

print how many errors messages have been sent to the output stream

Definition at line 77 of file MessageService.cpp.

77  {
78 
79  //turns out that it never gets destructed so this doesn't work. Bit of a shame
80  if (_errorCount != 0){
81  _errorCount--; //This isn't actually an error, so -1
82  getMessageService(ERROR) << "There were " << _errorCount << " errors during runtime" << std::endl;
83  }
84 }
static MessageSerivce & getMessageService()
long int _errorCount

Member Data Documentation

◆ _endlCalled

bool MessageSerivce::_endlCalled

bool was the last command sent to the steam a std::cout ?

Definition at line 61 of file MessageService.h.

◆ _errorCount

long int MessageSerivce::_errorCount

Count the number of errors that happened.

Definition at line 74 of file MessageService.h.

◆ _errorType

ErrorType MessageSerivce::_errorType

The current message type of the MessageSerivce

Definition at line 70 of file MessageService.h.

◆ _outputHeaders

std::map<ErrorType, TString> MessageSerivce::_outputHeaders

this is the string that proceeds each of the message types

Definition at line 57 of file MessageService.h.

◆ _outputOptions

std::map<ErrorType, bool> MessageSerivce::_outputOptions

this map decides what message types should be printed to the output stream (verbose, welcome and goodbye are off by default)

Definition at line 53 of file MessageService.h.

◆ _printOrNot

bool MessageSerivce::_printOrNot

For the current message type, should I be printing to the stream (means you don't have to use the map many times in a row i.e. faster)

Definition at line 66 of file MessageService.h.

◆ _stream

std::ostream& MessageSerivce::_stream

the output stream - by default this is std:cout

Definition at line 48 of file MessageService.h.

◆ s_messageService

MessageSerivce * MessageSerivce::s_messageService = 0
staticprivate

static variable that holds the singleton object

Definition at line 38 of file MessageService.h.


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