xml_configuration_parsing.h
Go to the documentation of this file.
1 // Copyright (c) 2021 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #include <string>
17 #include <stdexcept>
18 
19 #include <tinyxml2.h>
20 
22 
23 #ifndef PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
24 #define PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
25 
27 {
28 namespace configuration
29 {
34 namespace xml_config_parsing
35 {
36 class XMLConfigurationParserException : public std::runtime_error
37 {
38 public:
39  XMLConfigurationParserException(const std::string& msg) : std::runtime_error(msg)
40  {
41  }
42 };
43 
57 unsigned long ro_value_to_uint(const std::string& ro_value)
58 {
59  auto string_cpy = ro_value;
60  std::swap(string_cpy[0], string_cpy[2]);
61  std::swap(string_cpy[1], string_cpy[3]);
62  return std::stoul(string_cpy, nullptr, 16);
63 }
64 
74 std::vector<unsigned long> ro_string_to_vec(const std::string& ro_string)
75 {
76  std::vector<unsigned long> vec;
77 
78  try
79  {
80  for (size_t i = 0; i < ro_string.length(); i += 4)
81  {
82  const auto substr = ro_string.substr(i, 4);
83  if (substr.length() == 4)
84  {
85  vec.push_back(ro_value_to_uint(substr));
86  }
87  }
88  }
89  catch (const std::exception& e)
90  {
91  throw XMLConfigurationParserException(e.what());
92  }
93 
94  return vec;
95 }
96 
97 ZoneSetConfiguration parseFile(const char* filename);
98 ZoneSetConfiguration parseString(const char* xml);
99 
100 } // namespace xml_config_parsing
101 } // namespace configuration
102 } // namespace psen_scan_v2_standalone
103 
104 #endif // PSEN_SCAN_V2_XML_CONFIGURATION_PARSER_H
psen_scan_v2_standalone::configuration::ZoneSetConfiguration
Definition: zoneset_configuration.h:26
psen_scan_v2_standalone::configuration::xml_config_parsing::XMLConfigurationParserException
Definition: xml_configuration_parsing.h:36
zoneset_configuration.h
psen_scan_v2_standalone::configuration::xml_config_parsing::ro_value_to_uint
unsigned long ro_value_to_uint(const std::string &ro_value)
Converts a quadrupel <ro> value into the respective length in mm.
Definition: xml_configuration_parsing.h:57
psen_scan_v2_standalone::configuration::xml_config_parsing::parseFile
ZoneSetConfiguration parseFile(const char *filename)
Definition: xml_configuration_parsing.cpp:487
psen_scan_v2_standalone::configuration::xml_config_parsing::parseString
ZoneSetConfiguration parseString(const char *xml)
Definition: xml_configuration_parsing.cpp:499
std
psen_scan_v2_standalone
Root namespace in which the software components to communicate with the scanner (firmware-version: 2)...
Definition: udp_client.h:41
psen_scan_v2_standalone::configuration::xml_config_parsing::XMLConfigurationParserException::XMLConfigurationParserException
XMLConfigurationParserException(const std::string &msg)
Definition: xml_configuration_parsing.h:39
psen_scan_v2_standalone::protocol_layer::scanner_events
Contains the events needed to define and implement the scanner protocol.
Definition: scanner_events.h:30
psen_scan_v2_standalone::configuration::xml_config_parsing::ro_string_to_vec
std::vector< unsigned long > ro_string_to_vec(const std::string &ro_string)
Convert string from a <ro> element to values.
Definition: xml_configuration_parsing.h:74


psen_scan_v2
Author(s): Pilz GmbH + Co. KG
autogenerated on Sat Jun 22 2024 02:46:12