libUTL++
StringVars.h
1 #pragma once
2 
4 
5 #include <libutl/Hashtable.h>
6 #include <libutl/Pair.h>
7 #include <libutl/SortedCollection.h>
8 
10 
11 UTL_NS_BEGIN;
12 
14 
15 class Pair;
16 
18 
26 
28 class StringVars : public utl::Object
29 {
31 
32 public:
33  virtual int compare(const utl::Object& rhs) const;
34 
35  virtual void copy(const utl::Object& rhs);
36 
37  virtual void serialize(utl::Stream& stream, uint_t io, uint_t mode = utl::ser_default);
38 
39  virtual size_t innerAllocatedSize() const;
40 
42  bool
43  empty() const
44  {
45  return _vars.empty();
46  }
47 
49  bool
50  isNull(const char* name) const
51  {
52  return isNull(String(name, false));
53  }
54 
56  bool isNull(const String& name) const;
57 
59  void
60  setNull(const char* name)
61  {
62  setNull(String(name, false));
63  }
64 
66  void setNull(const String& name);
67 
73  const String&
74  valueOf(const char* name) const
75  {
76  return valueOf(String(name, false));
77  }
78 
84  const String& valueOf(const String& name) const;
85 
92  String&
93  valueOf(const char* name, bool create)
94  {
95  return valueOf(String(name, false), create);
96  }
97 
104  String& valueOf(const String& name, bool create);
105 
112  Pair*
113  setValue(const char* name, const char* value)
114  {
115  return setValue(new String(name, false), new String(value, false));
116  }
117 
124  Pair*
125  setValue(const String& name, const char* value)
126  {
127  return setValue(name.clone(), new String(value, false));
128  }
129 
136  Pair*
137  setValue(const char* name, const String& value)
138  {
139  return setValue(new String(name, false), value.clone());
140  }
141 
148  Pair*
149  setValue(const String& name, const String& value)
150  {
151  return setValue(name.clone(), value.clone());
152  }
153 
160  Pair* setValue(String* name, String* value);
161 
163  void
165  {
166  _vars.clear();
167  }
168 
172  {
173  return _vars;
174  }
175 
177  const utl::Collection&
178  container() const
179  {
180  return _vars;
181  }
182 
184  void add(const StringVars& vars);
185 
187  void intersect(const utl::SortedCollection& vars);
188 
189 private:
190  void
191  init()
192  {
193  }
194  void
195  deInit()
196  {
197  ASSERTD(nonConstEmptyString.empty());
198  }
199 
200 private:
201  static String nonConstEmptyString;
202  utl::Hashtable _vars;
203 };
204 
206 
207 UTL_NS_END;
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
void intersect(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false, bool multiSet=false, bool outIsLHS=false)
Determine the intersection of two sorted sequences.
void deInit()
De-initialize UTL++.
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Pair * setValue(const char *name, const String &value)
Set a variable.
Definition: StringVars.h:137
Character string.
Definition: String.h:31
String & valueOf(const char *name, bool create)
Get the value of a variable (non-const version).
Definition: StringVars.h:93
bool isNull(const char *name) const
Is the given variable null?
Definition: StringVars.h:50
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
Abstraction for a Collection whose objects may be sorted.
void clear()
Clear out contents.
Definition: StringVars.h:164
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Pair * setValue(const String &name, const String &value)
Set a variable.
Definition: StringVars.h:149
void setNull(const char *name)
Remove the given variable (make it null).
Definition: StringVars.h:60
Stream I/O abstraction.
Definition: Stream.h:68
bool empty() const
Empty?
Definition: StringVars.h:43
const utl::Collection & container() const
Get the container.
Definition: StringVars.h:178
Chained hashing collection.
Definition: Hashtable.h:92
const String & valueOf(const char *name) const
Get the value of a variable.
Definition: StringVars.h:74
utl::Collection & container()
Get the container.
Definition: StringVars.h:171
Pair * setValue(const String &name, const char *value)
Set a variable.
Definition: StringVars.h:125
Simple container for two objects.
Definition: Pair.h:25
A set of (variable-name, variable-value) tuples.
Definition: StringVars.h:28
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void init()
Initialize UTL++.
Pair * setValue(const char *name, const char *value)
Set a variable.
Definition: StringVars.h:113
#define ASSERTD
Do an assertion in DEBUG mode only.
A collection of objects.
Definition: Collection.h:62