Flatland
Public Types | Public Member Functions | Public Attributes | List of all members
flatland_server::YamlReader Class Reference
Collaboration diagram for flatland_server::YamlReader:
Collaboration graph
[legend]

Public Types

enum  NodeTypeCheck { MAP, LIST, NO_CHECK }
 

Public Member Functions

 YamlReader ()
 Default constructor for yaml reader, initialize with a empty yaml Node.
 
 YamlReader (const YAML::Node &node)
 Constructor with a given node. More...
 
 YamlReader (const std::string &path)
 Constructor with a given path to a yaml file, throws exception on failure. More...
 
void SetErrorInfo (std::string entry_location, std::string entry_name="")
 Use this method to set the entry location and entry name for error message purposes. More...
 
void SetFile (const std::string &file_path)
 Use this method to set the file location of the yaml node. More...
 
void EnsureAccessedAllKeys ()
 This method checks all keys in the yaml node are used, otherwise it throws an exception.
 
YAML::Node Node ()
 
bool IsNodeNull ()
 
int NodeSize ()
 
YamlReader Subnode (int index, NodeTypeCheck type_check, std::string sub_node_location="")
 Get one of the subnode using a index, throws exception on failure, file path is inherited from the parent. More...
 
YamlReader Subnode (const std::string &key, NodeTypeCheck type_check, std::string sub_node_location="")
 Get one of the subnode using a key, throws exception on failure, file path is inherited from the parent. More...
 
YamlReader SubnodeOpt (const std::string &key, NodeTypeCheck type_check, std::string sub_node_location="")
 Optionally get one of the subnode using a key, throws exception on failure, file path is inherited from the parent. More...
 
template<typename T >
As ()
 Convert the current node in yaml reader to a given template type. It uses yaml-cpp's as<T>() function, you could specify conversion for custom datatypes using yaml cpp's documented ways, this method throws exception on failure. More...
 
template<typename T >
std::vector< T > AsList (int min_size, int max_size)
 Convert the current node to a list of given type, throws exception on failure. More...
 
template<typename T , int N>
std::array< T, N > AsArray ()
 Convert the current node to a array of given type, throws exception on failure. More...
 
template<typename T >
Get (const std::string &key)
 Get subnode with a given key and converted to the given type, throws on failure. More...
 
template<typename T >
Get (const std::string &key, const T &default_val)
 Optionally get subnode with a given key and converted to the given type, throws on failure. More...
 
template<typename T >
std::vector< T > GetList (const std::string &key, int min_size, int max_size)
 Get subnode with a given key and converted to list of the given type, throws on failure. More...
 
template<typename T >
std::vector< T > GetList (const std::string &key, const std::vector< T > default_val, int min_size, int max_size)
 Optionally get subnode with a given key and converted to list of the given type, throws on failure. More...
 
template<typename T , int N>
std::array< T, N > GetArray (const std::string &key)
 Get subnode with a given key and converted to array of the given type, throws on failure. More...
 
template<typename T , int N>
std::array< T, N > GetArray (const std::string &key, const std::array< T, N > default_val)
 Optionally get subnode with a given key and converted to array of a given type, throws on failure. More...
 
Vec2 GetVec2 (const std::string &key)
 
Vec2 GetVec2 (const std::string &key, const Vec2 &default_val)
 
Color GetColor (const std::string &key, const Color &default_val)
 
Pose GetPose (const std::string &key)
 
Pose GetPose (const std::string &key, const Pose &default_val)
 

Public Attributes

YAML::Node node_
 The YAML Node this processes.
 
std::set< std::string > accessed_keys_
 
std::string filename_
 < location of the entry, used to show where the error come from More...
 
std::string file_path_
 
std::string entry_location_
 name of the yaml entry, used to show where the error come from
 
std::string entry_name_
 
std::string fmt_in_
 formatted entry location for display
 
std::string fmt_name_
 formatted entry location for display
 

Constructor & Destructor Documentation

flatland_server::YamlReader::YamlReader ( const YAML::Node &  node)

Constructor with a given node.

Parameters
[in]nodeA Yaml node to get data from
flatland_server::YamlReader::YamlReader ( const std::string &  path)

Constructor with a given path to a yaml file, throws exception on failure.

Parameters
[in]pathPath to the yaml file

Member Function Documentation

template<typename T >
T flatland_server::YamlReader::As ( )

Convert the current node in yaml reader to a given template type. It uses yaml-cpp's as<T>() function, you could specify conversion for custom datatypes using yaml cpp's documented ways, this method throws exception on failure.

Returns
The value after conversion.
template<typename T , int N>
std::array< T, N > flatland_server::YamlReader::AsArray ( )

Convert the current node to a array of given type, throws exception on failure.

Returns
Array of given type
template<typename T >
std::vector< T > flatland_server::YamlReader::AsList ( int  min_size,
int  max_size 
)

Convert the current node to a list of given type, throws exception on failure.

Returns
List of given type
template<typename T >
T flatland_server::YamlReader::Get ( const std::string &  key)

Get subnode with a given key and converted to the given type, throws on failure.

Parameters
[in]keyKey to access the subnode
Returns
Value of the converted subnode
template<typename T >
T flatland_server::YamlReader::Get ( const std::string &  key,
const T &  default_val 
)

