OnixS C++ CME MDP Streamlined Market Data Handler 1.2.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
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
132 bool
134 const Item& item)
135 {
136 if (end() == find(item))
137 {
138 items_.push_back(item);
139
140 return true;
141 }
142
143 return false;
144 }
145
149 bool
151 const Item& item)
152 {
153 typename
154 Items::iterator
155 const
156 found =
157 std::find(
158 items_.begin(),
159 items_.end(),
160 item);
161
162 if (items_.end() == found)
163 return false;
164
165 items_.erase(found);
166
167 return true;
168 }
169
171 void
173 {
174 items_.clear();
175 }
176
178 void
180 TinySet& other)
181 {
182 std::swap(
183 items_,
184 other.items_);
185 }
186
188 TinySet&
189 operator =(
190 const TinySet& other)
191 {
192 if (&other != this)
193 {
194 TinySet copy(other);
195
196 swap(copy);
197 }
198
199 return *this;
200 }
201
202private:
203 Items items_;
204};
205
209{
210public:
212 typedef
213 std::vector<std::string>
215
217 typedef
218 Items::const_iterator
220
223 {
224 }
225
228 const TinyStrSetIterator& other)
229 : iterator_(other.iterator_)
230 {
231 }
232
234 explicit
236 const ItemIterator& iterator)
237 : iterator_(iterator)
238 {
239 }
240
243 {
244 }
245
247 StrRef
248 operator *() const
249 {
250 return toStrRef(*iterator_);
251 }
252
254 bool
255 operator ==(
256 const
257 TinyStrSetIterator& other) const
258 {
259 return iterator_ == other.iterator_;
260 }
261
263 bool
264 operator !=(
265 const
266 TinyStrSetIterator& other) const
267 {
268 return iterator_ != other.iterator_;
269 }
270
273 operator =(
274 const
275 TinyStrSetIterator& other)
276 {
277 iterator_ = other.iterator_;
278
279 return *this;
280 }
281
284 operator ++()
285 {
286 ++iterator_;
287
288 return *this;
289 }
290
291private:
292 ItemIterator iterator_;
293};
294
303{
304public:
306 typedef StrRef Item;
307
309 typedef
312
315 {
316 }
317
320 explicit
322 size_t capacity)
323 {
324 reserve(capacity);
325 }
326
329 const TinyStrSet& other)
330 : items_(other.items_)
331 {
332 }
333
336 {
337 }
338
340 bool empty() const
341 {
342 return items_.empty();
343 }
344
346 size_t size() const
347 {
348 return items_.size();
349 }
350
353 void
355 size_t capacity)
356 {
357 items_.reserve(capacity);
358 }
359
361 ConstIterator
362 begin() const
363 {
364 return
366 items_.begin());
367 }
368
370 ConstIterator
371 end() const
372 {
373 return
375 items_.end());
376 }
377
379 ConstIterator
381 const Item& item) const
382 {
383 return
385 std::find_if(
386 items_.begin(),
387 items_.end(),
388 ItemLocator(item)));
389 }
390
398 bool
400 const Item& item)
401 {
402 if (end() == find(item))
403 {
404 items_.push_back(toStr(item));
405
406 return true;
407 }
408
409 return false;
410 }
411
415 bool
417 const Item& item)
418 {
419 ItemIterator
420 const found =
421 std::find_if(
422 items_.begin(),
423 items_.end(),
424 ItemLocator(item));
425
426 if (items_.end() == found)
427 return false;
428
429 items_.erase(found);
430
431 return true;
432 }
433
435 void
437 {
438 items_.clear();
439 }
440
442 void
444 TinyStrSet& other)
445 {
446 std::swap
447 (
448 items_,
449 other.items_
450 );
451 }
452
453private:
454 typedef
455 std::vector<std::string>
456 Items;
457
458 typedef
459 Items::const_iterator
460 ItemConstIterator;
461
462 typedef
463 Items::iterator
464 ItemIterator;
465
466 class ItemLocator
467 {
468 StrRef sought_;
469
470 public:
471 ItemLocator(
472 const StrRef& sought)
473 : sought_(sought)
474 {
475 }
476
477 bool
478 operator ()(
479 const
480 std::string& other) const
481 {
482 return sought_ == other;
483 }
484 };
485
486 Items items_;
487};
488
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:169
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition Bootstrap.h:173
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS
Definition Bootstrap.h:111
Provides efficient way of accessing text-based FIX field values.
Definition String.h:40
Class implementing set optimized for storing small number of items.
Definition TinySet.h:38
size_t size() const
Number of items in the set.
Definition TinySet.h:88
void swap(TinySet &other)
Swaps content with the other instance.
Definition TinySet.h:179
TinySet(size_t capacity)
Initializes empty set and configures internal storage to be enough capacious to store given number of...
Definition TinySet.h:63
bool empty() const
Indicates whether 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 set as copy of other one.
Definition TinySet.h:70
bool insert(const Item &item)
Inserts items into the set.
Definition TinySet.h:133
ConstIterator find(const Item &item) const
Tells whether set contains given item.
Definition TinySet.h:118
void clear()
Brings set to blank state.
Definition TinySet.h:172
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:104
bool erase(const Item &item)
Removes given item from the set.
Definition TinySet.h:150
TinySet()
Initializes empty set.
Definition TinySet.h:55
Implements iterator for TinyStrSet class.
Definition TinySet.h:209
std::vector< std::string > Items
Aliases internal representation.
Definition TinySet.h:214
TinyStrSetIterator(const TinyStrSetIterator &other)
Initializes instance as copy of the other one.
Definition TinySet.h:227
Items::const_iterator ItemIterator
Aliases iterator over internal store.
Definition TinySet.h:219
TinyStrSetIterator()
Initializes iterator pointing to nowhere.
Definition TinySet.h:222
TinyStrSetIterator(const ItemIterator &iterator)
Initializes from iterator over internal store.
Definition TinySet.h:235
void reserve(size_t capacity)
Makes internal storage capacious enough to store given number of items.
Definition TinySet.h:354
StrRef Item
Items of collection.
Definition TinySet.h:306
size_t size() const
Returns number of items in the set.
Definition TinySet.h:346
TinyStrSet(size_t capacity)
Initializes empty set capacious enough to store given number of items.
Definition TinySet.h:321
TinyStrSetIterator ConstIterator
Aliases iterator type.
Definition TinySet.h:311
bool empty() const
Indicates whether set is empty.
Definition TinySet.h:340
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:371
void swap(TinyStrSet &other)
Exchanges content with the other instance.
Definition TinySet.h:443
TinyStrSet(const TinyStrSet &other)
Initializes as copy of other instance.
Definition TinySet.h:328
bool insert(const Item &item)
Inserts item into set.
Definition TinySet.h:399
ConstIterator find(const Item &item) const
Tells whether set contains given item.
Definition TinySet.h:380
TinyStrSet()
Initializes empty set.
Definition TinySet.h:314
void clear()
Brings set to blank/empty state.
Definition TinySet.h:436
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:362
bool erase(const Item &item)
Removes given item from the set.
Definition TinySet.h:416
void copy(VectorOverArray< TargetItem, TargetSize > &target, const VectorOverArray< SourceItem, TargetSize > &source, SourceSize itemCount=static_cast< SourceSize >(-1))
Copies items from source to target.
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition String.h:166
void toStr(std::string &str, const Decimal &number)
Definition Decimal.h:502