Bayeux  3.4.1
Core Foundation library for SuperNEMO
Public Types | Public Member Functions | Static Public Member Functions | List of all members
datatools::properties::config Class Reference

Class for ASCII file I/O operations with properties objects. More...

#include <bayeux/datatools/properties.h>

Public Types

enum  decoration_mode_type {
  MODE_BARE = 0, MODE_HEADER_FOOTER = 1, MODE_DEFAULT = MODE_BARE, mode_bare = MODE_BARE,
  mode_header_footer = MODE_HEADER_FOOTER
}
 Decoration mode. More...
 
enum  options_flag {
  SKIP_PRIVATE = bit_mask::bit00, FORBID_VARIANTS = bit_mask::bit01, LOG_MUTE = bit_mask::bit02, LOG_DEBUG = bit_mask::bit03,
  LOG_TRACE = bit_mask::bit04, SMART_MODULO = bit_mask::bit05, HEADER_FOOTER = bit_mask::bit06, REQUESTED_TOPIC = bit_mask::bit07,
  FORBID_INCLUDES = bit_mask::bit08, DONT_CLEAR = bit_mask::bit09, RESOLVE_PATH = bit_mask::bit10, ALLOW_KEY_OVERRIDE = bit_mask::bit11,
  LOG_WARNING = bit_mask::bit12
}
 Option flags used at construction. More...
 

Public Member Functions

 config (uint32_t options_=0, const std::string &topic_="", const std::string &section_name_="", int section_start_line_number_=-1)
 Constructor. More...
 
virtual ~config ()
 Destructor. More...
 
datatools::logger::priority get_logging () const
 Return the logging priority threshold. More...
 
void set_logging (datatools::logger::priority)
 Set the logging priority threshold. More...
 
void read (std::istream &in_, properties &prop_)
 
void read (const std::string &in_, properties &prop_)
 Read a properties container from an input file. More...
 
void write (std::ostream &out_, const properties &prop_)
 Write a properties container to an output stream. More...
 
void write (const std::string &filename_, const properties &prop_)
 Write a properties container to an output file. More...
 
int get_current_line_number () const
 Return the current value of the line counter. More...
 
void set_reader_input (const std::string &filename_, int line_count_=-1)
 Set the filename and the line counter before parsing. More...
 
bool has_topic () const
 Check if topic is set. More...
 
void set_topic (const std::string &topic_)
 Set the topic that should be matched. More...
 
const std::string & get_topic () const
 Return the topic. More...
 
bool has_section_info () const
 Check if section info is set. More...
 
void set_section_info (const std::string &section_name_, int section_start_line_number_)
 Set the section info. More...
 
void reset_section_info ()
 Reset the section info. More...
 
const std::string & get_section_name () const
 Return the section. More...
 
int get_section_start_line_number () const
 Return the section start line. More...
 
void reset ()
 Reset. More...
 
void write_metacomment (std::ostream &out_, const std::string &tag_, const std::string &value_="", const std::string &comment_="")
 Write metacomment. More...
 
void write_data (std::ostream &out_, const std::string &data_key_, const properties::data &prop_data_, const std::string &unit_symbol_="", const std::string &unit_label_="", const std::string &comment_="")
 Write a property data. More...
 

Static Public Member Functions

static const std::string & lock_decorator ()
 
static const std::string & as_directive ()
 
static const std::string & in_directive ()
 
static const std::string & path_decorator ()
 
static const std::string & metacomment_prefix ()
 

Detailed Description

Class for ASCII file I/O operations with properties objects.

Member Enumeration Documentation

◆ decoration_mode_type

Decoration mode.

Deprecated:
is replaced by the dedicated options_flag (HEADER_FOOTER) in constructor.
Enumerator
MODE_BARE 

No decoration.

MODE_HEADER_FOOTER 

Header/footer decoration.

MODE_DEFAULT 

Default decoration mode.

mode_bare 
mode_header_footer 

◆ options_flag

Option flags used at construction.

Enumerator
SKIP_PRIVATE 

Skip private properties bit.

FORBID_VARIANTS 

Forbid variant directives bit.

LOG_MUTE 

Mute mode activation bit.

LOG_DEBUG 

Debug mode activation bit.

LOG_TRACE 

Trace mode activation bit.

SMART_MODULO 

Use smart modulo (write)

HEADER_FOOTER 

Use header/footer (write)

REQUESTED_TOPIC 

Requested topic (read/write)

FORBID_INCLUDES 

Forbid include directives bit.

DONT_CLEAR 

Don't clear before parsing bit (read)

RESOLVE_PATH 

Resolve path for input filename (read/write)

ALLOW_KEY_OVERRIDE 

Allow key override (write)

