Stroika Library 3.0d21
 
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 // by default fOptionsFile_ requires Execution::Logger::Activator logMgrActivator in main(), or use different Logger CTOR argument
44 : fOptionsFile_{
45 /*
46 * Any module name will do. This will map (by default) to a AppSettings.json file in XXX.
47 * If you require a single configuration file 'Main" might be a better module name.
48 * But if you have multiple modules with configuration data, pick a name that matches that module,
49 * and they will all be stored under a folder for all your apps configuration.
50 */
51 "AppSettings"sv,
52
53 /*
54 */
55 AppConfigurationType::kMapper,
56
57 /*
58 * Hooks for versioning, to manage as your application evolves and the configuration data changes
59 */
60 OptionsFile::kDefaultUpgrader,
61
62 /*
63 */
64 OptionsFile::mkFilenameMapper ("Put-Your-App-Name-Here"sv)}
65 , fActualCurrentConfigData_{fOptionsFile_.Read<AppConfigurationType> (AppConfigurationType{})}
66{
67 Set (fActualCurrentConfigData_); // assure derived data (and changed fields etc) up to date
68}
69
70AppConfigurationType AppConfiguration_Storage_IMPL_::Get () const
71{
72 return fActualCurrentConfigData_;
73}
74
75void AppConfiguration_Storage_IMPL_::Set (const AppConfigurationType& v)
76{
77 fActualCurrentConfigData_ = v;
78 fOptionsFile_.Write (v);
79}
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.