OnixS C++ CME MDP Premium Market Data Handler 5.11.1
Users' manual and API documentation
Loading...
Searching...
No Matches
SettingGroup.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
27#include <OnixS/CME/MDH/Utils.h>
28
30
32
38{
43 virtual void beginChange(const SettingGroup& group, const Messaging::Char* details) = 0;
44
51 virtual void endChange() = 0;
52};
53
54
60{
62 void beginChange(const SettingGroup& group, const Messaging::Char* details) noexcept override ONIXS_CMEMDH_EMPTY_BODY(group, details)
63
64
65 void endChange() noexcept override ONIXS_CMEMDH_EMPTY_BODY()
66
72 static SettingChangeController& self() noexcept;
73};
74
80{
81public:
89 : controller_(controller)
90 {
91 controller_.beginChange(group, details);
92 }
93
96 {
97 controller_.endChange();
98 }
99
100private:
101 SettingChangeController& controller_;
102
103 SettingChangeGuard(const SettingChangeGuard&) = delete;
104 SettingChangeGuard& operator=(const SettingChangeGuard&) = delete;
105};
106
112{
113public:
119 : controller_(controller ? *controller : TrivialChangeController::self())
120 {
121 }
122
124 ~SettingGroup() = default;
125
135 template <class Assignee, class Value>
136 void controlAssignment(const Messaging::Char* description, Assignee& assignee, Value value) const
137 {
138 const SettingChangeGuard guard(controller_, *this, description);
139 assignee = value;
140 }
141
149 template <class Changeable>
150 void controlChange(const Messaging::Char* description, void (Changeable::*change)(), Changeable& changeable) const
151 {
152 const SettingChangeGuard guard(controller_, *this, description);
153 (changeable.*change)();
154 }
155
166 template <class Change, class Changeable, class Arg>
167 void controlChange(const Messaging::Char* description, Change change, Changeable& changeable, const Arg& arg) const
168 {
169 const SettingChangeGuard guard(controller_, *this, description);
170 (changeable.*change)(arg);
171 }
172
185 template <class Change, class Changeable, class Arg1, class Arg2>
186 void controlChange(const Messaging::Char* description, Change change, Changeable& changeable, const Arg1& arg1, const Arg2& arg2) const
187 {
188 const SettingChangeGuard guard(controller_, *this, description);
189 (changeable.*change)(arg1, arg2);
190 }
191
196 static const SettingGroup& null() noexcept;
197
198private:
199 // Controller for the given group of settings.
200 SettingChangeController& controller_;
201
202 SettingGroup(const SettingGroup&) = delete;
203
204 SettingGroup& operator=(const SettingGroup&) = delete;
205};
206
211inline bool operator==(const SettingGroup& left, const SettingGroup& right)
212{
213 return (&left == &right);
214}
215
220inline bool operator!=(const SettingGroup& left, const SettingGroup& right)
221{
222 return (&left != &right);
223}
224
225// Pre-defined collections.
226
233template <class Type, class Container = std::vector<Type> >
235{
236public:
238 using Item = Type;
239
241 using Items = Container;
242
244 using Size = typename Items::size_type;
245
247 using Iterator = typename Items::const_iterator;
248
253 explicit ListSetting(const SettingGroup* group = nullptr)
254 : group_(group ? *group : SettingGroup::null())
255 {
256 }
257
263 : group_(SettingGroup::null())
264 , items_(other.items_)
265 {
266 }
267
274 template <class InputIterator>
275 ListSetting(InputIterator first, InputIterator last)
276 : group_(SettingGroup::null())
277 , items_(first, last)
278 {
279 }
280
286 operator const Items&() const
287 {
288 return items_;
289 }
290
294 bool empty() const
295 {
296 return items_.empty();
297 }
298
302 Size size() const
303 {
304 return items_.size();
305 }
306
311 {
312 return items_.begin();
313 }
314
318 Iterator end() const
319 {
320 return items_.end();
321 }
322
328 const Item& operator[](Size index) const
329 {
330 return items_[index];
331 }
332
342 template <class Initializer>
343 void initialize(Initializer initializer)
344 {
345 group_.controlChange("Initialize List", &ListSetting::initNoControl<Initializer>, *this, initializer);
346 }
347
353 void push_back(const Item& item)
354 {
355 group_.controlChange(
356 "Append an Item", static_cast<void (Items::*)(const Item&)>(&Items::push_back), items_, item
357 );
358 }
359
366 void clear()
367 {
368 group_.controlChange("Clear the List", &Items::clear, items_);
369 }
370
379 {
380 group_.controlChange("Assign List", &ListSetting::assignNoControl, *this, other);
381
382 return *this;
383 }
384
394 template <class InputIterator>
395 ListSetting& assign(InputIterator first, InputIterator last)
396 {
397 group_.controlChange("Assign List", &ListSetting::assignRangeNoControl<InputIterator>, *this, first, last);
398
399 return *this;
400 }
401
409 {
410 items_ = other.items_;
411
412 return *this;
413 }
414
415private:
416 const SettingGroup& group_;
417
418 Container items_;
419
420 template <class Initializer>
421 void initNoControl(Initializer initializer)
422 {
423 items_.clear();
424
425 initializer(items_);
426 }
427
428 template <class InputIterator>
429 void assignRangeNoControl(InputIterator first, InputIterator last)
430 {
431 items_.assign(first, last);
432 }
433};
434
443template <class Type, class Container>
444void toStr(std::string& str, const ListSetting<Type, Container>& list, Messaging::Char delimiter = ',')
445{
446 const auto endOfList = list.end();
447
448 auto item = list.begin();
449
450 while (item != endOfList)
451 {
452 Messaging::toStr(str, *item);
453
454 ++item;
455
456 if (item != endOfList)
457 str += delimiter;
458 }
459}
460
468template <class Type, class Container>
470std::string toStr(const ListSetting<Type, Container>& list, Messaging::Char delimiter = ',')
471{
472 std::string str;
473 toStr(str, list, delimiter);
474 return str;
475}
476
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:69
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:61
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition Bootstrap.h:63
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition Bootstrap.h:62
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:73
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:165
Stores a controller-aware list of setting values.
Iterator begin() const
Obtains an iterator to the first item.
ListSetting & assign(InputIterator first, InputIterator last)
Replaces the items with a guarded copy of an iterator range.
const Item & operator[](Size index) const
Accesses an item without bounds checking.
ListSetting & operator=(const ListSetting &other)
Replaces the items with a guarded copy of another list.
void initialize(Initializer initializer)
Replaces the list contents through a guarded initializer callback.
ListSetting & assignNoControl(const ListSetting &other)
Replaces the items without consulting the change controller.
Iterator end() const
Obtains an iterator past the final item.
bool empty() const
Checks whether the list contains no items.
ListSetting(InputIterator first, InputIterator last)
Creates an unmanaged list from an iterator range.
ListSetting(const ListSetting &other)
Copies another list's items into an unmanaged list.
void push_back(const Item &item)
Appends a copy of an item through the associated change controller.
void clear()
Removes all items through the associated change controller.
Size size() const
Obtains the number of items in the list.
typename Items::const_iterator Iterator
ListSetting(const SettingGroup *group=nullptr)
Creates an empty list associated with a setting group.
Pairs a successful beginChange() call with endChange().
~SettingChangeGuard()
Completes the guarded setting change.
SettingChangeGuard(SettingChangeController &controller, const SettingGroup &group, const Messaging::Char *details)
Starts a guarded setting change.
Associates setting mutations with a change controller.
SettingGroup(SettingChangeController *controller=nullptr)
Creates a setting group that uses the specified controller.
void controlChange(const Messaging::Char *description, Change change, Changeable &changeable, const Arg1 &arg1, const Arg2 &arg2) const
Invokes a two-argument member function as a guarded change.
~SettingGroup()=default
Destroys the group without destroying its controller.
void controlChange(const Messaging::Char *description, void(Changeable::*change)(), Changeable &changeable) const
Invokes a zero-argument member function as a guarded change.
void controlAssignment(const Messaging::Char *description, Assignee &assignee, Value value) const
Assigns a value while coordinating the change with the controller.
static const SettingGroup & null() noexcept
Obtains the shared group that accepts every change.
void controlChange(const Messaging::Char *description, Change change, Changeable &changeable, const Arg &arg) const
Invokes a one-argument member function as a guarded change.
char Char
Character type alias.
Definition String.h:30
void toStr(std::string &, Int8)
Serializes given integer into a string.
void toStr(std::string &str, BookState::Enum bookState)
Appends a string representation of a book state.
bool operator!=(const MemoryPoolAllocator< Object > &left, const MemoryPoolAllocator< OtherObject > &right) noexcept
Tests whether two allocators use different pools.
Definition MemoryPool.h:316
Coordinates changes to settings that belong to a setting group.
virtual void endChange()=0
Completes the current guarded setting change.
virtual void beginChange(const SettingGroup &group, const Messaging::Char *details)=0
Starts a guarded setting change.
Controller implementation that accepts every setting change.
static SettingChangeController & self() noexcept
Obtains the shared controller that accepts every change.
void endChange() noexcept override
Completes the current guarded setting change.
void beginChange(const SettingGroup &group, const Messaging::Char *details) noexcept override
Starts a guarded setting change.