bpp-core  2.2.0
bpp::KeyvalTools Class Reference

Tools to deal with the keyval syntax. More...

#include <Bpp/Text/KeyvalTools.h>

Public Member Functions

 KeyvalTools ()
 
virtual ~KeyvalTools ()
 

Static Public Member Functions

static void singleKeyval (const std::string &desc, std::string &key, std::string &val, const std::string &split="=") throw (KeyvalException)
 Split a string into a key and a value (General purpose function). More...
 
static void multipleKeyvals (const std::string &desc, std::map< std::string, std::string > &keyvals, const std::string &split=",", bool nested=true) throw (KeyvalException)
 Split a string into several keys and corresponding values (General purpose function). More...
 
static void parseProcedure (const std::string &desc, std::string &name, std::map< std::string, std::string > &args) throw (KeyvalException)
 Parse (not recursively) a procedure string. More...
 

Detailed Description

Tools to deal with the keyval syntax.

This class contains method to deal with parameter=value syntax procedure. A keyval procedure takes the form

proc(p1=v1,p2=v2,p3=v3,etc)

where 'p' are parameter names, and 'v' are the corresponding values. These values can be nested keyval procedures.

Definition at line 74 of file KeyvalTools.h.

Constructor & Destructor Documentation

◆ KeyvalTools()

bpp::KeyvalTools::KeyvalTools ( )

◆ ~KeyvalTools()

virtual bpp::KeyvalTools::~KeyvalTools ( )
virtual

Member Function Documentation

◆ multipleKeyvals()

void KeyvalTools::multipleKeyvals ( const std::string &  desc,
std::map< std::string, std::string > &  keyvals,
const std::string &  split = ",",
bool  nested = true 
)
throw (KeyvalException
)
static

Split a string into several keys and corresponding values (General purpose function).

Parameters
desc[in] A string descibing the keyval, with format key1=val1,key2=val2,etc (space are considered normal character, that's up to you to deal with that afterward!).
keyvals[out] Will contain the text of the keys and their corresponding values.
split[in] The keyval delimiter.the default is a coma, but a space character can be used for instance.
nested[in] Tell if nested keyval procedures are expected.
Exceptions
KeyvalExceptionIf the syntax describing the keyval is not correct.

Definition at line 58 of file KeyvalTools.cpp.

References bpp::StringTokenizer::hasMoreToken(), bpp::StringTokenizer::nextToken(), and bpp::TextTools::removeSurroundingWhiteSpaces().

Referenced by bpp::NumCalcApplicationTools::getVector().

◆ parseProcedure()

void KeyvalTools::parseProcedure ( const std::string &  desc,
std::string &  name,
std::map< std::string, std::string > &  args 
)
throw (KeyvalException
)
static

Parse (not recursively) a procedure string.

Parameters
desc[in] A string descibing the keyval procedure.
name[out] Outputs the name of the procedure.
args[out] Fills a map with all keys and values for parameters.
Exceptions
KeyvalExceptionIf the description is invalid (one parenthesis is missing for instance).

Definition at line 98 of file KeyvalTools.cpp.

References bpp::TextTools::isEmpty(), and bpp::TextTools::removeFirstWhiteSpaces().

Referenced by bpp::BppODiscreteDistributionFormat::read().

◆ singleKeyval()

void KeyvalTools::singleKeyval ( const std::string &  desc,
std::string &  key,
std::string &  val,
const std::string &  split = "=" 
)
throw (KeyvalException
)
static

Split a string into a key and a value (General purpose function).

Parameters
desc[in] A string descibing the keyval, with format key=val (space are considered normal character, that's up to you to deal with that afterward!).
key[out] Will contain the text of the key.
val[out] Will contain the text of the value.
split[in] The delimiter. Default is '=' but ':' can be used.
Exceptions
KeyvalExceptionIf the syntax describing the keyval is not correct.

Definition at line 49 of file KeyvalTools.cpp.


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