inicpp
C++ parser of INI files with schema validation.
inicpp::option Class Reference

#include <option.h>

Public Member Functions

 option ()=delete
 
 option (const option &source)
 
optionoperator= (const option &source)
 
 option (option &&source)
 
optionoperator= (option &&source)
 
 option (const std::string &name, const std::string &value="")
 
 option (const std::string &name, const std::vector< std::string > &values)
 
const std::string & get_name () const
 
option_type get_type () const
 
bool is_list () const
 
template<typename ValueType >
void set (ValueType value)
 
optionoperator= (boolean_ini_t arg)
 
optionoperator= (signed_ini_t arg)
 
optionoperator= (unsigned_ini_t arg)
 
optionoperator= (float_ini_t arg)
 
optionoperator= (const char *arg)
 
optionoperator= (string_ini_t arg)
 
optionoperator= (enum_ini_t arg)
 
template<typename ReturnType >
ReturnType get () const
 
template<typename ValueType >
void set_list (const std::vector< ValueType > &list)
 
template<typename ReturnType >
std::vector< ReturnType > get_list () const
 
template<typename ValueType >
void add_to_list (ValueType value)
 
template<typename ValueType >
void add_to_list (ValueType value, size_t position)
 
template<typename ValueType >
void remove_from_list (ValueType value)
 
void remove_from_list_pos (size_t position)
 
void validate (const option_schema &opt_schema)
 
bool operator== (const option &other) const
 
bool operator!= (const option &other) const
 

Friends

INICPP_API friend std::ostream & operator<< (std::ostream &os, const option &opt)
 

Detailed Description

Represent ini configuration option. Can store one element or list of elements. Stored elements should have only supported types from option_type enum.

Definition at line 141 of file option.h.

Constructor & Destructor Documentation

inicpp::option::option ( )
delete

Default constructor is deleted.

inicpp::option::option ( const option source)

Copy constructor.

Definition at line 5 of file option.cpp.

inicpp::option::option ( option &&  source)

Move constructor.

Definition at line 35 of file option.cpp.

inicpp::option::option ( const std::string &  name,
const std::string &  value = "" 
)

Construct ini option with specified value of specified type.

Parameters
namename of newly created option
valueinitial value

Definition at line 54 of file option.cpp.

inicpp::option::option ( const std::string &  name,
const std::vector< std::string > &  values 
)

Construct ini option with specified value of specified list type.

Parameters
namename of newly created option
valuesinitial value

Definition at line 59 of file option.cpp.

Member Function Documentation

template<typename ValueType >
void inicpp::option::add_to_list ( ValueType  value)
inline

Adds element to internal value list. If option was single value than its transformed to list.

Parameters
valuepushed value
Exceptions
bad_cast_exceptionif ValueType cannot be casted

Definition at line 369 of file option.h.

template<typename ValueType >
void inicpp::option::add_to_list ( ValueType  value,
size_t  position 
)
inline

Add element to list on specified position. If option was single value than its transformed to list.

Parameters
valueadded value
positionposition in internal list
Exceptions
bad_cast_exceptionif ValueType cannot be casted
not_found_exceptionif position is not in internal list

Definition at line 386 of file option.h.

template<typename ReturnType >
ReturnType inicpp::option::get ( ) const
inline

Get single element value. If option value is list, than return first element of array.

Returns
templated copy by value
Exceptions
bad_cast_exceptionif internal type cannot be casted
not_found_exceptionif there is no value

Definition at line 315 of file option.h.

template<typename ReturnType >
std::vector<ReturnType> inicpp::option::get_list ( ) const
inline

Get list of internal values. Returning list is newly created. If option contains single value than its returned list with one element.

Returns
new list of all stored values
Exceptions
bad_cast_exceptionif internal type cannot be casted
not_found_exceptionif there is no value

Definition at line 350 of file option.h.

const std::string & inicpp::option::get_name ( ) const

Gets this option name.

Returns
constant reference to name

Definition at line 67 of file option.cpp.

option_type inicpp::option::get_type ( ) const

Gets current type of inner value.

Returns
current type

Definition at line 72 of file option.cpp.

bool inicpp::option::is_list ( ) const

Determines if option is list or not.

Returns
true if option is list, false otherwise

Definition at line 143 of file option.cpp.

bool inicpp::option::operator!= ( const option other) const

Inequality operator.

Parameters
other
Returns

Definition at line 138 of file option.cpp.

option & inicpp::option::operator= ( const option source)

Copy assignment.

Definition at line 10 of file option.cpp.

option & inicpp::option::operator= ( option &&  source)

Move assignment.

Definition at line 43 of file option.cpp.

option & inicpp::option::operator= ( boolean_ini_t  arg)

Overloaded alias for set() function.

Parameters
argboolean_t
Returns
reference to this

Definition at line 148 of file option.cpp.

option & inicpp::option::operator= ( signed_ini_t  arg)

Overloaded alias for set() function.

Parameters
argsigned_t
Returns
reference to this

Definition at line 156 of file option.cpp.

option & inicpp::option::operator= ( unsigned_ini_t  arg)

Overloaded alias for set() function.

Parameters
argunsigned_t
Returns
reference to this

Definition at line 164 of file option.cpp.

option & inicpp::option::operator= ( float_ini_t  arg)

Overloaded alias for set() function.

Parameters
argfloat_t
Returns
reference to this

Definition at line 172 of file option.cpp.

option & inicpp::option::operator= ( const char *  arg)

Overloaded alias for set() function.

Parameters
argstring_t
Returns
reference to this

Definition at line 180 of file option.cpp.

option & inicpp::option::operator= ( string_ini_t  arg)

Overloaded alias for set() function.

Parameters
argstring_t
Returns
reference to this

Definition at line 188 of file option.cpp.

option & inicpp::option::operator= ( enum_ini_t  arg)

Overloaded alias for set() function.

Parameters
argenum_t
Returns
reference to this

Definition at line 196 of file option.cpp.

bool inicpp::option::operator== ( const option other) const

Equality operator.

Parameters
other
Returns

Definition at line 90 of file option.cpp.

template<typename ValueType >
void inicpp::option::remove_from_list ( ValueType  value)
inline

Remove element with same value as given one.

Parameters
value
Exceptions
bad_cast_exceptionif ValueType cannot be casted

Definition at line 403 of file option.h.

void inicpp::option::remove_from_list_pos ( size_t  position)

Remove list element on specified position.

Parameters
position
Exceptions
not_found_exceptionin case of out of range

Definition at line 77 of file option.cpp.

template<typename ValueType >
void inicpp::option::set ( ValueType  value)
inline

Set single element value. If option cointaned list of values, than its transformed to single value.

Parameters
valuenewly assigned option value

Definition at line 261 of file option.h.

template<typename ValueType >
void inicpp::option::set_list ( const std::vector< ValueType > &  list)
inline

Set internal list of values to given one. If option contained single value than its transformed to list with given values.

Parameters
listreference to list of new values
Exceptions
bad_cast_exceptionif ValueType cannot be casted to internal type

Definition at line 333 of file option.h.

void inicpp::option::validate ( const option_schema opt_schema)

Validate this option against given option_schema.

Parameters
opt_schemavalidation schema
Exceptions
validation_exceptionif error occured

Definition at line 85 of file option.cpp.

Friends And Related Function Documentation

INICPP_API friend std::ostream& operator<< ( std::ostream &  os,
const option opt 
)
friend

Classic stream operator for printing this instance to output stream.

Parameters
osoutput stream
optreference to option instance to be written
Returns
reference to output stream which allows chaining

Definition at line 272 of file option.cpp.


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