-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExecArgs.cpp
More file actions
156 lines (143 loc) · 7.2 KB
/
ExecArgs.cpp
File metadata and controls
156 lines (143 loc) · 7.2 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* @brief This file contains the implementation of the execution arguments, which should can be passed to the
* Exec function and can be converted to a string which is sent to the device.
* @authors Florian Frank
*/
#include "ExecArgs.h"
#include <utility>
/**
* @brief Add a new argument to the execution argument.
* e.g. argument = voltage, value = 3 and seperator = : can be transformed into a string: voltage = 3
* @param argument the argument to which the value gets assigned.
* @param value an integer value which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(std::string argument, int value, std::string seperator) {
auto value_tuple = std::make_tuple(argument, std::to_string(value));
auto arg_tuple = std::make_tuple(ARG_TYPE_INTEGER, seperator, value_tuple);
m_ArgList.push_back(arg_tuple);
return *this;
}
/**
* @brief Add a new argument to the execution argument.
* e.g. argument = voltage, value = 3 and seperator = : can be transformed into a string: voltage = 3
* @param argument the argument to which the value gets assigned.
* @param value a string which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(std::string argument, double value, std::string seperator) {
auto value_tuple = std::make_tuple(argument, std::to_string(value));
auto arg_tuple = std::make_tuple(ARG_TYPE_FLOAT, seperator, value_tuple);
m_ArgList.push_back(arg_tuple);
return *this;
}
/**
* @brief Add a new argument to the execution argument.
* e.g. argument = voltage, value = 3 and seperator = : can be transformed into a string: voltage = 3
* @param argument the argument to which the value gets assigned.
* @param value a double value which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(const std::string &argument, const std::string &value, const std::string &seperator) {
auto value_tuple = std::make_tuple(argument, value);
auto arg_tuple = std::make_tuple(ARG_TYPE_STRING, seperator, value_tuple);
m_ArgList.push_back(arg_tuple);
return *this;
}
/**
* @brief Add a subarg as argument to the ExecArgList.
* This is necessary when the argument itself consists of multiple parts. E.g. smua.measurement.voltage = 3.
* Here smua.measurement.voltage is encapsulated in a SubArg.
* @param argument sub-argument which internally transformed into a string.
* @param value an integer value which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(SubArg argument, int value, std::string seperator) {
return AddArgument(argument.toString(), value, std::move(seperator));
}
/**
* @brief Add a subarg as argument to the ExecArgList.
* This is necessary when the argument itself consists of multiple parts. E.g. smua.measurement.voltage = 3.
* Here smua.measurement.voltage is encapsulated in a SubArg.
* @param argument sub-argument which internally transformed into a string.
* @param value a double value which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(SubArg argument, double value, std::string seperator) {
return AddArgument(argument.toString(), value, std::move(seperator));
}
/**
* @brief Add a subarg as argument to the ExecArgList.
* This is necessary when the argument itself consists of multiple parts. E.g. smua.measurement.voltage = 3.
* Here smua.measurement.voltage is encapsulated in a SubArg.
* @param argument sub-argument which internally transformed into a string.
* @param value a string which is internally transformed to a string.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(SubArg argument, const std::string &value, const std::string &seperator) {
return AddArgument(argument.toString(), value, seperator);
}
/**
* @brief Add a subarg as argument to the ExecArgList.
* This is necessary when the argument itself consists of multiple parts. E.g. smua.measurement.voltage = 3.
* Here smua.measurement.voltage is encapsulated in a SubArg.
* @param argument sub-argument which internally transformed into a string.
* @param value add a sub-argument e.g. when the value consists of multiple sub-arguments smua.OUTPUT_ON.
* @param seperator the seperator which separates the value and argument.
* @return this object to allow further assignments in one line.
*/
ExecArgs &ExecArgs::AddArgument(SubArg argument, SubArg &value, const std::string &seperator) {
return AddArgument(argument.toString(), value.toString(), seperator);
}
/**
* @brief Transforms the list of arguments to a string which can be passed to the Exec function.
* @return execution argument as string.
*/
std::string ExecArgs::GetArgumentsAsString() {
std::string retStr;
for (auto arg: m_ArgList) {
retStr += GetArgumentFromArgTuple(arg) +
GetSeperatorFromArgTuple(arg) + GetValueFromArgTuple(arg) + "";
}
return retStr;
}
/**
* @brief Returns the argument type of an argument tuple. Can be integer, double or string.
* @param argTuple Tuple of arguments consisting of ARGUMENT_TYPE, seperator and value_tuple (key, value).
* @return ARGUMENT_TYPE (integer, double or string)
*/
/*static*/ ExecArgs::ARGUMENT_TYPE ExecArgs::GetArgumentTypeFromArgTuple(ExecArgs::ArgTuple &argTuple) {
return std::get<0>(argTuple);
}
/**
* @brief Returns the seperator from the argument tuple. E.g. ' = '
* @param argTuple Tuple of arguments consisting of ARGUMENT_TYPE, seperator and value_tuple (key, value).
* @return seperator as string.
*/
/*static*/ std::string ExecArgs::GetSeperatorFromArgTuple(ExecArgs::ArgTuple &argTuple) {
return std::get<1>(argTuple);
}
/**
* @brief Returns the argument from the argument tuple.
* @param argTuple Tuple of arguments consisting of ARGUMENT_TYPE, seperator and value_tuple (key, value).
* @return argument as string. For a tuple like INTEGER, '=', <voltage, 3>, voltage is returned.
*/
/*static*/ std::string ExecArgs::GetArgumentFromArgTuple(ExecArgs::ArgTuple &argTuple) {
std::tuple<std::string, std::string> keyValuePair = std::get<2>(argTuple);
return std::get<0>(keyValuePair);
}
/**
* @brief Returns the value from the argument tuple.
* @param argTuple Tuple of arguments consisting of ARGUMENT_TYPE, seperator and value_tuple (key, value).
* @return argument as string. For a tuple like INTEGER, '=', <voltage, 3>, 3 is returned.
*/
/*static*/ std::string ExecArgs::GetValueFromArgTuple(ExecArgs::ArgTuple &argTuple) {
auto keyValuePair = std::get<2>(argTuple);
return std::get<1>(keyValuePair);
}