DefinedObject.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-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, AS TO THE CORRECTNESS
00008 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00009 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00010 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00011 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00012 //
00013 //  Use, duplication, or disclosure by the U.S. Government is subject to
00014 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00015 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00016 //  Data and Computer Software), as applicable.
00017 //
00018 
00019 
00020 #ifndef _DWFTK_DEFINED_OBJECT_H
00021 #define _DWFTK_DEFINED_OBJECT_H
00022 
00027 
00028 
00029 #include "dwfcore/STL.h"
00030 #include "dwfcore/SkipList.h"
00031 using namespace DWFCore;
00032 
00033 #include "dwf/Toolkit.h"
00034 #include "dwf/package/XML.h"
00035 #include "dwf/package/reader/PackageReader.h"
00036 #include "dwf/package/utility/PropertyContainer.h"
00037 
00038 namespace DWFToolkit
00039 {
00040 
00041 //
00042 // fwd decl
00043 //
00044 class DWFDefinedObjectInstance;
00045 
00055 // TODO: Find a more global home for this.
00056 //
00057 template <class Key, class Value, typename Comp=tDWFCompareLess<Key> >
00058 class DWFSTDMap : public _DWFTK_STD_MAP_COMP(Key, Value, Comp)
00059 {
00060 public:
00061     typedef typename _DWFTK_STD_MAP_COMP(Key, Value, Comp)   _tMapType;
00062     typedef typename _tMapType::iterator                     _tMapIteratorType;
00063 
00069     class Iterator : public DWFIterator<Value>
00070                      _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00071     {
00072 
00073     public:
00074 
00082         Iterator( _tMapIteratorType iBegin,
00083                   _tMapIteratorType iEnd )
00084             throw()
00085             : _imBegin( iBegin )
00086             , _imEnd( iEnd )
00087             , _imCurrent( iBegin )
00088         {;}
00089 
00095         virtual ~Iterator()
00096             throw()
00097         {;}
00098 
00102         void reset()
00103             throw()
00104         {
00105                     _imCurrent = _imBegin;
00106         }
00107 
00111         bool valid()
00112             throw()
00113         {
00114             return (_imCurrent != _imEnd);
00115         }
00116 
00120         bool next()
00121             throw()
00122         {
00123             if (valid())
00124             {
00125                             _imCurrent++;
00126 
00127                 return valid();
00128             }
00129             else
00130             {
00131                 return false;
00132             }
00133         }
00134 
00138         Value& get()
00139             throw( DWFException )
00140         {
00141             if (valid())
00142             {
00143                 return _imCurrent->second;
00144             }
00145             else
00146             {
00147                 _DWFCORE_THROW( DWFDoesNotExistException, /*NOXLATE*/L"No more elements" );
00148             }
00149         }
00150 
00151         //
00152         // Provided for backwards compatibility with the old skip-list based Iterator.
00153         //
00154         Value& value()
00155             throw( DWFException )
00156         {
00157             return get();
00158         }
00159 
00160     private:
00161 
00162         _tMapIteratorType _imBegin;
00163         _tMapIteratorType _imEnd;
00164         _tMapIteratorType _imCurrent;
00165     };
00166 
00167 public:
00168 
00169     Iterator* getIterator()
00170     {
00171         return DWFCORE_ALLOC_OBJECT( Iterator( this->begin(), this->end() ) );
00172     }
00173 };
00174 
00175 
00199 class DWFDefinedObject : public DWFXMLBuildable
00200 
00201 #ifndef DWFTK_READ_ONLY
00202                        , public DWFXMLSerializable
00203 #endif
00204                        , public DWFPropertyContainer
00205                        _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00206 {
00207 
00208 public:
00209 
00213     typedef _DWFTK_STD_VECTOR(DWFDefinedObject*)    tList;
00214 
00221         typedef DWFSTDMap<const wchar_t*, DWFDefinedObject*, tDWFWCharCompareLess> tMap;
00222 
00226     typedef DWFStringVectorIterator< _DWFTK_STL_ALLOCATOR< DWFString > >     _tStringVectorIterator;
00227 
00228 
00229 public:
00230 
00238     _DWFTK_API
00239     DWFDefinedObject( const DWFString& zID = /*NOXLATE*/L"" )
00240         throw();
00241 
00247     _DWFTK_API
00248     virtual ~DWFDefinedObject()
00249         throw();
00250 
00257     _DWFTK_API
00258     const DWFString& id() const
00259         throw();
00260 
00268     _DWFTK_API
00269     void identify( const DWFString& zID )
00270         throw();
00271 
00283     _DWFTK_API
00284     DWFDefinedObjectInstance* instance( const DWFString& zNode )
00285         throw( DWFException );
00286 
00304     _DWFTK_API
00305     DWFDefinedObjectInstance* getInstance( const DWFString& zNode )
00306         throw( DWFException );
00307 
00321     _DWFTK_API
00322     void removeInstance( const DWFString& zNode )
00323         throw( DWFException );
00324 
00342     _DWFTK_API
00343     DWFIterator<DWFString>* getPropertyRefs()
00344         throw();
00345 
00361     _DWFTK_API
00362     void addPropertyReference( const char* zReferenceID )
00363         throw( DWFException );
00364 
00376 
00379     _DWFTK_API
00380     void addChild( DWFDefinedObject* pChild, uint32_t nKey = 0 )
00381         throw();
00382 
00386     _DWFTK_API
00387     virtual void parseAttributeList( const char** ppAttributeList )
00388         throw( DWFException );
00389 
00390 #ifndef DWFTK_READ_ONLY
00391 
00395     _DWFTK_API
00396     virtual void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00397         throw( DWFException );
00398 
00399 #endif
00400 
00401 protected:
00402 
00406     DWFString               _zID;
00407 
00408     typedef _DWFTK_STD_VECTOR(DWFString) _tStringList;
00413    _tStringList  _oPropertyRefs;
00414 
00419     DWFDefinedObject::tMap  _oInstances;
00420 
00424     typedef std::multimap<uint32_t, DWFDefinedObject*>   _tGroupedChildMap;
00425 
00429     _tGroupedChildMap       _oChildren;
00430 
00431 private:
00432 
00433     DWFDefinedObject( const DWFDefinedObject& );
00434     DWFDefinedObject& operator=( const DWFDefinedObject& );
00435 };
00436 
00457 class DWFDefinedObjectInstance : public DWFDefinedObject
00458                                  _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00459 {
00460 
00461 
00462 public:
00463 
00467     typedef _DWFTK_STD_VECTOR(DWFDefinedObjectInstance*)    tList;
00474         typedef DWFSTDMap<const wchar_t*, DWFDefinedObjectInstance*, tDWFWCharCompareLess> tMap;
00475 
00476 
00477 public:
00478 
00485     _DWFTK_API
00486     DWFDefinedObjectInstance( unsigned long nSequence )
00487         throw();
00488 
00496     _DWFTK_API
00497     DWFDefinedObjectInstance( DWFDefinedObject& rObject,
00498                               const DWFString&  zNode )
00499         throw();
00500 
00506     _DWFTK_API
00507     virtual ~DWFDefinedObjectInstance()
00508         throw();
00509 
00516     _DWFTK_API
00517     const DWFString& node() const
00518         throw();
00519 
00526     _DWFTK_API
00527     const DWFString& object() const
00528         throw();
00529 
00536     _DWFTK_API
00537     unsigned long sequence() const
00538         throw();
00539 
00548     _DWFTK_API
00549     DWFIterator<DWFString>* children()
00550         throw();
00551 
00566     _DWFTK_API
00567     void addChild( DWFDefinedObjectInstance* pChild, uint32_t nKey = 0 )
00568         throw();
00569 
00578     _DWFTK_API
00579     void resolveObject( DWFDefinedObject* pObject )
00580         throw();
00581 
00589     _DWFTK_API
00590     void resolveChild( DWFDefinedObjectInstance* pInstance )
00591         throw();
00592 
00600     _DWFTK_API
00601     void resolveParent( DWFDefinedObjectInstance* pInstance )
00602         throw();
00603 
00612     _DWFTK_API
00613     DWFDefinedObject* resolvedObject() const
00614         throw();
00615 
00624     _DWFTK_API
00625     DWFDefinedObjectInstance* resolvedParent() const
00626         throw();
00627 
00638     _DWFTK_API
00639     DWFDefinedObjectInstance::tMap::Iterator* resolvedChildren()
00640         throw();
00641 
00645     _DWFTK_API
00646     virtual void parseAttributeList( const char** ppAttributeList )
00647         throw( DWFException );
00648 
00649 #ifndef DWFTK_READ_ONLY
00650 
00654     _DWFTK_API
00655     virtual void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00656         throw( DWFException );
00657 
00658 #endif
00659 
00660 private:
00661 
00662     unsigned long           _nSequence;
00663 
00664     DWFString               _zNode;
00665     DWFString               _zObject;
00666     typedef _DWFTK_STD_VECTOR(DWFString)  _tStringList;
00667     _tStringList  _oChildIDs;
00668 
00669     typedef std::multimap<uint32_t, DWFDefinedObjectInstance*>   _tGroupedChildMap;
00670     _tGroupedChildMap       _oChildren;
00671 
00672     DWFDefinedObject*                       _pResolvedObject;
00673     DWFDefinedObjectInstance*               _pResolvedParent;
00674     DWFDefinedObjectInstance::tMap          _oResolvedChildren;
00675 
00676 private:
00677 
00678     DWFDefinedObjectInstance( const DWFDefinedObjectInstance& );
00679     DWFDefinedObjectInstance& operator=( const DWFDefinedObjectInstance& );
00680 };
00681 
00682 
00683 
00684 }
00685 
00686 #endif

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