[complement-svn] SF.net SVN: complement: [1929] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2008-06-30 06:28:37
|
Revision: 1929 http://complement.svn.sourceforge.net/complement/?rev=1929&view=rev Author: complement Date: 2008-06-29 23:28:32 -0700 (Sun, 29 Jun 2008) Log Message: ----------- libmisc 1.10.1; free allocated objects. add tests for is_set with/without default value, that not pass (unexpected behaviour) Modified Paths: -------------- trunk/complement/explore/include/misc/opts.h trunk/complement/explore/lib/misc/ChangeLog trunk/complement/explore/lib/misc/Makefile.inc trunk/complement/explore/lib/misc/ut/opts_test.cc Modified: trunk/complement/explore/include/misc/opts.h =================================================================== --- trunk/complement/explore/include/misc/opts.h 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/include/misc/opts.h 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/29 22:16:12 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:00:22 ptr> /* * Copyright (c) 2008 @@ -110,6 +110,9 @@ { return *__x == __y; } }; +inline void option_base_destroyer( option_base* p ) +{ delete p; } + } // namespace detail template <class T> @@ -361,6 +364,9 @@ Opts() { } + ~Opts() + { std::for_each( storage.begin(), storage.end(), detail::option_base_destroyer ); } + void description( const char* text ) { _brief = text; } Modified: trunk/complement/explore/lib/misc/ChangeLog =================================================================== --- trunk/complement/explore/lib/misc/ChangeLog 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ChangeLog 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,5 +1,9 @@ 2008-06-30 Petr Ovtchenkov <pt...@is...> + * opts.h: free allocated objects; + + * libmisc: version 1.10.1. + * opts.h, opts.cc: revision of options framework; insert object with type and type check into option; default value passed via [] operator; Modified: trunk/complement/explore/lib/misc/Makefile.inc =================================================================== --- trunk/complement/explore/lib/misc/Makefile.inc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/Makefile.inc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -# -*- Makefile -*- Time-stamp: <08/06/30 01:39:17 ptr> +# -*- Makefile -*- Time-stamp: <08/06/30 10:25:33 ptr> # I have only one reason while I should use "C++" variant of MD5 instead of "C": # names like MD5Init is wide distributed, but some cool programmers use this @@ -10,6 +10,6 @@ LIBNAME = misc MAJOR = 1 MINOR = 10 -PATCH = 0 +PATCH = 1 SRC_CC = CyrMoney.cc args.cc arguments.cc opts.cc SRC_C = md5.c Modified: trunk/complement/explore/lib/misc/ut/opts_test.cc =================================================================== --- trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-29 21:48:33 UTC (rev 1928) +++ trunk/complement/explore/lib/misc/ut/opts_test.cc 2008-06-30 06:28:32 UTC (rev 1929) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <08/06/30 01:10:34 ptr> +// -*- C++ -*- Time-stamp: <08/06/30 10:08:01 ptr> /* * Copyright (c) 2008 @@ -294,26 +294,63 @@ int EXAM_IMPL(opts_test::defaults) { - const char* argv[] = { "name" }; - int argc = sizeof( argv ) / sizeof(argv[0]); + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); - Opts opts; + Opts opts; - opts << option<int>( "listen tcp port", 'p', "port" )[0]; + opts << option<int>( "listen tcp port", 'p', "port" )[0]; - try { - opts.parse( argc, argv ); + try { + opts.parse( argc, argv ); + EXAM_CHECK( !opts.is_set( 'p' ) ); + EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + } + catch ( const Opts::unknown_option& e ) { + } + catch ( const Opts::arg_typemismatch& e ) { + } + catch ( ... ) { + } + } - EXAM_CHECK( !opts.is_set( 'p' ) ); - EXAM_CHECK( opts.get<int>( 'p' ) == 0 ); + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["0"]; + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( const Opts::unknown_option& e ) { + + { + const char* argv[] = { "name" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" )["20"]; + + EXAM_CHECK( opts.is_set( 'r' ) == false ); // not set + EXAM_CHECK( opts.get<string>( 'r' ) == "20" ); // but has default value } - catch ( const Opts::arg_typemismatch& e ) { + + { + const char* argv[] = { "name", "-r", "10" }; + int argc = sizeof( argv ) / sizeof(argv[0]); + + Opts opts; + + opts << option<string>( "run tests by number", 'r', "run" ); + + EXAM_CHECK( opts.is_set( 'r' ) ); + EXAM_CHECK( opts.get<string>( 'r' ) == "10" ); } - catch ( ... ) { - } return EXAM_RESULT; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |