From 6c7c0dc81b10aa38bbcf45fb15aca8dcbd51212d Mon Sep 17 00:00:00 2001 From: VB Date: Tue, 11 Mar 2014 12:41:25 +1100 Subject: [PATCH] proof-reading --- doc/01_introduction.qbk | 6 +- doc/04_getting_started.qbk | 8 ++- doc/05_getting_serious.qbk | 6 +- doc/06_algorithms.qbk | 10 +++ doc/07_converters.qbk | 4 +- doc/08_lexcast_converter.qbk | 2 +- doc/09_sstream_converter.qbk | 8 +-- doc/10_type_requirements.qbk | 2 +- doc/11_other.qbk | 2 +- doc/13_performance.qbk | 29 +++++--- doc/html/boost/convert.html | 56 +++++++-------- doc/html/boost/convert/algorithm_helper.html | 30 ++++---- .../convert/algorithm_helper__idm26160.html | 64 +++++++++++++++++ ...2.html => algorithm_helper__idm26192.html} | 30 ++++---- .../convert/algorithm_helper__idm26304.html | 64 +++++++++++++++++ doc/html/boost/convert/result.html | 48 ++++++------- .../boost_convert/include/parameters_hpp.html | 10 +-- doc/html/index.html | 20 ++++-- doc/html/index/s16.html | 14 ++-- doc/html/standalone_HTML.manifest | 2 +- ..._boost__lexical_cast__based_converter.html | 2 +- .../__std__stringstream__based_converter.html | 17 +++-- .../locale_support.html | 2 +- .../convert_algorithms.html | 12 ++++ .../the_boost_convert_library/converters.html | 6 +- .../getting_serious.html | 12 ++-- .../getting_started.html | 13 +++- .../other_conversions.html | 2 +- .../performance.html | 69 ++++++++++++------- .../type_requirements.html | 2 +- include/api.hpp | 3 +- test/algorithms.cpp | 30 +++++++- test/encryption.cpp | 33 +++++++++ test/test.hpp | 1 + test/test_convert.cpp | 26 +------ 35 files changed, 439 insertions(+), 206 deletions(-) create mode 100644 doc/html/boost/convert/algorithm_helper__idm26160.html rename doc/html/boost/convert/{algorithm_helper__idm26272.html => algorithm_helper__idm26192.html} (85%) create mode 100644 doc/html/boost/convert/algorithm_helper__idm26304.html create mode 100644 test/encryption.cpp diff --git a/doc/01_introduction.qbk b/doc/01_introduction.qbk index c1133c4..013c38f 100644 --- a/doc/01_introduction.qbk +++ b/doc/01_introduction.qbk @@ -2,9 +2,9 @@ [*Please note that the described framework is not part of the Boost library collection even though in this document it is referred to as ['Boost.Convert]. This is done in preparation for potential submission of the library to ['Boost].] -The main purpose of the framework is to channel various conversion facilities through one uniform interface and to provide generic consistent behavior -- one of the factors in improving productivity and code-correctness in commercial s/w development environment. +The main purpose of the framework is to unify and to deploy various conversion facilities through one uniform interface, to provide generic consistent behavior -- one of the factors in improving productivity and code-correctness in commercial s/w development environment. -['Boost.Convert] builds on the ['boost::lexical_cast] design and experience and takes those conversion\/transformation-related ideas further +['Boost.Convert] builds on the ['boost::lexical_cast] experience and takes those conversion\/transformation-related ideas further * to be applicable to a wider range of conversion-related deployment scenarios, * to provide a more flexible, extensible and configurable type-conversion framework. @@ -14,6 +14,8 @@ The main purpose of the framework is to channel various conversion facilities th * the API facade to provide simple, minimal and uniform deployment interface and behavior; * the extendible library of pluggable converters. +The API facade ['specifies and formalizes the contract] between the user and actual conversion facilities. That minimizes dependency of the application-domain (user) code on any particular infrastructure (conversion) API. New (quicker or richer in functionality or domain-specific) converters can be deployed later in the development process and with minimal or no impact on the existing code base as long as those converters conform to that specified contract. + The API facade implements new and familiar conversion\/transformation-related behavior such as: * flexible throwing, delayed-throwing and non-throwing failed-conversion behavior; diff --git a/doc/04_getting_started.qbk b/doc/04_getting_started.qbk index b9bdef2..6dde50c 100644 --- a/doc/04_getting_started.qbk +++ b/doc/04_getting_started.qbk @@ -1,6 +1,8 @@ [section Getting Started] -In its simplest form the conversion functionality might be deployed as follows: +Given the ubiquity of and the familiarity of the programming community with ['boost::lexical_cast], here and further in the documentation ['boost::lexical_cast] is often mentioned as a reference. + +In its simplest form the ['Boost.Convert] functionality might be deployed as follows: #include #include @@ -13,7 +15,7 @@ In its simplest form the conversion functionality might be deployed as follows: int i2 = convert::from(str, cnv).value(); // Throws if the conversion fails int i3 = convert::from(str, cnv).value_or(-1); // Returns -1 if the conversion fails -These calls can be interpreted as "['Convert a string to int]" for ['i1] and ['i2] and "['Convert a string to int and return -1 if the conversion fails]" for ['i3]. +The above calls can be interpreted as "['Convert a string to int]" for ['i1] and ['i2] and "['Convert a string to int and return -1 if the conversion fails]" for ['i3]. The ['i1] and ['i2] deployments look sufficiently close and, in fact, are identical behaviorally. Namely, if the requested conversion fails, an exception is thrown. The user request -- "['Convert a string to int]" -- lacks the specification for the failure use-case. Consequently, ['boost::lexical_cast] and ['boost::convert] resort to handling that not-mentioned use-case in the standard way. @@ -38,7 +40,7 @@ Or even shorter, if we do not care logging: ... proceed -So far the deployment of ['boost::convert] seems more compact and natural (your mileage may vary) and might be potentially more efficient compared to ['boost::lexical_cast] deployment which achieves a similar (excluding formatting) result with something like +So far the deployment of ['boost::convert] seems more compact and natural (your mileage may vary) and might be potentially more efficient compared to ['boost::lexical_cast] deployment which achieves a similar (excluding ['hex] and ['decimal] formatting) result with something like int num_threads; diff --git a/doc/05_getting_serious.qbk b/doc/05_getting_serious.qbk index ad5e2ce..8a01f41 100644 --- a/doc/05_getting_serious.qbk +++ b/doc/05_getting_serious.qbk @@ -4,7 +4,7 @@ if (i2 == -1) failed to convert -The code above is sufficiently straightforward. A wrinkle though is that it is not entirely generic and deterministic as -1 might be the result of a conversion failure or the successful conversion of the "-1" string. Still, with "spare" values available outside the valid\/sensible range to indicate conversion failures such deployment might be quite adequate without introducing the above-mentioned behavioral non-determinism. Alternatively, it might be not that uncommon for applications to ignore conversion failures altogether and to simply proceed with the supplied fallback value. +The code above is sufficiently straightforward. A wrinkle though is that it is not entirely generic and deterministic as -1 might be the result of a conversion failure or the successful conversion of the "-1" string. Still, with "spare" values available outside the valid\/sensible range to indicate conversion failures such deployment might be adequate without introducing the above-mentioned behavioral non-determinism. Alternatively, it might be not that uncommon for applications to ignore conversion failures altogether and to simply proceed with the supplied fallback value. Applications outside these mentioned categories still require a conversion failure reliably detected and processed accordingly. The ['boost::lexical_cast]'s answer to the problem is to throw on failure and ['boost::convert] supports that behavior as well: @@ -16,7 +16,7 @@ Applications outside these mentioned categories still require a conversion failu } catch (...) { - Conversion failed + // Handle failed conversion } However, to cater for a wider range of program-flow variations ['boost::convert] adds the flexibility of @@ -36,7 +36,7 @@ However, to cater for a wider range of program-flow variations ['boost::convert] } catch (...) { - Conversion failed + // Handle failed conversion } // Exceptions are avoided altogether diff --git a/doc/06_algorithms.qbk b/doc/06_algorithms.qbk index 59c7b87..c860a58 100644 --- a/doc/06_algorithms.qbk +++ b/doc/06_algorithms.qbk @@ -64,4 +64,14 @@ And at last a fully working version (with a conversion-failure fallback value pr BOOST_ASSERT(integers[3] == 18); BOOST_ASSERT(integers[4] == -1); // Failed conversion +The following ['convert::result]-based version is not available with pre-C++11 compilers: + + std::vector::result> opt_ints; + + std::transform( + strings.begin(), + strings.end(), + std::back_inserter(opt_ints), + convert::from(ccnv(std::hex))); + [endsect] diff --git a/doc/07_converters.qbk b/doc/07_converters.qbk index 4d7bb70..33a07af 100644 --- a/doc/07_converters.qbk +++ b/doc/07_converters.qbk @@ -1,6 +1,6 @@ [section Converters] -The ['Boost.Convert] facade API plays an important role as it is responsible for and provides a uniform interface and ensures consistent behavior. However, it is the respective plugged-in converter who does the hard work of turning integers to strings and strings to custom-types, etc., i.e. the hard work of actual type conversion\/transformation. +The ['Boost.Convert] facade API plays an important role as it is responsible for and provides a uniform interface and ensures consistent behavior. However, it is the respective plugged-in converter who does the hard work of turning integers into strings and strings into custom-types, etc., i.e. the hard work of actual type conversion\/transformation. For a converter to be plugged in to the ['Boost.Convert] framework it needs to be a ['callable] with the following signature: @@ -11,7 +11,7 @@ if that is a general-purpose converter capable of handling many types (like stri bool operator()(TypeIn const& value_in, TypeOut& result_out) const; -if its sole purpose is to handle one particular conversion\/transformation of TypeIn to TypeOut. For example, a converter from the operating-system-specific MBCS string format to the UCS-2 or UCS-4 (depending on wchar_t size) does not seem like such a crazy idea: +if its sole purpose is to handle one particular conversion\/transformation of TypeIn to TypeOut. For example, a converter from the operating-system-specific MBCS string format to the UCS-2 or UCS-4 (depending on wchar_t size) does not seem like such a unreasonable idea: bool operator()(std::string const& value_in, std::wstring& result_out) const; diff --git a/doc/08_lexcast_converter.qbk b/doc/08_lexcast_converter.qbk index 6c06cba..3f54cb6 100644 --- a/doc/08_lexcast_converter.qbk +++ b/doc/08_lexcast_converter.qbk @@ -2,7 +2,7 @@ The converter is deployed with - #include + #include The purpose of the converter is diff --git a/doc/09_sstream_converter.qbk b/doc/09_sstream_converter.qbk index 78d5875..2a4fcce 100644 --- a/doc/09_sstream_converter.qbk +++ b/doc/09_sstream_converter.qbk @@ -4,9 +4,9 @@ The converter is deployed with - #include + #include -The purpose of this converter is to provide conversion-related formatting and locale support not present in ['boost::lexical_cast]. Advantages of a ['std::stream]-based engine are +Its purpose is to provide conversion-related formatting and locale support not present in ['boost::lexical_cast]. Advantages of a ['std::stream]-based engine are * availability and maturity; * formatting and locale support; @@ -16,7 +16,7 @@ The purpose of this converter is to provide conversion-related formatting and lo [section Formatting Support] -Formatting support is provided by the underlying ['std::stringstream]. Consequently, ['sstream_converter] API heavily borrows formatting metaphors from this underlying component. One such metaphor is the ['manipulator] represented by ['std::hex], ['std::dec], ['std::uppercase], ['std::scientific], etc. +Formatting support is provided by the underlying ['std::stringstream]. Consequently, the API heavily borrows formatting metaphors from this underlying component. One such metaphor is the ['manipulator] represented by ['std::hex], ['std::dec], ['std::uppercase], ['std::scientific], etc. The following code demonstrates how the converter is configured on-the-fly to read ['char] and ['wchar_t] strings in the ['std::hex] or ['std::dec] format: @@ -61,7 +61,7 @@ which is equivalent to the following ['manipulator]-based variant: Locale support is similar to the formatting support as demonstrated by the following example (the Linux version): - #include + #include using boost::convert; diff --git a/doc/10_type_requirements.qbk b/doc/10_type_requirements.qbk index d932eb0..209faf1 100644 --- a/doc/10_type_requirements.qbk +++ b/doc/10_type_requirements.qbk @@ -12,7 +12,7 @@ The first two requirements are imposed by the ['boost::lexical_cast] design and In turn, the ['Boost.Convert] API facade has the following requirements: * TypeOut needs to be ['Copy Constructible]; -* TypeOut needs to be ['Default Constructible] by default. +* TypeOut needs to be ['Default Constructible] by ['default]. Additional requirements might be imposed by the respective converter. For example, both mentioned -- ['boost::lexical_cast]-based and ['std::stringstream]-based -- converters require diff --git a/doc/11_other.qbk b/doc/11_other.qbk index 7113fd9..e8cf588 100644 --- a/doc/11_other.qbk +++ b/doc/11_other.qbk @@ -2,7 +2,7 @@ An interesting (yet to be explored) feature of the described design is that ['Boost.Convert] is not limited to string-to-type and type-to-string conversions. The ['Boost.Convert] API facade is type-agnostic and the plugged-in converter ultimately dictates what type transformations are available. Consequently, a wide range of conversion\/transformation-related tasks can be addressed and deployed ['uniformly] by plugging-in special-purpose converters. -As an experiment the code below (taken from ['test/test_convert.cpp]) does not do type conversion. Instead it applies a string transformation: +As an experiment the code below (taken from ['test/encryption.cpp]) does not do type conversion. Instead it applies a string transformation: string encrypted = convert::from("ABC", my_cypher).value(); string decrypted = convert::from(encrypted, my_cypher).value(); diff --git a/doc/13_performance.qbk b/doc/13_performance.qbk index 39d9ce8..06598c0 100644 --- a/doc/13_performance.qbk +++ b/doc/13_performance.qbk @@ -1,19 +1,19 @@ [section Performance] -The performance of ['Boost.Convert] entirely depends on the converter deployed. The mentioned convertors have been tested as part of the ['Boost.Convert] framework. Raw ['scanf()] and ['boost::lexical_cast] have also been tested but showed identical results (when tests are built optimized) to when they were deployed through the ['Boost.Convert] framework. Consequently, for brevity those raw ['scanf()] and ['boost::lexical_cast] results are not shown here. The C++11 family of ['std::to_string()], ['std::stoi()], etc. were not tested due to unavailablility. +The performance of ['Boost.Convert] depends entirely on the converter deployed. The previously mentioned convertors have been tested as part of the ['Boost.Convert] framework (see ['test/performance.cpp]). Raw ['scanf()] and ['boost::lexical_cast] have also been tested but showed identical results (when tests are built optimized) to when they were deployed through the ['Boost.Convert] framework. Consequently, for brevity those raw ['scanf()] and ['boost::lexical_cast] results are not shown here. The C++11 family of ['std::to_string()], ['std::stoi()], etc. were not tested due to present unavailablility. -Performance was tested for string conversions to the ['integer] type and a user-defined type. See the actual code in ['test/performance.cpp]. On a Ubuntu box (compiled with gcc 4.6.3) tests produced the following results: +Performance was tested for string conversions to the ['integer] type and to a user-defined type. On a Ubuntu box (compiled with gcc 4.6.3) tests produced the following results: - g++ -O3 test_convert.cpp - str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.70 seconds. - int-to-str: ltostr/scanf/lcast/sstream=1.50/2.17/1.11/1.73 seconds. - str-to-user-type: lcast/sstream=3.26/2.58 seconds. - - g++ -O0 test_convert.cpp + g++ -O0 test_convert.cpp <--- NON-OPTIMIZED str-to-int: strtol/scanf/lcast/sstream=0.49/1.40/1.56/2.00 seconds. int-to-str: ltostr/scanf/lcast/sstream=3.10/2.62/2.42/2.52 seconds. str-to-user-type: lcast/sstream=4.94/3.19 seconds. + g++ -O3 test_convert.cpp <--- OPTIMIZED + str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.70 seconds. + int-to-str: ltostr/scanf/lcast/sstream=1.50/2.17/1.11/1.73 seconds. + str-to-user-type: lcast/sstream=3.26/2.58 seconds. + On the Cygwin platform compiled with gcc 4.8.2: g++ -O3 test_convert.cpp @@ -27,11 +27,18 @@ Compiled with MS Visual C++ 2010 Express optimized for speed: int-to-str: ltostr/scanf/lcast/sstream=1.11/1.86/1.91/5.92 seconds. str-to-user-type: lcast/sstream=6.81/3.30 seconds. -Non-optimized times are more of a curiosity -- to demonstrate (and to remind) that considerable performance is to be gained via optimized compilation. Optimized times are the ones to be looked at and analyzed. +Non-optimized times are more of a curiosity -- to demonstrate (and to remind) that a noticeable performance improvement is to be gained via optimized compilation. Optimized times are the ones to be looked at and analyzed. -For user-defined types only two converters were tested -- ['boost::lexical_cast]-based and the ['std::stringstream]-based converter. Other conversion facilities did not provide that functionality. +For user-defined types two converters -- ['boost::lexical_cast]-based and ['std::stringstream]-based -- were tested. Other conversion facilities did not provide that functionality. -Both converters provide ['string-to-type] and ['type-to-string] conversions. However, their priorities are quite different. For basic (['int], etc.) types ['boost::lexical_cast] performance has been optimized (see [link 5 \[5\]]). Therefore, if speed is your primary objective and your needs do not go beyond basic types, then deploying ['boost::lexical_cast] (directly or via the ['Boost.Convert] framework) might be an option to explore. However, for user-defined types it appears to be quite a different story with ['Boost.Convert] consistently outperforming ['boost::lexical_cast] in the tests. +Both converters provide ['string-to-type] and ['type-to-string] conversions; both deploy the same -- std::sstream -- conversion engine and I suspect both share the same noble goal -- to provide a uniform conversion interface and an extendible conversion framework where new types can be plugged in to the framework via: + + std::istream& operator>>(std::istream&, TypeOut&); + std::ostream& operator<<(std::ostream&, TypeIn const&); + +Unfortunately that comes at a price as ['std::sstream]-based conversions of the basic (['int], etc.) types are comparatively slow. Consequently, for basic types ['boost::lexical_cast] implementation has been optimized (see [link 5 \[5\]]) to exclude ['std::sstream]. ['Boost.Convert] also provides that "optimization" functionality via pluggable converters. Consequently, if speed is your primary objective and your needs do not go beyond basic types, then deploying ['std::to_string/std::stoi], ['strtol], ['printf/scanf], ['boost::lexical_cast] (directly or via the ['Boost.Convert] framework) might be an option to explore. + +However, for user-defined types it appears to be quite a different story with the ['std::stringstream]-based converter consistently outperforming ['boost::lexical_cast] in the tests. These results probably reflect different underlying designs. The standard ['Boost.Convert] usage pattern is to create a converter or converters once and then re-use them. Consequently, performance-wise this deployment pattern is likely to represent the fourth (['std::stringstream without construction]) column of the [link 5 \[5\]] table. diff --git a/doc/html/boost/convert.html b/doc/html/boost/convert.html index f534b85..6e4fc68 100644 --- a/doc/html/boost/convert.html +++ b/doc/html/boost/convert.html @@ -36,22 +36,22 @@ typedef algorithm_helper this_type; // construct/copy/destruct - algorithm_helper(Converter const &); + algorithm_helper(Converter const &); - // public member functions + // public member functions template<typename FallbackType> - with_fallback value_or(FallbackType const &); - TypeOut operator()(TypeIn const &); + with_fallback value_or(FallbackType const &); + TypeOut operator()(TypeIn const &); }; template<typename TypeIn, typename Converter> - struct algorithm_helper<TypeIn, Converter> { + struct algorithm_helper<TypeIn, Converter> { // types - typedef with_fallback this_type; - typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type; + typedef with_fallback this_type; + typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type; - // public member functions - with_fallback(base_type const &, TypeOut const &); - TypeOut operator()(TypeIn const &); + // public member functions + with_fallback(base_type const &, TypeOut const &); + TypeOut operator()(TypeIn const &); // public data members out_type fallback_; @@ -63,38 +63,38 @@ typedef boost::safebool< result > safebool; // construct/copy/destruct - result(out_type const &); + result(out_type const &); - // public member functions - bool operator!() const; - operator typename safebool::type() const; - out_type const & value() const; + // public member functions + bool operator!() const; + operator typename safebool::type() const; + out_type const & value() const; template<typename FallbackType> - out_type value_or(FallbackType const &) const; + out_type value_or(FallbackType const &) const; - // private member functions - this_type & operator()(bool); + // private member functions + this_type & operator()(bool); }; - // public static functions - static out_type create_storage(); + // public static functions + static out_type create_storage(); template<typename TypeIn, typename Converter> - static result_type from(TypeIn const &, Converter const &); + static result_type from(TypeIn const &, Converter const &); template<typename TypeIn, typename Converter> - static algorithm_helper< TypeIn, Converter > from(Converter const &); + static algorithm_helper< TypeIn, Converter > from(Converter const &); };
-

