OnixS C++ CME MDP Premium Market Data Handler 5.9.0
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
26
28
30
34{
40 virtual void beginChange(const SettingGroup&, const Char*) = 0;
41
47 virtual void endChange() = 0;
48};
49
50// Default attributes and functionality.
64
67{
68public:
70 SettingChangeGuard(SettingChangeController& controller, const SettingGroup& group, const Char* details)
71 : controller_(controller)
72 {
73 controller_.beginChange(group, details);
74 }
75
78 {
79 controller_.endChange();
80 }
81
82private:
83 SettingChangeController& controller_;
84
86
87 SettingChangeGuard& operator=(const SettingChangeGuard&);
88};
89
92{
93public:
97 : controller_(controller ? *controller : TrivialChangeController::self())
98 {
99 }
100
103
106 template <class Assignee, class Value>
107 void controlAssignment(const Char* description, Assignee& assignee, Value value) const
108 {
109 const SettingChangeGuard guard(controller_, *this, description);
110 {
111 assignee = value;
112 }
113 }
114
117 template <class Changeable>
118 void controlChange(const Char* description, void (Changeable::*change)(), Changeable& changeable) const
119 {
120 const SettingChangeGuard guard(controller_, *this, description);
121 {
122 (changeable.*change)();
123 }
124 }
125
128 template <class Change, class Changeable, class Arg>
129 void controlChange(const Char* description, Change change, Changeable& changeable, const Arg& arg) const
130 {
131 const SettingChangeGuard guard(controller_, *this, description);
132 {
133 (changeable.*change)(arg);
134 }
135 }
136
139 template <class Change, class Changeable, class Arg1, class Arg2>
140 void
141 controlChange(const Char* description, Change change, Changeable& changeable, const Arg1& arg1, const Arg2& arg2)
142 const
143 {
144 const SettingChangeGuard guard(controller_, *this, description);
145 {
146 (changeable.*change)(arg1, arg2);
147 }
148 }
149
153 static const SettingGroup& null();
154
155private:
156 // Controller for the given group of settings.
157 SettingChangeController& controller_;
158
160
161 SettingGroup& operator=(const SettingGroup&);
162};
163
165inline bool operator==(const SettingGroup& left, const SettingGroup& right)
166{
167 return (&left == &right);
168}
169
171inline bool operator!=(const SettingGroup& left, const SettingGroup& right)
172{
173 return (&left != &right);
174}
175
176// Pre-defined collections.
177
179template <class Type, class Container = std::vector<Type> >
181{
182public:
184 typedef Type Item;
185
187 typedef Container Items;
188
190 typedef typename Items::size_type Size;
191
193 typedef typename Items::const_iterator Iterator;
194
198 : group_(group ? *group : SettingGroup::null())
199 {
200 }
201
204 : group_(SettingGroup::null())
205 , items_(other.items_)
206 {
207 }
208
210 template <class InputIterator>
211 ListSetting(InputIterator first, InputIterator last)
212 : group_(SettingGroup::null())
213 , items_(first, last)
214 {
215 }
216
218 operator const Items&() const
219 {
220 return items_;
221 }
222
224 bool empty() const
225 {
226 return items_.empty();
227 }
228
230 Size size() const
231 {
232 return items_.size();
233 }
234
237 {
238 return items_.begin();
239 }
240
242 Iterator end() const
243 {
244 return items_.end();
245 }
246
248 const Item& operator[](Size index) const
249 {
250 return items_[index];
251 }
252
255 template <class Initializer>
256 void initialize(Initializer initializer)
257 {
258 group_.controlChange("Initialize List", &ListSetting::initNoControl<Initializer>, *this, initializer);
259 }
260
262 void push_back(const Item& item)
263 {
264 group_.controlChange(
265 "Append an Item", static_cast<void (Items::*)(const Item&)>(&Items::push_back), items_, item
266 );
267 }
268
273 void clear()
274 {
275 group_.controlChange("Clear the List", &Items::clear, items_);
276 }
277
280 {
281 group_.controlChange("Assign List", &ListSetting::assignNoControl, *this, other);
282
283 return *this;
284 }
285
287 template <class InputIterator>
288 ListSetting& assign(InputIterator first, InputIterator last)
289 {
290 group_.controlChange("Assign List", &Items::assign, items_, first, last);
291
292 return *this;
293 }
294
302 {
303 items_ = other.items_;
304
305 return *this;
306 }
307
308private:
309 const SettingGroup& group_;
310
311 Container items_;
312
313 template <class Initializer>
314 void initNoControl(Initializer initializer)
315 {
316 items_.clear();
317
318 initializer(items_);
319 }
320};
321
324template <class Type>
325void toStr(std::string& str, const ListSetting<Type>& list, Char delimiter = ',')
326{
327 const typename ListSetting<Type>::Iterator endOfList = list.end();
328
329 typename ListSetting<Type>::Iterator item = list.begin();
330
331 while (true)
332 {
333 toStr(str, *item);
334
335 if (++item == endOfList)
336 {
337 break;
338 }
339
340 str += delimiter;
341 }
342}
343
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:67
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:46
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition Bootstrap.h:48
#define ONIXS_CMEMDH_LTWT_EXPORTED
Definition Bootstrap.h:47
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:68
#define ONIXS_CMEMDH_NULLPTR
Definition Compiler.h:178
#define ONIXS_CMEMDH_OVERRIDE
Definition Compiler.h:176
Represents a setting which is a list of values.
Iterator begin() const
Returns iterator pointing to the beginning of the list.
ListSetting & assign(InputIterator first, InputIterator last)
Re-initialize the list as a copy of the given range.
const Item & operator[](Size index) const
Provides access to the items by its index.
ListSetting & operator=(const ListSetting &other)
Re-initialize the list as a copy of the other one.
void initialize(Initializer initializer)
Performs managed initialization of the list using the given functional object.
ListSetting & assignNoControl(const ListSetting &other)
Unmanaged assignment of the list.
Iterator end() const
Returns iterator pointing to the item beyond the last one.
bool empty() const
Indicates whether the list is an empty one.
ListSetting(InputIterator first, InputIterator last)
Initializes as copy of the given range of items.
ListSetting(const ListSetting &other)
Initializes as a copy the other instance.
void push_back(const Item &item)
Appends the given item to the tail of the list.
void clear()
Removes all items from the list.
Size size() const
Returns number of items in the given list.
ListSetting(const SettingGroup *group=nullptr)
Initializes the instance belonging to the given group of settings.
Scope guard to update setting in the safe way.
~SettingChangeGuard()
Accomplishes setting update.
SettingChangeGuard(SettingChangeController &controller, const SettingGroup &group, const Char *details)
Initializes the guard for the given setting update.
Base services for settings grouped by a certain criteria.
void controlAssignment(const Char *description, Assignee &assignee, Value value) const
Guarded assignment of the given value to the given variable.
void controlChange(const Char *description, Change change, Changeable &changeable, const Arg1 &arg1, const Arg2 &arg2) const
Guarded invoke of the given routine which assumes complex change or update for the given object.
SettingGroup(SettingChangeController *controller=nullptr)
Initializes the group of settings with the given validation services.
void controlChange(const Char *description, void(Changeable::*change)(), Changeable &changeable) const
Guarded invoke of the given routine which assumes complex change or update for the given object.
void controlChange(const Char *description, Change change, Changeable &changeable, const Arg &arg) const
Guarded invoke of the given routine which assumes complex change or update for the given object.
static const SettingGroup & null()
Returns an instance representing a null group.
~SettingGroup()
Does actually nothing.
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:96
char Char
Character type alias.
Definition String.h:36
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition Decimal.h:89
void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
Represents a service controlling change/update operations for the collections of settings.
virtual void endChange()=0
Accomplishes the setting change operation.
virtual void beginChange(const SettingGroup &, const Char *)=0
Begins the setting change operation.
void endChange() override
Implements base class interface.
static SettingChangeController & self()
Returns instance of the trivial assignment controller.
void beginChange(const SettingGroup &, const Char *) override
Implements base class interface.