Jpp
Functions
JHashSet.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include "JTools/JHashSet.hh"
#include "JLang/JObjectID.hh"
#include "JIO/JFileStreamIO.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 JTOOLS::JHashSet class.

Author
mdejong

Definition in file JHashSet.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 48 of file JHashSet.cc.

49 {
50  using namespace std;
51 
52  string inputFile;
53  string outputFile;
54  int debug;
55 
56  try {
57 
58  JParser<> zap("Example program to test hash set.");
59 
60  zap['f'] = make_field(inputFile) = "";
61  zap['o'] = make_field(outputFile) = "";
62  zap['d'] = make_field(debug) = 0;
63 
64  zap(argc, argv);
65  }
66  catch(const exception &error) {
67  FATAL(error.what() << endl);
68  }
69 
70 
71  using namespace JPP;
72 
73  typedef JHashSet<__A__> hash_set;
74 
75  hash_set buffer;
76 
77  if (inputFile != "") {
78 
79  DEBUG("Reading " << inputFile << "... " << flush);
80 
81  JFileStreamReader in(inputFile.c_str());
82 
83  in >> buffer;
84 
85  in.close();
86 
87  DEBUG("OK" << endl);
88 
89  } else {
90 
91  for (int i = 1<<10; i != 0; i >>= 1) {
92  buffer.insert(__A__(i));
93  }
94 
95  buffer.erase(buffer.find(1<<2), buffer.find(1<<4));
96 
97  if (!buffer.erase(1<<4)) {
98  FATAL("Erasing value failed." << endl);
99  }
100  }
101 
102  for (hash_set::const_iterator i = buffer.begin(); i != buffer.end(); ++i) {
103 
104  cout << setw(4) << *i;
105  cout << " == ";
106 
107  hash_set::const_iterator p = buffer.find(*i);
108 
109  if (p != buffer.end())
110  cout << setw(4) << *p << endl;
111  else
112  FATAL("Inconsistent has set at " << *i << endl);
113  }
114 
115  if (outputFile != "") {
116 
117  DEBUG("Writing " << outputFile << "... " << flush);
118 
119  JFileStreamWriter out(outputFile.c_str());
120 
121  out << buffer;
122 
123  out.close();
124 
125  DEBUG("OK" << endl);
126  }
127 }
JIO::JFileStreamWriter
Binary buffered file output.
Definition: JFileStreamIO.hh:72
JIO::JFileStreamReader
Binary buffered file input.
Definition: JFileStreamIO.hh:22
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
debug
int debug
debug level
Definition: JSirene.cc:59
JIO::JFileStreamWriter::close
void close()
Close file.
Definition: JFileStreamIO.hh:121
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JTOOLS::JHashSet
General purpose class for hash set of elements.
Definition: JHashSet.hh:34