|
Last change
on this file since 12 was
12,
checked in by landauf, 18 years ago
|
|
added boost
|
-
Property svn:executable set to
*
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
|---|
| 3 | // (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 4 | // http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 | |
|---|
| 6 | // See http://www.boost.org/libs/test for the library home page. |
|---|
| 7 | |
|---|
| 8 | // Boost.Runtime.Param |
|---|
| 9 | #include <boost/test/utils/runtime/cla/positional_parameter.hpp> |
|---|
| 10 | #include <boost/test/utils/runtime/cla/parser.hpp> |
|---|
| 11 | |
|---|
| 12 | namespace rt = boost::runtime; |
|---|
| 13 | namespace cla = boost::runtime::cla; |
|---|
| 14 | |
|---|
| 15 | // STL |
|---|
| 16 | #include <iostream> |
|---|
| 17 | |
|---|
| 18 | int main() { |
|---|
| 19 | char* argv[] = { "basic", "--klmn-- 14" }; |
|---|
| 20 | int argc = sizeof(argv)/sizeof(char*); |
|---|
| 21 | |
|---|
| 22 | try { |
|---|
| 23 | cla::parser P; |
|---|
| 24 | int i; |
|---|
| 25 | |
|---|
| 26 | P << cla::positional_parameter<std::string>( "abcd" ) |
|---|
| 27 | << cla::positional_parameter<int>() - (cla::assign_to = i) |
|---|
| 28 | << cla::positional_parameter<std::string>( "klmn" ) - (cla::default_value = std::string("file")) |
|---|
| 29 | << cla::positional_parameter<std::string>( "oprt" ) - cla::optional; |
|---|
| 30 | |
|---|
| 31 | P.parse( argc, argv ); |
|---|
| 32 | |
|---|
| 33 | std::cout << "abcd = " << P.get<std::string>( "abcd" ) << std::endl; |
|---|
| 34 | std::cout << "i = " << i << std::endl; |
|---|
| 35 | std::cout << "klmn = " << P.get<std::string>( "klmn" ) << std::endl; |
|---|
| 36 | std::cout << "oprt " << (P["oprt"] ? "present" : "not present" ) << std::endl; |
|---|
| 37 | } |
|---|
| 38 | catch( rt::logic_error const& ex ) { |
|---|
| 39 | std::cout << "Logic error: " << ex.msg() << std::endl; |
|---|
| 40 | return -1; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | return 0; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | // EOF |
|---|
Note: See
TracBrowser
for help on using the repository browser.