Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSTDObjectWriter.cc File Reference

Example program to test JLANG::JSTDObjectWriter class. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include "JLang/JSTDObjectWriter.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JLANG::JSTDObjectWriter class.

Author
mdejong

Definition in file JSTDObjectWriter.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 61 of file JSTDObjectWriter.cc.

62 {
63  using namespace std;
64 
65  int debug;
66 
67  try {
68 
69  JParser<> zap("Example program to test object output using STD containers.");
70 
71  zap['d'] = make_field(debug) = 3;
72 
73  zap(argc, argv);
74  }
75  catch(const exception &error) {
76  FATAL(error.what() << endl);
77  }
78 
79 
80  using namespace JPP;
81 
82  vector<double> data;
83 
84  data.push_back(3.0);
85  data.push_back(2.0);
86  data.push_back(1.0);
87 
88  print(cout, debug, "data", data.begin(), data.end());
89 
90  {
91  typedef vector<double> buffer_type;
92 
93  buffer_type buffer;
94 
95  JSTDObjectWriter<double> out(buffer);
96 
97  for (vector<double>::const_iterator i = data.begin(); i != data.end(); ++i) {
98  out.put(*i);
99  }
100 
101  print(cout, debug, "JSTDObjectWriter<double>(vector<double>&);", buffer.begin(), buffer.end());
102 
103  ASSERT(equals(data.begin(), data.end(),
104  buffer.begin(), buffer.end()));
105  }
106  {
107  typedef set<double> buffer_type;
108 
109  buffer_type buffer;
110 
111  JSTDObjectWriter<double> out(buffer);
112 
113  for (vector<double>::const_iterator i = data.begin(); i != data.end(); ++i) {
114  out.put(*i);
115  }
116 
117  print(cout, debug, "JSTDObjectWriter<double>(set<double>&);", buffer.begin(), buffer.end());
118 
119  ASSERT(equals(data.rbegin(), data.rend(),
120  buffer.begin(), buffer.end()));
121  }
122 
123  return 0;
124 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
bool equals(const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
Check equality.
Definition: JMathToolkit.hh:86