tinyxml.cpp
Go to the documentation of this file.
00001 // tutorial demo program
00002 //#include "stdafx.h"
00003 #include "tinyxml.h"
00004 
00005 // ----------------------------------------------------------------------
00006 // STDOUT dump and indenting utility functions
00007 // ----------------------------------------------------------------------
00008 const unsigned int NUM_INDENTS_PER_SPACE=2;
00009 
00010 const char * getIndent( unsigned int numIndents )
00011 {
00012   static const char * pINDENT="                                      + ";
00013   static const unsigned int LENGTH=strlen( pINDENT );
00014   unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
00015   if ( n > LENGTH ) n = LENGTH;
00016 
00017   return &pINDENT[ LENGTH-n ];
00018 }
00019 
00020 // same as getIndent but no "+" at the end
00021 const char * getIndentAlt( unsigned int numIndents )
00022 {
00023   static const char * pINDENT="                                        ";
00024   static const unsigned int LENGTH=strlen( pINDENT );
00025   unsigned int n=numIndents*NUM_INDENTS_PER_SPACE;
00026   if ( n > LENGTH ) n = LENGTH;
00027 
00028   return &pINDENT[ LENGTH-n ];
00029 }
00030 
00031 int dump_attribs_to_stdout(TiXmlElement* pElement, unsigned int indent)
00032 {
00033   if ( !pElement ) return 0;
00034 
00035   TiXmlAttribute* pAttrib=pElement->FirstAttribute();
00036   int i=0;
00037   int ival;
00038   double dval;
00039   const char* pIndent=getIndent(indent);
00040   printf("\n");
00041   while (pAttrib)
00042     {
00043       printf( "%s%s: value=[%s]", pIndent, pAttrib->Name(), pAttrib->Value());
00044 
00045       if (pAttrib->QueryIntValue(&ival)==TIXML_SUCCESS)    printf( " int=%d", ival);
00046       if (pAttrib->QueryDoubleValue(&dval)==TIXML_SUCCESS) printf( " d=%1.1f", dval);
00047       printf( "\n" );
00048       i++;
00049       pAttrib=pAttrib->Next();
00050     }
00051   return i;
00052 }
00053 
00054 void dump_to_stdout( TiXmlNode* pParent, unsigned int indent = 0 )
00055 {
00056   if ( !pParent ) return;
00057 
00058   TiXmlNode* pChild;
00059   TiXmlText* pText;
00060   int t = pParent->Type();
00061   //printf( "%s", getIndent(indent));
00062   int num;
00063 
00064   //switch ( t )
00065   //{
00066     // case TiXmlNode::DOCUMENT:
00067     //   printf( "Document" );
00068     //   break;
00069 
00070     //case TiXmlNode::ELEMENT:
00071     //case "picture_high":
00072   //  if (pParent->Value() == "picture_high")
00073   // {
00074       std::string pstring = pParent->Value();
00075       //      std::cerr << "pstring: " << pstring << std::endl;
00076       size_t found=pstring.rfind("picture_high");
00077       if (found!=std::string::npos)
00078         {
00079           std::cerr << "First child: " << pParent->FirstChild()->Value() << std::endl;
00080         }
00081         //      std::cerr << "picture_high: " << int(found) << std::endl;
00082       // exit(0);
00083       //  }
00084       //      printf( "Element value [%s]", pParent->Value() );
00085       // num=dump_attribs_to_stdout(pParent->ToElement(), indent+1);
00086       // switch(num)
00087       //        {
00088       //        case 0:  printf( " (No attributes)"); break;
00089       //        case 1:  printf( "%s1 attribute", getIndentAlt(indent)); break;
00090       //        default: printf( "%s%d attributes", getIndentAlt(indent), num); break;
00091       //        }
00092       // break;
00093 
00094     // case TiXmlNode::COMMENT:
00095     //   printf( "Comment: [%s]", pParent->Value());
00096     //   break;
00097 
00098     // case TiXmlNode::UNKNOWN:
00099     //   printf( "Unknown" );
00100     //   break;
00101 
00102     // case TiXmlNode::TEXT:
00103     //   pText = pParent->ToText();
00104     //   printf( "Text: [%s]", pText->Value() );
00105     //   break;
00106 
00107     // case TiXmlNode::DECLARATION:
00108     //   printf( "Declaration" );
00109     //   break;
00110       //    default:
00111       // break;
00112       //}
00113       //printf( "\n" );
00114       for ( pChild = pParent->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) 
00115         {
00116           dump_to_stdout( pChild, indent+1 );
00117         }
00118 }
00119 
00120 // load the named file and dump its structure to STDOUT
00121 void dump_to_stdout(const char* pFilename)
00122 {
00123   TiXmlDocument doc(pFilename);
00124   bool loadOkay = doc.LoadFile();
00125   if (loadOkay)
00126     {
00127       printf("\n%s:\n", pFilename);
00128       dump_to_stdout( &doc ); // defined later in the tutorial
00129     }
00130   else
00131     {
00132       printf("Failed to load file \"%s\"\n", pFilename);
00133     }
00134 }
00135 
00136 // ----------------------------------------------------------------------
00137 // main() for printing files named on the command line
00138 // ----------------------------------------------------------------------
00139 int main(int argc, char* argv[])
00140 {
00141   for (int i=1; i<argc; i++)
00142     {
00143       dump_to_stdout(argv[i]);
00144     }
00145   return 0;
00146 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


zbar_barcode_reader_node
Author(s): Dejan Pangercic
autogenerated on Thu May 23 2013 13:21:06