rohdeschwarz  0.2.0
TCPIP socket library for Rohde & Schwarz instrument control
index_name.cpp
Go to the documentation of this file.
1 
9 using namespace rohdeschwarz::scpi;
10 using namespace rohdeschwarz;
11 
12 
13 // std lib
14 #include <cstddef>
15 
16 
17 std::vector<IndexName> IndexName::parse(const char* csvList)
18 {
19  const std::string csv_list_str(csvList);
20  return IndexName::parse(csv_list_str);
21 }
22 
23 
24 std::vector<IndexName> IndexName::parse(const std::string& csvList)
25 {
26  // split csv list
27  std::vector<std::string> parts = split(csvList);
28 
29  // create vector of IndexNames
30  std::vector<IndexName> indexNames;
31  indexNames.reserve(parts.size() / 2);
32  for (int i = 0; i + 1 < parts.size(); i += 2)
33  {
34  // create IndexName
35  IndexName index_name;
36  index_name.index = std::stoi(parts[i]);
37  index_name.name = parts[i + 1];
38 
39  // insert
40  indexNames.push_back(index_name);
41  }
42  return indexNames;
43 }
44 
45 
46 std::vector<unsigned int> IndexName::indexesFrom(const std::vector<IndexName>& list)
47 {
48  // create vector; set capacity
49  std::vector<unsigned int> indexes;
50  indexes.reserve(list.size());
51 
52  // populate vector
53  for (int i = 0; i < list.size(); i++)
54  {
55  indexes.emplace_back(list[i].index);
56  }
57  return indexes;
58 }
59 
60 
61 std::vector<std::string> IndexName::namesFrom(const std::vector<IndexName>& list)
62 {
63  // create vector; set capacity
64  std::vector<std::string> names;
65  names.reserve(list.size());
66 
67  // populate vector
68  for (int i = 0; i < list.size(); i++)
69  {
70  names.emplace_back(list[i].name);
71  }
72  return names;
73 }
rohdeschwarz helper function definition
std::vector< std::string > split(const char *csvList, const char separator=',')
Splits string on separator.
Definition: helpers.cpp:136
Data type for handling named and indexed quantities.
Definition: index_name.hpp:30
static std::vector< unsigned int > indexesFrom(const std::vector< IndexName > &list)
Returns index list from IndexName list.
Definition: index_name.cpp:46
static std::vector< IndexName > parse(const char *csvList)
Parses index-name pairs from text.
Definition: index_name.cpp:17
static std::vector< std::string > namesFrom(const std::vector< IndexName > &list)
Returns names list from IndexName list.
Definition: index_name.cpp:61