LOG_WARNING 

Warning mode activation bit.

Constructor & Destructor Documentation

◆ config()

datatools::properties::config::config ( uint32_t  options_ = 0,
const std::string &  topic_ = "",
const std::string &  section_name_ = "",
int  section_start_line_number_ = -1 
)

Constructor.

◆ ~config()

virtual datatools::properties::config::~config ( )
virtual

Destructor.

Member Function Documentation

◆ as_directive()

static const std::string& datatools::properties::config::as_directive ( )
static

◆ get_current_line_number()

int datatools::properties::config::get_current_line_number ( ) const

Return the current value of the line counter.

◆ get_logging()

datatools::logger::priority datatools::properties::config::get_logging ( ) const

Return the logging priority threshold.

◆ get_section_name()

const std::string& datatools::properties::config::get_section_name ( ) const

Return the section.

◆ get_section_start_line_number()

int datatools::properties::config::get_section_start_line_number ( ) const

Return the section start line.

◆ get_topic()

const std::string& datatools::properties::config::get_topic ( ) const

Return the topic.

◆ has_section_info()

bool datatools::properties::config::has_section_info ( ) const

Check if section info is set.

◆ has_topic()

bool datatools::properties::config::has_topic ( ) const

Check if topic is set.

◆ in_directive()

static const std::string& datatools::properties::config::in_directive ( )
static

◆ lock_decorator()

static const std::string& datatools::properties::config::lock_decorator ( )
static

◆ metacomment_prefix()

static const std::string& datatools::properties::config::metacomment_prefix ( )
static

◆ path_decorator()

static const std::string& datatools::properties::config::path_decorator ( )
static

◆ read() [1/2]

void datatools::properties::config::read ( std::istream &  in_,
properties prop_ 
)

Read a properties container from an input stream

This method is the base of configuration file parsing.

Example of usage which loads a configuration file to store the configuration parameters of an algorithm in a properties object:

// A dictionary of configuration parameters
datatools::properties algo_parameters;
uint32_t parser_options = 0; // No print option
parser_options |= datatools::properties::config::LOG_DEBUG; // Add debug option
parser_options |= datatools::properties::config::RESOLVE_PATH; // Add path resolving option
algo_parameters.read_configuration("${MYSETUP}/config/algo.conf", parser_options);
{
// Smart print:
boost::property_tree::ptree smart_print_options;
smart_print_options.put("indent", "[debug] ");
smart_print_options.put("title", "Configuration parameters for my algorithm: ");
algo_parameters.print_tree(std::clog, smart_print_options);
}

Example of input file to be parsed:

