Simpatico  v1.10
Label.h
1 #ifndef UTIL_LABEL_H
2 #define UTIL_LABEL_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include <util/global.h>
12 #include <iostream>
13 #include <string>
14 #include <string>
15 
16 namespace Util
17 {
18 
36  class Label
37  {
38 
39  public:
40 
41  // Static Public Members
42 
44  static const int LabelWidth = 20;
45 
51  static void clear();
52 
56  static bool isClear();
57 
66  static bool isMatched();
67 
68  // Non-static Public Members
69 
75  explicit Label(bool isRequired = true);
76 
83  Label(std::string string, bool isRequired = true);
84 
91  Label(const char* string, bool isRequired = true);
92 
98  Label(const Label& other);
99 
103  virtual ~Label();
104 
110  void setString(std::string string);
111 
121  bool match(std::istream& in);
122 
126  std::string string() const;
127 
131  bool isRequired() const;
132 
133  private:
134 
140  bool isRequired_;
141 
145  std::string string_;
146 
147  // Static members:
148 
152  static bool isClear_;
153 
162  static bool isMatched_;
163 
165  static std::string input_;
166 
167  //friends:
168 
169  friend std::istream& operator >> (std::istream& in, Label label);
170  friend std::ostream& operator << (std::ostream& out, Label label);
171 
172  };
173 
174  // Friend function declarations
175 
182  std::istream& operator >> (std::istream& in, Label label);
183 
190  std::ostream& operator << (std::ostream& out, Label label);
191 
192  // Inline functions
193 
194  /*
195  * Is this label a required component of the file format?
196  */
197  inline bool Label::isRequired() const
198  { return isRequired_; }
199 
200  /*
201  * Did the most recent attempt to read match?
202  */
203  inline bool Label::isMatched()
204  { return isMatched_; }
205 
206 }
207 #endif
static bool isMatched()
Did the most recent attempt to match a Label succeed?
Definition: Label.h:203
static const int LabelWidth
Width of label field in file output format.
Definition: Label.h:44
bool isRequired() const
Is this the label for a required component?
Definition: Label.h:197
File containing preprocessor macros for error handling.
static bool isClear()
Is the input buffer clear?
Definition: Label.cpp:37
std::string string() const
Return label string.
Definition: Label.cpp:89
virtual ~Label()
Destructor.
Definition: Label.cpp:77
Utility classes for scientific computation.
Definition: accumulators.mod:1
friend std::ostream & operator<<(std::ostream &out, Label label)
Inserter for Label.
Definition: Label.cpp:158
void setString(std::string string)
Set the label string.
Definition: Label.cpp:83
A label string in a file format.
Definition: Label.h:36
bool match(std::istream &in)
Read and attempt to match next word in an input stream.
Definition: Label.cpp:95
friend std::istream & operator>>(std::istream &in, Label label)
Extractor for Label.
Definition: Label.cpp:104
Label(bool isRequired=true)
Constructor.
Definition: Label.cpp:45
static void clear()
Reset buffer and flags to initial state.
Definition: Label.cpp:27