Description

+

Description

-

-convert public static functions

+

+convert public static functions

    -
  1. static out_type create_storage();
  2. +
  3. static out_type create_storage();
  4. template<typename TypeIn, typename Converter> 
       static result_type 
    -  from(TypeIn const & value_in, Converter const & converter);
  5. + from(TypeIn const & value_in, Converter const & converter);
  6. template<typename TypeIn, typename Converter> 
    -  static algorithm_helper< TypeIn, Converter > from(Converter const & cnv);
  7. + static algorithm_helper< TypeIn, Converter > from(Converter const & cnv);
diff --git a/doc/html/boost/convert/algorithm_helper.html b/doc/html/boost/convert/algorithm_helper.html index 3c585df..7ab2a83 100644 --- a/doc/html/boost/convert/algorithm_helper.html +++ b/doc/html/boost/convert/algorithm_helper.html @@ -5,13 +5,13 @@ - + - +
-PrevUpHomeNext +PrevUpHomeNext
@@ -29,27 +29,27 @@ typedef algorithm_helper this_type; // construct/copy/destruct - algorithm_helper(Converter const &); + algorithm_helper(Converter const &); - // public member functions - template<typename FallbackType> with_fallback value_or(FallbackType const &); - TypeOut operator()(TypeIn const &); + // public member functions + template<typename FallbackType> with_fallback value_or(FallbackType const &); + TypeOut operator()(TypeIn const &); };
-

