Serial-TCP/IPbridge  1.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Config Class Reference

Base class for all configuration classes. More...

#include <config.h>

Inheritance diagram for Config:
SerialConfig TCPIPConfig

Classes

class  InvalidValueError
 This exception should be thrown if some configuration value is invalid. More...
 

Public Types

typedef std::map< std::string,
std::string > 
RawConfigValues
 Raw configuration option -> values mapping. More...
 
typedef size_t BufferSize
 Buffer size type. More...
 
typedef unsigned LengthField
 Length field type. More...
 
typedef std::tr1::uint32_t LengthFieldMessageLength
 Message length type when using length field. More...
 

Public Member Functions

 ~Config ()
 Destructor. More...
 
 Config (const Config &other)
 Copy constructor. More...
 
Configoperator= (const Config &other)
 Assignment operator. More...
 
bool operator== (const Config &other) const
 Equality comparison. More...
 
bool operator!= (const Config &other) const
 Non-equality comparison. More...
 
void swap (Config &other)
 Swap the contents of this object with the other object. More...
 
size_t getBufferSize () const
 Returns the buffer size (in bytes). More...
 
LengthField getLengthField () const
 Returns the size of a field containing the length of a message (in bytes). More...
 

Static Public Member Functions

static Config fromRawConfigValues (RawConfigValues rawConfigValues)
 Creates a Config object from raw configuration values. More...
 
static LengthFieldMessageLength binaryFieldLengthToNumber (const std::string &binaryNumber)
 Transforms the selected binary string into a number. More...
 
static LengthFieldMessageLength computeMaximalMessageLength (unsigned lengthField)
 Returns the maximal message size that can be stored in lengthField bytes. More...
 
static std::string messageLengthToBinaryLengthField (LengthFieldMessageLength messageLength, unsigned lengthField)
 Transforms the selected message length into a binary length field string. More...
 

Protected Member Functions

 Config ()
 Default constructor. More...
 
 Config (RawConfigValues rawConfigValues)
 Constructor. More...
 

Static Protected Member Functions

template<typename T >
static T parseNumber (const std::string &optionName, const std::string &rawValue, T minValue, T maxValue)
 Parses the selected number from the selected string. More...
 

Static Private Member Functions

static BufferSize parseBufferSize (const std::string &rawBufferSize)
 
static LengthField parseLengthField (const std::string &rawLengthField)
 

Private Attributes

BufferSize _bufferSize
 Buffer size (in bytes). More...
 
LengthField _lengthField
 Size of a field containing the length of a message (in bytes). More...
 

Static Private Attributes

static const BufferSize DEFAULT_BUFFER_SIZE
 Default buffer size (in bytes). More...
 
static const LengthField DEFAULT_LENGTH_FIELD
 Default length field (in bytes). More...
 

Detailed Description

Base class for all configuration classes.

Subclasses should provide value semantics (object copying and comparison should be allowed).

Member Typedef Documentation

typedef size_t Config::BufferSize

Buffer size type.

typedef unsigned Config::LengthField

Length field type.

typedef std::tr1::uint32_t Config::LengthFieldMessageLength

Message length type when using length field.

typedef std::map<std::string, std::string> Config::RawConfigValues

Raw configuration option -> values mapping.

Constructor & Destructor Documentation

Config::~Config ( )

Destructor.

Destroys a Config object.

Config::Config ( const Config other)

Copy constructor.

Parameters
otherObject that will be used as a model in the object creation.

Constructs a copy of the other object.

Config::Config ( )
protected

Default constructor.

Constructs an empty Config object.

Config::Config ( RawConfigValues  rawConfigValues)
protected

Constructor.

Parameters
rawConfigValuesRaw configuration option -> values mappings.

Constructs a Config object from the selected values.

Member Function Documentation

static LengthFieldMessageLength Config::binaryFieldLengthToNumber ( const std::string &  binaryNumber)
static

Transforms the selected binary string into a number.

Parameters
binaryNumberBinary field length value in a string.
Returns
Numeral representation of binaryNumber (host byte order).

Preconditions:

  • 1 <= binaryNumber.size() <= sizeof(LengthFieldMessageLength)
  • binaryNumber must be in network byte order (i.e. read from a socket)
static LengthFieldMessageLength Config::computeMaximalMessageLength ( unsigned  lengthField)
static

Returns the maximal message size that can be stored in lengthField bytes.

Parameters
lengthFieldSize of the length field.

Preconditions:

static Config Config::fromRawConfigValues ( RawConfigValues  rawConfigValues)
static

Creates a Config object from raw configuration values.

Parameters
rawConfigValuesRaw configuration option -> values mappings.

If some passed value is invalid, InvalidValueError will be thrown.

Preconditions:

  • each option name and value must be without beginning and trailing white spaces

Meets the strong guarantee of exception safety.

size_t Config::getBufferSize ( ) const
inline

Returns the buffer size (in bytes).

References _bufferSize.

LengthField Config::getLengthField ( ) const
inline

Returns the size of a field containing the length of a message (in bytes).

References _lengthField.

static std::string Config::messageLengthToBinaryLengthField ( LengthFieldMessageLength  messageLength,
unsigned  lengthField 
)
static

Transforms the selected message length into a binary length field string.

Parameters
messageLengthLength of the message.
lengthFieldLength field value (returned from getLengthField()).
Returns
Binary representation of messageLength in a string (network byte order).

Precodnitions:

  • messageLength must fit into lengthField bytes
  • lengthField must have been returned by getLengthField()

Postconditions:

  • size of returned string will be lengthField.
bool Config::operator!= ( const Config other) const

Non-equality comparison.

Parameters
otherObject that will be compared with this object.
Returns
True if this object is not equal to the other object.
Config& Config::operator= ( const Config other)

Assignment operator.

Parameters
otherObject that will be assigned to this object.
Returns
Reference to this object.

Guarantees the strong exception safety.

bool Config::operator== ( const Config other) const

Equality comparison.

Parameters
otherObject that will be compared with this object.
Returns
True if this object is equal to the other object.
static BufferSize Config::parseBufferSize ( const std::string &  rawBufferSize)
staticprivate
static LengthField Config::parseLengthField ( const std::string &  rawLengthField)
staticprivate
template<typename T >
static T Config::parseNumber ( const std::string &  optionName,
const std::string &  rawValue,
minValue,
maxValue 
)
inlinestaticprotected

Parses the selected number from the selected string.

Parameters
optionNameName of the option.
rawValueNumber value in a string.
minValueMinimal valid number value.
maxValueMaximal valid number value.
Returns
Number that corresponds to the selected string.

If there is some error, InvalidValueError will be thrown.

References strToNum(), and toString().

void Config::swap ( Config other)

Swap the contents of this object with the other object.

Parameters
otherObject that will be swapped with this object.

Guarantees nothrow exception safety.

Member Data Documentation

BufferSize Config::_bufferSize
private

Buffer size (in bytes).

Referenced by getBufferSize().

LengthField Config::_lengthField
private

Size of a field containing the length of a message (in bytes).

Referenced by getLengthField().

const BufferSize Config::DEFAULT_BUFFER_SIZE
staticprivate

Default buffer size (in bytes).

const LengthField Config::DEFAULT_LENGTH_FIELD
staticprivate

Default length field (in bytes).


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