|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67101 - in sandbox/configurator: boost/configurator boost/configurator/detail libs/configurator
From: for.dshevchenko_at_[hidden]
Date: 2010-12-08 08:57:37
Author: dshevchenko
Date: 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
New Revision: 67101
URL: http://svn.boost.org/trac/boost/changeset/67101
Log:
1.0pre
Added:
sandbox/configurator/boost/configurator/detail/macro.hpp (contents, props changed)
Text files modified:
sandbox/configurator/boost/configurator/configurator.hpp | 419 +++++++++++----------------------------
sandbox/configurator/boost/configurator/detail/comments_remover.hpp | 4
sandbox/configurator/boost/configurator/detail/incorrect_options_checker.hpp | 8
sandbox/configurator/boost/configurator/detail/misc.hpp | 28 ++
sandbox/configurator/boost/configurator/detail/necessary_options_checker.hpp | 6
sandbox/configurator/boost/configurator/detail/option.hpp | 132 ++++++------
sandbox/configurator/boost/configurator/detail/options_repetition_handler.hpp | 8
sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp | 17
sandbox/configurator/boost/configurator/detail/semantics_checker.hpp | 2
sandbox/configurator/libs/configurator/index.html | 140 ++++++++-----
10 files changed, 321 insertions(+), 443 deletions(-)
Modified: sandbox/configurator/boost/configurator/configurator.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/configurator.hpp (original)
+++ sandbox/configurator/boost/configurator/configurator.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -8,7 +8,7 @@
#ifndef BOOST_CONFIGURATOR_HPP
#define BOOST_CONFIGURATOR_HPP
-#include <boost/configurator/detail/option.hpp>
+#include <boost/configurator/detail/macro.hpp>
#include <boost/configurator/detail/validators.hpp>
#include <boost/configurator/detail/comments_remover.hpp>
#include <boost/configurator/detail/pure_strings_obtainer.hpp>
@@ -28,36 +28,32 @@
/// \brief Main namespace of library.
namespace cf {
-/// \class configurator
-/// \brief Configurator.
-///
-/// Core class.
-class configurator : boost::noncopyable {
+struct configurator_settings {
+ configurator_settings() :
+ option_name_value_separator( '=' )
+ , option_name_value_separator_str( "=" )
+ , one_line_comment_sign( "//" )
+ , case_sensitivity( false ) {}
+public:
+ char option_name_value_separator;
+ std::string one_line_comment_sign;
+ bool case_sensitivity;
+ std::string option_name_value_separator_str;
+ //
public:
- configurator() :
- option_name_value_separator( "=" )
- , sections_separator( "::" )
- , case_sensitivity_for_names( false )
- , options_obtainer( option_name_value_separator
- , sections_separator
- , unique_names_of_sections
- , case_sensitivity_for_names )
- , check_incorrect_options( registered_options, sections_separator )
- , check_necessary_options( registered_options, sections_separator )
- , check_options_values_semantics( registered_options, sections_separator )
- , handle_options_repetition( registered_options, sections_separator )
- , reparsing( false ) {}
-private:
- std::string option_name_value_separator;
- const std::string sections_separator;
-public:
- void set_name_value_separator( char new_separator ) {
- check_separator_validity( new_separator );
- option_name_value_separator = new_separator;
+ configurator_settings& set_case_sensitivity_for_names() {
+ case_sensitivity = true;
+ return *this;
+ }
+
+ configurator_settings& set_name_value_separator( char separator ) {
+ option_name_value_separator = separator;
+ check_separator_validity();
+ return *this;
}
private:
- void check_separator_validity( char new_separator ) const {
- const int ascii_code = new_separator;
+ void check_separator_validity() const {
+ const int ascii_code = option_name_value_separator;
if ( ascii_code < 0x20 ) {
detail::o_stream what_happened;
what_happened << "Symbol (ASCII-code is " << ascii_code
@@ -66,116 +62,102 @@
notify( what_happened.str() );
} else {}
}
-private:
- bool case_sensitivity_for_names;
public:
- configurator& set_case_sensitivity_for_names() {
- case_sensitivity_for_names = true;
- return *this;
- }
+ //
+};
+
+/// \class configurator
+/// \brief Configurator.
+///
+/// Core class.
+class configurator : boost::noncopyable {
public:
- void use_canonical_one_line_comments() {
- remove_comments_from.use_canonical_one_line_comments();
- }
+ configurator() :
+ sections_separator( "::" )
+ , settings_of_configurator()
+ , options_obtainer( settings_of_configurator.option_name_value_separator_str
+ , sections_separator
+ , registered_options
+ , settings_of_configurator.case_sensitivity )
+ , check_incorrect_options( registered_options, sections_separator )
+ , check_necessary_options( registered_options, sections_separator )
+ , check_options_values_semantics( registered_options, sections_separator )
+ , handle_options_repetition( registered_options, sections_separator ) {}
private:
- options registered_options;
- detail::str_set unique_names_of_sections;
-public:
- configurator& in_section( const std::string& section_name ) {
- store_unique_section_name( section_name );
- if ( this_is_begin_call() ) {
- current_section_path.clear();
- } else {}
- current_section_path += section_name + sections_separator;
- return *this;
- }
+ const std::string sections_separator;
private:
- void store_unique_section_name( const std::string& section_name ) {
- std::string name( section_name.begin(), section_name.end() );
- convert_name_depending_on_case_sensitivity( name );
- unique_names_of_sections.insert( name );
- }
-
- bool this_is_begin_call() const {
- return !std::equal( sections_separator.begin()
- , sections_separator.end()
- , current_section_path.rbegin() );
- }
+ configurator_settings settings_of_configurator;
public:
- configurator& in( const std::string& section_name ) {
- return in_section( section_name );
- }
-
- configurator& from_section( const std::string& section_name ) {
- return in_section( section_name );
- }
-
- configurator& from( const std::string& section_name ) {
- return from_section( section_name );
+ configurator_settings& settings() {
+ return settings_of_configurator;
}
public:
- option& add_option( const std::string& option_name ) {
- std::string full_name_of_option( option_name.begin(), option_name.end() );
- convert_name_depending_on_case_sensitivity( full_name_of_option );
- registered_options.push_back( new option( full_name_of_option, sections_separator ) );
- return registered_options.back();
- }
-
- option& add( const std::string& option_name ) {
- return add_option( option_name );
+ template< typename Option >
+ option& add() {
+ Option* option = new Option();
+ registered_options.push_back( option );
+ return *option;
}
-
- option& add_option_here( const std::string& option_name ) {
- cut_current_section_path_if_necessary();
- std::string full_name_of_option = current_section_path + option_name;
- convert_name_depending_on_case_sensitivity( full_name_of_option );
- current_section_path += option_name;
- registered_options.push_back( new option( full_name_of_option, sections_separator ) );
- return registered_options.back();
- }
-
- option& add_here( const std::string& option_name ) {
- return add_option_here( option_name );
+public:
+ template< typename Option >
+ std::string get_value_of() {
+ registered_option_const_it it = std::find( registered_options.begin()
+ , registered_options.end()
+ , typeid( Option ) );
+ if ( registered_options.end() == it ) {
+ notify( std::string( "Option with type '" )
+ + BOOST_PP_STRINGIZE( Option )
+ + "' is not registered!" );
+ } else {}
+ const std::string& value = it->value;
+ check_factual_existence_of_value< Option >( value );
+ return value;
}
private:
- void cut_current_section_path_if_necessary() {
- detail::string_it previous_option_name_begin =
- boost::find_last( current_section_path, sections_separator ).end();
- detail::string_it previous_option_name_end = current_section_path.end();
- current_section_path.erase( previous_option_name_begin, previous_option_name_end );
- }
-
- void convert_name_depending_on_case_sensitivity( std::string& full_name_of_option ) const {
- if ( !case_sensitivity_for_names ) {
- boost::to_lower( full_name_of_option );
+ template< typename Option >
+ void check_factual_existence_of_value( const std::string& value ) const {
+ if ( value.empty() ) {
+ notify( std::string( "You have requested a value of option '" )
+ + BOOST_PP_STRINGIZE( Option ) + "' and such option was registered, "
+ + "but it missed in configuration file and have not default value!" );
} else {}
}
-private:
- // detail::str_storage multiply_sections_names;
public:
- configurator& allow_multiplicity() {
- // Not implemented yet, planning...
- //
- // std::string section_name( current_section_path.begin(), current_section_path.end() );
- // convert_name_depending_on_case_sensitivity( section_name );
- // multiply_sections_names.push_back( section_name );
+ template
+ <
+ typename Option
+ , typename Value
+ >
+ Value get_value_of() {
+ const std::string value_as_string = get_value_of< Option >();
+ return detail::cast< Value >( value_as_string );
+ }
+
+ template
+ <
+ typename Option
+ , typename Value
+ >
+ configurator& get_value_of( Value& value ) {
+ const std::string value_as_string = get_value_of< Option >();
+ value = detail::cast< Value >( value_as_string );
return *this;
}
private:
- std::string current_section_path;
+ options registered_options;
+private:
detail::comments_remover remove_comments_from;
detail::pure_strings_obtainer obtain_pure_strings;
detail::pure_options_obtainer options_obtainer;
detail::incorrect_options_checker check_incorrect_options;
detail::necessary_options_checker check_necessary_options;
- detail::semantics_checker check_options_values_semantics;
+ detail::semantics_checker check_options_values_semantics;
detail::options_repetition_handler handle_options_repetition;
public:
- void parse( const std::string& path_to_configuration_file ) {
- check_registered_options_existence();
- check_configuration_file_existence( path_to_configuration_file );
+ void load( const std::string& path_to_configuration_file ) {
+ primary_check( path_to_configuration_file );
detail::str_storage obtained_strings = obtain_pure_strings( path_to_configuration_file );
- check_actual_data_existence( obtained_strings );
+ check_actual_data_existence_in( obtained_strings );
remove_comments_from( obtained_strings );
pure_options factual_obtained_options = options_obtainer( obtained_strings );
prepare_names_depending_on_case_sensitivity( factual_obtained_options );
@@ -184,61 +166,29 @@
handle_options_repetition( factual_obtained_options );
store_obtained_values( factual_obtained_options );
check_options_values_semantics();
- current_section_path.clear();
- }
-
- void load( const std::string& path_to_configuration_file ) {
- parse( path_to_configuration_file );
- }
-private:
- bool reparsing;
-
- struct reparsing_flag_switch {
- explicit reparsing_flag_switch( bool& _reparsing ) :
- reparsing( _reparsing ) {
- reparsing = true;
- }
- ~reparsing_flag_switch() {
- reparsing = false;
- }
- private:
- bool& reparsing;
- };
-public:
- void reparse( const std::string& new_path_to_configuration_file ) {
- reparsing_flag_switch s( reparsing );
- parse( new_path_to_configuration_file );
- }
-
- void reload( const std::string& new_path_to_configuration_file ) {
- reparse( new_path_to_configuration_file );
- }
-
- void reparse() {
- reparsing_flag_switch s( reparsing );
- const std::string previous_path_to_configuration_file = obtain_pure_strings.stored_path();
- parse( previous_path_to_configuration_file );
- }
-
- void reload() {
- reparse();
}
private:
+ void primary_check( const std::string& path_to_configuration_file ) const {
+ check_registered_options_existence();
+ check_configuration_file_existence( path_to_configuration_file );
+ }
+
void check_registered_options_existence() const {
if ( registered_options.empty() ) {
- notify( "Cannot parse configuration file, because no one option registered!" );
+ notify( "Cannot continue, because no one option has not been registered!" );
} else {}
}
void check_configuration_file_existence( const std::string& path_to_configuration_file ) const {
try {
detail::pure_check_path_existence( path_to_configuration_file );
+ detail::check_is_it_file( path_to_configuration_file );
} catch ( const std::exception& exc ) {
notify( std::string( "Invalid path to configuration file: " ) + exc.what() );
}
- }
-
- void check_actual_data_existence( detail::str_storage& obtained_strings ) const {
+ }
+private:
+ void check_actual_data_existence_in( detail::str_storage& obtained_strings ) const {
if ( at_least_one_option_has_default_value() ) {
return;
} else {}
@@ -260,13 +210,13 @@
}
void prepare_names_depending_on_case_sensitivity( pure_options& factual_obtained_options ) {
- if ( !case_sensitivity_for_names ) {
+ if ( !settings_of_configurator.case_sensitivity ) {
BOOST_FOREACH ( option& option, registered_options ) {
- boost::to_lower( option.name );
+ boost::to_lower( option.location );
}
BOOST_FOREACH ( pure_option& option, factual_obtained_options ) {
- boost::to_lower( option.name );
+ boost::to_lower( option.location );
}
} else {}
}
@@ -275,15 +225,11 @@
BOOST_FOREACH ( const pure_option& option, factual_obtained_options ) {
option_it it = std::find( registered_options.begin()
, registered_options.end()
- , option.name );
+ , option.location );
if ( registered_options.end() != it ) {
store_if_need( it->value, option.value );
} else {}
- }
-
- if ( reparsing ) {
- use_default_value_reserves( factual_obtained_options );
- } else {}
+ }
}
void store_if_need( std::string& value_of_registered_option
@@ -293,151 +239,22 @@
, value_of_obtained_option.end() );
} else {}
}
-
- void use_default_value_reserves( const pure_options& factual_obtained_options ) {
- // Not implemented yet.
- }
-public:
- std::string get_value( const std::string& name_of_option ) {
- std::string full_name_of_option( name_of_option.begin(), name_of_option.end() );
- return get_value_by_name( full_name_of_option );
- }
-
- std::string get( const std::string& name_of_option ) {
- return get_value( name_of_option );
- }
-public:
- template< typename ValueType >
- ValueType get_value( const std::string& name_of_option ) {
- std::string value_as_string = get_value( name_of_option );
- ValueType value;
- try {
- value = boost::lexical_cast< ValueType >( value_as_string );
- } catch ( const std::exception& /* exc */ ) {
- notify( "Value '" + value_as_string + "' of option '" + name_of_option
- + "' cannot be cast to <" + get_type_identifier< ValueType >() + ">!" );
- }
- return value;
- }
-
- template< typename ValueType >
- ValueType get( const std::string& name_of_option ) {
- return get_value< ValueType >( name_of_option );
- }
-
- template< typename ValueType >
- configurator& get_value( const std::string& name_of_option, ValueType& value ) {
- value = get_value< ValueType >( name_of_option );
- return *this;
- }
-
- template< typename ValueType >
- configurator& get( const std::string& name_of_option, ValueType& value ) {
- return get_value( name_of_option, value );
- }
public:
- std::string get_value_from_here( const std::string& name_of_option ) {
- cut_current_section_path_if_necessary();
- std::string full_name_of_option = current_section_path + name_of_option;
- current_section_path += name_of_option;
- return get_value_by_name( full_name_of_option );
- }
-
- std::string get_from_here( const std::string& name_of_option ) {
- return get_value_from_here( name_of_option );
- }
-
- template< typename ValueType >
- ValueType get_value_from_here( const std::string& name_of_option ) {
- std::string value_as_string = get_value_from_here( name_of_option );
- ValueType value;
- try {
- value = boost::lexical_cast< ValueType >( value_as_string );
- } catch ( const std::exception& /* exc */ ) {
- const std::string full_name_of_option = current_section_path;
- notify( "Value '" + value_as_string + "' of option '"
- + detail::prepare_full_name_for_log( full_name_of_option, sections_separator )
- + "' cannot be cast to <" + get_type_identifier< ValueType >() + ">!" );
- }
- return value;
- }
-
- template< typename ValueType >
- ValueType get_from_here( const std::string& name_of_option ) {
- return get_value_from_here< ValueType >( name_of_option );
- }
-
- template< typename ValueType >
- configurator& get_value_from_here( const std::string& name_of_option, ValueType& value ) {
- value = get_value_from_here< ValueType >( name_of_option );
- return *this;
- }
-
- template< typename ValueType >
- configurator& get_from_here( const std::string& name_of_option, ValueType& value ) {
- return get_value_from_here( name_of_option, value );
- }
-private:
- std::string get_value_by_name( std::string& full_name_of_option ) const {
- convert_name_depending_on_case_sensitivity( full_name_of_option );
- option_const_it it = std::find( registered_options.begin()
- , registered_options.end()
- , full_name_of_option );
- std::string value;
- if ( registered_options.end() != it ) {
- const std::string& value_of_registered_option = it->value;
- check_factual_obtaining( value_of_registered_option, full_name_of_option );
- value.assign( value_of_registered_option.begin(), value_of_registered_option.end() );
- } else {
- notify( "You request a value of option '"
- + detail::prepare_full_name_for_log( full_name_of_option, sections_separator )
- + "', but such option not registered!" );
- }
- return value;
- }
-
- void check_factual_obtaining( const std::string& value_of_registered_option
- , const std::string& full_name_of_option ) const {
- if ( value_of_registered_option.empty() ) {
- notify( "You request a value of option '"
- + detail::prepare_full_name_for_log( full_name_of_option, sections_separator )
- + "' and such option was registered, but it missed in configuration file!" );
- } else {}
+ void reload( const std::string& new_path_to_configuration_file ) {
+ load( new_path_to_configuration_file );
}
-private:
- template< typename ArgType >
- std::string get_type_identifier() const {
- std::string identifier;
-
- if ( typeid( ArgType ) == typeid( bool ) ) { identifier = "bool"; }
- else if ( typeid( ArgType ) == typeid( char ) ) { identifier = "char"; }
- else if ( typeid( ArgType ) == typeid( signed char ) ) { identifier = "signed char"; }
- else if ( typeid( ArgType ) == typeid( unsigned char ) ) { identifier = "unsigned char"; }
- else if ( typeid( ArgType ) == typeid( int ) ) { identifier = "int"; }
- else if ( typeid( ArgType ) == typeid( signed int ) ) { identifier = "signed int"; }
- else if ( typeid( ArgType ) == typeid( unsigned int ) ) { identifier = "unsigned int"; }
- else if ( typeid( ArgType ) == typeid( short int ) ) { identifier = "short int"; }
- else if ( typeid( ArgType ) == typeid( long int ) ) { identifier = "long int"; }
- else if ( typeid( ArgType ) == typeid( unsigned long int ) ) { identifier = "unsigned long int"; }
- else if ( typeid( ArgType ) == typeid( unsigned short int ) ) { identifier = "unsigned short int"; }
- else if ( typeid( ArgType ) == typeid( signed long int ) ) { identifier = "signed long int"; }
- else if ( typeid( ArgType ) == typeid( signed short int ) ) { identifier = "signed short int"; }
- else if ( typeid( ArgType ) == typeid( float ) ) { identifier = "float"; }
- else if ( typeid( ArgType ) == typeid( double ) ) { identifier = "double"; }
- else if ( typeid( ArgType ) == typeid( long double ) ) { identifier = "long double"; }
- else if ( typeid( ArgType ) == typeid( std::string ) ) { identifier = "std::string"; }
- else { identifier = "unknown"; }
- return identifier;
+ void reload() {
+ const std::string previous_path_to_configuration_file = obtain_pure_strings.stored_path();
+ reload( previous_path_to_configuration_file );
}
};
#ifdef WITH_SINGLETON
/// \class single_configurator
/// \brief Singleton-variant of configurator class.
-class single_configurator :
- public configurator
- , public detail::singleton< single_configurator > {
+class single_configurator : public configurator
+ , public detail::singleton< single_configurator > {
private:
single_configurator() {}
~single_configurator() {}
Modified: sandbox/configurator/boost/configurator/detail/comments_remover.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/comments_remover.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/comments_remover.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -42,8 +42,8 @@
const std::string multi_line_comment_begin_sign;
const std::string multi_line_comment_end_sign;
public:
- void use_canonical_one_line_comments() {
- one_line_comment_sign = "#";
+ void set_one_line_comment_sign( const std::string& sign ) {
+ one_line_comment_sign = sign;
}
public:
void operator()( str_storage& obtained_strings ) const {
Modified: sandbox/configurator/boost/configurator/detail/incorrect_options_checker.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/incorrect_options_checker.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/incorrect_options_checker.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -38,9 +38,9 @@
BOOST_FOREACH ( const pure_option& option, factual_obtained_options ) {
option_const_it it = std::find( registered_options.begin()
, registered_options.end()
- , option.name );
+ , option.location );
if ( registered_options.end() == it ) {
- store_incorrect_option( option.name );
+ store_incorrect_option( option.location );
} else {}
}
@@ -49,8 +49,8 @@
private:
str_storage incorrect_options;
private:
- void store_incorrect_option( const std::string& option_name ) {
- incorrect_options += option_name;
+ void store_incorrect_option( const std::string& option_location ) {
+ incorrect_options += option_location;
}
void notify_about_incorrect_options_if_such_exists() const {
Added: sandbox/configurator/boost/configurator/detail/macro.hpp
==============================================================================
--- (empty file)
+++ sandbox/configurator/boost/configurator/detail/macro.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -0,0 +1,32 @@
+// Configurator (C++ library for configuration file parsing)
+//
+// Copyright (C) 2010 Denis Shevchenko (for @ dshevchenko.biz)
+//
+// Distributed under the Boost Software License, version 1.0
+// (see http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CONFIGURATOR_MACRO_HPP
+#define BOOST_CONFIGURATOR_MACRO_HPP
+
+#include <boost/configurator/detail/option.hpp>
+
+namespace boost {
+
+/// \namespace cf
+/// \brief Main namespace of library.
+namespace cf {
+
+/// \namespace cf::detail
+/// \brief Details of realization.
+namespace detail {
+
+#define BOOST_CONFIGURATOR_OPTION( type ) \
+ struct type : public boost::cf::detail::option { \
+ type() : boost::cf::detail::option( typeid( type ).name(), #type ) {} \
+ };
+
+} // namespace detail
+} // namespace cf
+} // namespace boost
+
+#endif // BOOST_CONFIGURATOR_MACRO_HPP
Modified: sandbox/configurator/boost/configurator/detail/misc.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/misc.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/misc.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -74,13 +74,21 @@
if ( boost::filesystem::exists( path_name ) ) {
if ( !boost::filesystem::exists( full_path_name ) ) {
- notify_without_prefix( "directory '" + path_name + "' exists, but there is no file '" + file_name + "'!" );
+ notify_without_prefix( "directory '" + path_name
+ + "' exists, but there is no file '" + file_name + "'!" );
} else {}
} else {
notify_without_prefix( "directory '" + path_name + "' not exists!" );
}
}
+inline void check_is_it_file( const std::string& _path ) {
+ boost::filesystem::path path( _path );
+ if ( !boost::filesystem::is_regular_file( path ) ) {
+ notify_without_prefix( "path '" + _path + "' exists, but it is not a regular file!" );
+ } else {}
+}
+
inline std::string prepare_full_name_for_log( const std::string& full_name_of_option
, const std::string& sections_separator ) {
std::string s( full_name_of_option.begin(), full_name_of_option.end() );
@@ -105,6 +113,24 @@
}
}
+template
+<
+ typename SourceType
+ , typename TargetType
+>
+inline TargetType cast( const SourceType& source ) {
+ TargetType target;
+ try {
+ target = boost::lexical_cast< TargetType >( source );
+ } catch ( const std::exception& /* exc */ ) {
+ notify( std::string( "Cannot cast value of type '" )
+ + BOOST_PP_STRINGIZE( SourceType )
+ + "' to type '"
+ + BOOST_PP_STRINGIZE( TargetType ) + "'!" );
+ }
+ return target;
+}
+
} // namespace detail
} // namespace cf
} // namespace boost
Modified: sandbox/configurator/boost/configurator/detail/necessary_options_checker.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/necessary_options_checker.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/necessary_options_checker.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -45,8 +45,8 @@
str_storage collect_names_of_necessary_options() const {
str_storage names;
BOOST_FOREACH ( const option& registered_option, registered_options ) {
- if ( registered_option.is_necessary ) {
- names += registered_option.name;
+ if ( registered_option.is_necessary() ) {
+ names += registered_option.location;
} else {}
}
return names;
@@ -55,7 +55,7 @@
void remove_names_of_inputed_necessary_options( const pure_options& factual_obtained_options
, str_storage& names_that_should_be ) const {
BOOST_FOREACH ( const pure_option& obtained_option, factual_obtained_options ) {
- delete_element( names_that_should_be, obtained_option.name );
+ delete_element( names_that_should_be, obtained_option.location );
}
}
Modified: sandbox/configurator/boost/configurator/detail/option.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/option.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/option.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -21,107 +21,103 @@
/// \brief Details of realization.
namespace detail {
-/// \class option
-/// \brief One option.
-///
-/// Presents functionality of one configuration option.
-class option {
-public:
- explicit option( const std::string& _name, const std::string& _sections_separator ) :
- sections_separator( _sections_separator )
- , name( _name.begin(), _name.end() )
+
+struct option {
+ option() {}
+ explicit option( const std::string& _type_id, const std::string& _type_name ) :
+ type_id( _type_id.begin(), _type_id.end() )
+ , type_name( _type_name.begin(), _type_name.end() )
+ , location( _type_name.begin(), _type_name.end() )
, value()
, semantic( no_semantic )
- , is_necessary( false )
+ , necessary( false )
, multi_values_allowed( false ) {}
+ virtual ~option() {}
private:
- const std::string& sections_separator;
-public:
- std::string name;
- std::string value;
- value_semantic semantic;
- bool is_necessary;
- bool multi_values_allowed;
+ const std::string type_id;
+ const std::string type_name;
public:
- bool operator==( const std::string& full_name ) const {
- return full_name == name;
+ std::string location;
+ std::string section;
+ std::string value;
+ value_semantic semantic;
+ bool necessary;
+ bool multi_values_allowed;
+ std::string default_value;
+public:
+ option& set_location( const std::string& _location ) {
+ location.assign( _location.begin(), _location.end() );
+ string_it end_it = boost::find_last( location, "::" ).begin();
+ section.assign( location.begin(), end_it );
+ return *this;
}
-private:
- std::string default_value_reserve;
-public:
- void use_default_value_reserve() {
- if ( !default_value_reserve.empty() ) {
- value.assign( default_value_reserve.begin(), default_value_reserve.end() );
- } else {}
+public:
+ bool operator==( const std::type_info& type ) const {
+ return type_id == type.name();
}
-public:
- template< typename ValueType >
- option& default_value( const ValueType& _value ) {
+
+ bool operator==( const std::string& _location ) const {
+ return _location == location;
+ }
+
+ bool corresponds_by_section( const std::string& _section ) const {
+ return _section == section;
+ }
+public:
+ template< typename Value >
+ option& set_default_value( const Value& _value ) {
check_option_necessity();
- try {
- value = boost::lexical_cast< std::string >( _value );
- default_value_reserve.assign( value.begin(), value.end() );
- } catch ( const std::exception& /* exc */ ) {
- notify( "Default value for option '" + name + "' cannot be stringified!" );
- }
+ value = cast< std::string >( _value );
+ default_value.assign( value.begin(), value.end() );
return *this;
}
private:
void check_option_necessity() const {
- if ( is_necessary ) {
- notify( "Option '"
- + prepare_full_name_for_log( name, sections_separator )
+ if ( necessary ) {
+ notify( "Option '" + type_name
+ "' registered as necessary, so it cannot have default_value!" );
} else {}
}
public:
- option& default_value( const std::string& _value ) {
- value.assign( _value.begin(), _value.end() );
- return *this;
- }
-public:
- option& necessary() {
+ option& set_necessity() {
check_default_value_existence();
- is_necessary = true;
+ necessary = true;
return *this;
}
private:
void check_default_value_existence() const {
- if ( !value.empty() ) {
- notify( "Option '"
- + prepare_full_name_for_log( name, sections_separator )
- + "' already have default value '" + value + "', "
+ if ( !default_value.empty() ) {
+ notify( "Option '" + type_name
+ + "' already have default value '" + default_value + "', "
+ "so it cannot be necessary!" );
} else {}
}
public:
option& check_semantic( const value_semantic& _semantic ) {
- check_correctness_of( _semantic );
+ check_semantic_correctness( _semantic );
semantic = _semantic;
return *this;
}
private:
- void check_correctness_of( const value_semantic& semantic ) const {
+ void check_semantic_correctness( const value_semantic& semantic ) const {
if ( semantic < no_semantic || semantic > exp_record ) {
o_stream what_happened;
- what_happened << "invalid semantic value '" << semantic
+ what_happened << "Invalid semantic value '" << semantic
+ << "' for option '" << type_name
<< "', use supported semantic only (see documentation)!"
;
notify( what_happened.str() );
} else {}
}
public:
- bool semantic_defined() const {
- return no_semantic != semantic;
- }
-public:
option& allow_multi_values() {
multi_values_allowed = true;
return *this;
}
public:
- bool already_has_default_value() const { return !value.empty(); }
- bool it_is_necessary() const { return is_necessary; }
+ bool semantic_defined() const { return no_semantic != semantic; }
+ bool already_has_default_value() const { return !default_value.empty(); }
+ bool is_necessary() const { return necessary; }
bool empty() const { return value.empty(); }
};
@@ -131,28 +127,28 @@
/// Presents pure option obtained from configuration file.
struct pure_option {
pure_option() {}
- pure_option( const std::string& _name, const std::string& _value ) :
- name( _name.begin(), _name.end() )
+ pure_option( const std::string& _location, const std::string& _value ) :
+ location( _location.begin(), _location.end() )
, value( _value.begin(), _value.end() ) {}
public:
- std::string name;
+ std::string location;
std::string value;
public:
bool empty() const {
return value.empty();
}
- bool operator==( const std::string& _name ) const {
- return _name == name;
+ bool operator==( const std::string& _location ) const {
+ return _location == location;
}
bool operator==( const pure_option& another ) const {
- return another.name == name;
+ return another.location == location;
}
};
inline bool operator<( const pure_option& left, const pure_option& right ) {
- return left.name < right.name;
+ return left.location < right.location;
}
} // namespace detail
@@ -160,8 +156,10 @@
typedef detail::option option;
typedef boost::ptr_vector< option > options;
-typedef options::iterator option_it;
-typedef options::const_iterator option_const_it;
+typedef options::iterator registered_option_it;
+typedef options::const_iterator registered_option_const_it;
+typedef registered_option_it option_it;
+typedef registered_option_const_it option_const_it;
typedef detail::pure_option pure_option;
typedef std::vector< pure_option > pure_options;
Modified: sandbox/configurator/boost/configurator/detail/options_repetition_handler.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/options_repetition_handler.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/options_repetition_handler.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -49,11 +49,11 @@
BOOST_FOREACH ( const pure_option& unique_option, unique_options ) {
pure_option_it first_repeating = std::find( factual_obtained_options.begin()
, factual_obtained_options.end()
- , unique_option.name );
+ , unique_option.location );
if ( factual_obtained_options.end() != first_repeating ) {
size_t how_many_times_it_repeats = (size_t)std::count( factual_obtained_options.begin()
, factual_obtained_options.end()
- , unique_option.name );
+ , unique_option.location );
if ( 1 == how_many_times_it_repeats ) {
continue;
} else {}
@@ -92,10 +92,10 @@
void check_multi_values_allowance( const pure_option& factual_obtained_option ) const {
option_const_it it = std::find( registered_options.begin()
, registered_options.end()
- , factual_obtained_option.name );
+ , factual_obtained_option.location );
if ( registered_options.end() != it ) {
if ( !it->multi_values_allowed ) {
- notify( "Option '" + prepare_full_name_for_log( factual_obtained_option.name
+ notify( "Option '" + prepare_full_name_for_log( factual_obtained_option.location
, sections_separator )
+ "' has multiple values, but it not allowed to have multiply values!" );
} else {}
Modified: sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -1,4 +1,4 @@
-// Configurator (C++ library for configuration file parsing)
+// Boost.Configurator
//
// Copyright (C) 2010 Denis Shevchenko (for @ dshevchenko.biz)
//
@@ -31,11 +31,11 @@
public:
pure_options_obtainer( std::string& _option_name_value_separator
, const std::string& _sections_separator
- , const str_set& _unique_names_of_sections
+ , const options& _registered_options
, const bool& _case_sensitivity_for_names ) :
option_name_value_separator( _option_name_value_separator )
, sections_separator( _sections_separator )
- , unique_names_of_sections( _unique_names_of_sections )
+ , registered_options( _registered_options )
, case_sensitivity_for_names( _case_sensitivity_for_names )
, open_section_tag_begin_sign( "<" )
, open_section_tag_end_sign( ">" )
@@ -54,7 +54,7 @@
private:
std::string& option_name_value_separator;
const std::string& sections_separator;
- const str_set& unique_names_of_sections;
+ const options& registered_options;
const bool& case_sensitivity_for_names;
private:
const std::string open_section_tag_begin_sign;
@@ -229,9 +229,12 @@
}
void check_section_existence( std::string& section_name ) const {
- convert_name_depending_on_case_sensitivity( section_name );
- str_unique_const_it it = unique_names_of_sections.find( section_name );
- if ( unique_names_of_sections.end() == it ) {
+ registered_option_const_it it = std::find_if( registered_options.begin()
+ , registered_options.end()
+ , boost::bind( &option::corresponds_by_section
+ , _1
+ , section_name ) );
+ if ( registered_options.end() == it ) {
notify_about_incorrect_section_name( section_name );
} else {}
}
Modified: sandbox/configurator/boost/configurator/detail/semantics_checker.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/semantics_checker.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/semantics_checker.hpp 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -93,7 +93,7 @@
if ( !registered_options.empty()
&& registered_option.semantic_defined() ) {
const std::string& value = registered_option.value;
- const std::string name = prepare_full_name_for_log( registered_option.name
+ const std::string name = prepare_full_name_for_log( registered_option.location
, sections_separator );
semantic_checkers[ registered_option.semantic ]( value, name );
} else {}
Modified: sandbox/configurator/libs/configurator/index.html
==============================================================================
--- sandbox/configurator/libs/configurator/index.html (original)
+++ sandbox/configurator/libs/configurator/index.html 2010-12-08 08:57:34 EST (Wed, 08 Dec 2010)
@@ -4,73 +4,107 @@
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
- <link rel="stylesheet" type="text/css" href="../../../boost.css">
+ <link rel="stylesheet" type="text/css" href="doc/own.css">
<title>Configurator</title>
<link rel="icon" href="/favicon.ico" type="image/ico"><link rel="stylesheet" type="text/css" href="/style-v2/section-basic.css"></head>
-<body link="#0000FF" vlink="#800080"> <div id="boost-common-heading-doc">
- <div class="heading-inner">
- <div class="heading-placard"></div>
-
- <h1 class="heading-title">
- <a href="/">
- <img src="/gfx/space.png" alt= "Boost C++ Libraries" class="heading-logo" />
- <span class="heading-boost">Boost</span>
- <span class="heading-cpplibraries">C++ Libraries</span>
- </a></h1>
-
- <p class="heading-quote">
- <q>...one of the most highly
- regarded and expertly designed C++ library projects in the
- world.</q> <span class="heading-attribution">— <a href=
- "http://www.gotw.ca/" class="external">Herb Sutter</a> and <a href=
- "http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="external">Andrei
- Alexandrescu</a>, <a href=
- "http://safari.awprofessional.com/?XmlId=0321113586" class="external">C++
- Coding Standards</a></span></p>
-
- <div class="heading-sections">
- <ul>
- <li class="welcome-section-tab">Welcome</li>
- <li class="boost-section-tab">Introduction</li>
- <li class="community-section-tab">Community</li>
- <li class="development-section-tab">Development</li>
- <li class="support-section-tab">Support</li>
- <li class="doc-section-tab">Documentation</li>
- </ul>
- </div>
-</div>
- </div>
+<body>
+
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+</tr></table>
+<hr>
- <div id="boost-common-heading-doc-spacer"></div>
-
- <h1 align="center">Configurator</h1>
- <h2 align="center">0.9.2</h2>
- <h2>Contents</h2>
- <dl class="index">
- <dt>Rationale</dt>
- <dt>Overview</dt>
- <dt>Acknowledgments</dt>
- </dl>
- <hr/>
- <br/>
- This document describes Configurator, flexible and easy-to-use library for configuration file parsing.
- <br/>
- This is first version of documentation, future documentation will significantly improve.
- <br/>
- <hr/>
+
+
+
+ <h1 class="first_title">Boost.Configurator</h1>
+<div class="table_of_contents">
+ <h2>Table of contents</h2>
+
+<ol>
+<li><dt>Introduction</dt>
+ <ul>
+ <li><dt>About</dt></li>
+ <li><dt>Motivation</dt></li>
+ <li><dt>Hello, world!</dt></li>
+ <li><dt>Features</dt></li>
+ </ul>
+
+<li><dt>Requirements</dt>
+ <ul>
+ <li><dt>Necessary Boost libraries</dt></li>
+ <li><dt>Compiling programs with Configurator</dt></li>
+ </ul>
+
+<li><dt>Configuration file format</dt>
+ <ul>
+ <li><dt>Option</dt></li>
+ <li><dt>Section</dt></li>
+ <li><dt>Comments</dt></li>
+ </ul>
+
+<li><dt>Common usage</dt>
+ <ul>
+ <li><dt>Defining concepts</dt></li>
+ <li><dt>Options adding</dt></li>
+ <li><dt>Loading</dt></li>
+ <li><dt>Values obtaining</dt></li>
+ </ul>
+
+<li><dt>Advanced usage</dt>
+ <ul>
+ <li><dt>Option's location</dt></li>
+ <li><dt>Option's default value</dt></li>
+ <li><dt>Option's necessity</dt></li>
+ <li><dt>Semantic of option's value</dt></li>
+ <li><dt>Multi values for option</dt></li>
+ </ul>
+
+<li><dt>Configuration file customizing</dt>
+ <ul>
+ <li><dt>Name-value separator for options</dt></li>
+ <li><dt>Canonical comments</dt></li>
+ <li><dt>Section names edging</dt></li>
+ </ul>
+
+<li><dt>Reference</dt>
+ <ul>
+ <li><dt>1</dt></li>
+ <li><dt>2</dt></li>
+ </ul>
+
+<li><dt>Examples</dt>
+ <ul>
+ <li><dt>Hello, world!</dt></li>
+ <li><dt>Advanced</dt></li>
+ </ul>
+
+<li><dt>Appendix</dt>
+ <ul>
+ <dt>Error messages</dt>
+ </ul>
+
+<li><dt>Acknowledgments</dt>
+</ol>
+</div>
+
+
+
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->30
November, 2010<!--webbot bot="Timestamp" endspan i-checksum="38514" --></p>
-
<p><i>Copyright © 2010 Denis Shevchenko</i></p>
-
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file LICENSE_1_0.txt or
copy at <a href=
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk