Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JStreamAvailable.cc
Go to the documentation of this file.
1#include <iostream>
2#include <iomanip>
3#include <vector>
4
6#include "JLang/JBool.hh"
7
8#include "Jeep/JParser.hh"
9#include "Jeep/JMessage.hh"
10
11
12struct __A__ {
13
14 /**
15 * Read object from input.
16 *
17 * \param in input stream
18 * \param object object
19 * \return input stream
20 */
21 friend inline std::istream& operator>>(std::istream& in, __A__& object)
22 {
23 return in;
24 }
25};
26
27
28template<class T>
29struct __B__ {};
30
31/**
32 * Write object to output.
33 *
34 * \param out output stream
35 * \param object object
36 * \return output stream
37 */
38template<class T>
39inline std::ostream& operator<<(std::ostream& out, const __B__<T>& object)
40{
41 return out << "__B__";
42}
43
44
45struct __C__ {};
46
47
48namespace std {
49 /**
50 * Read <tt>std::vector<int></tt> from input.
51 *
52 * \param in input stream
53 * \param object object
54 * \return input stream
55 */
56 inline std::istream& operator>>(std::istream& in, std::vector<int>& object)
57 {
58 for (int value; in >> value; ) {
59 object.push_back(value);
60 }
61
62 return in;
63 }
64
65
66 /**
67 * Write <tt>std::vector<int></tt> to output.
68 *
69 * \param out output stream
70 * \param object object
71 * \return output stream
72 */
73 inline std::ostream& operator<<(std::ostream& out, const std::vector<int>& object)
74 {
75 for (std::vector<int>::const_iterator i = object.begin(); i != object.end(); ++i) {
76 out << ' ' << *i;
77 }
78
79 return out;
80 }
81}
82
83namespace {
84
85 /**
86 * Print object.
87 *
88 * \param out output stream
89 * \param object object
90 * \param option true
91 */
92 template<class T>
93 inline void print(std::ostream& out, const T& object, JLANG::JBool<true> option)
94 {
95 out << object << std::endl;
96 }
97
98
99 /**
100 * Print object.
101 *
102 * \param out output stream
103 * \param object object
104 * \param option false
105 */
106 template<class T>
107 inline void print(std::ostream& out, const T& object, JLANG::JBool<false> option)
108 {
109 out << "No output operation available." << std::endl;
110 }
111
112
113 /**
114 * Print object.
115 *
116 * \param out output stream
117 * \param object object
118 */
119 template<class T>
120 inline void print(std::ostream& out, const T& object)
121 {
123 }
124}
125
126/**
127 * Print class parameters.
128 *
129 * \param OUT output stream
130 * \param CLASS class
131 */
132#define PRINT(OUT, CLASS) \
133 OUT << std::setw(12) << std::left << #CLASS << ' ' ; \
134 OUT << JStreamAvailable<CLASS>::has_istream << '/'; \
135 OUT << JStreamAvailable<CLASS>::has_ostream << std::endl;
136
137
138
139/**
140 * \file
141 *
142 * Example program to test JLANG::JStreamAvailable class.
143 * \author mdejong
144 */
145int main(int argc, char **argv)
146{
147 using namespace std;
148 using namespace JPP;
149
150 int debug;
151
152 try {
153
154 JParser<> zap("Example program to test availability of I/O stream redirection.");
155
156 zap['d'] = make_field(debug) = 3;
157
158 zap(argc, argv);
159 }
160 catch(const exception &error) {
161 FATAL(error.what() << endl);
162 }
163
164
165 if (debug >= debug_t) {
166
167 cout << setw(12) << left << "class" << " I/O" << endl;
168 cout << setw(12) << right << setfill('-') << "" << "+---" << setfill(' ') << endl;
169
170 PRINT(cout, double);
171 PRINT(cout, __A__);
172 PRINT(cout, __B__<int>);
173 PRINT(cout, __C__);
174 PRINT(cout, vector<int>);
175
176 print(cout, vector<int>(5, 1));
177 print(cout, vector<double>(5, 1.0));
178
179 __A__ a;
180 __B__<int> b;
181 __C__ c;
182
183 cout << "STREAM << __A__: " << STREAM("?") << a << endl;
184 cout << "STREAM << __B__: " << STREAM("?") << b << endl;
185 cout << "STREAM << __C__: " << STREAM("?") << c << endl;
186 }
187
190 ASSERT(!JStreamAvailable< __B__<int> >::has_istream);
191 ASSERT( JStreamAvailable< __B__<int> >::has_ostream);
194 ASSERT( JStreamAvailable< std::vector<int> >::has_istream);
195 ASSERT( JStreamAvailable< vector<int> >::has_ostream);
196 ASSERT(!JStreamAvailable< vector<double> >::has_istream);
197 ASSERT(!JStreamAvailable< vector<double> >::has_ostream);
198
199 return 0;
200}
201
General purpose messaging.
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#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)
#define PRINT(OUT, CLASS)
Print class parameters.
std::ostream & operator<<(std::ostream &out, const __B__< T > &object)
Write object to output.
void print(const TH1 &h1, std::ostream &out)
Print histogram parameters.
Utility class to parse command line options.
Definition JParser.hh:1698
Test availability of stream operators.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
std::istream & operator>>(std::istream &in, std::vector< int > &object)
Read std::vector<int> from input.
std::ostream & operator<<(std::ostream &out, const std::vector< int > &object)
Write std::vector<int> to output.
Auxiliary template class for type bool.
Definition JBool.hh:21
Auxiliary data structure for handling std::ostream.
friend std::istream & operator>>(std::istream &in, __A__ &object)
Read object from input.