OnixS C++ CME MDP Premium Market Data Handler 5.9.0
API Documentation
Loading...
Searching...
No Matches
TinySet.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
23#include <vector>
24#include <iterator>
25#include <algorithm>
26
28
30
33template <class Key>
35{
36public:
38 typedef Key Item;
39
41 typedef std::vector<Item> Items;
42
44 typedef typename Items::const_iterator ConstIterator;
45
48
52 explicit TinySet(size_t capacity)
53 {
54 reserve(capacity);
55 }
56
58 TinySet(const TinySet& other)
59 : items_(other.items_)
60 {
61 }
62
65
67 bool empty() const
68 {
69 return items_.empty();
70 }
71
73 size_t size() const
74 {
75 return items_.size();
76 }
77
80 void reserve(size_t capacity)
81 {
82 items_.reserve(capacity);
83 }
84
87 {
88 return items_.begin();
89 }
90
93 {
94 return items_.end();
95 }
96
98 ConstIterator find(const Item& item) const
99 {
100 return std::find(items_.begin(), items_.end(), item);
101 }
102
108 bool insert(const Item& item)
109 {
110 if (end() == find(item))
111 {
112 items_.push_back(item);
113
114 return true;
115 }
116
117 return false;
118 }
119
124 bool erase(const Item& item)
125 {
126 typename Items::iterator const found = std::find(items_.begin(), items_.end(), item);
127
128 if (items_.end() == found)
129 return false;
130
131 items_.erase(found);
132
133 return true;
134 }
135
137 void clear()
138 {
139 items_.clear();
140 }
141
143 void swap(TinySet& other)
144 {
145 std::swap(items_, other.items_);
146 }
147
150 TinySet& operator=(const TinySet& other)
151 {
152 if (&other != this)
153 {
154 TinySet copy(other);
155
156 swap(copy);
157 }
158
159 return *this;
160 }
161
162private:
163 Items items_;
164};
165
168{
169public:
171 typedef std::vector<std::string> Items;
172
174 typedef Items::const_iterator ItemIterator;
175
178
181 : iterator_(other.iterator_)
182 {
183 }
184
186 explicit TinyStrSetIterator(const ItemIterator& iterator)
187 : iterator_(iterator)
188 {
189 }
190
193
196 {
197 return toStrRef(*iterator_);
198 }
199
201 bool operator==(const TinyStrSetIterator& other) const
202 {
203 return iterator_ == other.iterator_;
204 }
205
207 bool operator!=(const TinyStrSetIterator& other) const
208 {
209 return iterator_ != other.iterator_;
210 }
211
214 {
215 iterator_ = other.iterator_;
216
217 return *this;
218 }
219
223 {
224 ++iterator_;
225
226 return *this;
227 }
228
229private:
230 ItemIterator iterator_;
231};
232
241{
242public:
244 typedef StrRef Item;
245
248
251
254 explicit TinyStrSet(size_t capacity)
255 {
256 reserve(capacity);
257 }
258
260 TinyStrSet(const TinyStrSet& other)
261 : items_(other.items_)
262 {
263 }
264
267
269 bool empty() const
270 {
271 return items_.empty();
272 }
273
275 size_t size() const
276 {
277 return items_.size();
278 }
279
282 void reserve(size_t capacity)
283 {
284 items_.reserve(capacity);
285 }
286
289 {
290 return ConstIterator(items_.begin());
291 }
292
295 {
296 return ConstIterator(items_.end());
297 }
298
301 ConstIterator find(const Item& item) const
302 {
303 return ConstIterator(std::find_if(items_.begin(), items_.end(), ItemLocator(item)));
304 }
305
314 bool insert(const Item& item)
315 {
316 if (end() == find(item))
317 {
318 items_.push_back(toStr(item));
319
320 return true;
321 }
322
323 return false;
324 }
325
330 bool erase(const Item& item)
331 {
332 const ItemIterator found = std::find_if(items_.begin(), items_.end(), ItemLocator(item));
333
334 if (items_.end() == found)
335 return false;
336
337 items_.erase(found);
338
339 return true;
340 }
341
343 void clear()
344 {
345 items_.clear();
346 }
347
349 void swap(TinyStrSet& other)
350 {
351 std::swap(items_, other.items_);
352 }
353
354private:
355 typedef std::vector<std::string> Items;
356
357 typedef Items::const_iterator ItemConstIterator;
358
359 typedef Items::iterator ItemIterator;
360
361 class ItemLocator
362 {
363 StrRef sought_;
364
365 public:
366 ItemLocator(const StrRef& sought)
367 : sought_(sought)
368 {
369 }
370
371 bool operator()(const std::string& other) const
372 {
373 return sought_ == other;
374 }
375 };
376
377 Items items_;
378};
379
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:67
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:46
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:68
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition String.h:42
void reserve(size_t capacity)
Definition TinySet.h:80
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:73
void swap(TinySet &other)
Swaps content with the other instance.
Definition TinySet.h:143
TinySet(size_t capacity)
Initializes the empty set and configures the internal storage to be enough capacious to store the giv...
Definition TinySet.h:52
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:67
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:92
~TinySet()
Cleans everything up.
Definition TinySet.h:64
TinySet(const TinySet &other)
Initializes the set as a copy of the other one.
Definition TinySet.h:58
bool insert(const Item &item)
Inserts the given item into the set.
Definition TinySet.h:108
ConstIterator find(const Item &item) const
Tells whether the set contains given item.
Definition TinySet.h:98
void clear()
Brings the set to the blank state.
Definition TinySet.h:137
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:86
bool erase(const Item &item)
Removes the given item from the set.
Definition TinySet.h:124
Items::const_iterator ConstIterator
Definition TinySet.h:44
TinySet & operator=(const TinySet &other)
Re-initializes the instance as a copy of the other one.
Definition TinySet.h:150
TinySet()
Initializes the empty set.
Definition TinySet.h:47
Implements iterator for the TinyStrSet class.
Definition TinySet.h:168
bool operator!=(const TinyStrSetIterator &other) const
Compares with the other instance.
Definition TinySet.h:207
TinyStrSetIterator & operator=(const TinyStrSetIterator &other)
Re-initializes as a copy of the other instance.
Definition TinySet.h:213
std::vector< std::string > Items
Aliases for internal representation.
Definition TinySet.h:171
TinyStrSetIterator(const TinyStrSetIterator &other)
Initializes the instance as a copy of the other one.
Definition TinySet.h:180
TinyStrSetIterator & operator++()
Advances the instance to the next item in the collection.
Definition TinySet.h:222
Items::const_iterator ItemIterator
Aliases iterator over the internal store.
Definition TinySet.h:174
TinyStrSetIterator()
Initializes the iterator pointing to nowhere.
Definition TinySet.h:177
bool operator==(const TinyStrSetIterator &other) const
Compares with the other instance.
Definition TinySet.h:201
TinyStrSetIterator(const ItemIterator &iterator)
Initializes from iterator over the internal storage.
Definition TinySet.h:186
StrRef operator*() const
Provides access to the underlying object.
Definition TinySet.h:195
~TinyStrSetIterator()
Cleans everything up.
Definition TinySet.h:192
void reserve(size_t capacity)
Makes the internal storage capacious enough to store the given number of items.
Definition TinySet.h:282
StrRef Item
Items of collection.
Definition TinySet.h:244
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:275
TinyStrSet(size_t capacity)
Initializes the empty set capacious enough to store the given number of items.
Definition TinySet.h:254
TinyStrSetIterator ConstIterator
Aliases iterator type.
Definition TinySet.h:247
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:269
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:294
void swap(TinyStrSet &other)
Exchanges content with the other instance.
Definition TinySet.h:349
TinyStrSet(const TinyStrSet &other)
Initializes as a copy of the other instance.
Definition TinySet.h:260
~TinyStrSet()
Destructs the internal storage.
Definition TinySet.h:266
bool insert(const Item &item)
Inserts the given item into the set.
Definition TinySet.h:314
ConstIterator find(const Item &item) const
Looks for the given item and returns iterator pointing to the found entry or to nowhere.
Definition TinySet.h:301
TinyStrSet()
Initializes the empty set.
Definition TinySet.h:250
void clear()
Brings the set to the blank (empty) state.
Definition TinySet.h:343
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:288
bool erase(const Item &item)
Removes the given item from the set.
Definition TinySet.h:330
MboBook & copy(MboBook &target, const MboBook &source)
Copies content of MBO book to the other one.
Definition MboBook.h:210
void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition String.h:155