INET Framework for OMNeT++/OMNEST
inet::xmlutils Namespace Reference

Functions

const cXMLElement * getUniqueChild (const cXMLElement *node, const char *name)
 
const cXMLElement * getUniqueChildIfExists (const cXMLElement *node, const char *name)
 
bool parseBool (const char *text)
 
void checkTags (const cXMLElement *node, const char *allowed)
 
const char * getParameterStrValue (const cXMLElement *ptr, const char *name, const char *def)
 
bool getParameterBoolValue (const cXMLElement *ptr, const char *name, bool def)
 
bool getParameterBoolValue (const cXMLElement *ptr, const char *name)
 
const char * getParameterStrValue (const cXMLElement *ptr, const char *name)
 
int getParameterIntValue (const cXMLElement *ptr, const char *name, int def)
 
int getParameterIntValue (const cXMLElement *ptr, const char *name)
 
IPv4Address getParameterIPAddressValue (const cXMLElement *ptr, const char *name, IPv4Address def)
 
IPv4Address getParameterIPAddressValue (const cXMLElement *ptr, const char *name)
 
double getParameterDoubleValue (const cXMLElement *ptr, const char *name, double def)
 
double getParameterDoubleValue (const cXMLElement *ptr, const char *name)
 
const char * getRequiredAttribute (const cXMLElement &node, const char *attr)
 
bool getAttributeBoolValue (const cXMLElement *node, const char *attrName, bool defVal)
 
bool getAttributeBoolValue (const cXMLElement *node, const char *attrName)
 

Function Documentation

INET_API void inet::xmlutils::checkTags ( const cXMLElement *  node,
const char *  allowed 
)

Referenced by inet::RSVP::delSession(), inet::SimpleClassifier::readItemFromXML(), inet::LIBTable::readTableFromXML(), inet::SimpleClassifier::readTableFromXML(), inet::RSVP::readTrafficFromXML(), inet::RSVP::readTrafficRouteFromXML(), and inet::RSVP::readTrafficSessionFromXML().

55 {
56  std::vector<const char *> tags;
57 
58  cStringTokenizer st(allowed, " ");
59  const char *nt;
60  while ((nt = st.nextToken()) != nullptr)
61  tags.push_back(nt);
62 
63  for (cXMLElement *child = node->getFirstChild(); child; child = child->getNextSibling()) {
64  unsigned int i;
65  for (i = 0; i < tags.size(); i++)
66  if (!strcmp(child->getTagName(), tags[i]))
67  break;
68 
69  if (i == tags.size())
70  throw cRuntimeError("Subtag <%s> not expected in <%s>",
71  child->getTagName(), node->getTagName());
72  }
73 }
INET_API bool inet::xmlutils::getAttributeBoolValue ( const cXMLElement *  node,
const char *  attrName,
bool  defVal 
)

Referenced by inet::IPv4NetworkConfigurator::readInterfaceConfiguration().

160 {
161  const char *attrStr = node->getAttribute(attrName);
162  if (attrStr && *attrStr)
163  return parseBool(attrStr);
164  return defVal;
165 }
bool parseBool(const char *text)
Definition: XMLUtils.cc:28
INET_API bool inet::xmlutils::getAttributeBoolValue ( const cXMLElement *  node,
const char *  attrName 
)
168 {
169  const char *attrStr = getRequiredAttribute(*node, attrName);
170  return parseBool(attrStr);
171 }
const char * getRequiredAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:150
bool parseBool(const char *text)
Definition: XMLUtils.cc:28
INET_API bool inet::xmlutils::getParameterBoolValue ( const cXMLElement *  ptr,
const char *  name,
bool  def 
)

Referenced by inet::RSVP::readTrafficSessionFromXML().

85 {
86  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
87  if (xvalue)
88  return parseBool(xvalue->getNodeValue());
89  else
90  return def;
91 }
bool parseBool(const char *text)
Definition: XMLUtils.cc:28
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API bool inet::xmlutils::getParameterBoolValue ( const cXMLElement *  ptr,
const char *  name 
)
94 {
95  const cXMLElement *xvalue = getUniqueChild(ptr, name);
96  return parseBool(xvalue->getNodeValue());
97 }
bool parseBool(const char *text)
Definition: XMLUtils.cc:28
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
INET_API double inet::xmlutils::getParameterDoubleValue ( const cXMLElement *  ptr,
const char *  name,
double  def 
)

Referenced by inet::RSVP::readTrafficSessionFromXML().

136 {
137  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
138  if (xvalue)
139  return strtod(xvalue->getNodeValue(), nullptr);
140  else
141  return def;
142 }
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API double inet::xmlutils::getParameterDoubleValue ( const cXMLElement *  ptr,
const char *  name 
)
145 {
146  const cXMLElement *xvalue = getUniqueChild(ptr, name);
147  return strtod(xvalue->getNodeValue(), nullptr);
148 }
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
INET_API int inet::xmlutils::getParameterIntValue ( const cXMLElement *  ptr,
const char *  name,
int  def 
)

Referenced by inet::RSVP::delSession(), inet::SimpleClassifier::readItemFromXML(), inet::LIBTable::readTableFromXML(), and inet::RSVP::readTrafficSessionFromXML().

