Jpp  16.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
12 struct __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 
28 template<class T>
29 struct __B__ {};
30 
31 /**
32  * Write object to output.
33  *
34  * \param out output stream
35  * \param object object
36  * \return output stream
37  */
38 template<class T>
39 inline std::ostream& operator<<(std::ostream& out, const __B__<T>& object)
40 {
41  return out << "__B__";
42 }
43 
44 
45 struct __C__ {};
46 
47 
48 /**
49  * Read <tt>std::vector<int></tt> from input.
50  *
51  * \param in input stream
52  * \param object object
53  * \return input stream
54  */
55 inline std::istream& operator>>(std::istream& in, std::vector<int>& object)
56 {
57  for (int value; in >> value; ) {
58  object.push_back(value);
59  }
60 
61  return in;
62 }
63 
64 
65 /**
66  * Write <tt>std::vector<int></tt> to output.
67  *
68  * \param out output stream
69  * \param object object
70  * \return output stream
71  */
72 inline std::ostream& operator<<(std::ostream& out, const std::vector<int>& object)
73 {
74  for (std::vector<int>::const_iterator i = object.begin(); i != object.end(); ++i) {
75  out << ' ' << *i;
76  }
77 
78  return out;
79 }
80 
81 
82 namespace {
83 
84  /**
85  * Print object.
86  *
87  * \param out output stream
88  * \param object object
89  * \param option true
90  */
91  template<class T>
92  inline void print(std::ostream& out, const T& object, JLANG::JBool<true> option)
93  {
94  out << object << std::endl;
95  }
96 
97 
98  /**
99  * Print object.
100  *
101  * \param out output stream
102  * \param object object
103  * \param option false
104  */
105  template<class T>
106  inline void print(std::ostream& out, const T& object, JLANG::JBool<false> option)
107  {
108  out << "No output operation available." << std::endl;
109  }
110 
111 
112  /**
113  * Print object.
114  *
115  * \param out output stream
116  * \param object object
117  */
118  template<class T>
119  inline void print(std::ostream& out, const T& object)
120  {
122  }
123 }
124 
125 /**
126  * Print class parameters.
127  *
128  * \param OUT output stream
129  * \param CLASS class
130  */
131 #define PRINT(OUT, CLASS) \
132  OUT << std::setw(12) << std::left << #CLASS << ' ' ; \
133  OUT << JStreamAvailable<CLASS>::has_istream << '/'; \
134  OUT << JStreamAvailable<CLASS>::has_ostream << std::endl;
135 
136 
137 
138 /**
139  * \file
140  *
141  * Example program to test JLANG::JStreamAvailable class.
142  * \author mdejong
143  */
144 int main(int argc, char **argv)
145 {
146  using namespace std;
147  using namespace JPP;
148 
149  int debug;
150 
151  try {
152 
153  JParser<> zap("Example program to test availability of I/O stream redirection.");
154 
155  zap['d'] = make_field(debug) = 3;
156 
157  zap(argc, argv);
158  }
159  catch(const exception &error) {
160  FATAL(error.what() << endl);
161  }
162 
163 
164  cout.tie(&cerr);
165 
166  if (debug >= debug_t) {
167 
168  cout << setw(12) << left << "class" << " I/O" << endl;
169  cout << setw(12) << right << setfill('-') << "" << "+---" << setfill(' ') << endl;
170 
171  PRINT(cout, double);
172  PRINT(cout, __A__);
173  PRINT(cout, __B__<int>);
174  PRINT(cout, __C__);
175  PRINT(cout, vector<int>);
176 
177  print(cout, vector<int>(5, 1));
178  print(cout, vector<double>(5, 1.0));
179 
180  __A__ a;
181  __B__<int> b;
182  __C__ c;
183 
184  cout << "STREAM << __A__: " << STREAM("?") << a << endl;
185  cout << "STREAM << __B__: " << STREAM("?") << b << endl;
186  cout << "STREAM << __C__: " << STREAM("?") << c << endl;
187  }
188 
191  ASSERT(!JStreamAvailable< __B__<int> >::has_istream);
192  ASSERT( JStreamAvailable< __B__<int> >::has_ostream);
195  ASSERT( JStreamAvailable< vector<int> >::has_istream);
196  ASSERT( JStreamAvailable< vector<int> >::has_ostream);
197  ASSERT(!JStreamAvailable< vector<double> >::has_istream);
198  ASSERT(!JStreamAvailable< vector<double> >::has_ostream);
199 
200  return 0;
201 }
202 
Utility class to parse command line options.
Definition: JParser.hh:1500
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
Test availability of stream operators.
friend std::istream & operator>>(std::istream &in, __A__ &object)
Read object from input.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
Auxiliary template class for type bool.
Definition: JBool.hh:20
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Auxiliary data structure for handling std::ostream.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
int debug
debug level
Definition: JSirene.cc:63
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
#define PRINT(OUT, CLASS)
Print class parameters.
std::istream & operator>>(std::istream &in, JAANET::JHead &header)
Read header from input.
Definition: JHead.hh:1693
then JCalibrateToT a
Definition: JTuneHV.sh:116
Utility class to parse command line options.
$WORKDIR ev_configure_domsimulator txt echo process $DOM_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DOM_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42