PSCF v1.1
FlagSet.h
1#ifndef UTIL_FLAG_SET_H
2#define UTIL_FLAG_SET_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 <string>
13#include <map>
14
15namespace Util
16{
17
28 class FlagSet
29 {
30
31 public:
32
36 FlagSet();
37
45 FlagSet(std::string allowed);
46
55 void setAllowed(std::string allowed);
56
69 void setActualOrdered(std::string actual);
70
76 bool isActive(char c) const;
77
81 const std::string& allowed() const;
82
86 const std::string& actual() const;
87
88 private:
89
91 typedef std::map<char, bool> MapType;
92
94 std::string allowed_;
95
97 std::string actual_;
98
100 MapType map_;
101
102 };
103
104 // Inline function
105
106 /*
107 * Is this flag active?
108 */
109 inline
110 bool FlagSet::isActive(char c) const
111 {
112 MapType::const_iterator iter = map_.find(c);
113 if (iter == map_.end()) {
114 UTIL_THROW("Unknown character");
115 }
116 return iter->second;
117 }
118
119 /*
120 * Return the string of allowed characters.
121 */
122 inline
123 const std::string& FlagSet::allowed() const
124 { return allowed_; }
125
126 /*
127 * Return the string of actual character flags.
128 */
129 inline
130 const std::string& FlagSet::actual() const
131 { return actual_; }
132
133}
134#endif
A set of boolean variables represented by characters.
Definition: FlagSet.h:29
void setActualOrdered(std::string actual)
Set the string of actual flag characters.
Definition: FlagSet.cpp:47
bool isActive(char c) const
Is the flag associated with character c active?
Definition: FlagSet.h:110
const std::string & allowed() const
Return the string of allowed characters.
Definition: FlagSet.h:123
const std::string & actual() const
Return the string of character for which flags are set.
Definition: FlagSet.h:130
void setAllowed(std::string allowed)
Set or reset the string of allowed flags.
Definition: FlagSet.cpp:29
FlagSet()
Default constructor.
Definition: FlagSet.cpp:17
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
Utility classes for scientific computation.
Definition: accumulators.mod:1