Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
MoreConfiguration.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2021. All rights reserved
3 */
4#ifndef _StroikaSample_AppSettings_MoreConfiguration_h_
5#define _StroikaSample_AppSettings_MoreConfiguration_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
12#include "Stroika/Foundation/Execution/ModuleGetterSetter.h"
14
15/*
16 * A more complicated example of configuration, fancier usage patterns (e.g. watching for config changes)
17 */
19
20 using namespace std;
21 using namespace Stroika::Foundation;
23 using namespace Stroika::Foundation::Time;
24
25 /*
26 * This is the data you wish to write out as configuration to control your application, or to track persistently.
27 */
28 struct MoreOptionsData_ {
29 bool fEnabled = false;
30 optional<DateTime> fLastSynchronizedAt;
31 };
32
33 namespace Private_ {
34
35 /*
36 * OptionsData_Storage_IMPL_ is a 'traits' object, defining a GET and SET method to save/restore
37 * OptionsData_.
38 *
39 * This need not worry about thread safety:
40 * o in the constructor because C++ guarantees this for statically constructed objects
41 * o and in the Get/Set methods because ModuleGetterSetter manages this locking
42 *
43 * A user COULD either choose NOT to persist the data (in which case the logic with fOptionsFile_
44 * would be removed/unneeded). Or could persist another way.
45 *
46 * But this example shows using OptionsFile to persist the data to a local JSON file, using
47 * the ObjectVariantMapper to serialize/deserialize C++ data structures.
48 */
49 struct MoreOptionsData_Storage_IMPL_ {
50 MoreOptionsData_Storage_IMPL_ ();
51 MoreOptionsData_ Get () const;
52 void Set (const MoreOptionsData_& v);
53
54 private:
55 OptionsFile fOptionsFile_;
56 MoreOptionsData_ fActualCurrentConfigData_; // automatically initialized just in time, and externally synchronized
57 };
58
59 }
60
62
63 void TestUse1 ();
64 void TestUse2 ();
65 void TestUse3 ();
66 void TestUse4 ();
67}
68/*
69 ********************************************************************************
70 ***************************** Implementation Details ***************************
71 ********************************************************************************
72 */
73#include "MoreConfiguration.inl"
74
75#endif /*_StroikaSample_AppSettings_MoreConfiguration_h_*/
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
STL namespace.
Helper to define synchronized, lazy constructed, module initialization (intended to work with DataExc...