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 * getMandatoryAttribute (const cXMLElement &node, const char *attr)
 
const char * getMandatoryFilledAttribute (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

◆ checkTags()

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

Referenced by inet::RsvpTe::delSession(), inet::RsvpClassifier::readItemFromXML(), inet::LibTable::readTableFromXML(), inet::RsvpClassifier::readTableFromXML(), inet::RsvpTe::readTrafficFromXML(), inet::RsvpTe::readTrafficRouteFromXML(), and inet::RsvpTe::readTrafficSessionFromXML().

◆ getAttributeBoolValue() [1/2]

INET_API bool inet::xmlutils::getAttributeBoolValue ( const cXMLElement *  node,
const char *  attrName 
)
178 {
179  const char *attrStr = getMandatoryFilledAttribute(*node, attrName);
180  return parseBool(attrStr);
181 }

◆ getAttributeBoolValue() [2/2]

INET_API bool inet::xmlutils::getAttributeBoolValue ( const cXMLElement *  node,
const char *  attrName,
bool  defVal 
)
170 {
171  const char *attrStr = node->getAttribute(attrName);
172  if (attrStr && *attrStr)
173  return parseBool(attrStr);
174  return defVal;
175 }

Referenced by inet::MatrixCloudDelayer::initialize(), inet::MatrixCloudDelayer::MatrixEntry::MatrixEntry(), inet::SettableClock::processCommand(), inet::ScenarioManager::processCreateModuleCommand(), and inet::Ipv4NetworkConfigurator::readInterfaceConfiguration().

◆ getMandatoryAttribute()

const INET_API char * inet::xmlutils::getMandatoryAttribute ( const cXMLElement &  node,
const char *  attr 
)
152 {
153  const char *s = node.getAttribute(attr);
154  if (s == nullptr)
155  throw cRuntimeError("required attribute %s of <%s> missing at %s",
156  attr, node.getTagName(), node.getSourceLocation());
157  return s;
158 }

Referenced by inet::MultiFieldClassifier::configureFilters(), inet::ScenarioManager::createConnection(), getMandatoryFilledAttribute(), inet::ScenarioManager::processSetChannelParamCommand(), inet::ScenarioManager::processSetParamCommand(), and inet::Ipv4NetworkConfigurator::readManualRouteConfiguration().

◆ getMandatoryFilledAttribute()

◆ getParameterBoolValue() [1/2]

INET_API bool inet::xmlutils::getParameterBoolValue ( const cXMLElement *  ptr,
const char *  name 
)
95 {
96  const cXMLElement *xvalue = getUniqueChild(ptr, name);
97  return parseBool(xvalue->getNodeValue());
98 }

◆ getParameterBoolValue() [2/2]

INET_API bool inet::xmlutils::getParameterBoolValue ( const cXMLElement *  ptr,
const char *  name,
bool  def 
)
86 {
87  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
88  if (xvalue)
89  return parseBool(xvalue->getNodeValue());
90  else
91  return def;
92 }

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

◆ getParameterDoubleValue() [1/2]

INET_API double inet::xmlutils::getParameterDoubleValue ( const cXMLElement *  ptr,
const char *  name 
)
146 {
147  const cXMLElement *xvalue = getUniqueChild(ptr, name);
148  return strtod(xvalue->getNodeValue(), nullptr);
149 }

◆ getParameterDoubleValue() [2/2]

INET_API double inet::xmlutils::getParameterDoubleValue ( const cXMLElement *  ptr,
const char *  name,
double  def 
)
137 {
138  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
139  if (xvalue)
140  return strtod(xvalue->getNodeValue(), nullptr);
141  else
142  return def;
143 }

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

◆ getParameterIntValue() [1/2]

INET_API int inet::xmlutils::getParameterIntValue ( const cXMLElement *  ptr,
const char *  name 
)
116 {
117  const cXMLElement *xvalue = getUniqueChild(ptr, name);
118  return atoi(xvalue->getNodeValue());
119 }

◆ getParameterIntValue() [2/2]

INET_API int inet::xmlutils::getParameterIntValue ( const cXMLElement *  ptr,
const char *  name,
int  def 
)
107 {
108  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
109  if (xvalue)
110  return atoi(xvalue->getNodeValue());
111  else
112  return def;
113 }

Referenced by inet::RsvpTe::delSession(), inet::RsvpClassifier::readItemFromXML(), inet::LibTable::readTableFromXML(), and inet::RsvpTe::readTrafficSessionFromXML().

◆ getParameterIPAddressValue() [1/2]

INET_API Ipv4Address inet::xmlutils::getParameterIPAddressValue ( const cXMLElement *  ptr,
const char *  name 
)
131 {
132  const cXMLElement *xvalue = getUniqueChild(ptr, name);
133  return L3AddressResolver().resolve(xvalue->getNodeValue()).toIpv4();
134 }

◆ getParameterIPAddressValue() [2/2]

INET_API Ipv4Address inet::xmlutils::getParameterIPAddressValue ( const cXMLElement *  ptr,
const char *  name,
Ipv4Address  def 
)
122 {
123  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
124  if (xvalue)
125  return L3AddressResolver().resolve(xvalue->getNodeValue()).toIpv4();
126  else
127  return def;
128 }

Referenced by inet::RsvpTe::delSession(), inet::RsvpClassifier::readItemFromXML(), and inet::RsvpTe::readTrafficSessionFromXML().

◆ getParameterStrValue() [1/2]

const INET_API char * inet::xmlutils::getParameterStrValue ( const cXMLElement *  ptr,
const char *  name 
)
101 {
102  const cXMLElement *xvalue = getUniqueChild(ptr, name);
103  return xvalue->getNodeValue();
104 }

◆ getParameterStrValue() [2/2]

const INET_API char * inet::xmlutils::getParameterStrValue ( const cXMLElement *  ptr,
const char *  name,
const char *  def 
)
77 {
78  const cXMLElement *xvalue = getUniqueChildIfExists(ptr, name);
79  if (xvalue)
80  return xvalue->getNodeValue();
81  else
82  return def;
83 }

Referenced by inet::LibTable::readTableFromXML(), and inet::RsvpTe::readTrafficSessionFromXML().

◆ getUniqueChild()

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

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

◆ getUniqueChildIfExists()

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

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

◆ parseBool()

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

Referenced by getAttributeBoolValue(), and getParameterBoolValue().

inet::xmlutils::parseBool
bool parseBool(const char *text)
Definition: XMLUtils.cc:29
inet::xmlutils::getMandatoryAttribute
const char * getMandatoryAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:151
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::xmlutils::getUniqueChild
const cXMLElement * getUniqueChild(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:9
inet::xmlutils::getUniqueChildIfExists
const cXMLElement * getUniqueChildIfExists(const cXMLElement *node, const char *name)
Definition: XMLUtils.cc:18
tags
* tags
Definition: IUdp-gates.txt:3
inet::xmlutils::getMandatoryFilledAttribute
const char * getMandatoryFilledAttribute(const cXMLElement &node, const char *attr)
Definition: XMLUtils.cc:160