Description

+

Description

-

+

algorithm_helper public construct/copy/destruct

-
  1. algorithm_helper(Converter const & cnv);
+
  1. algorithm_helper(Converter const & cnv);
-

-algorithm_helper public member functions

+

+algorithm_helper public member functions

    -
  1. template<typename FallbackType> with_fallback value_or(FallbackType const &);
  2. -
  3. TypeOut operator()(TypeIn const & value_in);
  4. +
  5. template<typename FallbackType> with_fallback value_or(FallbackType const &);
  6. +
  7. TypeOut operator()(TypeIn const & value_in);
@@ -64,7 +64,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost/convert/algorithm_helper__idm26160.html b/doc/html/boost/convert/algorithm_helper__idm26160.html new file mode 100644 index 0000000..0cd9d55 --- /dev/null +++ b/doc/html/boost/convert/algorithm_helper__idm26160.html @@ -0,0 +1,64 @@ + + + +Struct template algorithm_helper<TypeIn, Converter> + + + + + + + + +
+PrevUpHomeNext +
+
+
+
+

Struct template algorithm_helper<TypeIn, Converter>

+

boost::convert::algorithm_helper<TypeIn, Converter>

+
+

Synopsis

+
// In header: </home/vbatov/dev/boost.convert/include/api.hpp>
+
+
+template<typename TypeIn, typename Converter> 
+struct algorithm_helper<TypeIn, Converter> {
+  // types
+  typedef with_fallback                                                    this_type;
+  typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type;
+
+  // public member functions
+   with_fallback(base_type const &, TypeOut const &);
+  TypeOut operator()(TypeIn const &);
+
+  // public data members
+  out_type fallback_;
+};
+
+

