SST  12.0.1
StructuralSimulationToolkit
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 
24 namespace SST {
25 namespace Core {
26 namespace Environment {
27 
28 /***
29 \class EnvironmentConfigGroup envconfig.h "sst/core/env/envconfig.h"
30 
31 Specifies a class which contains a group of key=value pairs. A group
32 is a logical unit of management for collecting configuration parameters.
33 For instance, these might relate to an specific dependency or element
34 etc.
35 
36 Grouping of key=value pairs allows entire lists of parameters to be
37 removed from the configuration system when needed.
38 
39 In general the core expects to default to either the "default" group
40 or the "SSTCore" group, with the configuration populating the "SSTCore"
41 group with parameters during the initial configure script process.
42 
43 The configuration and management systems treat the "default" and
44 "SSTCore" groups with special handling and no guarantee is provided
45 that these settings can be modified, removed or added to (since they
46 may be held in configuration files that are not accessible to the
47 user).
48 
49 Groups also allow printing (to standard output) or files directly
50 of all members.
51 
52 Although a logical interface may be the utilization of a map, groups
53 do not expose this currently to allow for modification in the
54 implementation in the future when more complex schemes are expected
55 to be used. Users of the group class should use the public accessor
56 methods provided to ensure forwards compatibility with future
57 SST releases.
58 
59 */
60 
62 {
63 
64 public:
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 
73 protected:
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 
81 The EnvironmentConfiguration class provides an entire configuration
82 set for SST, which will include zero or more EnvironmentConfigGroup
83 instances (essentially zero or more groups). In the usual course of
84 operations the environment will contains two "special" groups called
85 "default" (unpopulated but is provided for any ungrouped parameter
86 values) and "SSTCore" which houses parameters encoded during the
87 core's configuration process.
88 
89 EnvironmentConfiguration instances can be loaded from a single file
90 or via the standard precedence ordered SST loading mechanisms. In the
91 case of loading from a specific file, the core makes no guarantees
92 about the number of groups provided (zero or more). The user should
93 make no assumptions in this case.
94 
95 If the EnvironmentConfiguration is loaded via the SST precedence
96 ordered mechanisms, then the "default" and "SSTCore" groups will be
97 provided.
98 
99 Although it may seem logical to provide a map structure of group
100 names to group instances, the design is not implemented this way
101 to permit future modification in the underlying structures. Users
102 should use the public methods provided to ensure future compatibility
103 with SST releases.
104 
105 */
107 {
108 
109 public:
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 
121 private:
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