NANDRAD Data Model Library  Version 2.0
NANDRAD
NANDRAD_IDGroup.h
1 /* The NANDRAD data model library.
2 
3  Copyright (c) 2012-today, Institut für Bauklimatik, TU Dresden, Germany
4 
5  Primary authors:
6  Andreas Nicolai <andreas.nicolai -[at]- tu-dresden.de>
7  Anne Paepcke <anne.paepcke -[at]- tu-dresden.de>
8 
9  This library is part of SIM-VICUS (https://github.com/ghorwin/SIM-VICUS)
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 */
21 
22 #ifndef NANDRAD_IDGroupH
23 #define NANDRAD_IDGroupH
24 
25 #include <string>
26 #include <set>
27 #include <vector>
28 #include <utility> // for std::pair
29 
30 namespace NANDRAD {
31 
32 /*! An IDGroup references one or more IDs and handles the encoding/decoding
33  of an IDGroup-string.
34  \code
35  // supported encodings
36  string severalIDs = "16,20,22";
37  string allIDs = "*";
38  string idInterval = "5-10,50-60";
39  string mixedIDs = "1,3,55,5-10";
40  // decode with IDGroup
41  IDGroup grp;
42  grp.setEncodedString(severalIDs);
43  // encode string
44  grp.encodedString();
45  \endcode
46 */
47 class IDGroup {
48 public:
49 
50  /*! Set ID group data from an encoded string.
51  This function throws an exception, if an invalid format is encountered or
52  IDs are specified in addition to a wildcard character.
53  */
54  void setEncodedString(const std::string & encodedString);
55 
56  /*! Encode ID group data into a string representation. */
57  std::string encodedString() const;
58 
59  /*! Returns true if neither the wildcard flag m_allIDs is set, nor any IDs are
60  specified in m_ids or m_idIntervals. */
61  bool empty() const;
62 
63  /*! Returns true if either the wildcard flag m_allIDs is set, or the
64  id is in m_ids or enclosed in m_idIntervals.
65  */
66  bool contains(unsigned int id) const;
67 
68  /*! Merges two id groups. */
69  const IDGroup operator+(const IDGroup &);
70 
71  /*! Comparison operator by value. */
72  bool operator==(const IDGroup & other) const { return !operator!=(other); }
73  /*! Not-equal comparison operator by value. */
74  bool operator!=(const IDGroup & other) const;
75 
76 
77  // *** PUBLIC MEMBER VARIABLES ***
78 
79  /*! If true, the encoded string containted a wildcard character * to indicate all IDs.
80  \warning A wildcard overrides all other IDs.
81  */
82  bool m_allIDs = false;
83  /*! Set of individually listed IDs. */
84  std::set<unsigned int> m_ids;
85  /*! Model id intervals.*/
86  std::vector<std::pair<unsigned int, unsigned int> > m_idIntervals;
87 
88 
89 }; // IDGroup
90 
91 
92 } // namespace NANDRAD
93 
94 #endif // NANDRAD_IDGroupH
void setEncodedString(const std::string &encodedString)
Set ID group data from an encoded string.
std::vector< std::pair< unsigned int, unsigned int > > m_idIntervals
Model id intervals.
bool contains(unsigned int id) const
Returns true if either the wildcard flag m_allIDs is set, or the id is in m_ids or enclosed in m_idIn...
bool m_allIDs
If true, the encoded string containted a wildcard character * to indicate all IDs.
An IDGroup references one or more IDs and handles the encoding/decoding of an IDGroup-string.
std::string encodedString() const
Encode ID group data into a string representation.
const IDGroup operator+(const IDGroup &)
Merges two id groups.
bool operator!=(const IDGroup &other) const
Not-equal comparison operator by value.
std::set< unsigned int > m_ids
Set of individually listed IDs.
The namespace NANDRAD contains the data model classes that make up the NANDRAD solver input data...
bool empty() const
Returns true if neither the wildcard flag m_allIDs is set, nor any IDs are specified in m_ids or m_id...
bool operator==(const IDGroup &other) const
Comparison operator by value.