Jpp  17.1.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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

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 }
std::vector< int > count
Definition: JAlgorithm.hh:180
static const boost::char_separator< char > args_sep(";")
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 
68  boost::tokenizer<boost::char_separator<char> > tok(line, args_sep);
69 
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;
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;
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
static const boost::char_separator< char > fields_sep("=")
static const boost::char_separator< char > white_spaces("\t ")
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
std::string trim(const std::string &buffer)
Trim string.
Definition: JLangToolkit.hh:79
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
static const boost::char_separator< char > args_sep(";")
const char * map
Definition: elog.cc:87