Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ResourceContainer.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (c) 1996-2005 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_RESOURCE_CONTAINER_H
00021 #define _DWFTK_RESOURCE_CONTAINER_H
00022 
00027 
00028 #include "dwfcore/Owner.h"
00029 #include "dwfcore/UUID.h"
00030 using namespace DWFCore;
00031 
00032 #include "dwf/Toolkit.h"
00033 #include "dwf/package/Resource.h"
00034 
00035 
00036 namespace DWFToolkit
00037 {
00038 
00049 class DWFResourceContainer : protected DWFOwner
00050 {                            
00051 
00052 public:
00053 
00059     class ResourceIterator : public DWFIterator<DWFResource*>
00060     {
00061 
00062     public:
00063 
00071         ResourceIterator( DWFResource::tMultiMap::iterator iBegin,
00072                           DWFResource::tMultiMap::iterator iEnd )
00073             throw()
00074             : _iBegin( iBegin )
00075             , _iEnd( iEnd )
00076             , _iCurrent( iBegin )
00077         {;}
00078 
00085         ResourceIterator( const ResourceIterator& i )
00086             throw()
00087             : _iBegin( i._iBegin )
00088             , _iEnd( i._iEnd )
00089             , _iCurrent( i._iCurrent )
00090         {;}
00091 
00098         ResourceIterator& operator=( const ResourceIterator& i )
00099             throw()
00100         {
00101             _iBegin = i._iBegin;
00102             _iEnd = i._iEnd;
00103             _iCurrent = i._iCurrent;
00104 
00105             return *this;
00106         }
00107 
00113         virtual ~ResourceIterator()
00114             throw()
00115         {;}
00116 
00120         void reset()
00121             throw()
00122         {
00123             _iCurrent = _iBegin;
00124         }
00125 
00129         bool valid()
00130             throw()
00131         {
00132             return (_iCurrent != _iEnd);
00133         }
00134 
00138         bool next()
00139             throw()
00140         {
00141             if (valid())
00142             {
00143                 _iCurrent++;
00144                 return valid();
00145             }
00146             else
00147             {
00148                 return false;
00149             }
00150         }
00151 
00155         DWFResource*& get()
00156             throw( DWFException )
00157         {
00158             if (valid())
00159             {
00160                 return _iCurrent->second;
00161             }
00162             else
00163             {
00164                 _DWFCORE_THROW( DWFDoesNotExistException, L"No more elements" );
00165             }
00166         }
00167 
00168     private:
00169 
00170         DWFResource::tMultiMap::iterator _iBegin;
00171         DWFResource::tMultiMap::iterator _iEnd;
00172         DWFResource::tMultiMap::iterator _iCurrent;
00173     };
00174 
00180     class ResourceKVIterator : public DWFKVIterator<const wchar_t*, DWFResource*>
00181     {
00182 
00183     public:
00184 
00192         ResourceKVIterator( DWFResource::tMultiMap::iterator iBegin,
00193                             DWFResource::tMultiMap::iterator iEnd )
00194             throw()
00195             : _iBegin( iBegin )
00196             , _iEnd( iEnd )
00197             , _iCurrent( iBegin )
00198         {;}
00199 
00206         ResourceKVIterator( const ResourceKVIterator& i )
00207             throw()
00208             : _iBegin( i._iBegin )
00209             , _iEnd( i._iEnd )
00210             , _iCurrent( i._iCurrent )
00211         {;}
00212 
00219         ResourceKVIterator& operator=( const ResourceKVIterator& i )
00220             throw()
00221         {
00222             _iBegin = i._iBegin;
00223             _iEnd = i._iEnd;
00224             _iCurrent = i._iCurrent;
00225 
00226             return *this;
00227         }
00228 
00234         virtual ~ResourceKVIterator()
00235             throw()
00236         {;}
00237 
00241         void reset()
00242             throw()
00243         {
00244             _iCurrent = _iBegin;
00245         }
00246 
00250         bool valid()
00251             throw()
00252         {
00253             return (_iCurrent != _iEnd);
00254         }
00255 
00259         bool next()
00260             throw()
00261         {
00262             if (valid())
00263             {
00264                 _iCurrent++;
00265                 return valid();
00266             }
00267             else
00268             {
00269                 return false;
00270             }
00271         }
00272 
00276         const wchar_t*& key()
00277             throw( DWFException )
00278         {
00279             if (valid())
00280             {
00281                 return (const wchar_t*&)(_iCurrent->first);
00282             }
00283             else
00284             {
00285                 _DWFCORE_THROW( DWFDoesNotExistException, L"No more elements" );
00286             }
00287         }
00288 
00292         DWFResource*& value()
00293             throw( DWFException )
00294         {
00295             if (valid())
00296             {
00297                 return _iCurrent->second;
00298             }
00299             else
00300             {
00301                 _DWFCORE_THROW( DWFDoesNotExistException, L"No more elements" );
00302             }
00303         }
00304 
00305     private:
00306 
00307         DWFResource::tMultiMap::iterator _iBegin;
00308         DWFResource::tMultiMap::iterator _iEnd;
00309         DWFResource::tMultiMap::iterator _iCurrent;
00310     };
00311 
00312 
00313 
00314 public:
00315 
00324     _DWFTK_API
00325     virtual ~DWFResourceContainer()
00326         throw();
00327 
00334     _DWFTK_API
00335     size_t resourceCount() const
00336         throw();
00337 
00348     _DWFTK_API
00349     DWFResource* findResourceByHREF( const DWFString& zHRef )
00350         throw();
00351 
00364     _DWFTK_API
00365     ResourceIterator* findResourcesByRole( const DWFString& zRole )
00366         throw();
00367 
00380     _DWFTK_API
00381     ResourceIterator* findResourcesByMIME( const DWFString& zMIME )
00382         throw();
00383 
00399     _DWFTK_API
00400     ResourceKVIterator* getResourcesByHREF()
00401         throw();
00402 
00418     _DWFTK_API
00419     ResourceKVIterator* getResourcesByRole()
00420         throw();
00421 
00437     _DWFTK_API
00438     ResourceKVIterator* getResourcesByMIME()
00439         throw();
00440 
00457     _DWFTK_API
00458     DWFResource* removeResource( DWFResource& rResource,
00459                                  bool         bDeleteIfOwned )
00460         throw( DWFException );
00461 
00475     _DWFTK_API
00476     DWFResource* removeResourceByHREF( const DWFString& zHRef,
00477                                        bool             bDeleteIfOwned )
00478         throw( DWFException );
00479 
00493     _DWFTK_API
00494     ResourceIterator* removeResourcesByRole( const DWFString& zRole,
00495                                              bool             bDeleteIfOwned )
00496         throw( DWFException );
00497 
00511     _DWFTK_API
00512     ResourceIterator* removeResourcesByMIME( const DWFString&   zMIME,
00513                                              bool               bDeleteIfOwned )
00514         throw( DWFException );
00515 
00535     _DWFTK_API
00536     DWFResource* addResource( DWFResource*       pResource,
00537                               bool               bOwnResource,
00538                               bool               bReplace = true,
00539                               bool               bDeleteReplacedIfOwned = true,
00540                               const DWFResource* pParentResource = NULL )
00541         throw( DWFException );
00542 
00543 #ifndef DWFTK_READ_ONLY
00544 
00552     DWFXMLSerializable& getSerializable() const
00553         throw()
00554     {
00555         return (DWFXMLSerializable&)_oSerializer;
00556     }
00557 
00558 #endif
00559 
00560 protected:
00561 
00567     _DWFTK_API
00568     DWFResourceContainer()
00569         throw();
00570 
00582     void rename( const DWFString& zName )
00583         throw()
00584     {
00585         _zName = zName;
00586     }
00587 
00591     _DWFTK_API
00592     virtual void notifyOwnerChanged( DWFOwnable& rOwnable )
00593         throw( DWFException );
00594 
00598     _DWFTK_API
00599     virtual void notifyOwnableDeletion( DWFOwnable& rOwnable )
00600         throw( DWFException );
00601 
00602 #ifndef DWFTK_READ_ONLY
00603 
00604 private:
00605 
00606     //
00607     // in order to avoid bizarre diamond patterns and
00608     // excessively overload base implementations,
00609     // all container classes must define and implementation this
00610     // internal [PRIVATE] class utility for serializing themselves into XML.
00611     //
00612     class _Serializer : public DWFXMLSerializable
00613     {
00614 
00615     public:
00616 
00617         _Serializer()
00618             throw()
00619             : DWFXMLSerializable()
00620             , _pContainer( NULL )
00621         {;}
00622 
00623         virtual ~_Serializer()
00624             throw()
00625         {;}
00626 
00627         void is( DWFResourceContainer* pContainer )
00628         {
00629             _pContainer = pContainer;
00630         }
00631 
00632         //
00633         //
00634         //
00635         virtual void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00636             throw( DWFException );
00637 
00638     private:
00639 
00640         DWFResourceContainer* _pContainer;
00641     };
00642 
00643 #endif
00644 
00645 
00646 private:
00647 
00648     DWFResource* _remove( DWFResource* pResource, bool bDeleteIfOwned )
00649         throw();
00650 
00651 protected:
00652 
00656     typedef multimap<const DWFResource*, DWFResource*> tResourcePointerMultiMap;
00657 
00661     DWFUUID                     _oUUID;
00665     DWFResource::tMap           _oResourcesByHREF;
00669     DWFResource::tMultiMap      _oResourcesByRole;
00673     DWFResource::tMultiMap      _oResourcesByMIME;
00677     tResourcePointerMultiMap    _oResourceHierarchy;
00678 
00679 private:
00680 
00681     DWFString                   _zName;
00682 
00683 #ifndef DWFTK_READ_ONLY
00684 
00685     _Serializer                 _oSerializer;
00686 
00687 #endif
00688 
00689 
00690 private:
00691 
00692     DWFResourceContainer( const DWFResourceContainer& );
00693     DWFResourceContainer& operator=( const DWFResourceContainer& );
00694 };
00695 
00696 }
00697 
00698 #endif

Generated on Tue May 17 12:38:51 2005 for Autodesk DWF Toolkit by  doxygen 1.4.1