|
NIREP
|
00001 /*************************************************************************************** 00002 * Programmer: Gary E. Christensen 00003 * Date: 6/24/2010 00004 * Name: BasicDescription 00005 * Purpose: This class holds descriptive information about namespaces, 00006 * algorithms, coordinate systems, images, object maps, landmark files, 00007 * and contour files from disk. 00008 * Objects of this class are filled with information by parsing a resource description list. 00009 * All non-required tags and their values are stored in the attribute list. 00010 * Optional XML Tags: 00011 * attributes - contains user defined XML tags and values 00012 ******************************************************************************************/ 00013 00014 #include "BasicDescription.h" 00015 00022 TiXmlElement * BasicDescription::CreateDOM(const std::string & tag){ 00023 00024 // descrip is the main element to hold the DOM tree for this object 00025 TiXmlElement * descrip = new TiXmlElement( tag.c_str() ); 00026 00027 if (descrip){ 00028 // Only save description id if there is one 00029 if (!m_id.empty()){ 00030 descrip->SetAttribute("id", m_id.c_str()); 00031 } 00032 // Only save namespace if there is one 00033 if (!m_ns.empty()){ 00034 descrip->SetAttribute("ns", m_ns.c_str()); 00035 } 00036 } else { 00037 return NULL; // Failed to allocate memory 00038 } 00039 00040 // Add non-required attributes to descrip 00041 // Cycle through all the attributes and store them in DOM 00042 AttributeList::iterator iter; 00043 for (iter=m_attribute.begin(); iter != m_attribute.end(); iter++) { 00044 const std::string & key= iter->first; 00045 const std::string & value= iter->second; 00046 00047 TiXmlElement * p_attribute = new TiXmlElement(key.c_str()); 00048 TiXmlText * p_text = new TiXmlText(value.c_str()); 00049 00050 if (p_attribute && p_text){ 00051 p_attribute->LinkEndChild( p_text ); 00052 descrip->LinkEndChild( p_attribute ); 00053 } else { 00054 return NULL; // Failed to allocate memory 00055 } 00056 } 00057 00058 return descrip; 00059 } 00060 00061 00069 bool BasicDescription::FillUsingDom(TiXmlElement * descrip){ 00070 // Return false if called with NULL pointer 00071 if (!descrip){ 00072 return false; 00073 } 00074 00075 //set id if there is one 00076 std::string buf; 00077 int readOkay; 00078 readOkay = descrip->QueryStringAttribute("id", &buf); 00079 if (readOkay == TIXML_SUCCESS){ 00080 SetID(buf); 00081 } 00082 00083 // set namespace if there is one 00084 readOkay = descrip->QueryStringAttribute("ns", &buf); 00085 if (readOkay == TIXML_SUCCESS){ 00086 SetNameSpace(buf); 00087 } 00088 00089 // pElem used to move through children of descrip 00090 TiXmlElement* pElem; 00091 TiXmlHandle hDescrip(descrip); 00092 00093 //Go to first attribute child of description and set attributes 00094 pElem=hDescrip.FirstChildElement().Element(); 00095 for( pElem; pElem; pElem=pElem->NextSiblingElement()) { 00096 const char *pKey=pElem->Value(); 00097 const char *pText=pElem->GetText(); 00098 if (pKey && pText) { 00099 AddAttribute(pKey,pText); 00100 } 00101 } 00102 00103 return true; 00104 }