cgv
Loading...
Searching...
No Matches
cgv::gui::property_string Class Reference

A convenience class for compiling strings of delimited key-value pairs useful for defining GUI control options. More...

#include <property_string.h>

Public Member Functions

 property_string (const std::string &key_value_delimiter="=", const std::string &property_delimiter=";")
 Construct a new empty property string using the given delimiters.
 
bool empty () const
 Check if empty.
 
void clear ()
 Clear content.
 
template<typename T >
void add (const std::string &key, T value)
 Add key-value pair to end of content, converting value to string.
 
template<typename T >
void add_bracketed (const std::string &key, const T value, char bracket='\'')
 See add.
 
template<typename T >
void add_bracketed (const std::string &key, const T value, char opening_bracket, char closing_bracket)
 See add.
 
 operator std::string () const
 Implicit conversion to std::string.
 

Detailed Description

A convenience class for compiling strings of delimited key-value pairs useful for defining GUI control options.

Both the key-value and the pair delimiters can be set separately. Instances of this class are implicitly convertible to string.

Usage: cgv::gui::property_string options; // using default delimiters options.add("width", 100); options.add("active", "true"); options.add_bracketed("label", "Example");

// use as string with implicit conversion std::string str = options;

Results in: "width=100;active=true;label='Example'"

Definition at line 24 of file property_string.h.

Constructor & Destructor Documentation

◆ property_string()

cgv::gui::property_string::property_string ( const std::string &  key_value_delimiter = "=",
const std::string &  property_delimiter = ";" 
)
inline

Construct a new empty property string using the given delimiters.

Parameters
key_value_delimiterThe delimiter used between key and value.
property_delimiterThe delimiter used between key-value pairs (properties).

Definition at line 89 of file property_string.h.

Member Function Documentation

◆ add()

template<typename T >
void cgv::gui::property_string::add ( const std::string &  key,
value 
)
inline

Add key-value pair to end of content, converting value to string.

Template Parameters
TThe value type.
Parameters
keyThe key string.
valueThe value.

Definition at line 110 of file property_string.h.

Referenced by cgv::gui::directory_helper::create_gui(), and cgv::gui::file_helper::create_gui().

◆ add_bracketed() [1/2]

template<typename T >
void cgv::gui::property_string::add_bracketed ( const std::string &  key,
const T  value,
char  bracket = '\'' 
)
inline

See add.

Enclose value in given bracket.

Template Parameters
TThe value type.
Parameters
keyThe key string.
valueThe value.
bracketThe bracket character used to enclose the value.

Definition at line 121 of file property_string.h.

Referenced by cgv::gui::directory_helper::create_gui(), and cgv::gui::file_helper::create_gui().

◆ add_bracketed() [2/2]

template<typename T >
void cgv::gui::property_string::add_bracketed ( const std::string &  key,
const T  value,
char  opening_bracket,
char  closing_bracket 
)
inline

See add.

Enclose value in given bracket.

Template Parameters
TThe value type.
Parameters
keyThe key string.
valueThe value.
bracketThe bracket character used to enclose the value.

Definition at line 133 of file property_string.h.

◆ clear()

void cgv::gui::property_string::clear ( )
inline

Clear content.

Definition at line 100 of file property_string.h.

◆ empty()

bool cgv::gui::property_string::empty ( ) const
inline

Check if empty.

Returns
True if empty, false otherwise.

Definition at line 95 of file property_string.h.

◆ operator std::string()

cgv::gui::property_string::operator std::string ( ) const
inline

Implicit conversion to std::string.

Definition at line 139 of file property_string.h.


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