-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMHO_ControlDefinitions.cc
More file actions
126 lines (109 loc) · 3.24 KB
/
Copy pathMHO_ControlDefinitions.cc
File metadata and controls
126 lines (109 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "MHO_ControlDefinitions.hh"
#include "MHO_DirectoryInterface.hh"
#include "MHO_Message.hh"
#include <fstream>
#include <iostream>
namespace hops
{
std::string MHO_ControlDefinitions::GetFormatDirectory()
{
//the control-format .json files live under <install_prefix>/data/control/
//(the prefix is resolved at runtime so no absolute path is baked into the binary)
std::string prefix = MHO_DirectoryInterface::GetHopsInstallPrefix();
if(prefix.empty())
{
msg_warn("control", "could not determine HOPS install prefix; using relative path for control format directory" << eom);
prefix = ".";
}
std::string format_dir = prefix + "/data/control/";
return format_dir;
}
std::vector< std::string > MHO_ControlDefinitions::GetKeywordNames()
{
std::vector< std::string > keywords;
std::string format_dir = GetFormatDirectory();
MHO_DirectoryInterface dirInterface;
dirInterface.SetCurrentDirectory(format_dir);
dirInterface.ReadCurrentDirectory();
dirInterface.GetFilesMatchingExtension(keywords, "json");
for(std::size_t i = 0; i < keywords.size(); i++)
{
std::string tmp = MHO_DirectoryInterface::GetBasename(keywords[i]);
keywords[i] = MHO_DirectoryInterface::StripExtensionFromBasename(tmp);
}
return keywords;
}
control_element_type MHO_ControlDefinitions::DetermineControlType(std::string etype)
{
if(etype == "int")
{
return control_int_type;
}
if(etype == "list_int")
{
return control_list_int_type;
}
if(etype == "real")
{
return control_real_type;
}
if(etype == "list_real")
{
return control_list_real_type;
}
if(etype == "string")
{
return control_string_type;
}
if(etype == "list_string")
{
return control_list_string_type;
}
if(etype == "fixed_length_list_string")
{
return control_fixed_length_list_string_type;
}
if(etype == "logical_intersection_list_string")
{
return control_list_string_type;
}
if(etype == "conditional")
{
return control_conditional_type;
}
if(etype == "bool")
{
return control_bool_type;
}
if(etype == "compound")
{
return control_compound_type;
}
return control_unknown_type;
}
mho_json MHO_ControlDefinitions::GetControlFormat()
{
//load all of the .json format files here so they are in memory
//TODO -- we may also want to combine all the format files into a single file
std::string format_dir = GetFormatDirectory();
std::vector< std::string > keywords = GetKeywordNames();
mho_json format_obj;
for(auto keyIt = keywords.begin(); keyIt != keywords.end(); keyIt++)
{
std::string key = *keyIt;
std::string element_format_file = key + ".json";
std::string format_file = format_dir + element_format_file;
//TODO should check that the file exists
std::ifstream bf_ifs;
bf_ifs.open(format_file.c_str(), std::ifstream::in);
mho_json bformat;
if(bf_ifs.is_open())
{
bformat = mho_json::parse(bf_ifs);
format_obj[key] = bformat;
}
bf_ifs.close();
}
return format_obj;
}
} // namespace hops