PSCF v1.1
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
15namespace Util
16{
17
72 class Label
73 {
74
75 public:
76
77 // Static public members
78
80 static const int LabelWidth = 20;
81
91 static void read(std::istream& in);
92
96 static void clear();
97
103 static void setIsMatched(bool isMatched);
104
108 static std::string buffer();
109
113 static bool isClear();
114
123 static bool isMatched();
124
125 // Non-static Public Members
126
132 explicit Label(bool isRequired = true);
133
140 Label(std::string string, bool isRequired = true);
141
148 Label(const char* string, bool isRequired = true);
149
155 Label(const Label& other);
156
160 virtual ~Label();
161
167 void setString(std::string string);
168
174 void setIsRequired(bool isRequired);
175
185 bool match(std::istream& in);
186
190 std::string string() const;
191
195 bool isRequired() const;
196
197 private:
198
202 std::string string_;
203
209 bool isRequired_;
210
211 // Static members:
212
216 static bool isClear_;
217
226 static bool isMatched_;
227
229 static std::string buffer_;
230
231 // friends:
232
233 friend std::istream& operator >> (std::istream& in, Label label);
234 friend std::ostream& operator << (std::ostream& out, Label label);
235
236 };
237
238 // Friend function declarations
239
246 std::istream& operator >> (std::istream& in, Label label);
247
254 std::ostream& operator << (std::ostream& out, Label label);
255
256 // Inline functions
257
258 /*
259 * Is this label a required component of the file format?
260 */
261 inline bool Label::isRequired() const
262 { return isRequired_; }
263
264 /*
265 * Is the input buffer clear? (static member function).
266 */
267 inline bool Label::isClear()
268 { return isClear_; }
269
270 /*
271 * Did the most recent attempt to read match?
272 * (static member function)
273 */
274 inline bool Label::isMatched()
275 { return isMatched_; }
276
277 /*
278 * Manually set isMatched.
279 */
280 inline void Label::setIsMatched(bool isMatched)
281 { isMatched_ = isMatched; }
282
283 /*
284 * Get the string that is currently stored in the buffer.
285 */
286 inline std::string Label::buffer()
287 { return buffer_; }
288
289}
290#endif
A label string in a file format.
Definition: Label.h:73
std::string string() const
Return label string.
Definition: Label.cpp:111
friend std::istream & operator>>(std::istream &in, Label label)
Extractor for Label.
Definition: Label.cpp:126
static std::string buffer()
Get the string that is currently in the input buffer.
Definition: Label.h:286
static const int LabelWidth
Width of label field in file output format.
Definition: Label.h:80
static bool isMatched()
Did the most recent attempt to match a Label succeed?
Definition: Label.h:274
static void read(std::istream &in)
Read a string without checking its value.
Definition: Label.cpp:35
static void clear()
Clear the input buffer.
Definition: Label.cpp:25
virtual ~Label()
Destructor.
Definition: Label.cpp:93
bool match(std::istream &in)
Read and attempt to match next word in an input stream.
Definition: Label.cpp:117
void setString(std::string string)
Set the label string.
Definition: Label.cpp:99
void setIsRequired(bool isRequired)
Set the isRequired boolean flag.
Definition: Label.cpp:105
bool isRequired() const
Is this the label for a required component?
Definition: Label.h:261
static void setIsMatched(bool isMatched)
Explicitly set the isMatched flag.
Definition: Label.h:280
static bool isClear()
Is the input buffer clear?
Definition: Label.h:267
friend std::ostream & operator<<(std::ostream &out, Label label)
Inserter for Label.
Definition: Label.cpp:169
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition: Pair.h:57