Changeset 10943
- Timestamp:
- 01/11/10 18:36:03 (3 years ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 2 modified
-
include/osgDB/XmlParser (modified) (1 diff)
-
src/osgDB/XmlParser.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgDB/XmlParser
r10534 r10943 133 133 bool read(Input& input); 134 134 135 bool write(std::ostream& fout ) const;135 bool write(std::ostream& fout, const std::string& indent = "") const; 136 136 bool writeString(std::ostream& fout, const std::string& str) const; 137 137 138 protected: 139 140 bool writeChildren(std::ostream& fout, const std::string& indent) const; 141 bool writeProperties(std::ostream& fout) const; 138 142 }; 139 143 -
OpenSceneGraph/trunk/src/osgDB/XmlParser.cpp
r10930 r10943 308 308 ++input; 309 309 osg::notify(osg::INFO)<<"tag is closed correctly"<<std::endl; 310 childNode->type = ATOM; 310 311 } 311 312 else … … 361 362 } 362 363 363 bool XmlNode::write(std::ostream& fout ) const364 bool XmlNode::write(std::ostream& fout, const std::string& indent) const 364 365 { 365 366 switch(type) … … 369 370 case(ATOM): 370 371 { 371 fout<<"<"<<name; 372 for(Properties::const_iterator oitr = properties.begin(); 373 oitr != properties.end(); 374 ++oitr) 375 { 376 fout<<oitr->first<<"\""; 377 writeString(fout,oitr->second); 378 fout<<"\""<<std::endl; 379 } 380 return true; 372 fout<<indent<<"<"<<name; 373 writeProperties(fout); 381 374 fout<<" />"<<std::endl; 375 return true; 382 376 } 383 377 case(ROOT): 384 378 { 385 for(Children::const_iterator citr = children.begin(); 386 citr != children.end(); 387 ++citr) 388 { 389 (*citr)->write(fout); 390 } 379 writeChildren(fout, indent); 391 380 return true; 392 381 } 393 382 case(NODE): 394 {395 fout<<"<"<<name;396 for(Properties::const_iterator oitr = properties.begin();397 oitr != properties.end();398 ++oitr)399 {400 fout<<" "<<oitr->first<<"=\"";401 writeString(fout,oitr->second);402 fout<<"\"";403 }404 405 if (children.empty() && contents.empty())406 {407 fout<<" />"<<std::endl;408 }409 else410 {411 fout<<">";412 for(Children::const_iterator citr = children.begin();413 citr != children.end();414 ++citr)415 {416 (*citr)->write(fout);417 }418 419 if (!contents.empty()) writeString(fout,contents);420 421 fout<<"</"<<name<<">"<<std::endl;422 }423 return true;424 }425 383 case(GROUP): 426 384 { 427 fout<<"<"<<name; 428 for(Properties::const_iterator oitr = properties.begin(); 429 oitr != properties.end(); 430 ++oitr) 431 { 432 fout<<" "<<oitr->first<<"=\""; 433 writeString(fout,oitr->second); 434 fout<<"\""; 435 } 385 fout<<indent<<"<"<<name; 386 writeProperties(fout); 436 387 fout<<">"<<std::endl; 437 388 438 for(Children::const_iterator citr = children.begin(); 439 citr != children.end(); 440 ++citr) 441 { 442 (*citr)->write(fout); 443 } 444 445 fout<<"</"<<name<<">"<<std::endl; 389 writeChildren(fout, indent + " "); 390 391 fout<<indent<<"</"<<name<<">"<<std::endl; 446 392 return true; 447 393 } 448 394 case(COMMENT): 449 395 { 450 fout<< "<!--"<<contents<<"-->"<<std::endl;396 fout<<indent<<"<!--"<<contents<<"-->"<<std::endl; 451 397 return true; 452 398 } 453 399 case(INFORMATION): 454 400 { 455 fout<< "<?"<<contents<<"?>"<<std::endl;401 fout<<indent<<"<?"<<contents<<"?>"<<std::endl; 456 402 return true; 457 403 } … … 465 411 return true; 466 412 } 413 414 bool XmlNode::writeChildren(std::ostream& fout, const std::string& indent) const 415 { 416 for(Children::const_iterator citr = children.begin(); 417 citr != children.end(); 418 ++citr) 419 { 420 if (!(*citr)->write(fout, indent)) 421 return false; 422 } 423 424 return true; 425 } 426 427 bool XmlNode::writeProperties(std::ostream& fout) const 428 { 429 for(Properties::const_iterator oitr = properties.begin(); 430 oitr != properties.end(); 431 ++oitr) 432 { 433 fout<<" "<<oitr->first<<"=\""; 434 if (!writeString(fout,oitr->second)) 435 return false; 436 fout<<"\""; 437 } 438 439 return true; 440 }