Optionally get subnode with a given key and converted to the given type, throws on failure.

Parameters
[in]keyKey to access the subnode
[in]default_valDefault value
Returns
Value of the converted subnode, or default value if node with key does not exist
template<typename T , int N>
std::array< T, N > flatland_server::YamlReader::GetArray ( const std::string &  key)

Get subnode with a given key and converted to array of the given type, throws on failure.

Parameters
[in]keyKey to access the subnode
Returns
Value of the converted subnode
template<typename T , int N>
std::array< T, N > flatland_server::YamlReader::GetArray ( const std::string &  key,
const std::array< T, N >  default_val 
)

Optionally get subnode with a given key and converted to array of a given type, throws on failure.

Parameters
[in]keyKey to access the subnode
[in]default_valDefault value
Returns
Value of the converted subnode
Color flatland_server::YamlReader::GetColor ( const std::string &  key,
const Color default_val 
)
Returns
A Color value accessed by a given key, or default value if key does not exist
template<typename T >
std::vector< T > flatland_server::YamlReader::GetList ( const std::string &  key,
int  min_size,
int  max_size 
)

Get subnode with a given key and converted to list of the given type, throws on failure.

Parameters
[in]keyKey to access the subnode
[in]min_sizeMinimum size of the list, -1 to ignore
[in]max_sizeMaximum size of the list, -1 to ignore
Returns
Value of the converted subnode
template<typename T >
std::vector< T > flatland_server::YamlReader::GetList ( const std::string &  key,
const std::vector< T >  default_val,
int  min_size,
int  max_size 
)

Optionally get subnode with a given key and converted to list of the given type, throws on failure.

Parameters
[in]keyKey to access the subnode
[in]default_valDefault value
[in]min_sizeMinimum size of the list, -1 to ignore
[in]max_sizeMaximum size of the list, -1 to ignore
Returns
Value of the converted subnode
Pose flatland_server::YamlReader::GetPose ( const std::string &  key)
Returns
A Pose value accessed by a given key
Pose flatland_server::YamlReader::GetPose ( const std::string &  key,
const Pose default_val 
)
Returns
A Pose value accessed by a given key, or default value if key does not exist
Vec2 flatland_server::YamlReader::GetVec2 ( const std::string &  key)
Returns
A Vec2 accessed by a given key
Vec2 flatland_server::YamlReader::GetVec2 ( const std::string &  key,
const Vec2 default_val 
)
Returns
A Vec2 accessed by a given key, or default value if key does not exist
bool flatland_server::YamlReader::IsNodeNull ( )
Returns
If the node is null, a.k.a if it is empty
YAML::Node flatland_server::YamlReader::Node ( )
Returns
The yaml cpp Yaml Node
int flatland_server::YamlReader::NodeSize ( )
Returns
The number of subnodes in the node, a.k.a size of the node
void flatland_server::YamlReader::SetErrorInfo ( std::string  entry_location,
std::string  entry_name = "" 
)

Use this method to set the entry location and entry name for error message purposes.

Parameters
[in]entry_locationLocation of the entry, use "_NONE_" for no entry, empty string indicates keep current value
[in]entry_nameName of the entry, optional, use "_NONE_" for no entry, empty string indicates keep current value
void flatland_server::YamlReader::SetFile ( const std::string &  file_path)

Use this method to set the file location of the yaml node.

Parameters
[in]file_pathpath to the file, use "_NONE_" for empty string, file_path with empty string will keep current path
YamlReader flatland_server::YamlReader::Subnode ( int  index,
NodeTypeCheck  type_check,
std::string  sub_node_location = "" 
)

Get one of the subnode using a index, throws exception on failure, file path is inherited from the parent.

Parameters
[in]indexIndex of the subnode
[in]type_checkCheck if the type of the subnode, i.e. list or map
[in]sub_node_locationThe error location of the subnode, optional, if not provided or a given an empty string, it will generate the location using its parents entry location and entry name. It also accepts "_NONE_"
Returns
YamlReader of the sub node
YamlReader flatland_server::YamlReader::Subnode ( const std::string &  key,
NodeTypeCheck  type_check,
std::string  sub_node_location = "" 
)

Get one of the subnode using a key, throws exception on failure, file path is inherited from the parent.

Parameters
[in]keyKey of the subnode
[in]type_checkCheck if the type of the subnode, i.e. list or map
[in]sub_node_locationThe error location of the subnode, optional, if not provided or a given an empty string, it will generate the location using its parents entry location and entry name. It also accepts "_NONE_"
Returns
YamlReader of the sub node
YamlReader flatland_server::YamlReader::SubnodeOpt ( const std::string &  key,
NodeTypeCheck  type_check,
std::string  sub_node_location = "" 
)

Optionally get one of the subnode using a key, throws exception on failure, file path is inherited from the parent.

Parameters
[in]keyKey of the subnode
[in]type_checkCheck if the type of the subnode, i.e. list or map
[in]sub_node_locationThe error location of the subnode, optional, if not provided or a given an empty string, it will generate the location using its parents entry location and entry name. It also accepts "_NONE_"
Returns
YamlReader of the sub node, or a YamlReader of a empty node if a node with the given key does not exist

Member Data Documentation

std::string flatland_server::YamlReader::filename_

< location of the entry, used to show where the error come from

Records of the keys processed


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