39 #include <libxml/parser.h> 43 xmlParserCtxtPtr pContext{xmlNewParserCtxt()};
50 xmlDocPtr pDoc{xmlCtxtReadFile(pContext, sAntennaProfileURI.c_str(), NULL, XML_PARSE_DTDVALID)};
55 xmlFreeParserCtxt(pContext);
56 throw makeException<AntennaProfileException>(
"Unable to read %s",sAntennaProfileURI.c_str());
59 if(pContext->valid ==
false)
62 xmlFreeParserCtxt(pContext);
63 throw makeException<AntennaProfileException>(
"Validation failure %s",sAntennaProfileURI.c_str());
66 xmlNodePtr pRoot{xmlDocGetRootElement(pDoc)};
71 xmlFreeParserCtxt(pContext);
72 throw makeException<AntennaProfileException>(
"Invalid document root %s",
73 sAntennaProfileURI.c_str());
76 for(xmlNodePtr pNode = pRoot->children; pNode; pNode = pNode->next)
78 if(pNode->type == XML_ELEMENT_NODE)
80 if(!xmlStrcmp(pNode->name,BAD_CAST
"profile"))
82 xmlChar * pId{xmlGetProp(pNode,BAD_CAST
"id")};
89 xmlChar * pAntennaPatternURI{xmlGetProp(pNode,BAD_CAST
"antennapatternuri")};
91 std::string sAntennaPatternURI{
reinterpret_cast<const char *
>(pAntennaPatternURI)};
93 xmlFree(pAntennaPatternURI);
95 xmlChar * pBlockagePatternURI{xmlGetProp(pNode,BAD_CAST
"blockagepatternuri")};
97 std::string sBlockagePatternURI{};
99 if(pBlockagePatternURI)
101 sBlockagePatternURI =
reinterpret_cast<const char *
>(pBlockagePatternURI);
103 xmlFree(pBlockagePatternURI);
108 for(xmlNodePtr pChileNode = pNode->children; pChileNode; pChileNode = pChileNode->next)
110 if(pChileNode->type == XML_ELEMENT_NODE)
112 if(!xmlStrcmp(pChileNode->name,BAD_CAST
"placement"))
114 xmlChar * pNorth{xmlGetProp(pChileNode,BAD_CAST
"north")};
121 xmlChar * pEast{xmlGetProp(pChileNode,BAD_CAST
"east")};
127 xmlChar * pUp{xmlGetProp(pChileNode,BAD_CAST
"up")};
141 auto iter = antennaPatternStore_.find(sAntennaPatternURI);
143 if(iter == antennaPatternStore_.end())
147 antennaPatternStore_.insert(std::make_pair(sAntennaPatternURI,
148 std::unique_ptr<AntennaPattern>(pAntennaPattern)));
152 pAntennaPattern = iter->second.get();
158 if(!sBlockagePatternURI.empty())
160 auto iter = antennaPatternStore_.find(sBlockagePatternURI);
162 if(iter == antennaPatternStore_.end())
164 pBlockagePattern =
new AntennaPattern{sBlockagePatternURI,
"blockagepattern",0};
166 antennaPatternStore_.insert(std::make_pair(sBlockagePatternURI,
167 std::unique_ptr<AntennaPattern>(pBlockagePattern)));
171 pBlockagePattern = iter->second.get();
175 if(!profiles_.insert(std::make_pair(u16Id,
176 std::make_tuple(pAntennaPattern,pBlockagePattern,antennaPlacement))).second)
178 throw makeException<AntennaProfileException>(
"Duplicate antenna profile id %hu",u16Id);
185 xmlFreeParserCtxt(pContext);
189 std::pair<std::tuple<EMANE::AntennaPattern *,EMANE::AntennaPattern *,EMANE::PositionNEU>,
bool>
192 const auto iter = profiles_.find(antennaProfileId);
194 if(iter != profiles_.end())
196 return {iter->second,
true};
void load(const std::string &sAntennaProfileURI)
std::uint16_t toUINT16(std::uint16_t u16Min=std::numeric_limits< std::uint16_t >::min(), std::uint16_t u16Max=std::numeric_limits< std::uint16_t >::max()) const
double toDouble(double dMin=std::numeric_limits< double >::lowest(), double dMax=std::numeric_limits< double >::max()) const
std::uint16_t AntennaProfileId
Parameter conversion class with range checks.
std::pair< std::tuple< AntennaPattern *, AntennaPattern *, PositionNEU >, bool > getProfileInfo(AntennaProfileId antennaProfileId) const