Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
dom_map.cpp File Reference
#include "dom_map.hpp"
#include <stdexcept>
#include <cstdlib>
#include <boost/tokenizer.hpp>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/trim.hpp>

Go to the source code of this file.

Functions

uint32_t getDomId (std::string const &s_domid)
 
dom_map_type load_dom_map (std::istream &map)
 

Function Documentation

◆ getDomId()

uint32_t getDomId ( std::string const & s_domid)
Author
cpellegrino

Definition at line 15 of file dom_map.cpp.

16{
17 if (s_domid.find(":") == std::string::npos) {
18 return boost::lexical_cast<uint32_t>(s_domid);
19 } else {
20 boost::char_separator<char> const args_sep(":");
21 boost::tokenizer<boost::char_separator<char> > tok(s_domid, args_sep);
22
23 std::stringstream ss;
24 int count = 0;
25
26 BOOST_FOREACH(std::string byte, tok) {
27 if (byte.size() != 2) {
28 throw std::runtime_error("Error: malformed MAC address");
29 }
30
31 if (count > 1) {
32 ss << byte;
33 } else {
34 if (count == 0 && byte == "08") {
35 } else if (count == 1 && byte == "00") {
36 } else {
37 throw std::runtime_error(
38 "Error: the provided MAC address is not a CLB MAC."
39 );
40 }
41 }
42 ++count;
43 }
44
45 return std::strtol(ss.str().c_str(), 0, 16);
46 }
47}

◆ load_dom_map()

dom_map_type load_dom_map ( std::istream & map)

Definition at line 49 of file dom_map.cpp.

50{
51 boost::char_separator<char> const args_sep(";");
52 boost::char_separator<char> const fields_sep("=");
53 boost::char_separator<char> const white_spaces("\t ");
54
55 dom_map_type dom_map;
56
57 while (map.peek() != EOF) {
58 std::string line;
59 getline(map, line);
60
61 std::string::size_type const pound = line.find('#');
62
63 if (pound != std::string::npos) {
64 line = line.substr(0, pound);
65 }
66
67 boost::algorithm::trim(line);
68 boost::tokenizer<boost::char_separator<char> > tok(line, args_sep);
69
70 BOOST_FOREACH(std::string s, tok) {
71 boost::algorithm::trim(s);
72 boost::tokenizer<boost::char_separator<char> > fields(s, fields_sep);
73 typedef boost::tokenizer<boost::char_separator<char> >::iterator Iter;
74
75 Iter it = fields.begin();
76
77 std::string s_domid = *it;
78 boost::algorithm::trim(s_domid);
79 uint32_t const domid = getDomId(s_domid);
80
81 ++it;
82 if (it != fields.end()) {
83 std::string name = *it;
84 boost::algorithm::trim(name);
85
86 dom_map.insert(std::make_pair(domid, name));
87 } else {
88 throw std::runtime_error("Error: malformed assignment");
89 }
90 }
91 }
92
93 return dom_map;
94}
uint32_t getDomId(std::string const &s_domid)
Definition dom_map.cpp:15
const char * map
Definition elog.cc:87
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478