diff --git a/convert-example b/convert-example new file mode 100755 index 0000000..4873def Binary files /dev/null and b/convert-example differ diff --git a/convert-test b/convert-test new file mode 100755 index 0000000..55ea463 Binary files /dev/null and b/convert-test differ diff --git a/example/algorithms.cpp b/example/algorithms.cpp index 92bdd9f..b246811 100644 --- a/example/algorithms.cpp +++ b/example/algorithms.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/example/default_converter.cpp b/example/default_converter.cpp index 14cd0ab..77d74d6 100644 --- a/example/default_converter.cpp +++ b/example/default_converter.cpp @@ -7,6 +7,7 @@ //[default_converter_declaration #include #include +#include struct boost::cnv::by_default : public boost::cnv::lexical_cast {}; //] diff --git a/example/example.hpp b/example/example.hpp index 1b81023..2148888 100644 --- a/example/example.hpp +++ b/example/example.hpp @@ -5,8 +5,6 @@ #ifndef BOOST_CONVERT_EXAMPLE_HPP #define BOOST_CONVERT_EXAMPLE_HPP -#include - struct example { static void getting_started (); diff --git a/example/getting_started.cpp b/example/getting_started.cpp index bc43479..01fd44b 100644 --- a/example/getting_started.cpp +++ b/example/getting_started.cpp @@ -3,6 +3,7 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./example.hpp" +#include static void diff --git a/example/lexical_cast.cpp b/example/lexical_cast.cpp index f7be072..d0fe468 100644 --- a/example/lexical_cast.cpp +++ b/example/lexical_cast.cpp @@ -6,6 +6,7 @@ //[lexical_cast_headers1 #include #include +#include using std::string; using boost::convert; diff --git a/example/main.cpp b/example/main.cpp new file mode 100644 index 0000000..1a8f4b1 --- /dev/null +++ b/example/main.cpp @@ -0,0 +1,20 @@ +// Boost.Convert test and usage example +// Copyright (c) 2009-2014 Vladimir Batov. +// Use, modification and distribution are subject to the Boost Software License, +// Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. + +#include "./example.hpp" +#include + +int +main(int argc, char const* argv[]) +{ + example::getting_started(); + example::getting_serious(); + example::algorithms(); + example::stream(); + example::lexcast_converter(); + example::default_converter(); + + return boost::report_errors(); +} diff --git a/example/stream.cpp b/example/stream.cpp index 31b7e0e..eabcc72 100644 --- a/example/stream.cpp +++ b/example/stream.cpp @@ -7,6 +7,7 @@ //[stream_headers1 #include #include +#include using std::string; using boost::convert; diff --git a/include/boost/convert/printf.hpp b/include/boost/convert/printf.hpp index 784d292..500ebfa 100644 --- a/include/boost/convert/printf.hpp +++ b/include/boost/convert/printf.hpp @@ -6,6 +6,8 @@ #define BOOST_CONVERT_PRINTF_HPP #include +#include +#include #include #if defined(_MSC_VER) diff --git a/include/boost/convert/strtol.hpp b/include/boost/convert/strtol.hpp index a0e2df1..92213af 100644 --- a/include/boost/convert/strtol.hpp +++ b/include/boost/convert/strtol.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace boost { namespace cnv { diff --git a/makefile b/makefile index 36f17d0..1c79ba4 100644 --- a/makefile +++ b/makefile @@ -2,16 +2,23 @@ ifneq ($(DEVMAKE),) BOOST_ROOT = $(HOME)/dev/boost_1_55_0 -cflags = -Iinclude -I$(BOOST_ROOT) -Wno-unused-local-typedefs -Wno-unused-variable -Wno-uninitialized -target = test-convert.exe -sources = $(wildcard example/*.cpp) $(wildcard test/*.cpp) +cflags = -Iinclude -I$(BOOST_ROOT) -Wno-unused-local-typedefs -Wno-unused-variable -Wno-uninitialized +target_1 = convert-test.exe +sources_1 = $(wildcard test/*.cpp) +target_2 = convert-example.exe +sources_2 = $(wildcard example/*.cpp) include $(DEVMAKE)/makefile else -all: $(wildcard example/*.cpp) $(wildcard test/*.cpp) - g++ $^ -I./include -I../boost_1_55_0 -lrt +all: convert-test convert-example + +convert-test: $(wildcard test/*.cpp) + g++ -O3 -o $@ $^ -I./include -I../boost_1_55_0 -lrt + +convert-example: $(wildcard example/*.cpp) + g++ -O3 -o $@ $^ -I./include -I../boost_1_55_0 -lrt endif diff --git a/test/callable.cpp b/test/callable.cpp index b60ad03..48c994a 100644 --- a/test/callable.cpp +++ b/test/callable.cpp @@ -4,7 +4,11 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include #include +#include using std::string; using boost::convert; diff --git a/test/encryption.cpp b/test/encryption.cpp index e9451db..b65c96b 100644 --- a/test/encryption.cpp +++ b/test/encryption.cpp @@ -3,6 +3,8 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include static bool diff --git a/test/fallbacks.cpp b/test/fallbacks.cpp index e3104b5..1c13425 100644 --- a/test/fallbacks.cpp +++ b/test/fallbacks.cpp @@ -4,7 +4,11 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include #include +#include namespace { namespace local { diff --git a/test/int_to_str.cpp b/test/int_to_str.cpp index 9d524b7..a156397 100644 --- a/test/int_to_str.cpp +++ b/test/int_to_str.cpp @@ -4,6 +4,9 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include using std::string; using std::wstring; diff --git a/test/is_converter.cpp b/test/is_converter.cpp index 5045641..1c9ac6a 100644 --- a/test/is_converter.cpp +++ b/test/is_converter.cpp @@ -4,6 +4,8 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include using std::string; using std::wstring; diff --git a/test/lcast_converter.cpp b/test/lcast_converter.cpp index fac3a41..0424dff 100644 --- a/test/lcast_converter.cpp +++ b/test/lcast_converter.cpp @@ -4,6 +4,9 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include using std::string; diff --git a/test/main.cpp b/test/main.cpp index 7bc7c57..b8da81a 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -6,6 +6,14 @@ #include "./test.hpp" #include "./str_to_int.hpp" +#include +#include +#include +#include +#include + +#include + namespace arg = boost::cnv::parameter; using std::string; @@ -50,13 +58,6 @@ test::cnv::force_in_type() int main(int argc, char const* argv[]) { - example::getting_started(); - example::getting_serious(); - example::algorithms(); - example::stream(); - example::lexcast_converter(); - example::default_converter(); - test::cnv::scratchpad(); test::cnv::is_converter(); test::cnv::stream(); diff --git a/test/performance.cpp b/test/performance.cpp index baf1117..2a77350 100644 --- a/test/performance.cpp +++ b/test/performance.cpp @@ -4,7 +4,14 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include "./timer.hpp" +#include +#include +#include +#include #include +#include +#include using std::string; @@ -39,7 +46,7 @@ performance_str_to_int(Converter const& cnv) test::cnv::strings strings = test::cnv::get_strs(); // Create strings on the stack int const size = strings.size(); int sum = 0; - my_timer timer (sum); + test::cnv::timer timer (sum); for (int t = 0; t < test::cnv::num_cycles; ++t) for (int k = 0; k < size; ++k) @@ -55,7 +62,7 @@ test::performance::str_to_int(Converter const& try_converter) test::cnv::strings strings = test::cnv::get_strs(); // Create strings on the stack int const size = strings.size(); int sum = 0; - my_timer timer (sum); + test::cnv::timer timer (sum); for (int t = 0; t < test::cnv::num_cycles; ++t) for (int k = 0; k < size; ++k) @@ -68,10 +75,10 @@ template double test::performance::int_to_str(Converter const& try_converter) { - test::cnv::ints ints = test::cnv::get_ints(); - int const size = ints.size(); - int sum = 0; - my_timer timer (sum); + test::cnv::ints ints = test::cnv::get_ints(); + int const size = ints.size(); + int sum = 0; + test::cnv::timer timer (sum); for (int t = 0; t < test::cnv::num_cycles; ++t) for (int k = 0; k < size; ++k) @@ -84,9 +91,9 @@ template double performance_str_to_type(Converter const& try_converter) { - char const* input[] = { "no", "up", "dn" }; - int sum = 0; - my_timer timer (sum); + char const* input[] = { "no", "up", "dn" }; + int sum = 0; + test::cnv::timer timer (sum); for (int k = 0; k < test::cnv::num_cycles; ++k) { @@ -107,7 +114,7 @@ performance_type_to_str(Converter const& try_converter) boost::array input = {{ change::no, change::up, change::dn }}; boost::array results = {{ "no", "up", "dn" }}; int sum = 0; - my_timer timer (sum); + test::cnv::timer timer (sum); for (int k = 0; k < test::cnv::num_cycles; ++k) { diff --git a/test/performance_spirit.cpp b/test/performance_spirit.cpp index ea1d35e..f5eb3ad 100644 --- a/test/performance_spirit.cpp +++ b/test/performance_spirit.cpp @@ -8,7 +8,11 @@ // See these mentioned files for the copyright notice. #include "./test.hpp" +#include #include +#include +#include + //#define main() old_str_to_int_test_spirit() //#include #include diff --git a/test/prepare.cpp b/test/prepare.cpp index 9c12270..6f9f6f1 100644 --- a/test/prepare.cpp +++ b/test/prepare.cpp @@ -6,8 +6,9 @@ #include "./test.hpp" #include #include -#include #include +#include +#include namespace { namespace local { @@ -37,7 +38,7 @@ test::cnv::get_ints() if (!filled) { - boost::random::mt19937 gen (std::time(0)); + boost::random::mt19937 gen (::time(0)); boost::random::uniform_int_distribution<> dist (SHRT_MIN, SHRT_MAX); // SHRT_MAX(16) = 32767 // boost::random::uniform_int_distribution<> dist (INT_MIN, INT_MAX); // INT_MAX(32) = 2147483647 diff --git a/test/sfinae.cpp b/test/sfinae.cpp index 265eb6b..69e3ffc 100644 --- a/test/sfinae.cpp +++ b/test/sfinae.cpp @@ -4,6 +4,10 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include +#include namespace { namespace local { diff --git a/test/spirit.cpp b/test/spirit.cpp index ae75f0e..da85540 100644 --- a/test/spirit.cpp +++ b/test/spirit.cpp @@ -4,6 +4,7 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include #include void diff --git a/test/str_to_int.hpp b/test/str_to_int.hpp index cdcff34..84299c5 100644 --- a/test/str_to_int.hpp +++ b/test/str_to_int.hpp @@ -6,6 +6,8 @@ #define BOOST_CONVERT_TEST_STR_TO_INT_HPP #include "./test.hpp" +#include +#include using std::string; diff --git a/test/stream.cpp b/test/stream.cpp index b00ac94..3cfaf4b 100644 --- a/test/stream.cpp +++ b/test/stream.cpp @@ -4,6 +4,9 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include namespace cnv = boost::cnv; namespace arg = boost::cnv::parameter; diff --git a/test/test.hpp b/test/test.hpp index af71572..d9dfe7e 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -5,24 +5,10 @@ #ifndef BOOST_CONVERT_TEST_HPP #define BOOST_CONVERT_TEST_HPP -#include "../example/example.hpp" -#include -#include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include - -//#undef BOOST_TEST -//#define BOOST_TEST BOOST_ASSERT +#include //[change_declaration struct change @@ -118,29 +104,6 @@ struct my_string char storage_[size_]; }; -struct my_timer : boost::noncopyable -{ - my_timer (int const& sum) : sum_(sum), beg_(times(&tms_beg_)) {} - - double value() const - { - struct tms tms_end; - double const end = times(&tms_end); - int const use_sum = (sum_ % 2) ? 0 : (sum_ % 2); BOOST_TEST(use_sum == 0); - double use_beg = tms_beg_.tms_utime + tms_beg_.tms_stime; - double use_end = tms_end .tms_utime + tms_end .tms_stime; - -// This returns real time, i.e. affected by other processes. Still, it's OK if run as "nice -20 program-name". -// return (end - beg_) / sysconf(_SC_CLK_TCK) + use_sum; - return (use_end - use_beg) / sysconf(_SC_CLK_TCK) + use_sum; - } - private: - - int const& sum_; - struct tms tms_beg_; - double const beg_; -}; - namespace test { struct cnv @@ -161,6 +124,8 @@ namespace test #error "Add here." #endif + struct timer; + // C1. 18 = 9 positive + 9 negative numbers with the number of digits from 1 to 9. // Even though INT_MAX(32) = 2147483647, i.e. 10 digits (not to mention long int) // we only test up to 9 digits as Spirit does not handle more than 9. diff --git a/test/timer.cpp b/test/timer.cpp new file mode 100644 index 0000000..5faf441 --- /dev/null +++ b/test/timer.cpp @@ -0,0 +1,15 @@ +#include "./test.hpp" +#include "./timer.hpp" +#include + +double +test::cnv::timer::value() const +{ + struct tms tms_end; + double const end = times(&tms_end); + int const use_sum = (sum_ % 2) ? 0 : (sum_ % 2); BOOST_TEST(use_sum == 0); + double use_beg = tms_beg_.tms_utime + tms_beg_.tms_stime; + double use_end = tms_end .tms_utime + tms_end .tms_stime; + + return (use_end - use_beg) / sysconf(_SC_CLK_TCK) + use_sum; +} diff --git a/test/timer.hpp b/test/timer.hpp new file mode 100644 index 0000000..c114afb --- /dev/null +++ b/test/timer.hpp @@ -0,0 +1,19 @@ +#include "./test.hpp" +#include +#include + +namespace test +{ + struct cnv::timer : boost::noncopyable + { + timer (int const& sum) : sum_(sum), beg_(times(&tms_beg_)) {} + + double value() const; + + private: + + int const& sum_; + struct tms tms_beg_; + double const beg_; + }; +} diff --git a/test/user_type.cpp b/test/user_type.cpp index e4e8995..2769017 100644 --- a/test/user_type.cpp +++ b/test/user_type.cpp @@ -4,6 +4,10 @@ // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt. #include "./test.hpp" +#include +#include +#include +#include using std::string; using std::wstring;