Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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

◆ main()

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}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
Utility class to parse command line options.
Definition JParser.hh:1698
@ debug_t
debug
Definition JMessage.hh:29
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).