23 #define SCPIParsing_UNUSED_VAR(x) (void)x; // Prevents from unereferenced variable when compiling in release
41 template <
class iterator_type>
42 bool IsArbitraryBlock(
const iterator_type first,
const iterator_type last,
size_t & rStartOffset,
size_t & rLength);
48 void ToArbitraryBlock(
const std::string & rStr, std::string & rArbitraryBlock,
bool InfiniteFormat =
false);
55 template <
class iterator_type>
78 void SplitString(
const std::string & rStr, std::vector<std::string> & rStrings,
char Sep);
86 template <
class iterator_type>
87 bool IsArbitraryBlock(
const iterator_type first,
const iterator_type last,
size_t & rStartOffset,
size_t & rLength)
96 if (*(first+1) ==
'0')
99 rLength = last - first - rStartOffset;
106 size_t l_PrefixLen = std::stoul(std::string(&*(first+1), 1));
107 rStartOffset = 2 + l_PrefixLen;
108 rLength = std::stoul(std::string(&*(first+2), l_PrefixLen));
111 size_t l_BufferLength = last - first - rStartOffset;
112 if (rLength > l_BufferLength)
124 catch (std::invalid_argument & rE)
132 catch (std::out_of_range & rE)
142 inline void ToArbitraryBlock(
const std::string & rStr, std::string & rArbitraryBlock,
bool InfiniteFormat)
146 rArbitraryBlock =
"#0" + rStr;
150 std::string l_mmm = std::to_string(rStr.length());
151 rArbitraryBlock =
"#" + std::to_string(l_mmm.length()) + l_mmm + rStr;
154 template <
class iterator_type>
157 rChannelList.clear();
159 if (std::regex_match(first, last, std::regex(
"^\\(@[0-9!,:]*\\)[^]*$")))
162 if (std::regex_match(first, last, std::regex(
"^\\(@\\)[^]*$")))
166 for (
size_t l_Index = 2, PortStart = 2; l_Index < (size_t)(last - first); l_Index++)
168 char c = *(first + l_Index);
169 if (c >=
'0' && c <=
'9')
174 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
175 PortStart = l_Index + 1;
180 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
182 rChannelList.push_back(l_Chan);
184 PortStart = l_Index + 1;
189 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
191 rChannelList.push_back(l_Chan);
193 l_Index = last - first;
206 for (tChannelList::const_iterator l_it = rChannelList.begin(); l_it != rChannelList.end(); l_it++)
209 for (tChannel::const_iterator portit = l_it->begin(); portit != l_it->end(); portit++)
211 rStr += std::to_string(*portit);
212 if (portit + 1 != l_it->end())
215 if (l_it + 1 != rChannelList.end())
223 rChannelList.clear();
225 for (
size_t l_Index = 0; l_Index < Len; l_Index++)
227 if (pBinaryChanList[l_Index] != 0)
228 l_Chan.push_back(pBinaryChanList[l_Index]);
231 rChannelList.push_back(l_Chan);
236 rChannelList.push_back(l_Chan);
240 rBinaryChanList.clear();
242 for (tChannelList::const_iterator l_it = rChannelList.begin(); l_it != rChannelList.end(); l_it++)
245 for (tChannel::const_iterator portit = l_it->begin(); portit != l_it->end(); portit++)
247 rBinaryChanList.push_back(*portit);
249 if (l_it + 1 != rChannelList.end())
250 rBinaryChanList.push_back(0);
253 inline void SplitString(
const std::string & rStr, std::vector<std::string> & rStrings,
char Sep)
263 size_t l_Next = rStr.find_first_of(Sep);
264 rStrings.push_back(rStr.substr(l_Start, l_Next - l_Start));
267 for (l_Start = l_Next + 1;
268 l_Next != std::string::npos;
269 l_Start = l_Next + 1)
271 l_Next = rStr.find_first_of(Sep, l_Start);
272 rStrings.push_back(rStr.substr(l_Start, l_Next - l_Start));
276 #undef SCPIParsing_UNUSED_VAR