SST 15.0
Structural Simulation Toolkit
envconfig.h
1// Copyright 2009-2025 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2025, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_ENV_ENVCONFIG_H
13#define SST_CORE_ENV_ENVCONFIG_H
14
15#include <climits>
16#include <cstdio>
17#include <cstdlib>
18#include <iostream>
19#include <map>
20#include <set>
21#include <string>
22#include <vector>
23
24namespace SST::Core::Environment {
25
26/***
27\class EnvironmentConfigGroup envconfig.h "sst/core/env/envconfig.h"
28
29Specifies a class which contains a group of key=value pairs. A group
30is a logical unit of management for collecting configuration parameters.
31For instance, these might relate to an specific dependency or element
32etc.
33
34Grouping of key=value pairs allows entire lists of parameters to be
35removed from the configuration system when needed.
36
37In general the core expects to default to either the "default" group
38or the "SSTCore" group, with the configuration populating the "SSTCore"
39group with parameters during the initial configure script process.
40
41The configuration and management systems treat the "default" and
42"SSTCore" groups with special handling and no guarantee is provided
43that these settings can be modified, removed or added to (since they
44may be held in configuration files that are not accessible to the
45user).
46
47Groups also allow printing (to standard output) or files directly
48of all members.
49
50Although a logical interface may be the utilization of a map, groups
51do not expose this currently to allow for modification in the
52implementation in the future when more complex schemes are expected
53to be used. Users of the group class should use the public accessor
54methods provided to ensure forwards compatibility with future
55SST releases.
56
57*/
58
59class EnvironmentConfigGroup
60{
61
62public:
63 explicit EnvironmentConfigGroup(const std::string& name) :
64 groupName(name)
65 {}
66 std::string getName() const;
67 std::set<std::string> getKeys() const;
68 std::string getValue(const std::string& key);
69 void setValue(const std::string& key, const std::string& value);
70 void print();
71 void writeTo(FILE* outFile);
72
73protected:
74 std::string groupName;
75 std::map<std::string, std::string> params;
76};
77
78/***
79\class EnvironmentConfiguration envconfig.h "sst/core/env/envconfig.h"
80
81The EnvironmentConfiguration class provides an entire configuration
82set for SST, which will include zero or more EnvironmentConfigGroup
83instances (essentially zero or more groups). In the usual course of
84operations the environment will contains two "special" groups called
85"default" (unpopulated but is provided for any ungrouped parameter
86values) and "SSTCore" which houses parameters encoded during the
87core's configuration process.
88
89EnvironmentConfiguration instances can be loaded from a single file
90or via the standard precedence ordered SST loading mechanisms. In the
91case of loading from a specific file, the core makes no guarantees
92about the number of groups provided (zero or more). The user should
93make no assumptions in this case.
94
95If the EnvironmentConfiguration is loaded via the SST precedence
96ordered mechanisms, then the "default" and "SSTCore" groups will be
97provided.
98
99Although it may seem logical to provide a map structure of group
100names to group instances, the design is not implemented this way
101to permit future modification in the underlying structures. Users
102should use the public methods provided to ensure future compatibility
103with SST releases.
104
105*/
106class EnvironmentConfiguration
107{
108
109public:
110 EnvironmentConfiguration();
111 ~EnvironmentConfiguration();
112
113 EnvironmentConfigGroup* createGroup(const std::string& groupName);
114 void removeGroup(const std::string& groupName);
115 std::set<std::string> getGroupNames();
116 EnvironmentConfigGroup* getGroupByName(const std::string& groupName);
117 void print();
118 void writeTo(const std::string& filePath);
119 void writeTo(FILE* outFile);
120
121private:
122 std::map<std::string, EnvironmentConfigGroup*> groups;
123};
124
125} // namespace SST::Core::Environment
126
127#endif // SST_CORE_ENV_ENVCONFIG_H