OnixS C++ CME MDP Premium Market Data Handler 5.10.3
Users' manual and 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
29
31
34template <class Key>
36{
37public:
39 typedef Key Item;
40
42 typedef std::vector<Item> Items;
43
45 typedef typename Items::const_iterator ConstIterator;
46
49
53 explicit TinySet(size_t capacity)
54 {
55 reserve(capacity);
56 }
57
59 TinySet(const TinySet& other)
60 : items_(other.items_)
61 {
62 }
63
66
68 bool empty() const
69 {
70 return items_.empty();
71 }
72
74 size_t size() const
75 {
76 return items_.size();
77 }
78
81 void reserve(size_t capacity)
82 {
83 items_.reserve(capacity);
84 }
85
88 {
89 return items_.begin();
90 }
91
94 {
95 return items_.end();
96 }
97
99 ConstIterator find(const Item& item) const
100 {
101 return std::find(items_.begin(), items_.end(), item);
102 }
103
109 bool insert(const Item& item)
110 {
111 if (end() == find(item))
112 {
113 items_.push_back(item);
114
115 return true;
116 }
117
118 return false;
119 }
120
125 bool erase(const Item& item)
126 {
127 typename Items::iterator const found = std::find(items_.begin(), items_.end(), item);
128
129 if (items_.end() == found)
130 return false;
131
132 items_.erase(found);
133
134 return true;
135 }
136
138 void clear()
139 {
140 items_.clear();
141 }
142
144 void swap(TinySet& other)
145 {
146 std::swap(items_, other.items_);
147 }
148
151 TinySet& operator=(const TinySet& other)
152 {
153 if (&other != this)
154 {
155 TinySet copy(other);
156
157 swap(copy);
158 }
159
160 return *this;
161 }
162
163private:
164 Items items_;
165};
166
169{
170public:
172 typedef std::vector<std::string> Items;
173
175 typedef Items::const_iterator ItemIterator;
176
179
182 : iterator_(other.iterator_)
183 {
184 }
185
187 explicit TinyStrSetIterator(const ItemIterator& iterator)
188 : iterator_(iterator)
189 {
190 }
191
194
197 {
198 return Messaging::toStrRef(*iterator_);
199 }
200
202 bool operator==(const TinyStrSetIterator& other) const
203 {
204 return iterator_ == other.iterator_;
205 }
206
208 bool operator!=(const TinyStrSetIterator& other) const
209 {
210 return iterator_ != other.iterator_;
211 }
212
215 {
216 iterator_ = other.iterator_;
217
218 return *this;
219 }
220
224 {
225 ++iterator_;
226
227 return *this;
228 }
229
230private:
231 ItemIterator iterator_;
232};
233
242{
243public:
246
249
252
255 explicit TinyStrSet(size_t capacity)
256 {
257 reserve(capacity);
258 }
259
261 TinyStrSet(const TinyStrSet& other)
262 : items_(other.items_)
263 {
264 }
265
268
270 bool empty() const
271 {
272 return items_.empty();
273 }
274
276 size_t size() const
277 {
278 return items_.size();
279 }
280
283 void reserve(size_t capacity)
284 {
285 items_.reserve(capacity);
286 }
287
290 {
291 return ConstIterator(items_.begin());
292 }
293
296 {
297 return ConstIterator(items_.end());
298 }
299
302 ConstIterator find(const Item& item) const
303 {
304 return ConstIterator(std::find_if(items_.begin(), items_.end(), ItemLocator(item)));
305 }
306
315 bool insert(const Item& item)
316 {
317 if (end() == find(item))
318 {
319 items_.push_back(Messaging::toStr(item));
320
321 return true;
322 }
323
324 return false;
325 }
326
331 bool erase(const Item& item)
332 {
333 const ItemIterator found = std::find_if(items_.begin(), items_.end(), ItemLocator(item));
334
335 if (items_.end() == found)
336 return false;
337
338 items_.erase(found);
339
340 return true;
341 }
342
344 void clear()
345 {
346 items_.clear();
347 }
348
350 void swap(TinyStrSet& other)
351 {
352 std::swap(items_, other.items_);
353 }
354
355private:
356 typedef std::vector<std::string> Items;
357
358 typedef Items::const_iterator ItemConstIterator;
359
360 typedef Items::iterator ItemIterator;
361
362 class ItemLocator
363 {
364 Messaging::StrRef sought_;
365
366 public:
367 ItemLocator(Messaging::StrRef sought)
368 : sought_(sought)
369 {
370 }
371
372 bool operator()(const std::string& other) const
373 {
374 return sought_ == other;
375 }
376 };
377
378 Items items_;
379};
380
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:54
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:46
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:55
void reserve(size_t capacity)
Definition TinySet.h:81
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:74
void swap(TinySet &other)
Swaps content with the other instance.
Definition TinySet.h:144
TinySet(size_t capacity)
Definition TinySet.h:53
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:68
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:93
~TinySet()
Cleans everything up.
Definition TinySet.h:65
TinySet(const TinySet &other)
Initializes the set as a copy of the other one.
Definition TinySet.h:59
bool insert(const Item &item)
Definition TinySet.h:109
ConstIterator find(const Item &item) const
Tells whether the set contains given item.
Definition TinySet.h:99
void clear()
Brings the set to the blank state.
Definition TinySet.h:138
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:87
bool erase(const Item &item)
Definition TinySet.h:125
Items::const_iterator ConstIterator
Definition TinySet.h:45
TinySet & operator=(const TinySet &other)
Definition TinySet.h:151
TinySet()
Initializes the empty set.
Definition TinySet.h:48
Implements iterator for the TinyStrSet class.
Definition TinySet.h:169
bool operator!=(const TinyStrSetIterator &other) const
Compares with the other instance.
Definition TinySet.h:208
TinyStrSetIterator & operator=(const TinyStrSetIterator &other)
Re-initializes as a copy of the other instance.
Definition TinySet.h:214
std::vector< std::string > Items
Aliases for internal representation.
Definition TinySet.h:172
TinyStrSetIterator(const TinyStrSetIterator &other)
Initializes the instance as a copy of the other one.
Definition TinySet.h:181
TinyStrSetIterator & operator++()
Definition TinySet.h:223
Messaging::StrRef operator*() const
Provides access to the underlying object.
Definition TinySet.h:196
Items::const_iterator ItemIterator
Aliases iterator over the internal store.
Definition TinySet.h:175
~TinyStrSetIterator()=default
Cleans everything up.
TinyStrSetIterator()
Initializes the iterator pointing to nowhere.
Definition TinySet.h:178
bool operator==(const TinyStrSetIterator &other) const
Compares with the other instance.
Definition TinySet.h:202
TinyStrSetIterator(const ItemIterator &iterator)
Initializes from iterator over the internal storage.
Definition TinySet.h:187
void reserve(size_t capacity)
Definition TinySet.h:283
size_t size() const
Returns the number of items in the set.
Definition TinySet.h:276
Messaging::StrRef Item
Items of collection.
Definition TinySet.h:245
TinyStrSet(size_t capacity)
Definition TinySet.h:255
TinyStrSetIterator ConstIterator
Aliases iterator type.
Definition TinySet.h:248
bool empty() const
Indicates whether the set is empty.
Definition TinySet.h:270
ConstIterator end() const
Provides iterating facilities.
Definition TinySet.h:295
void swap(TinyStrSet &other)
Exchanges content with the other instance.
Definition TinySet.h:350
TinyStrSet(const TinyStrSet &other)
Initializes as a copy of the other instance.
Definition TinySet.h:261
~TinyStrSet()
Destructs the internal storage.
Definition TinySet.h:267
bool insert(const Item &item)
Definition TinySet.h:315
ConstIterator find(const Item &item) const
Definition TinySet.h:302
TinyStrSet()
Initializes the empty set.
Definition TinySet.h:251
void clear()
Brings the set to the blank (empty) state.
Definition TinySet.h:344
ConstIterator begin() const
Provides iterating facilities.
Definition TinySet.h:289
bool erase(const Item &item)
Definition TinySet.h:331
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
StrRef toStrRef(const std::string &str)
Constructs a StrRef instance over th std::string content.
Definition StrRef.h:367
void toStr(std::string &, Int8)
Serializes given integer into a string.
MboBook & copy(MboBook &target, const MboBook &source)
Copies content of MBO book to the other one.
Definition MboBook.h:210