OnixS C++ CME MDP Conflated UDP Handler 1.1.2
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
34<
35 class Key
36>
38{
39public:
41 typedef Key Item;
42
44 typedef
45 std::vector<Item>
47
49 typedef
50 typename
51 Items::const_iterator
53
56 {
57 }
58
62 explicit
64 size_t capacity)
65 {
66 reserve(capacity);
67 }
68
71 const TinySet& other)
72 : items_(other.items_)
73 {
74 }
75
78 {
79 }
80
82 bool empty() const
83 {
84 return items_.empty();
85 }
86
88 size_t size() const
89 {
90 return items_.size();
91 }
92
95 void
97 size_t capacity)
98 {
99 items_.reserve(capacity);
100 }
101
103 ConstIterator
104 begin() const
105 {
106 return items_.begin();
107 }
108
110 ConstIterator
111 end() const
112 {
113 return items_.end();
114 }
115
117 ConstIterator
119 const Item& item) const
120 {
121 return
122 std::find(
123 items_.begin(),
124 items_.end(),
125 item);
126 }
127
133 bool
135 const Item& item)
136 {
137 if (end() == find(item))
138 {
139 items_.push_back(item);
140
141 return true;
142 }
143
144 return false;
145 }
146
151 bool
153 const Item& item)
154 {
155 typename
156 Items::iterator
157 const
158 found =
159 std::find(
160 items_.begin(),
161 items_.end(),
162 item);
163
164 if (items_.end() == found)
165 return false;
166
167 items_.erase(found);
168
169 return true;
170 }
171
173 void
175 {
176 items_.clear();
177 }
178
180 void
182 TinySet& other)
183 {
184 std::swap(
185 items_,
186 other.items_);
187 }
188
191 TinySet&
192 operator =(
193 const TinySet& other)
194 {
195 if (&other != this)
196 {
197 TinySet copy(other);
198
199 swap(copy);
200 }
201
202 return *this;
203 }
204
205private:
206 Items items_;
207};
208
212{
213public:
215 typedef
216 std::vector<std::string>
218
220 typedef
221 Items::const_iterator
223
226 {
227 }
228
231 const TinyStrSetIterator& other)
232 : iterator_(other.iterator_)
233 {
234 }
235
237 explicit
239 const ItemIterator& iterator)
240 : iterator_(iterator)
241 {
242 }
243
246 {
247 }
248
250 StrRef
251 operator *() const
252 {
253 return toStrRef(*iterator_);
254 }
255
257 bool
258 operator ==(
259 const
260 TinyStrSetIterator& other) const
261 {
262 return iterator_ == other.iterator_;
263 }
264
266 bool
267 operator !=(
268 const
269 TinyStrSetIterator& other) const
270 {
271 return iterator_ != other.iterator_;
272 }
273
276 operator =(
277 const
278 TinyStrSetIterator& other)
279 {
280 iterator_ = other.iterator_;
281
282 return *this;
283 }
284
288 operator ++()
289 {
290 ++iterator_;
291
292 return *this;
293 }
294
295private:
296 ItemIterator iterator_;
297};
298
308{
309 typedef
310 std::vector<std::string>
311 Items;
312
313 typedef
314 Items::const_iterator
315 ItemConstIterator;
316
317 typedef
318 Items::iterator
319 ItemIterator;
320
321 class ItemLocator
322 {
323 StrRef sought_;
324
325 public:
326 ItemLocator(
327 const StrRef& sought)
328 : sought_(sought)
329 {
330 }
331
332 bool
333 operator ()(
334 const
335 std::string& other) const
336 {
337 return sought_ == other;
338 }
339 };
340
341 Items items_;
342
343public:
345 typedef StrRef Item;
346
348 typedef
351
354 {
355 }
356
359 explicit
361 size_t capacity)
362 {
363 reserve(capacity);
364 }
365
368 const TinyStrSet& other)
369 : items_(other.items_)
370 {
371 }
372
375 {
376 }
377
379 bool empty() const
380 {
381 return items_.empty();
382 }
383
385 size_t size() const
386 {
387 return items_.size();
388 }
389
392 void
394 size_t capacity)
395 {
396 items_.reserve(capacity);
397 }
398
400 ConstIterator
401 begin() const
402 {
403 return
405 items_.begin());
406 }
407
409 ConstIterator
410 end() const
411 {
412 return
414 items_.end());
415 }
416
419 ConstIterator
421 const Item& item) const
422 {
423 return
425 std::find_if(
426 items_.begin(),
427 items_.end(),
428 ItemLocator(item)));
429 }
430
439 bool
441 const Item& item)
442 {
443 if (end() == find(item))
444 {
445 items_.push_back(toStr(item));
446
447 return true;
448 }
449
450 return false;
451 }
452
457 bool
459 const Item& item)
460 {
461 ItemIterator
462 const found =
463 std::find_if(
464 items_.begin(),
465 items_.end(),
466 ItemLocator(item));
467
468 if (items_.end() == found)
469 return false;
470
471 items_.erase(found);
472
473 return true;
474 }
475
477 void
479 {
480 items_.clear();
481 }
482
484 void
486 TinyStrSet& other)
487 {
488 std::swap
489 (
490 items_,
491 other.items_
492 );
493 }
494};
495
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition Bootstrap.h:95
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition Bootstrap.h:157
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition Bootstrap.h:153
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:88
void swap(TinySet &other)
Swaps content with the other instance.
Definition TinySet.h:181
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:82
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:111
~TinySet()
Cleans everything up.
Definition TinySet.h:77
TinySet(const TinySet &other)
Initializes the set as a copy of the other one.
Definition TinySet.h:70
bool insert(const Item &item)
Definition TinySet.h:134
ConstIterator find(const Item &item) const
Tells whether the set contains given item.
Definition TinySet.h:118
void clear()
Brings the set to the blank state.
Definition TinySet.h:174
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:104
bool erase(const Item &item)
Definition TinySet.h:152
TinySet()
Initializes the empty set.
Definition TinySet.h:55
Implements iterator for the TinyStrSet class.
Definition TinySet.h:212
std::vector< std::string > Items
Aliases for internal representation.
Definition TinySet.h:217
TinyStrSetIterator(const TinyStrSetIterator &other)
Initializes the instance as a copy of the other one.
Definition TinySet.h:230
Items::const_iterator ItemIterator
Aliases iterator over the internal store.
Definition TinySet.h:222
TinyStrSetIterator()
Initializes the iterator pointing to nowhere.
Definition TinySet.h:225
TinyStrSetIterator(const ItemIterator &iterator)
Initializes from iterator over the internal storage.
Definition TinySet.h:238
~TinyStrSetIterator()
Cleans everything up.
Definition TinySet.h:245
void reserve(size_t capacity)
Definition TinySet.h:393
StrRef Item
Items of collection.
Definition TinySet.h:345
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:385
TinyStrSetIterator ConstIterator
Aliases iterator type.
Definition TinySet.h:350
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:379
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:410
void swap(TinyStrSet &other)
Exchanges content with the other instance.
Definition TinySet.h:485
TinyStrSet(const TinyStrSet &other)
Initializes as a copy of the other instance.
Definition TinySet.h:367
~TinyStrSet()
Destructs the internal storage.
Definition TinySet.h:374
bool insert(const Item &item)
Definition TinySet.h:440
ConstIterator find(const Item &item) const
Definition TinySet.h:420
TinyStrSet()
Initializes the empty set.
Definition TinySet.h:353
void clear()
Brings the set to the blank (empty) state.
Definition TinySet.h:478
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:401
bool erase(const Item &item)
Definition TinySet.h:458
void copy(MbpBook< TargetPriceLevel, Depth > &target, const MbpBook< SourcePriceLevel, Depth > &source, Depth maxDepth=static_cast< Depth >(-1))
Definition MbpBook.h:280
ONIXS_CONFLATEDUDP_EXPORTED 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:174