Description

+
+

+algorithm_helper public member functions

+
    +
  1.  with_fallback(base_type const & ah, TypeOut const & fallback);
  2. +
  3. TypeOut operator()(TypeIn const & value_in);
  4. +
+
+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost/convert/algorithm_helper__idm26272.html b/doc/html/boost/convert/algorithm_helper__idm26192.html similarity index 85% rename from doc/html/boost/convert/algorithm_helper__idm26272.html rename to doc/html/boost/convert/algorithm_helper__idm26192.html index dfed2a4..b5e4d48 100644 --- a/doc/html/boost/convert/algorithm_helper__idm26272.html +++ b/doc/html/boost/convert/algorithm_helper__idm26192.html @@ -5,16 +5,16 @@ - +
-PrevUpHomeNext +PrevUpHomeNext
-
+

Struct template algorithm_helper<TypeIn, Converter>

boost::convert::algorithm_helper<TypeIn, Converter>

@@ -24,26 +24,26 @@ template<typename TypeIn, typename Converter> -struct algorithm_helper<TypeIn, Converter> { +struct algorithm_helper<TypeIn, Converter> { // types - typedef with_fallback this_type; - typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type; + typedef with_fallback this_type; + typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type; - // public member functions - with_fallback(base_type const &, TypeOut const &); - TypeOut operator()(TypeIn const &); + // public member functions + with_fallback(base_type const &, TypeOut const &); + TypeOut operator()(TypeIn const &); // public data members out_type fallback_; };
-

Description

+

Description

-

-algorithm_helper public member functions

+

+algorithm_helper public member functions

    -
  1.  with_fallback(base_type const & ah, TypeOut const & fallback);
  2. -
  3. TypeOut operator()(TypeIn const & value_in);
  4. +
  5.  with_fallback(base_type const & ah, TypeOut const & fallback);
  6. +
  7. TypeOut operator()(TypeIn const & value_in);
@@ -58,7 +58,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/boost/convert/algorithm_helper__idm26304.html b/doc/html/boost/convert/algorithm_helper__idm26304.html new file mode 100644 index 0000000..3a97233 --- /dev/null +++ b/doc/html/boost/convert/algorithm_helper__idm26304.html @@ -0,0 +1,64 @@ + + + +Struct template algorithm_helper<TypeIn, Converter> + + + + + + + + +
+PrevUpHomeNext +
+
+
+
+

Struct template algorithm_helper<TypeIn, Converter>

+

boost::convert::algorithm_helper<TypeIn, Converter>

+
+

Synopsis

+
// In header: </home/vbatov/dev/boost.convert/include/api.hpp>
+
+
+template<typename TypeIn, typename Converter> 
+struct algorithm_helper<TypeIn, Converter> {
+  // types
+  typedef with_fallback                                                    this_type;
+  typedef boost::convert< TypeOut >::algorithm_helper< TypeIn, Converter > base_type;
+
+  // public member functions
+   with_fallback(base_type const &, TypeOut const &);
+  TypeOut operator()(TypeIn const &);
+
+  // public data members
+  out_type fallback_;
+};
+
+

Description

+
+

+algorithm_helper public member functions

+
    +
  1.  with_fallback(base_type const & ah, TypeOut const & fallback);
  2. +
  3. TypeOut operator()(TypeIn const & value_in);
  4. +
+
+
+
+ + + +
+
+
+PrevUpHomeNext +
+ + diff --git a/doc/html/boost/convert/result.html b/doc/html/boost/convert/result.html index 28a7408..b368841 100644 --- a/doc/html/boost/convert/result.html +++ b/doc/html/boost/convert/result.html @@ -5,13 +5,13 @@ - - + +
-PrevUpHomeNext +PrevUpHomeNext
@@ -30,42 +30,42 @@ typedef boost::safebool< result > safebool; // construct/copy/destruct - result(out_type const &); + result(out_type const &); - // public member functions - bool operator!() const; - operator typename safebool::type() const; - out_type const & value() const; + // public member functions + bool operator!() const; + operator typename safebool::type() const; + out_type const & value() const; template<typename FallbackType> - out_type value_or(FallbackType const &) const; + out_type value_or(FallbackType const &) const; - // private member functions - this_type & operator()(bool); + // private member functions + this_type & operator()(bool); };
-

Description

+

Description

-

+

result public construct/copy/destruct

-
  1. result(out_type const & v);
+
  1. result(out_type const & v);
-

-result public member functions

+

+result public member functions

    -
  1. bool operator!() const;
  2. -
  3. operator typename safebool::type() const;
  4. -
  5. out_type const & value() const;
  6. +
  7. bool operator!() const;
  8. +
  9. operator typename safebool::type() const;
  10. +
  11. out_type const & value() const;
  12. template<typename FallbackType> 
    -  out_type value_or(FallbackType const & fallback) const;
  13. + out_type value_or(FallbackType const & fallback) const;
-

-result private member functions

-
  1. this_type & operator()(bool good);
+

+result private member functions

+
  1. this_type & operator()(bool good);
@@ -79,7 +79,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/header/home/vbatov/dev/boost_convert/include/parameters_hpp.html b/doc/html/header/home/vbatov/dev/boost_convert/include/parameters_hpp.html index 068af45..539bfc4 100644 --- a/doc/html/header/home/vbatov/dev/boost_convert/include/parameters_hpp.html +++ b/doc/html/header/home/vbatov/dev/boost_convert/include/parameters_hpp.html @@ -21,11 +21,11 @@ struct base; struct notation; namespace parameter { - BOOST_PARAMETER_KEYWORD(type, base); - BOOST_PARAMETER_KEYWORD(type, locale); - BOOST_PARAMETER_KEYWORD(type, precision); - BOOST_PARAMETER_KEYWORD(type, uppercase); - BOOST_PARAMETER_KEYWORD(type, notation); + BOOST_PARAMETER_KEYWORD(type, base); + BOOST_PARAMETER_KEYWORD(type, locale); + BOOST_PARAMETER_KEYWORD(type, precision); + BOOST_PARAMETER_KEYWORD(type, uppercase); + BOOST_PARAMETER_KEYWORD(type, notation); } } } diff --git a/doc/html/index.html b/doc/html/index.html index 02db06c..8913b52 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -74,15 +74,14 @@ submission of the library to Boost.

