Jpp  18.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 namespace 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 
83 namespace {
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  */
145 int 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 
Utility class to parse command line options.
Definition: JParser.hh:1514
debug
Definition: JMessage.hh:29
int main(int argc, char *argv[])
Definition: Main.cc:15
std::istream & operator>>(std::istream &in, std::vector< int > &object)
Read std::vector&lt;int&gt; from input.
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:1989
then JCalibrateToT a
Definition: JTuneHV.sh:116
Auxiliary data structure for handling std::ostream.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
print
Definition: JConvertDusj.sh:44
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
#define PRINT(OUT, CLASS)
Print class parameters.
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
Utility class to parse command line options.
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 JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level