Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67113 - in sandbox/configurator/boost/configurator: . detail
From: for.dshevchenko_at_[hidden]
Date: 2010-12-08 14:50:00


Author: dshevchenko
Date: 2010-12-08 14:49:58 EST (Wed, 08 Dec 2010)
New Revision: 67113
URL: http://svn.boost.org/trac/boost/changeset/67113

Log:
1.0pre, continue Spirit adding

Text files modified:
   sandbox/configurator/boost/configurator/configurator.hpp | 53 ++++++++++++++++++++++++++++++++++-----
   sandbox/configurator/boost/configurator/detail/misc.hpp | 19 -------------
   sandbox/configurator/boost/configurator/detail/option.hpp | 2
   3 files changed, 48 insertions(+), 26 deletions(-)

Modified: sandbox/configurator/boost/configurator/configurator.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/configurator.hpp (original)
+++ sandbox/configurator/boost/configurator/configurator.hpp 2010-12-08 14:49:58 EST (Wed, 08 Dec 2010)
@@ -18,6 +18,9 @@
 #include <boost/configurator/detail/necessary_options_checker.hpp>
 #include <boost/configurator/detail/semantics_checker.hpp>
 #include <boost/configurator/detail/options_repetition_handler.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_stl.hpp>
 
 #ifdef WITH_SINGLETON
 #include <boost/configurator/detail/singleton.hpp>
@@ -106,9 +109,7 @@
                                                    , registered_options.end()
                                                    , typeid( Option ) );
         if ( registered_options.end() == it ) {
- notify( std::string( "Option with type '" )
- + BOOST_PP_STRINGIZE( Option )
- + "' is not registered!" );
+ notify( "Option with type '" + name_of< Option >() + "' is not registered!" );
         } else {}
         const std::string& value = it->value;
         check_factual_existence_of_value< Option >( value );
@@ -118,8 +119,8 @@
     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, "
+ notify( "You have requested a value of option '"
+ + name_of< Option >() + "' and such option was registered, "
                     + "but it missed in configuration file and have not default value!" );
         } else {}
     }
@@ -131,7 +132,13 @@
>
     Value get_value_of() {
         const std::string value_as_string = get_value_of< Option >();
- return detail::cast< std::string, Value >( value_as_string );
+ Value value();
+ try {
+ value = boost::lexical_cast< Value >( value_as_string );
+ } catch ( const std::exception& /* exc */ ) {
+ notify_about_incorrect_type_of_value< Option, Value >( value_as_string );
+ }
+ return value;
     }
 
     template
@@ -141,10 +148,42 @@
>
     configurator& get_value_of( Value& value ) {
         const std::string value_as_string = get_value_of< Option >();
- value = detail::cast< std::string, Value >( value_as_string );
+ try {
+ value = boost::lexical_cast< Value >( value_as_string );
+ } catch ( const std::exception& /* exc */ ) {
+ notify_about_incorrect_type_of_value< Option, Value >( value_as_string );
+ }
         return *this;
     }
 private:
+ template
+ <
+ typename Option
+ , typename Value
+ >
+ void notify_about_incorrect_type_of_value( const std::string& value_as_string ) const {
+ detail::type_name type;
+ notify( "Value '" + value_as_string + "' of option '" + name_of< Option >()
+ + "' cannot be cast to type " + type.name_of< Value >() + "!" );
+ }
+
+ template< typename Option >
+ std::string name_of() const {
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::char_;
+ using boost::spirit::qi::parse;
+ using boost::spirit::qi::_1;
+ using boost::phoenix::ref;
+ using boost::phoenix::push_back;
+
+ std::string pure_name = typeid( Option ).name();
+ std::string name;
+ parse( pure_name.begin()
+ , pure_name.end()
+ , int_ >> +( char_[ push_back( ref(name), _1 ) ] ) );
+ return name;
+ }
+private:
     options registered_options;
 private:
     detail::comments_remover remove_comments_from;

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 14:49:58 EST (Wed, 08 Dec 2010)
@@ -10,6 +10,7 @@
 #define BOOST_CONFIGURATOR_MISC_HPP
 
 #include <boost/configurator/detail/types.hpp>
+#include <boost/configurator/detail/type_name.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string.hpp>
 #include <boost/filesystem/operations.hpp>
@@ -114,24 +115,6 @@
     }
 }
 
-template
-<
- typename Source
- , typename Target
->
-inline Target cast( const Source& source ) {
- Target target;
- try {
- target = boost::lexical_cast< Target >( source );
- } catch ( const std::exception& /* exc */ ) {
- notify( std::string( "Cannot cast value of type '" )
- + BOOST_PP_STRINGIZE( Source )
- + "' to type '"
- + BOOST_PP_STRINGIZE( Target ) + "'!" );
- }
- return target;
-}
-
 } // namespace detail
 } // namespace cf
 } // namespace boost

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 14:49:58 EST (Wed, 08 Dec 2010)
@@ -68,7 +68,7 @@
     template< typename Value >
     option& set_default_value( const Value& _value ) {
         check_option_necessity();
- value = cast< Value, std::string >( _value );
+ value = boost::lexical_cast< std::string >( _value );
         default_value.assign( value.begin(), value.end() );
         return *this;
     }


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