- The main purpose of the framework is to channel various conversion facilities - through one uniform interface and to provide generic consistent behavior -- - one of the factors in improving productivity and code-correctness in commercial + The main purpose of the framework is to unify and to deploy various conversion + facilities through one uniform interface, to provide generic consistent behavior + -- one of the factors in improving productivity and code-correctness in commercial s/w development environment.

Boost.Convert builds on the boost::lexical_cast - design and experience and takes those conversion/transformation-related ideas - further + experience and takes those conversion/transformation-related ideas further

  • @@ -105,6 +104,15 @@ the extendible library of pluggable converters.
+

+ The API facade specifies and formalizes the contract between + the user and actual conversion facilities. That minimizes dependency of the + application-domain (user) code on any particular infrastructure (conversion) + API. New (quicker or richer in functionality or domain-specific) converters + can be deployed later in the development process and with minimal or no impact + on the existing code base as long as those converters conform to that specified + contract. +

The API facade implements new and familiar conversion/transformation-related behavior such as: @@ -200,7 +208,7 @@ - +

Last revised: March 02, 2014 at 22:31:24 GMT

Last revised: March 11, 2014 at 01:40:09 GMT


diff --git a/doc/html/index/s16.html b/doc/html/index/s16.html index 192b042..ea1579f 100644 --- a/doc/html/index/s16.html +++ b/doc/html/index/s16.html @@ -14,7 +14,7 @@

