Jpp
18.0.0-rc.3
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JLang
JRedirectStream.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <sstream>
5
#include <iomanip>
6
7
#include "
JLang/JRedirectStream.hh
"
8
#include "
JLang/JNullStream.hh
"
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
*/
20
int
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
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
JEEP::debug_t
debug
Definition:
JMessage.hh:29
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
is
is
Definition:
JDAQCHSM.chsm:167
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
JRedirectStream.hh
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
NOTICE
#define NOTICE(A)
Definition:
JMessage.hh:64
JLANG::getline
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition:
JString.hh:478
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JLANG::null
static JNullStream null
Null I/O stream.
Definition:
JNullStream.hh:51
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
JNullStream.hh
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
Generated by
1.8.5