TF++, Miscellaneous classes and modules in C++:
rangetest.cc
Go to the documentation of this file.
1 
34 #define RANGETEST_VERSION \
35  "RANGETEST V1.0 test range code"
36 
37 #include <iostream>
38 #include <tfxx/commandline.h>
39 #include <tfxx/range.h>
40 #include <tfxx/rangelist.h>
41 #include <tfxx/rangestring.h>
42 
43 using std::cout;
44 using std::cerr;
45 using std::endl;
46 
48 #define CODE(line) cout.width(50); cout << endl << #line << "; --> "; line
49 
50 int main(int iargc, char* argv[])
51 {
52 
53  // define usage information
54  char usage_text[]=
55  {
57  "usage: rangetest [-v] [-step s] [-list l]" "\n"
58  " or: rangetest --help|-h" "\n"
59  };
60 
61  // define full help text
62  char help_text[]=
63  {
64  RANGETEST_CVSID
65  };
66 
67  // define commandline options
68  using namespace tfxx::cmdline;
69  static Declare options[]=
70  {
71  // 0: print help
72  {"help",arg_no,"-"},
73  // 1: verbose mode
74  {"v",arg_no,"-"},
75  // 2: step size
76  {"step",arg_yes,"1"},
77  // 3: step size
78  {"list",arg_yes,"1-10"},
79  {NULL}
80  };
81 
82  // no arguments? print usage...
83  if (iargc<1)
84  {
85  cerr << usage_text << endl;
86  exit(0);
87  }
88 
89  // collect options from commandline
90  Commandline cmdline(iargc, argv, options);
91 
92  // help requested? print full help text...
93  if (cmdline.optset(0))
94  {
95  cerr << usage_text << endl;
96  cerr << help_text << endl;
97  exit(0);
98  }
99 
100  int step=cmdline.int_arg(2);
101  std::string list=cmdline.string_arg(3);
102 
103  CODE( tfxx::Range<int> Tirange(5,12) );
105  CODE( while (RS.more()) { cout << ++RS << ", "; });
106  cout << endl;
107 
108  CODE( tfxx::Range<int> R1(5,12) );
109  CODE( tfxx::Range<int> R2(50) );
110  CODE( tfxx::Range<int> R3(18,29) );
112  CODE( RL.append(R1) );
113  CODE( RL.append(R2) );
114  CODE( RL.append(R3) );
115  CODE( tfxx::RangeListStepper<int> RLS(RL, 2) );
116  CODE( while (RLS.valid()) { cout << RLS << ", "; ++RLS; });
117  cout << endl;
118 
119  CODE( cout << step << endl );
120  CODE( cout << list << endl );
121  // tfxx::RangeListStepper<int> RLSsa(tfxx::string::rangelist<int>(list), step);
122  CODE( tfxx::RangeListStepper<int> RLSs(tfxx::string::rangelist<int>(list), step) );
123  CODE( while (RLSs.valid()) { cout << RLSs << ", "; ++RLSs; });
124  cout << endl;
125 }
126 
127 /* ----- END OF rangetest.cc ----- */
int int_arg(const int &iopt) const
return argument of option # iopt as int value
Definition: commandline.h:219
option requires an argument
Definition: commandline.h:102
bool optset(const int &iopt) const
true if option # iopt was set on commandline
Definition: commandline.h:213
RangeList & append(const Trange &r)
Definition: rangelist.h:54
#define RANGETEST_VERSION
Definition: rangetest.cc:34
A class to deal with numerical ranges.
Definition: range.h:50
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
#define CODE(line)
Show code along with output of executed code.
Definition: rangetest.cc:48
tfxx::Range< int > Tirange
Definition: handletest.cc:54
int main(int iargc, char *argv[])
Definition: rangetest.cc:50
struct to define options ,This struct is used to define a list of options. An example is: ...
Definition: commandline.h:136
option has no argument
Definition: commandline.h:100
std::string string_arg(const int &iopt) const
return argument of option # iopt as string value
Definition: commandline.h:216