Jpp  18.2.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JRedirectStream.cc File Reference

Example program to test JLANG::JRedirectStream class. More...

#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include "JLang/JRedirectStream.hh"
#include "JLang/JNullStream.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JLANG::JRedirectStream class.

Author
mdejong

Definition in file JRedirectStream.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 20 of file JRedirectStream.cc.

21 {
22  using namespace std;
23 
24  int debug;
25 
26  try {
27 
28  JParser<> zap("Example program to test redirection of I/O streams.");
29 
30  zap['d'] = make_field(debug) = 3;
31 
32  zap(argc, argv);
33  }
34  catch(const exception &error) {
35  FATAL(error.what() << endl);
36  }
37 
38 
39  using namespace JPP;
40 
41  string message = "hello world";
42 
43  NOTICE("debug = " << debug << endl);
44 
45  ostringstream os;
46 
47  {
48  NOTICE("The message <" << message << "> is re-directed to <null> if debug < " << JEEP::debug_t << endl);
49 
50  JRedirectStream redirect(cout, (debug >= JEEP::debug_t) ? static_cast<ostream&>(os) : null);
51 
52  cout << message << flush;
53  }
54 
55  NOTICE("result <" << os.str() << ">" << endl);
56 
57  ASSERT(debug >= JEEP::debug_t ? os.str() == message : os.str() == "");
58 
59  istringstream is;
60 
61  {
62  NOTICE("The following input message is re-directed to <null> if debug < " << JEEP::debug_t << endl);
63 
64  JRedirectStream redirect(cin, (debug >= JEEP::debug_t) ? static_cast<istream&>(is) : null);
65 
66  getline(cin, message);
67 
68  DEBUG("message <" << message << ">" << endl);
69  }
70 
71  NOTICE("result <" << is.str() << ">" << endl);
72 
73  ASSERT(debug >= JEEP::debug_t ? is.str() == message : is.str() == "");
74 
75  return 0;
76 }
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
is
Definition: JDAQCHSM.chsm:167
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define NOTICE(A)
Definition: JMessage.hh:64
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
#define FATAL(A)
Definition: JMessage.hh:67
static JNullStream null
Null I/O stream.
Definition: JNullStream.hh:51
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62