-Index

+Index

B C F O R S T V W

@@ -133,7 +133,7 @@
diff --git a/doc/html/standalone_HTML.manifest b/doc/html/standalone_HTML.manifest index caa75ab..0626d68 100644 --- a/doc/html/standalone_HTML.manifest +++ b/doc/html/standalone_HTML.manifest @@ -14,7 +14,7 @@ the_boost_convert_library/other_conversions.html convert_reference.html boost/convert.html boost/convert/algorithm_helper.html -boost/convert/algorithm_helper__idm26272.html +boost/convert/algorithm_helper__idm26160.html boost/convert/result.html header//home/vbatov/dev/boost_convert/include/parameters_hpp.html boost/conversion/base.html diff --git a/doc/html/the_boost_convert_library/__boost__lexical_cast__based_converter.html b/doc/html/the_boost_convert_library/__boost__lexical_cast__based_converter.html index 8281ba1..d592d4d 100644 --- a/doc/html/the_boost_convert_library/__boost__lexical_cast__based_converter.html +++ b/doc/html/the_boost_convert_library/__boost__lexical_cast__based_converter.html @@ -21,7 +21,7 @@

The converter is deployed with

-
#include <boost/convert/lexical_cast_converter.hpp>
+
#include <boost/convert/converter/lexical_cast.hpp>
 

The purpose of the converter is diff --git a/doc/html/the_boost_convert_library/__std__stringstream__based_converter.html b/doc/html/the_boost_convert_library/__std__stringstream__based_converter.html index 58de746..be372c9 100644 --- a/doc/html/the_boost_convert_library/__std__stringstream__based_converter.html +++ b/doc/html/the_boost_convert_library/__std__stringstream__based_converter.html @@ -33,12 +33,12 @@

The converter is deployed with

-
#include <boost/convert/sstream_converter.hpp>
+
#include <boost/convert/converter/sstream.hpp>
 

- The purpose of this converter is to provide conversion-related formatting and - locale support not present in boost::lexical_cast. Advantages - of a std::stream-based engine are + Its purpose is to provide conversion-related formatting and locale support + not present in boost::lexical_cast. Advantages of a std::stream-based + engine are

  • @@ -65,11 +65,10 @@

Formatting support is provided by the underlying std::stringstream. - Consequently, sstream_converter API heavily borrows - formatting metaphors from this underlying component. One such metaphor is - the manipulator represented by std::hex, - std::dec, std::uppercase, std::scientific, - etc. + Consequently, the API heavily borrows formatting metaphors from this underlying + component. One such metaphor is the manipulator represented + by std::hex, std::dec, std::uppercase, + std::scientific, etc.

The following code demonstrates how the converter is configured on-the-fly diff --git a/doc/html/the_boost_convert_library/__std__stringstream__based_converter/locale_support.html b/doc/html/the_boost_convert_library/__std__stringstream__based_converter/locale_support.html index f883970..1a41370 100644 --- a/doc/html/the_boost_convert_library/__std__stringstream__based_converter/locale_support.html +++ b/doc/html/the_boost_convert_library/__std__stringstream__based_converter/locale_support.html @@ -22,7 +22,7 @@ Locale support is similar to the formatting support as demonstrated by the following example (the Linux version):

-
#include <boost/convert/sstream_converter.hpp>
+
#include <boost/convert/converter/sstream.hpp>
 
 using boost::convert;
 
diff --git a/doc/html/the_boost_convert_library/convert_algorithms.html b/doc/html/the_boost_convert_library/convert_algorithms.html
index ccdbfcf..8adfbf9 100644
--- a/doc/html/the_boost_convert_library/convert_algorithms.html
+++ b/doc/html/the_boost_convert_library/convert_algorithms.html
@@ -90,6 +90,18 @@
 BOOST_ASSERT(integers[3] == 18);
 BOOST_ASSERT(integers[4] == -1); // Failed conversion
 
+

+ The following convert<int>::result-based version + is not available with pre-C++11 compilers: +

+
std::vector<convert<int>::result> opt_ints;
+
+std::transform(
+   strings.begin(),
+   strings.end(),
+   std::back_inserter(opt_ints),
+   convert<int>::from<std::string>(ccnv(std::hex)));
+
diff --git a/doc/html/the_boost_convert_library/converters.html b/doc/html/the_boost_convert_library/converters.html index 38c43d0..cc86c1a 100644 --- a/doc/html/the_boost_convert_library/converters.html +++ b/doc/html/the_boost_convert_library/converters.html @@ -21,8 +21,8 @@ The Boost.Convert facade API plays an important role as it is responsible for and provides a uniform interface and ensures consistent behavior. However, it is the respective plugged-in converter who does the hard - work of turning integers to strings and strings to custom-types, etc., i.e. - the hard work of actual type conversion/transformation. + work of turning integers into strings and strings into custom-types, etc., + i.e. the hard work of actual type conversion/transformation.

For a converter to be plugged in to the Boost.Convert @@ -43,7 +43,7 @@ if its sole purpose is to handle one particular conversion/transformation of TypeIn to TypeOut. For example, a converter from the operating-system-specific MBCS string format to the UCS-2 or UCS-4 (depending on wchar_t size) does not - seem like such a crazy idea: + seem like such a unreasonable idea:

bool operator()(std::string const& value_in, std::wstring& result_out) const;
 
diff --git a/doc/html/the_boost_convert_library/getting_serious.html b/doc/html/the_boost_convert_library/getting_serious.html index a0edbc4..5b621c2 100644 --- a/doc/html/the_boost_convert_library/getting_serious.html +++ b/doc/html/the_boost_convert_library/getting_serious.html @@ -26,10 +26,10 @@ is not entirely generic and deterministic as -1 might be the result of a conversion failure or the successful conversion of the "-1" string. Still, with "spare" values available outside the valid/sensible range to indicate - conversion failures such deployment might be quite adequate without introducing - the above-mentioned behavioral non-determinism. Alternatively, it might be - not that uncommon for applications to ignore conversion failures altogether - and to simply proceed with the supplied fallback value. + conversion failures such deployment might be adequate without introducing the + above-mentioned behavioral non-determinism. Alternatively, it might be not + that uncommon for applications to ignore conversion failures altogether and + to simply proceed with the supplied fallback value.

