forked from QMCPACK/qmcpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_stream_handler.cpp
39 lines (39 loc) · 1.11 KB
/
custom_stream_handler.cpp
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
class CustomTypeInput : public InputSection
{
public:
struct LabeledPosition
{
std::string letters;
std::array<int, 3> numbers;
};
CustomTestInput()
{
...
attributes = {"name", "custom_attribute"};
custom = {"labeled_position", "custom_attribute"};
}
void setFromStreamCustom(const std::string& ename, const std::string& name, std::istringstream& svalue) override
{
if (ename == "labeled_position")
{
LabeledPosition ws;
svalue >> ws.letters;
svalue >> ws.numbers[0];
svalue >> ws.numbers[1];
svalue >> ws.numbers[2];
values_[name] = ws;
}
else if (name == "custom_attribute")
{
std::string cus_at;
// otherwise you will get not consume the entire attribute just the next piece as determine by operator>> and
// the type you are going into.
std::getline(svalue, cus_at);
... // do your custom parsing.
values_[name] = cus_at;
}
else
throw std::runtime_error("bad name passed: " + name +
" or custom setFromStream not implemented in derived class.");
}
};