Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
AppSettings/Sources/AppConfiguration.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2021. All rights reserved
3 */
4#ifndef _StroikaSample_AppSettings_AppConfiguration_h_
5#define _StroikaSample_AppSettings_AppConfiguration_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
10#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
12#include "Stroika/Foundation/Execution/ModuleGetterSetter.h"
15
16/**
17 * A simple example of app configuration management using the Stroika toolkit
18 */
19
21
22 using namespace std;
23 using namespace Stroika::Foundation;
24
25 /*
26 * This is the type of object stored in configuration.
27 */
28 struct AppConfigurationType {
29 optional<IO::Network::PortType> WebServerPort;
30 static constexpr IO::Network::PortType kWebServerPort_Default = 80;
31
32 /*
33 * See the documentation on ObjectVariantMapper for more info on how to define mappers. But this maps between C++ structs, and VariantValue objects which
34 * can be serialized/deserialized to/from JSON configuration files (for example).
35 */
36 static const DataExchange::ObjectVariantMapper kMapper;
37 };
38
39 namespace Private_ {
40 /*
41 * This is a bit of magic used to encode knowledge of how/where to persist the configuration data.
42 */
43 struct AppConfiguration_Storage_IMPL_ {
44 AppConfiguration_Storage_IMPL_ ();
45 AppConfigurationType Get () const;
46 void Set (const AppConfigurationType& v);
47 DataExchange::OptionsFile fOptionsFile_;
48 AppConfigurationType fActualCurrentConfigData_;
49 };
50 }
51
52 /*
53 * gAppConfiguration is automatically internally synchronized ... - just call update / set / get to access options freely.
54 */
56
57}
58
59/*
60 ********************************************************************************
61 ***************************** Implementation Details ***************************
62 ********************************************************************************
63 */
64#include "AppConfiguration.inl"
65
66#endif /*_StroikaSample_AppSettings_AppConfiguration_h_*/
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
STL namespace.
Helper to define synchronized, lazy constructed, module initialization (intended to work with DataExc...