SST  10.0.0
StructuralSimulationToolkit
envconfig.h
1 // Copyright 2009-2020 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-2020, 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 _H_SST_CORE_ENV_CONFIG_H
13 #define _H_SST_CORE_ENV_CONFIG_H
14 
15 #include <string>
16 #include <map>
17 #include <set>
18 #include <vector>
19 #include <iostream>
20 #include <cstdio>
21 #include <cstdlib>
22 #include <climits>
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 public:
64  EnvironmentConfigGroup(const std::string& name) : groupName(name) {}
65  std::string getName() const;
66  std::set<std::string> getKeys() const;
67  std::string getValue(const std::string& key);
68  void setValue(const std::string& key, const std::string& value);
69  void print();
70  void writeTo(FILE* outFile);
71 
72 protected:
73  std::string groupName;
74  std::map<std::string, std::string> params;
75 
76 };
77 
78 
79 /***
80 \class EnvironmentConfiguration envconfig.h "sst/core/env/envconfig.h"
81 
82 The EnvironmentConfiguration class provides an entire configuration
83 set for SST, which will include zero or more EnvironmentConfigGroup
84 instances (essentially zero or more groups). In the usual course of
85 operations the environment will contains two "special" groups called
86 "default" (unpopulated but is provided for any ungrouped parameter
87 values) and "SSTCore" which houses parameters encoded during the
88 core's configuration process.
89 
90 EnvironmentConfiguration instances can be loaded from a single file
91 or via the standard precedence ordered SST loading mechanisms. In the
92 case of loading from a specific file, the core makes no guarantees
93 about the number of groups provided (zero or more). The user should
94 make no assumptions in this case.
95 
96 If the EnvironmentConfiguration is loaded via the SST precedence
97 ordered mechanisms, then the "default" and "SSTCore" groups will be
98 provided.
99 
100 Although it may seem logical to provide a map structure of group
101 names to group instances, the design is not implemented this way
102 to permit future modification in the underlying structures. Users
103 should use the public methods provided to ensure future compatibility
104 with SST releases.
105 
106 */
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 
126 }
127 }
128 }
129 
130 #endif