SDL2lazy
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SlValueParser Class Reference

#include <SlValueParser.h>

Public Member Functions

 SlValueParser (int width, int height)
 
 SlValueParser ()
 
 ~SlValueParser ()
 
SlValueParser & operator= (const SlValueParser &rhs)
 
 SlValueParser (const SlValueParser &toCopy)
 
void doubleFromString (const std::string &value, double &i)
 
void parseFormula (const std::vector< std::string > &stringValues, unsigned int &i, double &value)
 
void setDimensions (const int &width, const int &height)
 
void stringsToDoubles (const std::vector< std::string > &stringValues, double *values, unsigned int length)
 
template<typename T >
void stringsToNumbers (const std::vector< std::string > &stringValues, T *array, unsigned int length)
 
bool stringsToRenderOptions (const std::vector< std::string > &stringValues, int &options)
 
int screenWidth ()
 
int screenHeight ()
 

Private Member Functions

std::string assembleFormula (const std::vector< std::string > &stringValues, unsigned int &i)
 
double calculateFormula (std::queue< SlFormulaItem > &outputQueue)
 
SlFormulaItem getNextItem (std::string &formula)
 
std::queue< SlFormulaItem > shuntFormula (std::string &formula)
 

Private Attributes

int screen_width_ = 0
 
int screen_height_ = 0
 

Detailed Description

Translate string input from configuration files to int output.

Constructor & Destructor Documentation

SlValueParser::SlValueParser ( int  width,
int  height 
)

screen_width_ and screen_height_ are set in the constructor.

SlValueParser::SlValueParser ( )
inline

Default constructor

SlValueParser::~SlValueParser ( )
inline

Default destructor

SlValueParser::SlValueParser ( const SlValueParser &  toCopy)

Copy constructor.

Member Function Documentation

std::string SlValueParser::assembleFormula ( const std::vector< std::string > &  stringValues,
unsigned int &  i 
)
private

Generates the formula string from stringValues.

Exceptions
std::invalid_argumentif the end of the formula can't be found.

< already determined position 0 is '"'

< Remove trailing '"'

< This is where stringsToInts will continue

double SlValueParser::calculateFormula ( std::queue< SlFormulaItem > &  outputQueue)
private

Uses the outputQueue from shuntFormula() to calculate the result of the equation.

Exceptions
std::runtime_errorif the items in the provided queue do not match the expected Reverse Polish notation or if an unknown operator is encountered.

< number

< need two numbers to use operator

void SlValueParser::doubleFromString ( const std::string &  value,
double &  i 
)

Returns the double value for a string. Understands SCREEN_WIDTH and SCREEN_HEIGHT.

Exceptions
std::runtime_errorif the string can't be converted to double.

< account for unary -

SlFormulaItem SlValueParser::getNextItem ( std::string &  formula)
private

Extracts the next item from the given string, and cuts the corresponding part from the input string.

SlValueParser & SlValueParser::operator= ( const SlValueParser &  rhs)

Assignment.

void SlValueParser::parseFormula ( const std::vector< std::string > &  stringValues,
unsigned int &  i,
double &  value 
)

Calculates the results of a formula (only + and - implemented).

Exceptions
std::invalid_argumentif the formula can't be calculated (unknown operator).
int SlValueParser::screenHeight ( )
inline

Window height.

int SlValueParser::screenWidth ( )
inline

Window width.

void SlValueParser::setDimensions ( const int &  width,
const int &  height 
)

Sets the values used for keywords SCREEN_WIDTH, SCREEN_HEIGHT.

std::queue< SlFormulaItem > SlValueParser::shuntFormula ( std::string &  formula)
private

Parses equation from assembleFormula() in infix notation and sorts it into Reverse Polish notation.

< Check for leading unary -.

< Leading unary - (or plus)

< Should be '(' on top, discard.

void SlValueParser::stringsToDoubles ( const std::vector< std::string > &  stringValues,
double *  values,
unsigned int  length 
)

Takes a vector of strings, converts the strings to ints and returns them as an array.

Exceptions
std::invalid_argumentif the size of stringValues is less than length, i.e. to few parameters given.

Skip trailing whitespace at end of line otherwise causes exception.

template<typename T >
void SlValueParser::stringsToNumbers ( const std::vector< std::string > &  stringValues,
T *  array,
unsigned int  length 
)

Takes a vector of strings, converts the strings to type T (floating point or integer types) and returns them as an array.

bool SlValueParser::stringsToRenderOptions ( const std::vector< std::string > &  stringValues,
int &  options 
)

Translates strings into SlRenderOptions.

Member Data Documentation

int SlValueParser::screen_height_ = 0
private

Screen dimensions are needed to define a texture as having the dimensions of the window.

int SlValueParser::screen_width_ = 0
private

Screen dimensions are needed to define a texture as having the dimensions of the window.


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