Applications outside these mentioned categories still require a conversion @@ -45,7 +45,7 @@ } catch (...) { - Conversion failed + // Handle failed conversion }

@@ -73,7 +73,7 @@ } catch (...) { - Conversion failed + // Handle failed conversion } // Exceptions are avoided altogether diff --git a/doc/html/the_boost_convert_library/getting_started.html b/doc/html/the_boost_convert_library/getting_started.html index 48348c6..c05a0c3 100644 --- a/doc/html/the_boost_convert_library/getting_started.html +++ b/doc/html/the_boost_convert_library/getting_started.html @@ -18,7 +18,13 @@ Getting Started

- In its simplest form the conversion functionality might be deployed as follows: + Given the ubiquity of and the familiarity of the programming community with + boost::lexical_cast, here and further in the documentation + boost::lexical_cast is often mentioned as a reference. +

+

+ In its simplest form the Boost.Convert functionality might + be deployed as follows:

#include <boost/convert/api.hpp>
 #include <boost/convert/sstream_converter.hpp>
@@ -32,7 +38,7 @@
 int i3 = convert<int>::from(str, cnv).value_or(-1); // Returns -1 if the conversion fails
 

- These calls can be interpreted as "Convert a string to int" + The above calls can be interpreted as "Convert a string to int" for i1 and i2 and "Convert a string to int and return -1 if the conversion fails" for i3. @@ -77,7 +83,8 @@ So far the deployment of boost::convert seems more compact and natural (your mileage may vary) and might be potentially more efficient compared to boost::lexical_cast deployment which achieves - a similar (excluding formatting) result with something like + a similar (excluding hex and decimal + formatting) result with something like

int num_threads;
 
diff --git a/doc/html/the_boost_convert_library/other_conversions.html b/doc/html/the_boost_convert_library/other_conversions.html
index 168f5bc..58a21a1 100644
--- a/doc/html/the_boost_convert_library/other_conversions.html
+++ b/doc/html/the_boost_convert_library/other_conversions.html
@@ -27,7 +27,7 @@
       special-purpose converters.
     

- As an experiment the code below (taken from test/test_convert.cpp) + As an experiment the code below (taken from test/encryption.cpp) does not do type conversion. Instead it applies a string transformation:

string encrypted = convert<string>::from("ABC", my_cypher).value();
diff --git a/doc/html/the_boost_convert_library/performance.html b/doc/html/the_boost_convert_library/performance.html
index 4ae85e3..a03a2ba 100644
--- a/doc/html/the_boost_convert_library/performance.html
+++ b/doc/html/the_boost_convert_library/performance.html
@@ -18,30 +18,30 @@
 Performance
 
 

- The performance of Boost.Convert entirely depends on the - converter deployed. The mentioned convertors have been tested as part of the - Boost.Convert framework. Raw scanf() - and boost::lexical_cast have also been tested but showed - identical results (when tests are built optimized) to when they were deployed - through the Boost.Convert framework. Consequently, for - brevity those raw scanf() and boost::lexical_cast + The performance of Boost.Convert depends entirely on the + converter deployed. The previously mentioned convertors have been tested as + part of the Boost.Convert framework (see test/performance.cpp). + Raw scanf() and boost::lexical_cast + have also been tested but showed identical results (when tests are built optimized) + to when they were deployed through the Boost.Convert framework. + Consequently, for brevity those raw scanf() and boost::lexical_cast results are not shown here. The C++11 family of std::to_string(), - std::stoi(), etc. were not tested due to unavailablility. + std::stoi(), etc. were not tested due to present unavailablility.

Performance was tested for string conversions to the integer - type and a user-defined type. See the actual code in test/performance.cpp. - On a Ubuntu box (compiled with gcc 4.6.3) tests produced the following results: + type and to a user-defined type. On a Ubuntu box (compiled with gcc 4.6.3) + tests produced the following results:

-
g++ -O3 test_convert.cpp
-str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.70 seconds.
-int-to-str: ltostr/scanf/lcast/sstream=1.50/2.17/1.11/1.73 seconds.
-str-to-user-type: lcast/sstream=3.26/2.58 seconds.
-
-g++ -O0 test_convert.cpp
+
g++ -O0 test_convert.cpp <--- NON-OPTIMIZED
 str-to-int: strtol/scanf/lcast/sstream=0.49/1.40/1.56/2.00 seconds.
 int-to-str: ltostr/scanf/lcast/sstream=3.10/2.62/2.42/2.52 seconds.
 str-to-user-type: lcast/sstream=4.94/3.19 seconds.
+
+g++ -O3 test_convert.cpp <--- OPTIMIZED
+str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.70 seconds.
+int-to-str: ltostr/scanf/lcast/sstream=1.50/2.17/1.11/1.73 seconds.
+str-to-user-type: lcast/sstream=3.26/2.58 seconds.
 

On the Cygwin platform compiled with gcc 4.8.2: @@ -60,23 +60,40 @@

Non-optimized times are more of a curiosity -- to demonstrate (and to remind) - that considerable performance is to be gained via optimized compilation. Optimized - times are the ones to be looked at and analyzed. + that a noticeable performance improvement is to be gained via optimized compilation. + Optimized times are the ones to be looked at and analyzed.

- For user-defined types only two converters were tested -- boost::lexical_cast-based - and the std::stringstream-based converter. Other conversion + For user-defined types two converters -- boost::lexical_cast-based + and std::stringstream-based -- were tested. Other conversion facilities did not provide that functionality.

Both converters provide string-to-type and type-to-string - conversions. However, their priorities are quite different. For basic (int, - etc.) types boost::lexical_cast performance has been optimized - (see [5]). Therefore, if speed is your primary objective - and your needs do not go beyond basic types, then deploying boost::lexical_cast + conversions; both deploy the same -- std::sstream -- conversion engine and + I suspect both share the same noble goal -- to provide a uniform conversion + interface and an extendible conversion framework where new types can be plugged + in to the framework via: +

+
std::istream& operator>>(std::istream&, TypeOut&);
+std::ostream& operator<<(std::ostream&, TypeIn const&);
+
+

+ Unfortunately that comes at a price as std::sstream-based + conversions of the basic (int, etc.) types are comparatively + slow. Consequently, for basic types boost::lexical_cast + implementation has been optimized (see [5]) to exclude + std::sstream. Boost.Convert also + provides that "optimization" functionality via pluggable converters. + Consequently, if speed is your primary objective and your needs do not go beyond + basic types, then deploying std::to_string/std::stoi, + strtol, printf/scanf, boost::lexical_cast (directly or via the Boost.Convert framework) might be - an option to explore. However, for user-defined types it appears to be quite - a different story with Boost.Convert consistently outperforming + an option to explore. +

+

+ However, for user-defined types it appears to be quite a different story with + the std::stringstream-based converter consistently outperforming boost::lexical_cast in the tests.

diff --git a/doc/html/the_boost_convert_library/type_requirements.html b/doc/html/the_boost_convert_library/type_requirements.html index a7dd856..61b868e 100644 --- a/doc/html/the_boost_convert_library/type_requirements.html +++ b/doc/html/the_boost_convert_library/type_requirements.html @@ -49,7 +49,7 @@ TypeOut needs to be Copy Constructible;

  • - TypeOut needs to be Default Constructible by default. + TypeOut needs to be Default Constructible by default.
  • diff --git a/include/api.hpp b/include/api.hpp index e3e21fb..9142e49 100644 --- a/include/api.hpp +++ b/include/api.hpp @@ -101,6 +101,7 @@ struct boost::convert::result private: friend struct boost::convert; + template friend struct boost::convert::algorithm_helper; this_type& operator()(bool good) { return (good_ = good, *this); } @@ -126,7 +127,7 @@ struct boost::convert::algorithm_helper { out_type result = boost::convert::create_storage(); bool good = (*converter_)(value_in, result); - + if (!good) BOOST_THROW_EXCEPTION(std::invalid_argument("boost::convert failed")); diff --git a/test/algorithms.cpp b/test/algorithms.cpp index 55f794e..d12d69e 100644 --- a/test/algorithms.cpp +++ b/test/algorithms.cpp @@ -57,6 +57,7 @@ test::algorithms() //////////////////////////////////////////////////////////////////////////// // String to integer conversion. Explicit fallback, i.e. no throwing. Hex formatting. //////////////////////////////////////////////////////////////////////////// + std::transform( strings.begin(), strings.end(), @@ -70,9 +71,33 @@ test::algorithms() BOOST_ASSERT(integers[3] == 18); BOOST_ASSERT(integers[4] == -1); // Failed conversion +#ifdef NOT_AVAILABLE_UNTIL_CPP11 + + std::vector::result> opt_ints; + + std::transform( + strings.begin(), + strings.end(), + std::back_inserter(opt_ints), + boost::convert::from(ccnv(arg::base = cnv::base::hex))); + + BOOST_ASSERT(opt_ints.size() == 5); + BOOST_ASSERT( opt_ints[0]); + BOOST_ASSERT( opt_ints[1]); + BOOST_ASSERT( opt_ints[2]); + BOOST_ASSERT( opt_ints[3]); + BOOST_ASSERT(!opt_ints[4]); // Failed conversion + BOOST_ASSERT(opt_ints[0].value() == 15); + BOOST_ASSERT(opt_ints[1].value() == 16); + BOOST_ASSERT(opt_ints[2].value() == 17); + BOOST_ASSERT(opt_ints[3].value() == 18); + +#endif + //////////////////////////////////////////////////////////////////////////// // int-to-string conversion. No explicit fallback value. //////////////////////////////////////////////////////////////////////////// + std::transform( integers.begin(), integers.end(), @@ -85,4 +110,7 @@ test::algorithms() BOOST_ASSERT(new_strings[2] == "17"); BOOST_ASSERT(new_strings[3] == "18"); BOOST_ASSERT(new_strings[4] == "-1"); -} \ No newline at end of file + + + +} diff --git a/test/encryption.cpp b/test/encryption.cpp new file mode 100644 index 0000000..6b330d8 --- /dev/null +++ b/test/encryption.cpp @@ -0,0 +1,33 @@ +#include "./test.hpp" + +using std::string; +using std::wstring; +using boost::convert; + +static +bool +my_cypher(std::string const& value_in, std::string& value_out) +{ + size_t const cypher = 'A' - '1'; + + value_out = value_in; + + for (string::iterator it = value_out.begin(); it != value_out.end(); ++it) + (*it < 'A') ? (*it += cypher) : (*it -= cypher); + + return true; +} + +void +test::encryption() +{ + //////////////////////////////////////////////////////////////////////////// + // Testing custom converter. + //////////////////////////////////////////////////////////////////////////// + + string encrypted = convert::from("ABC", my_cypher).value(); + string decrypted = convert::from(encrypted, my_cypher).value(); + + BOOST_ASSERT(encrypted == "123"); + BOOST_ASSERT(decrypted == "ABC"); +} diff --git a/test/test.hpp b/test/test.hpp index 8d3d766..ea21758 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -96,6 +96,7 @@ struct test static void sfinae(); static void algorithms(); static void performance(); + static void encryption (); template static void type_to_string(Converter const&); template static void string_to_type(Converter const&); diff --git a/test/test_convert.cpp b/test/test_convert.cpp index 9caab09..995dfc8 100644 --- a/test/test_convert.cpp +++ b/test/test_convert.cpp @@ -8,26 +8,13 @@ #include "./sfinae.cpp" #include "./algorithms.cpp" #include "./performance.cpp" +#include "./encryption.cpp" #endif using std::string; using std::wstring; using boost::convert; -bool -my_cypher(std::string const& value_in, std::string& value_out) -{ - size_t const cypher = 'A' - '1'; - - value_out = value_in; - - for (string::iterator it = value_out.begin(); it != value_out.end(); ++it) - (*it < 'A') ? (*it += cypher) : (*it -= cypher); - - return true; -} - - template void test::type_to_string(Converter const& cnv) @@ -65,6 +52,7 @@ main(int argc, char const* argv[]) test::type_to_string(boost::printf_converter()); test::algorithms(); test::performance(); + test::encryption(); string const not_int_str = "not an int"; string const std_str = "-11"; @@ -368,16 +356,6 @@ main(int argc, char const* argv[]) // BOOST_ASSERT(bool_str3 == "1"); // BOOST_ASSERT(bool_str4 == "0"); - //////////////////////////////////////////////////////////////////////////// - // Testing custom converter. - //////////////////////////////////////////////////////////////////////////// - - string encrypted = convert::from("ABC", my_cypher).value(); - string decrypted = convert::from(encrypted, my_cypher).value(); - - BOOST_ASSERT(encrypted == "123"); - BOOST_ASSERT(decrypted == "ABC"); - printf("Test completed successfully.\n"); return 0; }