xmltools.hh
Go to the documentation of this file.
00001 #ifndef TYPELIB_LANG_TLB_XMLTOOLS_HH
00002 #define TYPELIB_LANG_TLB_XMLTOOLS_HH
00003 
00004 #include <libxml/xmlmemory.h>
00005 #include "parsing.hh"
00006 #include <boost/lexical_cast.hpp>
00007 
00008 namespace 
00009 {
00010     using std::string;
00011 
00012     template<typename Exception>
00013     void checkNodeName(xmlNodePtr node, const char* expected)
00014     {
00015         if (xmlStrcmp(node->name, reinterpret_cast<const xmlChar*>(expected)))
00016             throw Exception(reinterpret_cast<const char*>(node->name), expected, "");
00017     }
00018 
00019     std::string getStringAttribute(xmlNodePtr type, const char* att_name)
00020     {
00021         xmlChar* att = xmlGetProp(type, reinterpret_cast<const xmlChar*>(att_name) );
00022         if (! att)
00023             throw Parsing::MissingAttribute(att_name, "");
00024         std::string ret( reinterpret_cast<const char*>(att));
00025         xmlFree(att);
00026         return ret;
00027     }
00028 
00029     template<typename T>
00030     T getAttribute(xmlNodePtr type, char const* att_name)
00031     { return boost::lexical_cast<T>(getStringAttribute(type, att_name)); }
00032     template<>
00033     std::string getAttribute<std::string>(xmlNodePtr type, const char* att_name)
00034     { return getStringAttribute(type, att_name); }
00035 }
00036 
00037 #endif
00038 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 18:49:22