OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
DiscMeta.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef DISC_META_H
12 #define DISC_META_H
13 
14 // include files
15 #include "Utility/Inform.h"
16 #include "Utility/vmap.h"
17 
18 #include <cstdio>
19 
20 /***************************************************************************
21  * DiscMeta - reads in information in a Disc meta file, which is a file in
22  * the format
23  *
24  * # comment line
25  * keyword [=] value
26  * keyword [=] value
27  * ...
28  *
29  * An optional = may separate the single-word keyword and the value. This
30  * class stores the list of lines, and can be queried about them.
31  *
32  ***************************************************************************/
33 
34 
35 class DiscMeta {
36 
37 public:
38  // useful typedefs
39  typedef std::pair<int, std::string *> element_t;
44 
45 public:
46  // Constructor: specify the meta file filename. The constructor
47  // will parse the contents and store the results.
48  DiscMeta(const char *fname);
49 
50  // Destructor.
51  ~DiscMeta();
52 
53  //
54  // accessor functions
55  //
56 
57  // return the config filename
58  const std::string &getFilename() const { return MetaFile; }
59 
60  // return the number of valid lines in the file
61  unsigned int size() const { return Lines.size(); }
62 
63  // return the line number of the Nth valid line (in range 1 ... M)
64  int getLineNumber(unsigned int) const;
65 
66  // return the keyword of the Nth line
67  const std::string &getKeyword(unsigned int);
68 
69  // return the number of words in the value for the Nth line
70  int getNumWords(unsigned int) const;
71 
72  // return the list of words in the Nth line
73  std::string *getWords(unsigned int);
74 
75  // return begin/end iterators for iterating over the list of lines
76  iterator begin() { return Lines.begin(); }
77  iterator end() { return Lines.end(); }
78  const_iterator begin() const { return Lines.begin(); }
79  const_iterator end() const { return Lines.end(); }
80 
81  // print out debugging information
82  void printDebug(Inform &);
83 
84 private:
85  // the name of the meta file
86  std::string MetaFile;
87 
88  // the data for the lines themselves
90 
91  // the storage for the keywords
92  // read a single meta line, and return an array of strings as tokens
93  bool read_meta_line(FILE*, std::string *&, int &);
94 };
95 
96 #endif // DISC_META_H
97 
98 /***************************************************************************
99  * $RCSfile: DiscMeta.h,v $ $Author: adelmann $
100  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
101  * IPPL_VERSION_ID: $Id: DiscMeta.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
102  ***************************************************************************/
iterator begin()
Definition: vmap.h:125
unsigned int size() const
Definition: DiscMeta.h:61
std::string * getWords(unsigned int)
Definition: DiscMeta.cpp:134
std::pair< int, std::string * > element_t
Definition: DiscMeta.h:39
void printDebug(Inform &)
Definition: DiscMeta.cpp:185
iterator end()
Definition: DiscMeta.h:77
container_t Lines
Definition: DiscMeta.h:89
const std::string & getFilename() const
Definition: DiscMeta.h:58
~DiscMeta()
Definition: DiscMeta.cpp:75
const_iterator end() const
Definition: DiscMeta.h:79
iterator begin()
Definition: DiscMeta.h:76
container_t::value_type value_type
Definition: DiscMeta.h:43
DiscMeta(const char *fname)
Definition: DiscMeta.cpp:36
const_iterator begin() const
Definition: DiscMeta.h:78
std::string MetaFile
Definition: DiscMeta.h:86
int getNumWords(unsigned int) const
Definition: DiscMeta.cpp:115
bool read_meta_line(FILE *, std::string *&, int &)
Definition: DiscMeta.cpp:153
int getLineNumber(unsigned int) const
Definition: DiscMeta.cpp:86
container_t::const_iterator const_iterator
Definition: DiscMeta.h:42
std::pair< int, element_t > value_type
Definition: vmap.h:71
const std::string & getKeyword(unsigned int)
Definition: DiscMeta.cpp:105
container_t::iterator iterator
Definition: DiscMeta.h:41
size_type size() const
Definition: vmap.h:138
vmap< int, element_t > container_t
Definition: DiscMeta.h:40
rep_type::iterator iterator
Definition: vmap.h:116
Definition: Inform.h:41
rep_type::const_iterator const_iterator
Definition: vmap.h:117
iterator end()
Definition: vmap.h:126