int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const { TiXmlAttribute* node = attributeSet.Find( name ); if ( !node ) return TIXML_NO_ATTRIBUTE; return node->QueryDoubleValue( dval ); }
void HoOrionModelParser::ParseWire(TiXmlNode* pParent) { double C, R, Pitch; int Layer; TiXmlAttribute* Attribute = ( pParent->ToElement())->FirstAttribute() ; while (Attribute ) { if (string(Attribute->Name() ) == "type") { } else if (string(Attribute->Name() ) == "layer") { Attribute->QueryIntValue(&Layer) ; } else if (string(Attribute->Name() ) == "r") { Attribute->QueryDoubleValue(&R) ; } else if (string(Attribute->Name() ) == "c") { Attribute->QueryDoubleValue(&C) ; } else if (string(Attribute->Name() ) == "pitch") { Attribute->QueryDoubleValue(&Pitch) ; } else { cout << "Unknown attribute "<< Attribute->Name() << " for wire" << endl ; } Attribute = Attribute->Next() ; } mR[Layer] = R ; mC[Layer] = C ; mPitch[Layer] = Pitch ; }
//Función que vuelca el contenido de los atributos de un elemento del fichero XML, y // devuelve el número de atributos del elemento. int cLoadXML::Output_attributes(TiXmlElement* lpElement, unsigned int luiIndent) { if ( !lpElement ) return 0; //Se accede al primer atributo del elemento. TiXmlAttribute* lpAttrib = lpElement->FirstAttribute(); int i = 0; int liVal; double ldVal; //Se obtiene la cadena de indentación. const char* kpcIndent = GetIndent(luiIndent, true); OutputDebugString("\n"); //Se recorren los atributos. while (lpAttrib) { //Se imprime la indentación concatenada con el nombre del atributo y su valor. OutputDebugString( ((std::string)kpcIndent + lpAttrib->Name() + ": value = " + lpAttrib->Value()).c_str()); //"QueryIntValue()" es una alternativa al método IntValue() con verificación de error. Si el valor del atributo es integer, es almacenado en el parámetro // "liVal" y se retorna TIXML_SUCCESS. Si no es integer se devuelve TIXML_WRONG_TYPE. if (lpAttrib->QueryIntValue(&liVal)==TIXML_SUCCESS) { char lpcCadenaNum[4]; //Convertimos el número integer en cadena sprintf_s(lpcCadenaNum, 4, "%d", liVal); OutputDebugString((", the value is integer = " + (std::string)lpcCadenaNum).c_str()); } //"QueryDoubleValue()" es una alternativa al método DoubleValue() con verificación de error. Si el valor del atributo es double, es almacenado en el parámetro // "ldVal" y se retorna TIXML_SUCCESS. Si no es double se devuelve TIXML_WRONG_TYPE. else if (lpAttrib->QueryDoubleValue(&ldVal)==TIXML_SUCCESS) { char lpcCadenaNum[20]; //Convertimos el número integer en cadena sprintf_s(lpcCadenaNum, 20, "%0.2f", ldVal); OutputDebugString((", the value is double = " + (std::string)lpcCadenaNum).c_str()); } OutputDebugString("\n"); i++; //Next(): Get the next sibling attribute in the DOM. Returns null at end. lpAttrib=lpAttrib->Next(); } //Se devuelve el número de atributos return i; }
int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent) { if (!pElement) return 0; TiXmlAttribute* pAttrib = pElement->FirstAttribute(); int i = 0; int ival; double dval; const char* pIndent = getIndent(indent); printf("\n"); while (pAttrib) { printf("%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value()); if (pAttrib->QueryIntValue(&ival) == TIXML_SUCCESS) printf(" int=%d", ival); if (pAttrib->QueryDoubleValue(&dval) == TIXML_SUCCESS) printf(" d=%1.1f", dval); printf("\n"); i++; pAttrib = pAttrib->Next(); } return i; }
bool CGmResMan::ReadXML_Curves_( CList<CCurvePathBezier3 *> *poLstCurve, TiXmlNode* poParent, unsigned int uiCounter ) { if( !poParent ) return false; static CCurvePathBezier3 * poCurve_; static CCurveBezier3 * poBezier_; static unsigned int uiVertex_; static char acTxt_[256]; if( uiCounter == 0 ) { poCurve_ = 0; poBezier_ = 0; uiVertex_ = 0; } bool bCurveTag = false; bool bBezierTag = false; switch ( poParent->Type() ) { case TiXmlNode::DOCUMENT: LOG( "XML: Document" ); break; case TiXmlNode::ELEMENT: { const char *pcName = poParent->Value(); //LOG( "name: %s\n", pcName ); if( !strcmp( pcName, "curve" ) ) { LOG( "curve:\n" ); poCurve_ = new CCurvePathBezier3; poLstCurve->Append( poCurve_ ); bCurveTag = true; TiXmlElement * poElement = poParent->ToElement(); if( poElement ) { TiXmlAttribute* poAttrib = poElement->FirstAttribute(); while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "name" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "name: %s\n", acTxt_ ); poCurve_->m_oName = acTxt_; } poAttrib = poAttrib->Next(); } } } else if( !strcmp( pcName, "bezier" ) ) { LOG( "bezier:\n" ); poBezier_ = new CCurveBezier3; bBezierTag = true; } else if( !strcmp( pcName, "point" ) && poBezier_ ) { LOG( "point:\n" ); CCurve::CVertex oVertex; TiXmlElement * poElement = poParent->ToElement(); if( poElement ) { TiXmlAttribute* poAttrib = poElement->FirstAttribute(); while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "x" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); oVertex.m_oPos[0] = float( dVal ); } } else if( !strcmp( pcName, "y" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); oVertex.m_oPos[1] = float( dVal ); } } else if( !strcmp( pcName, "z" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); oVertex.m_oPos[2] = float( dVal ); } } else if( !strcmp( pcName, "weight" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); oVertex.m_fWeight0 = float( dVal ); } } poAttrib = poAttrib->Next(); } } poBezier_->m_aoVertex[uiVertex_] = oVertex; ++uiVertex_; } } break; case TiXmlNode::COMMENT: //LOG( "XML: Comment: [%s]", poParent->Value()); break; case TiXmlNode::UNKNOWN: //LOG( "XML: Unknown" ); break; case TiXmlNode::TEXT: //LOG( "XML: Text: [%s]", poParent->ToText()->Value() ); break; case TiXmlNode::DECLARATION: //LOG( "XML: Declaration" ); break; default: break; } LOG( "\n" ); ++uiCounter; TiXmlNode* poChild = poParent->FirstChild(); if( poChild ) { //LOG( "<tag>\n" ); for( ; poChild != 0; poChild = poChild->NextSibling() ) { ReadXML_Curves_( poLstCurve, poChild, uiCounter ); } //LOG( "</tag>\n" ); } if( bBezierTag ) { poCurve_->Append( poBezier_ ); poBezier_ = 0; uiVertex_ = 0; } else if( bCurveTag ) { poCurve_ = 0; } return true; }
void HoOrionModelParser::ParseRouter(TiXmlNode* pParent) { double TmpDouble; int TmpInt; string Type; stringstream Energy; stringstream Area; int MaxIn = 0; int MaxOut = 0; TiXmlAttribute* Attribute = ( pParent->ToElement())->FirstAttribute() ; while (Attribute ) { if (string(Attribute->Name() ) == "type") { Type = string(Attribute->Value() ) ; } else if (string(Attribute->Name() ) == "maxin") { Attribute->QueryIntValue(&TmpInt) ; MaxIn = TmpInt ; } else if (string(Attribute->Name() ) == "maxout") { Attribute->QueryIntValue(&TmpInt) ; MaxOut = TmpInt ; } else if (string(Attribute->Name() ) == "maxbw") { Attribute->QueryDoubleValue(&TmpDouble) ; //mModel->RouterMaxBw = TmpDouble ; } else if (string(Attribute->Name() ) == "energy") { Energy << Attribute->ValueStr() ; } else if (string(Attribute->Name() ) == "area") { Area << Attribute->ValueStr() ; } else { cout << "Unknown attribute "<< Attribute->Name() << " for wire" << endl ; } Attribute = Attribute->Next() ; } mMaxIn = MaxIn ; mMaxOut = MaxOut ; if (Type == "r1ch32") { mArouter1ch32.resize(MaxIn + 1) ; mErouter1ch32.resize(MaxIn + 1) ; mErouterLeak1ch32.resize(MaxIn + 1) ; mArouter1ch32[0].resize(MaxOut + 1) ; mErouter1ch32[0].resize(MaxOut + 1) ; mErouterLeak1ch32[0].resize(MaxOut + 1) ; for (int i = 1; i <= MaxIn ; i++) { mArouter1ch32[i].resize(MaxOut + 1) ; mErouter1ch32[i].resize(MaxOut + 1) ; mErouterLeak1ch32[i].resize(MaxOut + 1) ; for (int j = 1; j <= MaxOut ; j++) { Area >> mArouter1ch32[i][j]; mArouter1ch32[i][j] = mArouter1ch32[i][j]*1e-12; Energy >> mErouter1ch32[i][j]; Energy >> mErouterLeak1ch32[i][j]; } } //handle first rows nad first column for (int j = 0; j <= MaxOut ; j++) { mArouter1ch32[0][j] = 0; mErouter1ch32[0][j] = 0; mErouterLeak1ch32[0][j] = 0; } for (int i = 0; i <= MaxIn ; i++) { mArouter1ch32[i][0] = 0; mErouter1ch32[i][0] = 0; mErouterLeak1ch32[i][0] = 0; } } else if (Type == "r4ch32") {
bool CGmObjShapeStaticItem::ReadXML( TiXmlNode* poParent, unsigned int uiCounter ) { if( !poParent ) return false; static char acTxt_[256]; if( uiCounter == 0 ) { } switch ( poParent->Type() ) { case TiXmlNode::DOCUMENT: LOG( "XML: Document" ); break; case TiXmlNode::ELEMENT: { const char *pcName = poParent->Value(); //LOG( "name: %s\n", pcName ); if( !strcmp( pcName, "item" ) ) { LOG( "item:\n" ); TiXmlElement * poElement = poParent->ToElement(); if( poElement ) { TiXmlAttribute* poAttrib = poElement->FirstAttribute(); while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "name" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); m_oName = acTxt_; } if( !strcmp( pcName, "type" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); if( !strcmp( acTxt_, "weapon" ) ) m_eType = TYPE_WEAPON; else if( !strcmp( acTxt_, "energy" ) ) m_eType = TYPE_ENERGY; else if( !strcmp( acTxt_, "ammo" ) ) m_eType = TYPE_AMMO; else if( !strcmp( acTxt_, "key" ) ) m_eType = TYPE_KEY; else m_eType = TYPE_UNDEFINED; } if( !strcmp( pcName, "cycle_duration" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); if( dVal >= 0.0 ) m_iTickDurCycle = int( dVal / m_dTInteractionInterval_ ); else m_iTickDurCycle = -1; } } if( !strcmp( pcName, "rotation_y_speed" ) ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_fRotationYSpeed = float( dVal * 360.0 ); } } if( !strcmp( pcName, "weapon_name" ) && ( m_eType == TYPE_WEAPON || m_eType == TYPE_AMMO ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); m_oWeaponName = acTxt_; } if( !strcmp( pcName, "energy" ) && m_eType == TYPE_ENERGY ) { double dVal; if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_fEnergy = float( dVal ); } } if( !strcmp( pcName, "ammo" ) && ( m_eType == TYPE_WEAPON || m_eType == TYPE_AMMO ) ) { int iVal; if( poAttrib->QueryIntValue( &iVal ) == TIXML_SUCCESS && iVal > 0 ) { LOG( "%s: %d\n", poAttrib->Name(), iVal ); m_uiAmmo = iVal; } } if( !strcmp( pcName, "key" ) && m_eType == TYPE_ENERGY ) { int iVal; if( poAttrib->QueryIntValue( &iVal ) == TIXML_SUCCESS && iVal > 0 ) { LOG( "%s: %d\n", poAttrib->Name(), iVal ); m_uiKey = iVal; } } poAttrib = poAttrib->Next(); } } } if( !strcmp( pcName, "animation" ) ) { LOG( "animation:\n" ); TiXmlElement * poElement = poParent->ToElement(); if( poElement ) { TiXmlAttribute* poAttrib = poElement->FirstAttribute(); while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "file_name" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); m_poAnim = m_poResMan_->NewAnim3( CStr( "item/" ) + acTxt_ ); } poAttrib = poAttrib->Next(); } } } // Gleich wie in GmObjShapeDynamicEnemy.cpp. if( !strcmp( pcName, "mesh" ) ) { LOG( "mesh:\n" ); CStr oFileName, oSubDir; TiXmlElement * poElement = poParent->ToElement(); if( poElement ) { TiXmlAttribute* poAttrib = poElement->FirstAttribute(); while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "sub_dir" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); oSubDir = acTxt_; } else if( !strcmp( pcName, "file_name" ) ) { STRING_COPY( acTxt_, sizeof(acTxt_), poAttrib->Value() ); LOG( "%s: %s\n", poAttrib->Name(), acTxt_ ); oFileName = acTxt_; } poAttrib = poAttrib->Next(); } } if( oFileName.GetSize() ) { CGMesh * poMesh( m_poResMan_->NewMeshObj( oSubDir, oFileName ) ); //, false, false ) ); if( poMesh ) { m_oLstMesh.Append( poMesh ); } } } } break; case TiXmlNode::COMMENT: //LOG( "XML: Comment: [%s]", poParent->Value()); break; case TiXmlNode::UNKNOWN: //LOG( "XML: Unknown" ); break; case TiXmlNode::TEXT: //LOG( "XML: Text: [%s]", poParent->ToText()->Value() ); break; case TiXmlNode::DECLARATION: //LOG( "XML: Declaration" ); break; default: break; } LOG( "\n" ); ++uiCounter; for( TiXmlNode* poChild = poParent->FirstChild(); poChild != 0; poChild = poChild->NextSibling() ) { ReadXML( poChild, uiCounter ); } // Ganz am Schluss... if( uiCounter == 1 ) { } return true; }
int CSkeleton::CBone::ReadXMLAttrib( TiXmlElement* poElement ) { if( !poElement ) return 0; TiXmlAttribute* poAttrib = poElement->FirstAttribute(); int i = 0; int iVal; double dVal; static char acName_[256]; while( poAttrib ) { const char *pcName = poAttrib->Name(); if( !strcmp( pcName, "name" ) ) { SKELETON_STR_COPY( acName_, sizeof(acName_), poAttrib->Value() ); SKELETON_LOG( "name: %s\n", acName_ ); m_oName = acName_; } else if( !strcmp( pcName, "parent_index" ) ) { if( poAttrib->QueryIntValue( &iVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %d\n", poAttrib->Name(), iVal ); m_iIndexParent = iVal; } } else if( !strcmp( pcName, "head_x" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oHead[0] = float( dVal ); } } else if( !strcmp( pcName, "head_y" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oHead[1] = float( dVal ); } } else if( !strcmp( pcName, "head_z" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oHead[2] = float( dVal ); } } else if( !strcmp( pcName, "tail_x" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oTail[0] = float( dVal ); } } else if( !strcmp( pcName, "tail_y" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oTail[1] = float( dVal ); } } else if( !strcmp( pcName, "tail_z" ) ) { if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) { SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); m_oTail[2] = float( dVal ); } } #define CHECK_M( i, j ) \ else if( !strcmp( pcName, "m" #i #j ) ) \ { \ if( poAttrib->QueryDoubleValue( &dVal ) == TIXML_SUCCESS ) \ { \ SKELETON_LOG( "%s: %f\n", poAttrib->Name(), float( dVal ) ); \ m_oTransform( i, j ) = float( dVal ); \ } \ } CHECK_M( 0, 0 ) CHECK_M( 1, 0 ) CHECK_M( 2, 0 ) CHECK_M( 3, 0 ) CHECK_M( 0, 1 ) CHECK_M( 1, 1 ) CHECK_M( 2, 1 ) CHECK_M( 3, 1 ) CHECK_M( 0, 2 ) CHECK_M( 1, 2 ) CHECK_M( 2, 2 ) CHECK_M( 3, 2 ) CHECK_M( 0, 3 ) CHECK_M( 1, 3 ) CHECK_M( 2, 3 ) CHECK_M( 3, 3 ) #undef CHECK_M else { //m_bError = true; SKELETON_ERR( "undefined attribute, %s\n", pcName ); } i++; poAttrib = poAttrib->Next(); } return i; }
Graph read_graphml( std::string input_filename ) { typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex; #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) typedef typename __gnu_cxx::hash_map<std::string, vertex> HashMap; #else typedef typename std::unordered_map<std::string, vertex> HashMap; #endif TiXmlDocument doc(input_filename.c_str()); if (!doc.LoadFile()) throw std::runtime_error("read_graphml: cannot open input file"); TiXmlHandle hDoc(&doc); TiXmlElement *pElem; pElem = hDoc.FirstChildElement().Element(); if (!pElem || strcmp(pElem->Value(), "graphml")) throw std::runtime_error("read_graphml: malformed input graphml file"); pElem = hDoc.FirstChildElement().FirstChild().Element(); while (pElem) { if ( ! strcmp(pElem->Value(), "graph") ) break; pElem = pElem->NextSiblingElement(); } if ( ! pElem ) throw std::runtime_error("read_graphml: malformed input graphml file"); TiXmlHandle hRoot(pElem); Graph out_g; pElem = hRoot.FirstChild().Element(); HashMap id_hash; while (pElem) { std::string id, source_id, target_id, name; double weight = 1.0; TiXmlAttribute *pAttrib = pElem->FirstAttribute(); #ifdef CONAN_DEBUG std::cerr << " " << pElem->Value() << ":" << std::endl; #endif while (pAttrib) { if (!strcmp(pAttrib->Name(), "id")) { const char *pId = pAttrib->Value(); if (pId) id = pId; } else if (!strcmp(pAttrib->Name(), "source")) { const char *pSource = pAttrib->Value(); if (pSource) source_id = pSource; } else if (!strcmp(pAttrib->Name(), "target")) { const char *pTarget = pAttrib->Value(); if (pTarget) target_id = pTarget; } else if (!strcmp(pAttrib->Name(), "weight")) { if (pAttrib->QueryDoubleValue(&weight) != TIXML_SUCCESS) std::cerr << "weight isn't a double presicion number" << std::endl; } else if (!strcmp(pAttrib->Name(), "label")) { const char *pName = pAttrib->Value(); if (pName) name = pName; } #ifdef CONAN_DEBUG std::cerr << " " << pAttrib->Name() << " = " << pAttrib->Value() << std::endl; #endif pAttrib = pAttrib->Next(); } if (!strcmp(pElem->Value(), "node")) { vertex v = boost::add_vertex(out_g); id_hash[id] = v; if (!name.empty()) out_g[v].name = name; else out_g[v].name = id; #ifdef CONAN_DEBUG std::cerr << "Added node with id = " << id << " (remapped to " << v << ") and name = '" << out_g[v].name << "'" << std::endl; #endif } else if (!strcmp(pElem->Value(), "edge")) { boost::add_edge(id_hash[source_id], id_hash[target_id], weight, out_g); #ifdef CONAN_DEBUG std::cerr << "Added edge with id = " << id << ", source_id = " << source_id << " (" << id_hash[source_id] << "), target_id = " << target_id << " (" << id_hash[target_id] << ") and weight = " << weight << std::endl; #endif } pElem = pElem->NextSiblingElement(); } return out_g; }