#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.
◆ getDomId()
uint32_t getDomId |
( |
std::string const & |
s_domid | ) |
|
- Author
- cpellegrino
Definition at line 15 of file dom_map.cpp.
17 if (s_domid.find(
":") == std::string::npos) {
18 return boost::lexical_cast<uint32_t>(s_domid);
20 boost::char_separator<char>
const args_sep(
":");
21 boost::tokenizer<boost::char_separator<char> > tok(s_domid,
args_sep);
26 BOOST_FOREACH(std::string
byte, tok) {
27 if (
byte.size() != 2) {
28 throw std::runtime_error(
"Error: malformed MAC address");
34 if (count == 0 &&
byte ==
"08") {
35 }
else if (count == 1 &&
byte ==
"00") {
37 throw std::runtime_error(
38 "Error: the provided MAC address is not a CLB MAC."
45 return std::strtol(ss.str().c_str(), 0, 16);
static const boost::char_separator< char > args_sep(";")
◆ load_dom_map()
dom_map_type load_dom_map |
( |
std::istream & |
map | ) |
|
Definition at line 49 of file dom_map.cpp.
51 boost::char_separator<char>
const args_sep(
";");
52 boost::char_separator<char>
const fields_sep(
"=");
57 while (
map.peek() != EOF) {
61 std::string::size_type
const pound = line.find(
'#');
63 if (pound != std::string::npos) {
64 line = line.substr(0, pound);
68 boost::tokenizer<boost::char_separator<char> > tok(line,
args_sep);
70 BOOST_FOREACH(std::string s, tok) {
72 boost::tokenizer<boost::char_separator<char> > fields(s,
fields_sep);
73 typedef boost::tokenizer<boost::char_separator<char> >::iterator Iter;
75 Iter it = fields.begin();
77 std::string s_domid = *it;
79 uint32_t
const domid =
getDomId(s_domid);
82 if (it != fields.end()) {
83 std::string name = *it;
86 dom_map.insert(std::make_pair(domid, name));
88 throw std::runtime_error(
"Error: malformed assignment");
uint32_t getDomId(std::string const &s_domid)
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
std::string trim(const std::string &buffer)
Trim string.
static const boost::char_separator< char > fields_sep("=")
static const boost::char_separator< char > white_spaces("\t ")