PSCF v1.5.0
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, David Morse (morse012@um.edu)
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
110 #ifdef UTIL_MPI
119 static void bcast(MPI::Intracomm& communicator);
120 #endif
121
125 static bool isClear();
126
135 static bool isMatched();
136
137 // Non-static Public Members
138
144 explicit Label(bool isRequired = true);
145
152 Label(std::string string, bool isRequired = true);
153
160 Label(const char* string, bool isRequired = true);
161
167 Label(const Label& other);
168
172 virtual ~Label();
173
179 void setString(std::string string);
180
186 void setIsRequired(bool isRequired);
187
197 bool match(std::istream& in);
198
202 std::string string() const;
203
207 bool isRequired() const;
208
209 private:
210
214 std::string string_;
215
221 bool isRequired_;
222
223 // Static members:
224
228 static bool isClear_;
229
238 static bool isMatched_;
239
241 static std::string buffer_;
242
243 // friends:
244
245 friend std::istream& operator >> (std::istream& in, Label label);
246 friend std::ostream& operator << (std::ostream& out, Label label);
247
248 };
249
250 // Friend function declarations
251
258 std::istream& operator >> (std::istream& in, Label label);
259
266 std::ostream& operator << (std::ostream& out, Label label);
267
268 // Inline functions
269
270 /*
271 * Is this label a required component of the file format?
272 */
273 inline bool Label::isRequired() const
274 { return isRequired_; }
275
276 /*
277 * Is the input buffer clear? (static member function).
278 */
279 inline bool Label::isClear()
280 { return isClear_; }
281
282 /*
283 * Did the most recent attempt to read match?
284 * (static member function)
285 */
286 inline bool Label::isMatched()
287 { return isMatched_; }
288
289 /*
290 * Manually set isMatched.
291 */
293 { isMatched_ = isMatched; }
294
295 /*
296 * Get the string that is currently stored in the buffer.
297 */
298 inline std::string Label::buffer()
299 { return buffer_; }
300
301}
302#endif
A label string in a file format.
Definition Label.h:73
Label(bool isRequired=true)
Constructor.
Definition Label.cpp:75
std::string string() const
Return label string.
Definition Label.cpp:125
friend std::istream & operator>>(std::istream &in, Label label)
Extractor for Label.
Definition Label.cpp:140
static std::string buffer()
Get the string that is currently in the input buffer.
Definition Label.h:298
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:286
static void read(std::istream &in)
Read a string without checking its value.
Definition Label.cpp:38
static void clear()
Clear the input buffer.
Definition Label.cpp:28
bool match(std::istream &in)
Read and attempt to match next word in an input stream.
Definition Label.cpp:131
void setString(std::string string)
Set the label string.
Definition Label.cpp:113
void setIsRequired(bool isRequired)
Set the isRequired boolean flag.
Definition Label.cpp:119
bool isRequired() const
Is this the label for a required component?
Definition Label.h:273
static void setIsMatched(bool isMatched)
Explicitly set the isMatched flag.
Definition Label.h:292
static bool isClear()
Is the input buffer clear?
Definition Label.h:279
friend std::ostream & operator<<(std::ostream &out, Label label)
Inserter for Label.
Definition Label.cpp:188
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
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