SST 12.1.0
Structural Simulation Toolkit
envconfig.h
1// Copyright 2009-2022 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-2022, 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 {
25namespace Core {
26namespace Environment {
27
28/***
29\class EnvironmentConfigGroup envconfig.h "sst/core/env/envconfig.h"
30
31Specifies a class which contains a group of key=value pairs. A group
32is a logical unit of management for collecting configuration parameters.
33For instance, these might relate to an specific dependency or element
34etc.
35
36Grouping of key=value pairs allows entire lists of parameters to be
37removed from the configuration system when needed.
38
39In general the core expects to default to either the "default" group
40or the "SSTCore" group, with the configuration populating the "SSTCore"
41group with parameters during the initial configure script process.
42
43The configuration and management systems treat the "default" and
44"SSTCore" groups with special handling and no guarantee is provided
45that these settings can be modified, removed or added to (since they
46may be held in configuration files that are not accessible to the
47user).
48
49Groups also allow printing (to standard output) or files directly
50of all members.
51
52Although a logical interface may be the utilization of a map, groups
53do not expose this currently to allow for modification in the
54implementation in the future when more complex schemes are expected
55to be used. Users of the group class should use the public accessor
56methods provided to ensure forwards compatibility with future
57SST releases.
58
59*/
60
62{
63
64public:
65 EnvironmentConfigGroup(const std::string& name) : groupName(name) {}
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*/
107{
108
109public:
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 Environment
126} // namespace Core
127} // namespace SST
128
129#endif // SST_CORE_ENV_ENVCONFIG_H