SimpleEnumReader/SimpleEnumReader.cpp

This sample shows to read a DWF package (DWFToolkit::DWFPackageReader) an its manifest (DWFToolkit::DWFManifest), enumerate its sections (DWFToolkit::DWFSection, DWFToolkit::DWFGlobalSection) and contents, and hook filters (DWFToolkit::DWFDuplicateAttributeFilter) into the XML parser (DWFToolkit::DWFXMLCallback).

00001 //
00002 //  Copyright (c) 2006 by Autodesk, Inc.
00003 //
00004 //  By using this code, you are agreeing to the terms and conditions of
00005 //  the License Agreement included in the documentation for this code.
00006 //
00007 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED,
00008 //  AS TO THE CORRECTNESS OF THIS CODE OR ANY DERIVATIVE
00009 //  WORKS WHICH INCORPORATE IT.
00010 //
00011 //  AUTODESK PROVIDES THE CODE ON AN "AS-IS" BASIS
00012 //  AND EXPLICITLY DISCLAIMS ANY LIABILITY, INCLUDING
00013 //  CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00014 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00015 //
00016 //  Use, duplication, or disclosure by the U.S. Government is subject to
00017 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00018 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00019 //  Data and Computer Software), as applicable.
00020 //
00021 
00022 // SimpleEnumReader.cpp : Defines the entry point for the console application.
00023 //
00024 
00025 #include "stdafx.h"
00026 
00027 #ifdef _DWFCORE_WIN32_SYSTEM
00028 
00029     #if _USE_VLD
00030         #define _USE_VLD_FOR_MEMORY_LEAK_TEST
00031         #include <vld.h>
00032     #else
00033         #define _USE_CRTDBG_FOR_MEMORY_LEAK_TEST
00034         #include <crtdbg.h>
00035     #endif
00036 
00037 #endif
00038 
00039 using namespace std;
00040 using namespace DWFCore;
00041 using namespace DWFToolkit;
00042 
00043 
00044 void dump_bookmarks( const DWFBookmark* pRoot )
00045 {
00046     static size_t l = 0;
00047     size_t i;
00048 
00049     for (i=0;i<l;i++)
00050     {
00051         wcout << "  ";
00052     }
00053 
00054     if (pRoot->name())
00055     {
00056         wcout << (const wchar_t*)(pRoot->name()) << endl;
00057     }
00058 
00059     const DWFBookmark::tList& rChildren = pRoot->getChildBookmarks();
00060 
00061     for (i=0; i < rChildren.size(); i++)
00062     {
00063         l++;
00064         dump_bookmarks( rChildren[i] );
00065         l--;
00066     }
00067 }
00068 
00069 int main(int argc, char* argv[])
00070 {
00071 
00072 #if defined(_USE_CRTDBG_FOR_MEMORY_LEAK_TEST)
00073     //
00074     // Enable memory leak reporting in Debug mode under Win32.
00075     //
00076     int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
00077     // Turn on leak-checking bit
00078     tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
00079     // Turn off CRT block checking bit
00080     tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
00081     // Set flag to the new value
00082     _CrtSetDbgFlag( tmpFlag );
00083 
00084     // For mem leak debugging... Please do not delete.
00085     long foo = 0;
00086     _CrtSetBreakAlloc(foo);
00087 #endif
00088 
00089     if (argc < 2)
00090     {
00091         wcout << L"Usage:" << argv[0] << L" file.dwf" << endl;
00092         return ( 0 );
00093     }
00094 
00095     try
00096     {
00097         DWFFile oDWF( argv[1] );
00098         DWFPackageReader oReader( oDWF );
00099 
00100         DWFPackageReader::tPackageInfo tInfo;
00101         oReader.getPackageInfo( tInfo );
00102 
00103         wchar_t zBuffer[256] = {0};
00104 
00105         if (tInfo.eType != DWFPackageReader::eDWFPackage &&
00106             tInfo.eType != DWFPackageReader::eDWFXPackage)
00107         {
00108             _DWFCORE_SWPRINTF( zBuffer, 256, L"File is not a DWF package [%s]",
00109                         (tInfo.eType == DWFPackageReader::eW2DStream) ? L"W2D Stream" :
00110                         (tInfo.eType == DWFPackageReader::eDWFStream) ? L"DWF Stream (<6.0)" :
00111                         (tInfo.eType == DWFPackageReader::eZIPFile) ? L"ZIP Archive" : L"Unknown" );
00112 
00113             wcout << zBuffer << endl;
00114             exit( 0 );
00115         }
00116 
00117         _DWFCORE_SWPRINTF( zBuffer, 256, L"DWF Package version [%0.2f]", (float)(tInfo.nVersion)/100.0f );
00118         wcout << zBuffer << endl;
00119 
00120         wcout << L"Reading the manifest..." << endl;
00121 
00122         DWFManifest& rManifest = oReader.getManifest();
00123 
00124         _DWFCORE_SWPRINTF( zBuffer, 256, L"\tVersion: %0.2g", rManifest.version() );
00125         wcout << zBuffer << endl;
00126         wcout << L"\tObject ID: " << (const wchar_t*)rManifest.objectID() << endl;
00127 
00128         DWFManifest::tInterfaceIterator* piInterfaces = rManifest.getInterfaces();
00129 
00130         if (piInterfaces)
00131         {
00132             for (;piInterfaces->valid(); piInterfaces->next())
00133             {
00134                 wcout << L"\tInterface found: " << (const wchar_t*)(piInterfaces->value()->name()) << endl;
00135             }
00136 
00137             DWFCORE_FREE_OBJECT( piInterfaces );
00138         }
00139 
00140         DWFProperty* pProperty = NULL;
00141         DWFProperty::tMap::Iterator* piProperties = rManifest.getProperties();
00142 
00143         if (piProperties)
00144         {
00145             for (;piProperties->valid(); piProperties->next())
00146             {
00147                 pProperty = piProperties->value();
00148                 wcout << L"\tProperty found: " << (const wchar_t*)(pProperty->name());
00149 
00150                 if (pProperty->value())
00151                 {
00152                     wcout << L" [" << (const wchar_t*)(pProperty->value()) << L"]";
00153                 }
00154 
00155                 if (pProperty->category())
00156                 {
00157                     wcout << L" [" << (const wchar_t*)(pProperty->category()) << L"]";
00158                 }
00159 
00160                 wcout << endl;
00161             }
00162 
00163             DWFCORE_FREE_OBJECT( piProperties );
00164         }
00165 
00166         DWFSection* pSection = NULL;
00167         DWFManifest::SectionIterator* piSections = rManifest.getSections();
00168 
00169         if (piSections)
00170         {
00171             for (;piSections->valid(); piSections->next())
00172             {
00173                 pSection = piSections->get();
00174 
00175                 //
00176                 // piSections->key() will also return the section name...
00177                 //
00178                 wcout << L"\tSection found: " << (const wchar_t*)(pSection->name());
00179 
00180                 if (pSection->type())
00181                 {
00182                     wcout << L" [" << (const wchar_t*)(pSection->type()) << L"]";
00183                 }
00184 
00185                 if (pSection->title())
00186                 {
00187                     wcout << L" [" << (const wchar_t*)(pSection->title()) << L"]";
00188                 }
00189 
00190                 wcout << endl;
00191             }
00192 
00193             wcout << "Reading section descriptors..." << endl << endl;
00194 
00195             for (piSections->reset(); piSections->valid(); piSections->next())
00196             {
00197                 pSection = piSections->get();
00198 
00199                 pSection->readDescriptor();
00200 
00201                 DWFGlobalSection* pGlobal = dynamic_cast<DWFGlobalSection*>(pSection);
00202 
00203                 if (pGlobal == NULL)
00204                 {
00205                     wcout << L"\t[OK] (" << pSection->order() << L") v" << pSection->version();
00206 
00207                     if (pSection->name())
00208                     {
00209                         wcout << L" [" << (const wchar_t*)(pSection->name()) << L"]";
00210                     }
00211 
00212                     if (pSection->objectID())
00213                     {
00214                         wcout << L" [" << (const wchar_t*)(pSection->objectID()) << L"]";
00215                     }
00216 
00217                     wcout << L" [" << pSection->order() << L"]";
00218 
00219                     wcout << endl;
00220                 }
00221                 else
00222                 {
00223                     wcout << L"\t[OK] (Global Section)" << endl;
00224 
00225                     const DWFBookmark* pRoot = pGlobal->bookmark();
00226                     if (pRoot)
00227                     {
00228                         wcout << L"\tDumping bookmarks..." << endl;
00229                         dump_bookmarks( pRoot );
00230                     }
00231                 }
00232             }
00233 
00234             DWFCORE_FREE_OBJECT( piSections );
00235         }
00236 
00237         wcout << L"OK\n";
00238     }
00239     catch (DWFException& ex)
00240     {
00241         wcout << ex.type() << endl;
00242         wcout << ex.message() << endl;
00243         wcout << ex.function() << endl;
00244         wcout << ex.file() << endl;
00245         wcout << ex.line() << endl;
00246     }
00247 
00248     return 0;
00249 }
00250 
00251 

Generated on Tue Jan 6 22:40:01 2009 for Autodesk DWF Toolkit by  doxygen 1.4.5