106 {
107  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
108  if (xvalue)
109  return atoi(xvalue->getNodeValue());
110  else
111  return def;
112 }
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API int inet::xmlutils::getParameterIntValue ( const cXMLElement *  ptr,
const char *  name 
)
115 {
116  const cXMLElement *xvalue = getUniqueChild(ptr, name);
117  return atoi(xvalue->getNodeValue());
118 }
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
INET_API IPv4Address inet::xmlutils::getParameterIPAddressValue ( const cXMLElement *  ptr,
const char *  name,
IPv4Address  def 
)

Referenced by inet::RSVP::delSession(), inet::SimpleClassifier::readItemFromXML(), and inet::RSVP::readTrafficSessionFromXML().

121 {
122  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
123  if (xvalue)
124  return L3AddressResolver().resolve(xvalue->getNodeValue()).toIPv4();
125  else
126  return def;
127 }
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API IPv4Address inet::xmlutils::getParameterIPAddressValue ( const cXMLElement *  ptr,
const char *  name 
)
130 {
131  const cXMLElement *xvalue = getUniqueChild(ptr, name);
132  return L3AddressResolver().resolve(xvalue->getNodeValue()).toIPv4();
133 }
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
INET_API const char * inet::xmlutils::getParameterStrValue ( const cXMLElement *  ptr,
const char *  name,
const char *  def 
)

Referenced by inet::LIBTable::readTableFromXML(), and inet::RSVP::readTrafficSessionFromXML().

76 {
77  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
78  if (xvalue)
79  return xvalue->getNodeValue();
80  else
81  return def;
82 }
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API const char * inet::xmlutils::getParameterStrValue ( const cXMLElement *  ptr,
const char *  name 
)
100 {
101  const cXMLElement *xvalue = getUniqueChild(ptr, name);
102  return xvalue->getNodeValue();
103 }
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:8
INET_API const char * inet::xmlutils::getRequiredAttribute ( const cXMLElement &  node,
const char *  attr 
)

Referenced by getAttributeBoolValue(), inet::ospf::OSPFConfigReader::getInterfaceByXMLAttributesOf(), inet::ospf::OSPFConfigReader::loadAreaFromXML(), inet::ospf::OSPFConfigReader::loadConfigFromXML(), inet::ospf::OSPFConfigReader::loadExternalRoute(), inet::ospf::OSPFConfigReader::loadHostRoute(), inet::ospf::OSPFConfigReader::loadInterfaceParameters(), and inet::ospf::OSPFConfigReader::loadVirtualLink().

151 {
152  const char *s = node.getAttribute(attr);
153  if (!(s && *s))
154  throw cRuntimeError("required attribute %s of <%s> missing at %s",
155  attr, node.getTagName(), node.getSourceLocation());
156  return s;
157 }
value< double, units::s > s
Definition: Units.h:1049
INET_API const cXMLElement * inet::xmlutils::getUniqueChild ( const cXMLElement *  node,
const char *  name 
)

Referenced by getParameterBoolValue(), getParameterDoubleValue(), getParameterIntValue(), getParameterIPAddressValue(), getParameterStrValue(), inet::MatrixCloudDelayer::initialize(), inet::LIBTable::readTableFromXML(), and inet::RSVP::readTrafficSessionFromXML().

9 {
10  const cXMLElement *child = getUniqueChildIfExists(node, name);
11  if (!child)
12  throw cRuntimeError("XML error: exactly one %s element expected", name);
13 
14  return child;
15 }
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:17
INET_API const cXMLElement * inet::xmlutils::getUniqueChildIfExists ( const cXMLElement *  node,
const char *  name 
)

Referenced by inet::RSVP::delSession(), getParameterBoolValue(), getParameterDoubleValue(), getParameterIntValue(), getParameterIPAddressValue(), getParameterStrValue(), getUniqueChild(), inet::SimpleClassifier::readItemFromXML(), and inet::RSVP::readTrafficSessionFromXML().

18 {
19  cXMLElementList list = node->getChildrenByTagName(name);
20  if (list.size() > 1)
21  throw cRuntimeError("XML error: at most one %s element expected", name);
22  else if (list.size() == 1)
23  return *list.begin();
24  else
25  return nullptr;
26 }
INET_API bool inet::xmlutils::parseBool ( const char *  text)

Referenced by getAttributeBoolValue(), and getParameterBoolValue().

29 {
30  if (!strcasecmp(text, "down"))
31  return false;
32  else if (!strcasecmp(text, "off"))
33  return false;
34  else if (!strcasecmp(text, "false"))
35  return false;
36  else if (!strcasecmp(text, "no"))
37  return false;
38  else if (!strcasecmp(text, "0"))
39  return false;
40  else if (!strcasecmp(text, "up"))
41  return true;
42  else if (!strcasecmp(text, "on"))
43  return true;
44  else if (!strcasecmp(text, "true"))
45  return true;
46  else if (!strcasecmp(text, "yes"))
47  return true;
48  else if (!strcasecmp(text, "1"))
49  return true;
50  else
51  throw cRuntimeError("Unknown bool constant: %s", text);
52 }