Turi Create  4.0
INI Utilities

Simple ini parsing utilities. More...

Functions

template<typename T >
std::vector< T > turi::ini::read_sequence_section (const boost::property_tree::ptree &data, std::string key, size_t expected_elements)
 
template<typename T >
std::map< std::string, T > turi::ini::read_dictionary_section (const boost::property_tree::ptree &data, std::string key)
 
template<typename T >
void turi::ini::write_sequence_section (boost::property_tree::ptree &data, const std::string &key, const std::vector< T > &values)
 
template<typename T >
void turi::ini::write_dictionary_section (boost::property_tree::ptree &data, const std::string &key, const std::map< std::string, T > &values)
 

Detailed Description

Simple ini parsing utilities.

Function Documentation

◆ read_dictionary_section()

template<typename T >
std::map<std::string, T> turi::ini::read_dictionary_section ( const boost::property_tree::ptree &  data,
std::string  key 
)

Reads a key in an ini/json file as a dictionary of values. In the ini file this will be represented as

[key] fish = "hello" and = "pika" chips = "chu"

In a JSON file this will be represented as {"fish":"hello", "and":"pika", "chips":"chu"}

This will return a 3 element map containing {"fish":"hello", "and":"pika", "chips":"chu"}.

See also
write_dictionary_section

Definition at line 99 of file boost_property_tree_utils.hpp.

◆ read_sequence_section()

template<typename T >
std::vector<T> turi::ini::read_sequence_section ( const boost::property_tree::ptree &  data,
std::string  key,
size_t  expected_elements 
)

Reads a key in an ini/json file as a sequence of values. In the ini file this will be represented as

[key] 0000 = "hello" 0001 = "pika" 0002 = "chu"

But in a JSON file this could be {"0000":"hello","0001":"pika","0002":"chu"} or ["hello","pika","chu"] depending on which writer is used. (The boost property tree writer will create the first, a regular JSON writer will create the second).

This will return a 3 element vector containing {"hello", "pika", "chu"}

See also
write_sequence_section

Definition at line 48 of file boost_property_tree_utils.hpp.

◆ write_dictionary_section()

template<typename T >
void turi::ini::write_dictionary_section ( boost::property_tree::ptree &  data,
const std::string &  key,
const std::map< std::string, T > &  values 
)

Writes a dictionary of values into an ini file as a section. For instance, given a 3 element map containing {"fish":"hello", "and":"pika", "chips":"chu"}.

In the ini file this will be represented as:

[key] fish = "hello" and = "pika" chips = "chu"

See also
read_dictionary_section

Definition at line 161 of file boost_property_tree_utils.hpp.

◆ write_sequence_section()

template<typename T >
void turi::ini::write_sequence_section ( boost::property_tree::ptree &  data,
const std::string &  key,
const std::vector< T > &  values 
)

Writes a vector of values into an ini file as a section.

For instance, given a 3 element vector containing {"hello", "pika", "chu"} The vector be represented as

[key] 0000 = "hello" 0001 = "pika" 0002 = "chu"

See also
read_sequence_section

Definition at line 133 of file boost_property_tree_utils.hpp.