Calculator
Extensible stack-based calculator primarily in library form
Calculator::Result Class Reference

Collection of Result information for an operation. More...

#include <Result.h>

Public Types

typedef std::string Message
 
typedef std::vector< MessageMessages
 
typedef std::pair< unsigned int, std::string > PositionMessage
 For convenience, we use a pair for the line and message for a position. More...
 
typedef std::vector< PositionMessagePositionMessages
 

Public Member Functions

 Result ()=default
 
 Result (std::initializer_list< Message > theMessages)
 Create with all messages in theMessage. More...
 
 Result (std::initializer_list< PositionMessage > thePositionMessages)
 Create with all the positional messages in thePositionMessages. More...
 
 Result (std::initializer_list< Message > theMessages, std::initializer_list< PositionMessage > thePositionMessages)
 Create with all messages in theMessage and all the positional messages in thePositionMessages. More...
 
const MessagesgetMessages () const
 
bool hasMessage (const std::string &message) const
 Convenience to test with message has been set. More...
 
void addMessage (const std::string &message)
 Add message. More...
 
const PositionMessagesgetPositionMessages () const
 
bool hasPositionMessage (const unsigned int position, const std::string &message) const
 Convenience to test if the positional message has been set at the position. More...
 
void addPositionMessage (const unsigned int position, const std::string &message)
 Add the positional message. More...
 
std::string toString () const
 
std::string toString (const std::string &prefix) const
 Create a string representation of this Result with prefix at the start of each line. More...
 

Detailed Description

Collection of Result information for an operation.

Contains non-positional message strings for things like "Ok". May be used by driving code to pass around commands like "quit".

Contains positional messages of stack position (0 is top) and message to indicate what failed, such as Stack Underflow or conversion error on a position in the stack.

Definition at line 30 of file Result.h.

Member Typedef Documentation

◆ Message

typedef std::string Calculator::Result::Message

Definition at line 32 of file Result.h.

◆ Messages

typedef std::vector<Message> Calculator::Result::Messages

Definition at line 33 of file Result.h.

◆ PositionMessage

typedef std::pair<unsigned int, std::string> Calculator::Result::PositionMessage

For convenience, we use a pair for the line and message for a position.

Definition at line 36 of file Result.h.

◆ PositionMessages

Definition at line 37 of file Result.h.

Constructor & Destructor Documentation

◆ Result() [1/4]

Calculator::Result::Result ( )
default

◆ Result() [2/4]

Calculator::Result::Result ( std::initializer_list< Message theMessages)

Create with all messages in theMessage.

Definition at line 24 of file Result.cpp.

◆ Result() [3/4]

Calculator::Result::Result ( std::initializer_list< PositionMessage thePositionMessages)

Create with all the positional messages in thePositionMessages.

Definition at line 28 of file Result.cpp.

◆ Result() [4/4]

Calculator::Result::Result ( std::initializer_list< Message theMessages,
std::initializer_list< PositionMessage thePositionMessages 
)

Create with all messages in theMessage and all the positional messages in thePositionMessages.

Definition at line 32 of file Result.cpp.

Member Function Documentation

◆ addMessage()

void Calculator::Result::addMessage ( const std::string &  message)

Add message.

Parameters
messageto add

Definition at line 48 of file Result.cpp.

◆ addPositionMessage()

void Calculator::Result::addPositionMessage ( const unsigned int  position,
const std::string &  message 
)

Add the positional message.

Parameters
positionthe message belongs to
messageto be added at position

Definition at line 61 of file Result.cpp.

◆ getMessages()

const Result::Messages & Calculator::Result::getMessages ( ) const
Returns
all the messages for iteration

Definition at line 39 of file Result.cpp.

◆ getPositionMessages()

const Result::PositionMessages & Calculator::Result::getPositionMessages ( ) const
Returns
all the positional messages for iteration

Definition at line 52 of file Result.cpp.

◆ hasMessage()

bool Calculator::Result::hasMessage ( const std::string &  message) const

Convenience to test with message has been set.

Parameters
messageto test
Returns
true if the message is present, otherwise false

Definition at line 43 of file Result.cpp.

◆ hasPositionMessage()

bool Calculator::Result::hasPositionMessage ( const unsigned int  position,
const std::string &  message 
) const

Convenience to test if the positional message has been set at the position.

Parameters
positionto look for message in
messageto look for in position
Returns
true if the message is present at position, otherwise false

Definition at line 56 of file Result.cpp.

◆ toString() [1/2]

std::string Calculator::Result::toString ( ) const
Returns
a string representation of this Result

Definition at line 66 of file Result.cpp.

◆ toString() [2/2]

std::string Calculator::Result::toString ( const std::string &  prefix) const

Create a string representation of this Result with prefix at the start of each line.

Parameters
prefixto put before each line
Returns
string representation

Definition at line 70 of file Result.cpp.


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