LBNEKeyedInput.hh
Go to the documentation of this file.
1 //*****************************************************************************
2 // class: LBNEKeyedInput
3 // author: Matthew Michelotti
4 // created: June 2010
5 //
6 // See LBNEKeyedInput.cc for documentation of member functions.
7 //
8 // This class is designed to read input similar to how GEANT3 read input
9 // using FFKEY calls. Each line of input is considered individually.
10 // The first word on the line is the key (the variable name). The remaining
11 // "words" in the line (delimited by spaces) form an array of integers,
12 // doubles, booleans, or strings, depending on the desired type of variable.
13 // An array can span multiple lines by using the same key multiple times
14 // and writing "#=" after the key, replacing # with the index number where the
15 // array left off (the first array index is 1). Comments can be placed on a
16 // line if the first series of alpha-numeric characters consists only of 'C',
17 // starting at the first column. None of the text is case sensitive.
18 //
19 // Example:
20 //
21 // C This is a comment at the top of the file.
22 // cc This is another comment.
23 // MyInt 5
24 // MyDoubleArr 3.0 -1.925E-3 4. .2 7
25 // MyString 'HELLO'
26 // MyBoolArr TRUE false 0 1
27 //
28 // Data0 1= 1.0 2.0 3.0 4.0
29 // Data1 1= -1.0 -2.0 -3.0 -4.0
30 //
31 // Data0 5= 5.0 6.0 7.0 8.0
32 // Data1 5= -5.0 -6.0 -7.0 -8.0
33 //
34 //*****************************************************************************
35 
36 #ifndef LBNEKeyedInput_h
37 #define LBNEKeyedInput_h
38 
39 #include "globals.hh"
40 #include <map>
41 #include <vector>
42 #include <sstream>
43 
45 
46 private:
47  typedef std::map<G4String,G4String> ssmap_t;
48  typedef const G4String& cstr_t;
49 
50 public:
51  explicit LBNEKeyedInput();
52 
53  void readFile(cstr_t filename);
54  void readString(cstr_t data);
55  void readStream(std::istream& in);
56 
57  G4bool contains(G4String name) const;
58 
59  void get(cstr_t name, G4int& buffer, G4int length=-1);
60  void get(cstr_t name, G4double& buffer, G4int length=-1);
61  void get(cstr_t name, G4bool& buffer, G4int length=-1);
62  void get(cstr_t name, G4String& buffer, G4int length=-1);
63 
64  void get(cstr_t name, std::vector<G4int>& buffer, G4int length=-1);
65  void get(cstr_t name, std::vector<G4double>& buffer, G4int length=-1);
66  void get(cstr_t name, std::vector<G4bool>& buffer, G4int length=-1);
67  void get(cstr_t name, std::vector<G4String>& buffer, G4int length=-1);
68 
69  void printAll() const;
70 
71 private:
72  void handleLine(cstr_t line);
73  static G4bool isLineComment(cstr_t line);
74  void readIndexSpec(std::istringstream& in, cstr_t name);
75  static G4int countTerms(cstr_t value);
76  static void fail(cstr_t message, cstr_t key="",
77  G4int expected=-1);
78 
79  template<class T>
80  void getSingle(cstr_t name, T& buffer);
81 
82  template<class T>
83  void getVector(G4String name, std::vector<T>& buffer, G4int length);
84 
85  static void parse(std::istream& in, G4int& buffer, cstr_t name);
86  static void parse(std::istream& in, G4double& buffer, cstr_t name);
87  static void parse(std::istream& in, G4bool& buffer, cstr_t name);
88  static void parse(std::istream& in, G4String& buffer, cstr_t name);
89 
90  static void checkGotTerm(std::istream& in, cstr_t message, cstr_t name);
91 
92  ssmap_t varMap;
93 };
94 
95 
96 #endif
static QCString name
Definition: declinfo.cpp:673
void readFile(cstr_t filename)
std::map< G4String, G4String > ssmap_t
void readStream(std::istream &in)
void getVector(G4String name, std::vector< T > &buffer, G4int length)
const char expected[]
Definition: Exception_t.cc:22
static G4bool isLineComment(cstr_t line)
void handleLine(cstr_t line)
G4bool contains(G4String name) const
void printAll() const
string filename
Definition: train.py:213
static void checkGotTerm(std::istream &in, cstr_t message, cstr_t name)
void readIndexSpec(std::istringstream &in, cstr_t name)
const G4String & cstr_t
static void parse(std::istream &in, G4int &buffer, cstr_t name)
void getSingle(cstr_t name, T &buffer)
static G4int countTerms(cstr_t value)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static void fail(cstr_t message, cstr_t key="", G4int expected=-1)
void readString(cstr_t data)