Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JRedirectStream.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <sstream>
5#include <iomanip>
6
9
10#include "Jeep/JParser.hh"
11#include "Jeep/JMessage.hh"
12
13
14/**
15 * \file
16 *
17 * Example program to test JLANG::JRedirectStream class.
18 * \author mdejong
19 */
20int main(int argc, char **argv)
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}
General purpose messaging.
#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
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
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
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).