OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringSet.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // OpenTrep
10 
11 namespace OPENTREP {
12 
13  // //////////////////////////////////////////////////////////////////////
15  }
16 
17  // //////////////////////////////////////////////////////////////////////
18  StringSet::StringSet (const StringSet& iStringSet) {
19  _set = iStringSet._set;
20  }
21 
22  // //////////////////////////////////////////////////////////////////////
23  StringSet::StringSet (const std::string& iString) {
24  if (iString.empty() == false) {
25  _set.push_back (iString);
26  }
27  }
28 
29  // //////////////////////////////////////////////////////////////////////
31  }
32 
33  // //////////////////////////////////////////////////////////////////////
34  size_t StringSet::size() const {
35  return _set.size();
36  }
37 
38  // //////////////////////////////////////////////////////////////////////
39  bool StringSet::empty() const {
40  return _set.empty();
41  }
42 
43  // //////////////////////////////////////////////////////////////////////
45  _set.clear();
46  }
47 
48  // //////////////////////////////////////////////////////////////////////
49  void StringSet::push_back (const std::string& iString) {
50  _set.push_back (iString);
51  }
52 
53  // //////////////////////////////////////////////////////////////////////
54  void StringSet::push_back (const StringSet& iStringSet) {
55  const StringSet_T& lStringSet = iStringSet._set;
56  for (StringSet_T::const_iterator itString = lStringSet.begin();
57  itString != lStringSet.end(); ++itString) {
58  const std::string& lString = *itString;
59  push_back (lString);
60  }
61  }
62 
63  // //////////////////////////////////////////////////////////////////////
64  std::string StringSet::getFirstString() const {
65  std::string oString ("");
66 
67  // When the underlying set is empty, then the first string is empty
68  if (_set.empty() == true) {
69  return oString;
70  }
71 
72  // Extract the first string of the underlying set
73  StringSet_T::const_iterator itString = _set.begin();
74  oString = *itString;
75 
76  //
77  return oString;
78  }
79 
80  // //////////////////////////////////////////////////////////////////////
81  std::string StringSet::describeKey() const {
82  std::ostringstream oStr;
83  oStr << "";
84  return oStr.str();
85  }
86 
87  // //////////////////////////////////////////////////////////////////////
88  std::string StringSet::describe() const {
89  std::ostringstream oStr;
90  oStr << describeKey();
91 
92  //
93  oStr << " {";
94 
95  short idx_string = 0;
96  for (StringSet_T::const_iterator itString = _set.begin();
97  itString != _set.end(); ++itString, ++idx_string) {
98  //
99  if (idx_string != 0) {
100  oStr << ", ";
101  }
102 
103  //
104  const std::string& lString = *itString;
105 
106  //
107  oStr << "\"" << lString << "\"";
108  }
109 
110  //
111  oStr << "}";
112 
113  return oStr.str();
114  }
115 
116  // //////////////////////////////////////////////////////////////////////
117  void StringSet::toStream (std::ostream& ioOut) const {
118  ioOut << describe();
119  }
120 
121  // //////////////////////////////////////////////////////////////////////
122  void StringSet::fromStream (std::istream& ioIn) {
123  }
124 
125 }
StringSet_T _set
Definition: StringSet.hpp:118
void toStream(std::ostream &) const
Definition: StringSet.cpp:117
bool empty() const
Definition: StringSet.cpp:39
std::string describe() const
Definition: StringSet.cpp:88
size_t size() const
Definition: StringSet.cpp:34
std::string getFirstString() const
Definition: StringSet.cpp:64
std::string describeKey() const
Definition: StringSet.cpp:81
void fromStream(std::istream &)
Definition: StringSet.cpp:122
Class holding a set of strings, e.g., {"rio", "de", "janeiro"}.
Definition: StringSet.hpp:19
void push_back(const std::string &)
Definition: StringSet.cpp:49
std::list< std::string > StringSet_T
Definition: StringSet.hpp:25