# Format:
# - Comment lines start with a '#'.
# This is a comment line...
# ...and this is another one.
test : boolean = true # The end of this property directive line is ignored.
# - Blank lines are ignored.
# - Lines starting with '#@' are considered as metacomments
# with special embedded parsing options and/or actions.
#@config Configuration parameters for a root finding algorithm
# This metacomment provides the general description of the set of properties.
# This directive must be given before any property directive.
#@description The name of the method
root_finder_type : string = "Newton-Raphson"
#@description The path of the log file
# The 'as path' directive indicates that the string value must
# be considered as a filesystem path.
log_file : string as path = "/tmp/root_finding.log"
#@description Relative tolerance (dimensionless)
relative_epsilon : real = 5e-6
#@description Absolute tolerance (with explicit dimension and associated unit)
# The 'as length' directive indicates that the real value has an explicit
# dimension. The explicit 'um' unit symbol after the numerical value must
# match the required dimension.
absolute_epsilon : real as length = 1.5 um # micrometer
#@description A constant value
# The 'const' directive will prevent any modification of the property
# value after parsing.
time_duration : const real as time = 0.05 ms
#@verbose_parsing
# Special directive which activates, from this point verbose parsing for debug purpose.
#@description Maximum number of iterations
max_iterations : integer = 100
#@description Array of guess values to start with (unit is explicitely given)
# The 'in mm' directive indicates that all real values in the array
# are explicitly expressed in 'mm' unit (of 'length' dimension).
# Also a long property directive can be splitted on several lines
# using a final '\' (after which no character is allowed).
guess_values : real[4] in mm = \ # no additional character after '\', even a space
1.0 \ # no additional character after '\', even a space or comment
1.2 \ # no additional character after '\'
2.4 \ # no additional character after '\'
4.8 # last value
#@description Algorithm verbosity
logging : string = "mute" # no print at all
#@allow_key_override
# From this point, overriding already defined/duplicated properties is allowed.
#@description Overriden algorithm verbosity (discard the first value above)
logging : string = "debug" # print debug messages
#@forbid_key_override # Special directive
# From this point, overriding already defined propertie is forbidden.
#@enable_variants
# Enable the parsing of variant preprocessor directives.
#@variant_only math:numerical_library/if_gsl
# This variant directive only applies to the next property directive
# if the "math:numerical_library/if_gsl" variant condition is set.
#@description GSL error handling flag is set only if the GSL library is used
gsl_error_support : boolean = true
#@description Default tolerance on double precision floats
#@variant_only math:tolerance/is_native|true
# This variant directive only applies to the next property directive
# if the "math:epsilon/is_native" variant condition is set.
# If the variant system is not activated, the 'true' value after
# the '|' character in the "@variant_only" directive is used to
# consider the condition set by default.
default_epsilon : real = 1e-15
#@variant_only math:tolerance/is_user|false
# This variant directive only applies to the next property directive
# if the "math:epsilon/is_user" variant condition is set.
# The parsed value is extracted by the variant preprocessor
# from a special variant variable (math:epsilon/is_user/epsilon) available
# only when the "math:epsilon/is_user" condition is set.
# If the variant system is not activated, the 'false' value after
# the '|' character in the "@variant_only" directive is used to consider
# the condition unset by default.
# If the variant system is not activated, the value '1.e-7' after
# the '|' character is used as a fallback value for this property.
#
default_epsilon : real = @variant(math:epsilon/is_user/epsilon|1.e-7)
#@variant_if math:numerical_library/if_std
# This variant directive starts a conditional block of property directives.
# The block is activated if and only if the "math:numerical_library/if_std"
# variant condition is set.
#@description The identifier of the base pseudo-random number generator (PRNG)
random_prng : string = "mersenne_twister"
# The next property directive is commented out.
# #@description The PRNG seed
# random_seed : integer = 314159
#@description The path of the input file where to load initial PRNG state
random_input_state_path : string as path = "${MYSETUP}/run_42/config/prng_state_in.state"
#@description The path of the output file where to save the final initial PRNG state
random_output_state_path : string as path = "${MYSETUP}/run_42/product/prng_state_out.data"
#@variant_endif # End of the variant conditional block of property directives
#@description The Pi constant in explicit angular unit
# The variant system provides three different options associated to the
# 'math:accuracy' variant parameter, each of them triggers
# the use of a specific value for the Pi constant in this file.
#@variant_only math:accuracy/if_accurate|true
Pi : const real as angle = 3.14159265358979 radian
#@variant_only math:accuracy/if_approximated|false
Pi : const real as angle = 3.14 radian
#@variant_only math:accuracy/if_inaccurate|false
Pi : const real as angle = 3 radian
#@disable_variants
# Disable variant preprocessor directives support from this point.
#@description GUI activation
gui : boolean = false
#@description GUI mode
gui.mode : string = "light"
#@description GUI colors (background, foreground then alarm foreground)
gui.colors : string[3] = "grey" "black" "red"
#@end
# Special directive which forces the end of parsing so that
# next lines will be ignored.
not_parsed : string = "unused" # This property directive will not be parsed.

◆ read() [2/2]

void datatools::properties::config::read ( const std::string &  in_,
properties prop_ 
)

Read a properties container from an input file.

◆ reset()

void datatools::properties::config::reset ( )

Reset.

◆ reset_section_info()

void datatools::properties::config::reset_section_info ( )

Reset the section info.

◆ set_logging()

void datatools::properties::config::set_logging ( datatools::logger::priority  )

Set the logging priority threshold.

◆ set_reader_input()

void datatools::properties::config::set_reader_input ( const std::string &  filename_,
int  line_count_ = -1 
)

Set the filename and the line counter before parsing.

◆ set_section_info()

void datatools::properties::config::set_section_info ( const std::string &  section_name_,
int  section_start_line_number_ 
)

Set the section info.

◆ set_topic()

void datatools::properties::config::set_topic ( const std::string &  topic_)

Set the topic that should be matched.

◆ write() [1/2]

void datatools::properties::config::write ( std::ostream &  out_,
const properties prop_ 
)

Write a properties container to an output stream.

◆ write() [2/2]

void datatools::properties::config::write ( const std::string &  filename_,
const properties prop_ 
)

Write a properties container to an output file.

◆ write_data()

void datatools::properties::config::write_data ( std::ostream &  out_,
const std::string &  data_key_,
const properties::data prop_data_,
const std::string &  unit_symbol_ = "",
const std::string &  unit_label_ = "",
const std::string &  comment_ = "" 
)

Write a property data.

◆ write_metacomment()

void datatools::properties::config::write_metacomment ( std::ostream &  out_,
const std::string &  tag_,
const std::string &  value_ = "",
const std::string &  comment_ = "" 
)

Write metacomment.


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