- Timestamp:
- Nov 4, 2010, 8:50:17 PM (14 years ago)
- Location:
- osgVisual
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
osgVisual/include/util/visual_util.h
r145 r146 221 221 222 222 /** 223 * \brief Parses for the XML node of the specified module.The caller has to clean up the xmlDoc and the parser, beside it returns NULL because the queried modules is not configured.223 * \brief Parses for the XML node of the specified module. The caller has to clean up the xmlDoc and the parser, beside it returns NULL because the queried modules is not configured. 224 224 * 225 225 * To clean up, call this two functions: … … 243 243 static xmlNode* getModuleXMLConfig(std::string configFilename, std::string moduleName, xmlDoc*& doc); 244 244 245 /** 246 * \brief Parses for the XML node of the scenery configuration. The caller has to clean up the xmlDoc and the parser, beside it returns NULL because the queried modules is not configured. 247 * 248 * @param configFilename : Config Filename to parse. 249 * @param doc : xmlDoc to use. Must be created outside that the caller can clean it up. 250 * @return : NULL on error, otherwise pointer to the xmlNode of the scenery configuration. 251 */ 252 static xmlNode* getSceneryXMLConfig(std::string configFilename, xmlDoc*& doc); 253 245 254 private: 246 255 /** … … 254 263 */ 255 264 static xmlNode* checkXMLNodeChildrenForModule(xmlNode* node, std::string moduleName); 265 266 /** 267 * \brief This functions checks a list of nodes and all of its children for the scenery configuration. 268 * 269 * @param node : Node to search in 270 * @return : NULL if the module configuration was not found, otherwise pointer to the XML Node with the configuration for the specified module. 271 */ 272 static xmlNode* checkXMLNodeChildrenForScenery(xmlNode* node); 256 273 }; 257 274 -
osgVisual/src/util/visual_util.cpp
r144 r146 25 25 util::~util(void) 26 26 { 27 } 28 29 xmlNode* util::getSceneryXMLConfig(std::string configFilename, xmlDoc*& doc) 30 { 31 doc = NULL; 32 xmlNode *root_element = NULL; 33 34 // Check for valid parameters 35 if(configFilename == "") 36 { 37 OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : Invalid Configuration Filename!" << std::endl; 38 return NULL; 39 } 40 41 // It is a valid XML document? 42 doc = xmlReadFile(configFilename.c_str(), NULL, 0); 43 if (doc == NULL) 44 { 45 OSG_ALWAYS << "ERROR - util::getModuleXMLConfig() : " << configFilename << " is not a valid XML file!" << std::endl; 46 return NULL; 47 } 48 49 // Get the root element node 50 root_element = xmlDocGetRootElement(doc); 51 52 // If file is a valid osgVisual config file, check all the root xml node and all of it's children of osgvisualconfiguration for the specified module 53 xmlNode* tmpNode = checkXMLNodeChildrenForScenery(root_element); 54 55 if( !tmpNode ) // if no valid node was found: clena up. Otherwise: the caller has to clean up. 56 { 57 xmlFreeDoc(doc); // free the document 58 xmlCleanupParser(); // Free the global variables that may have been allocated by the parser. 59 return NULL; 60 } 61 else 62 return tmpNode; 63 } 64 65 xmlNode* util::checkXMLNodeChildrenForScenery(xmlNode* node) 66 { 67 for (xmlNode *cur_node = node; cur_node; cur_node = cur_node->next) // iterate through all elements 68 { 69 // Is the node the one we are searching for? 70 if (cur_node->type == XML_ELEMENT_NODE) 71 { 72 std::string node_name=reinterpret_cast<const char*>(cur_node->name); 73 if (node_name == "scenery") 74 { 75 OSG_DEBUG << "XML node scenery found" << std::endl; 76 return cur_node; 77 } 78 else // Otherwise: check its children.. 79 { 80 xmlNode* tmp_XmlNode = checkXMLNodeChildrenForScenery(cur_node->children); 81 if(tmp_XmlNode) 82 return tmp_XmlNode; 83 } 84 } // IF NODE TYPE = ELEMENT END 85 86 // Proceed with next node in this loop. 87 } 88 return NULL; 27 89 } 28 90 … … 100 162 // Proceed with next node in this loop. 101 163 } 164 return NULL; 102 165 } 103 166
Note: See TracChangeset
for help on using the changeset viewer.