20#define SCPIParsing_UNUSED_VAR(x) (void)x;
38 template <
class iterator_type>
39 bool IsArbitraryBlock(
const iterator_type first,
const iterator_type last,
size_t & rStartOffset,
size_t & rLength);
45 void ToArbitraryBlock(
const std::string & rStr, std::string & rArbitraryBlock,
bool InfiniteFormat =
false);
52 template <
class iterator_type>
75 void SplitString(
const std::string & rStr, std::vector<std::string> & rStrings,
char Sep);
83 template <
class iterator_type>
84 bool IsArbitraryBlock(
const iterator_type first,
const iterator_type last,
size_t & rStartOffset,
size_t & rLength)
86 bool l_IsArbitraryBlock =
false;
95 l_IsArbitraryBlock =
true;
98 if (*(first + 1) ==
'0')
101 rLength = last - first - rStartOffset;
108 size_t l_PrefixLen = std::stoul(std::string(&*(first + 1), 1));
109 rStartOffset = 2 + l_PrefixLen;
110 rLength = std::stoul(std::string(&*(first + 2), l_PrefixLen));
113 size_t l_BufferLength = last - first - rStartOffset;
114 if (rLength > l_BufferLength)
127 l_IsArbitraryBlock =
false;
130 return l_IsArbitraryBlock;
132 inline void ToArbitraryBlock(
const std::string & rStr, std::string & rArbitraryBlock,
bool InfiniteFormat)
137 rArbitraryBlock =
"#0" + rStr;
142 std::string l_mmm = std::to_string(rStr.length());
143 rArbitraryBlock =
"#" + std::to_string(l_mmm.length()) + l_mmm + rStr;
146 template <
class iterator_type>
149 rChannelList.clear();
151 if (std::regex_match(first, last, std::regex(
"^\\(@[0-9!,:]*\\)[^]*$")))
154 if (std::regex_match(first, last, std::regex(
"^\\(@\\)[^]*$")))
158 for (
size_t l_Index = 2, PortStart = 2; l_Index < (size_t)(last - first); l_Index++)
160 char c = *(first + l_Index);
161 if (c >=
'0' && c <=
'9')
166 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
167 PortStart = l_Index + 1;
172 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
174 rChannelList.push_back(l_Chan);
176 PortStart = l_Index + 1;
181 l_Chan.push_back(atoi(std::string(first + PortStart, first + l_Index).c_str()));
183 rChannelList.push_back(l_Chan);
185 l_Index = last - first;
198 for (tChannelList::const_iterator l_it = rChannelList.begin(); l_it != rChannelList.end(); l_it++)
201 for (tChannel::const_iterator portit = l_it->begin(); portit != l_it->end(); portit++)
203 rStr += std::to_string(*portit);
204 if (portit + 1 != l_it->end())
207 if (l_it + 1 != rChannelList.end())
215 rChannelList.clear();
217 for (
size_t l_Index = 0; l_Index < Len; l_Index++)
219 if (pBinaryChanList[l_Index] != 0)
220 l_Chan.push_back(pBinaryChanList[l_Index]);
223 rChannelList.push_back(l_Chan);
228 rChannelList.push_back(l_Chan);
232 rBinaryChanList.clear();
234 for (tChannelList::const_iterator l_it = rChannelList.begin(); l_it != rChannelList.end(); l_it++)
237 for (tChannel::const_iterator portit = l_it->begin(); portit != l_it->end(); portit++)
239 rBinaryChanList.push_back(*portit);
241 if (l_it + 1 != rChannelList.end())
242 rBinaryChanList.push_back(0);
245 inline void SplitString(
const std::string & rStr, std::vector<std::string> & rStrings,
char Sep)
255 size_t l_Next = rStr.find_first_of(Sep);
256 rStrings.push_back(rStr.substr(l_Start, l_Next - l_Start));
259 for (l_Start = l_Next + 1;
260 l_Next != std::string::npos;
261 l_Start = l_Next + 1)
263 l_Next = rStr.find_first_of(Sep, l_Start);
264 rStrings.push_back(rStr.substr(l_Start, l_Next - l_Start));
268#undef SCPIParsing_UNUSED_VAR
void FromBinaryChannelList(const char *pBinaryChanList, size_t Len, tChannelList &rChannelList)
Decode binary channel list.
void ToStringChannelList(const tChannelList &rChannelList, std::string &rStr)
Encode channel list string.
std::vector< tChannel > tChannelList
SCPI channel list
void FromStringChannelList(iterator_type first, iterator_type last, tChannelList &rChannelList)
Decode channel list string.
std::vector< unsigned char > tChannel
SCPI channel
void ToArbitraryBlock(const std::string &rStr, std::string &rArbitraryBlock, bool InfiniteFormat=false)
Package data as an arbitrary block.
bool IsArbitraryBlock(const iterator_type first, const iterator_type last, size_t &rStartOffset, size_t &rLength)
Find arbitrary-block data within a buffer.
void SplitString(const std::string &rStr, std::vector< std::string > &rStrings, char Sep)
Split a string into substrings separated by a given character.
void ToBinaryChannelList(const tChannelList &rChannelList, std::vector< char > &rBinaryChanList)
Encode binary channel list.