OnixS C++ CME MDP Premium Market Data Handler 5.10.2
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
29
31
35{
41 virtual void beginChange(const SettingGroup&, const Messaging::Char*) = 0;
42
48 virtual void endChange() = 0;
49};
50
51// Default attributes and functionality.
65
68{
69public:
72 : controller_(controller)
73 {
74 controller_.beginChange(group, details);
75 }
76
79 {
80 controller_.endChange();
81 }
82
83private:
84 SettingChangeController& controller_;
85
87
88 SettingChangeGuard& operator=(const SettingChangeGuard&);
89};
90
93{
94public:
98 : controller_(controller ? *controller : TrivialChangeController::self())
99 {
100 }
101
104
107 template <class Assignee, class Value>
108 void controlAssignment(const Messaging::Char* description, Assignee& assignee, Value value) const
109 {
110 const SettingChangeGuard guard(controller_, *this, description);
111 {
112 assignee = value;
113 }
114 }
115
118 template <class Changeable>
119 void controlChange(const Messaging::Char* description, void (Changeable::*change)(), Changeable& changeable) const
120 {
121 const SettingChangeGuard guard(controller_, *this, description);
122 {
123 (changeable.*change)();
124 }
125 }
126
129 template <class Change, class Changeable, class Arg>
130 void controlChange(const Messaging::Char* description, Change change, Changeable& changeable, const Arg& arg) const
131 {
132 const SettingChangeGuard guard(controller_, *this, description);
133 {
134 (changeable.*change)(arg);
135 }
136 }
137
140 template <class Change, class Changeable, class Arg1, class Arg2>
141 void
142 controlChange(const Messaging::Char* description, Change change, Changeable& changeable, const Arg1& arg1, const Arg2& arg2)
143 const
144 {
145 const SettingChangeGuard guard(controller_, *this, description);
146 {
147 (changeable.*change)(arg1, arg2);
148 }
149 }
150
154 static const SettingGroup& null();
155
156private:
157 // Controller for the given group of settings.
158 SettingChangeController& controller_;
159
161
162 SettingGroup& operator=(const SettingGroup&);
163};
164
166inline bool operator==(const SettingGroup& left, const SettingGroup& right)
167{
168 return (&left == &right);
169}
170
172inline bool operator!=(const SettingGroup& left, const SettingGroup& right)
173{
174 return (&left != &right);
175}
176
177// Pre-defined collections.
178
180template <class Type, class Container = std::vector<Type> >
182{
183public:
185 typedef Type Item;
186
188 typedef Container Items;
189
191 typedef typename Items::size_type Size;
192
194 typedef typename Items::const_iterator Iterator;
195
198 explicit ListSetting(const SettingGroup* group = nullptr)
199 : group_(group ? *group : SettingGroup::null())
200 {
201 }
202
205 : group_(SettingGroup::null())
206 , items_(other.items_)
207 {
208 }
209
211 template <class InputIterator>
212 ListSetting(InputIterator first, InputIterator last)
213 : group_(SettingGroup::null())
214 , items_(first, last)
215 {
216 }
217
219 operator const Items&() const
220 {
221 return items_;
222 }
223
225 bool empty() const
226 {
227 return items_.empty();
228 }
229
231 Size size() const
232 {
233 return items_.size();
234 }
235
238 {
239 return items_.begin();
240 }
241
243 Iterator end() const
244 {
245 return items_.end();
246 }
247
249 const Item& operator[](Size index) const
250 {
251 return items_[index];
252 }
253
256 template <class Initializer>
257 void initialize(Initializer initializer)
258 {
259 group_.controlChange("Initialize List", &ListSetting::initNoControl<Initializer>, *this, initializer);
260 }
261
263 void push_back(const Item& item)
264 {
265 group_.controlChange(
266 "Append an Item", static_cast<void (Items::*)(const Item&)>(&Items::push_back), items_, item
267 );
268 }
269
274 void clear()
275 {
276 group_.controlChange("Clear the List", &Items::clear, items_);
277 }
278
281 {
282 group_.controlChange("Assign List", &ListSetting::assignNoControl, *this, other);
283
284 return *this;
285 }
286
288 template <class InputIterator>
289 ListSetting& assign(InputIterator first, InputIterator last)
290 {
291 group_.controlChange("Assign List", &Items::assign, items_, first, last);
292
293 return *this;
294 }
295
303 {
304 items_ = other.items_;
305
306 return *this;
307 }
308
309private:
310 const SettingGroup& group_;
311
312 Container items_;
313
314 template <class Initializer>
315 void initNoControl(Initializer initializer)
316 {
317 items_.clear();
318
319 initializer(items_);
320 }
321};
322
325template <class Type>
326void toStr(std::string& str, const ListSetting<Type>& list, Messaging::Char delimiter = ',')
327{
328 const typename ListSetting<Type>::Iterator endOfList = list.end();
329
330 typename ListSetting<Type>::Iterator item = list.begin();
331
332 while (true)
333 {
334 Messaging::toStr(str, *item);
335
336 if (++item == endOfList)
337 {
338 break;
339 }
340
341 str += delimiter;
342 }
343}
344
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:54
#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:55
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)
ListSetting & assignNoControl(const ListSetting &other)
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.
Size size() const
Returns number of items in the given list.
ListSetting(const SettingGroup *group=nullptr)
Scope guard to update setting in the safe way.
~SettingChangeGuard()
Accomplishes setting update.
SettingChangeGuard(SettingChangeController &controller, const SettingGroup &group, const Messaging::Char *details)
Initializes the guard for the given setting update.
Base services for settings grouped by a certain criteria.
SettingGroup(SettingChangeController *controller=nullptr)
void controlChange(const Messaging::Char *description, Change change, Changeable &changeable, const Arg1 &arg1, const Arg2 &arg2) const
void controlChange(const Messaging::Char *description, void(Changeable::*change)(), Changeable &changeable) const
void controlAssignment(const Messaging::Char *description, Assignee &assignee, Value value) const
void controlChange(const Messaging::Char *description, Change change, Changeable &changeable, const Arg &arg) const
static const SettingGroup & null()
~SettingGroup()
Does actually nothing.
char Char
Character type alias.
Definition String.h:30
void toStr(std::string &, Int8)
Serializes given integer into a string.
void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
bool operator==(const MemoryPoolAllocator< Object > &left, const MemoryPoolAllocator< OtherObject > &right)
Definition MemoryPool.h:181
bool operator!=(const MemoryPoolAllocator< Object > &left, const MemoryPoolAllocator< OtherObject > &right)
Definition MemoryPool.h:187
virtual void beginChange(const SettingGroup &, const Messaging::Char *)=0
void endChange() override
Implements base class interface.
static SettingChangeController & self()
void beginChange(const SettingGroup &, const Messaging::Char *) override
Implements base class interface.