Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
AppSettings/Sources/AppConfiguration.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2021. All rights reserved
3 */
4#include "Stroika/Frameworks/StroikaPreComp.h"
5
7
8#include "AppConfiguration.h"
9
10using namespace std;
11
12using namespace Stroika::Foundation;
16using namespace Stroika::Foundation::Execution;
17
18using namespace StroikaSample;
19using namespace StroikaSample::AppSettings;
20
21using StroikaSample::AppSettings::Private_::AppConfiguration_Storage_IMPL_;
22
23/*
24 ********************************************************************************
25 *************************** AppConfigurationType *******************************
26 ********************************************************************************
27 */
28const ObjectVariantMapper AppConfigurationType::kMapper = [] () {
30 mapper.AddCommonType<optional<IO::Network::PortType>> ();
31 mapper.AddClass<AppConfigurationType> ({
32 {"WebServerPort"sv, &AppConfigurationType::WebServerPort},
33 });
34 return mapper;
35}();
36
37/*
38 ********************************************************************************
39 ******************** Private_::AppConfiguration_Storage_IMPL_ ******************
40 ********************************************************************************
41 */
42AppConfiguration_Storage_IMPL_::AppConfiguration_Storage_IMPL_ ()
43 : fOptionsFile_{
44 /*
45 * Any module name will do. This will map (by default) to a AppSettings.json file in XXX.
46 * If you require a single configuration file 'Main" might be a better module name.
47 * But if you have multiple modules with configuration data, pick a name that matches that module,
48 * and they will all be stored under a folder for all your apps configuration.
49 */
50 "AppSettings"sv,
51
52 /*
53 */
54 AppConfigurationType::kMapper,
55
56 /*
57 * Hooks for versioning, to manage as your application evolves and the configuration data changes
58 */
59 OptionsFile::kDefaultUpgrader,
60
61 /*
62 */
63OptionsFile::mkFilenameMapper (L"Put-Your-App-Name-Here"sv)}
64 , fActualCurrentConfigData_{fOptionsFile_.Read<AppConfigurationType> (AppConfigurationType{})}
65{
66 Set (fActualCurrentConfigData_); // assure derived data (and changed fields etc) up to date
67}
68
69AppConfigurationType AppConfiguration_Storage_IMPL_::Get () const
70{
71 return fActualCurrentConfigData_;
72}
73
74void AppConfiguration_Storage_IMPL_::Set (const AppConfigurationType& v)
75{
76 fActualCurrentConfigData_ = v;
77 fOptionsFile_.Write (v);
78}
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...
nonvirtual void AddClass(const Traversal::Iterable< StructFieldInfo > &fieldDescriptions, const ClassMapperOptions< CLASS > &mapperOptions={})
nonvirtual void AddCommonType(ARGS &&... args)
STL namespace.