ResourceContainer.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 //  $Header: //DWF/Development/Components/Internal/DWF Toolkit/v7.6/develop/global/src/dwf/package/utility/ResourceContainer.h#3 $
00019 //  $DateTime: 2008/12/08 16:56:35 $
00020 //  $Author: gaoje $
00021 //  $Change: 125617 $
00022 //  $Revision: #3 $
00023 //
00024 
00025 
00026 
00027 #ifndef _DWFTK_RESOURCE_CONTAINER_H
00028 #define _DWFTK_RESOURCE_CONTAINER_H
00029 
00034 
00035 #include "dwfcore/Owner.h"
00036 #include "dwfcore/UUID.h"
00037 using namespace DWFCore;
00038 
00039 #include "dwf/Toolkit.h"
00040 #include "dwf/package/Resource.h"
00041 
00042 
00043 namespace DWFToolkit
00044 {
00045 
00056 class DWFResourceContainer  : protected DWFOwner
00057                             , public DWFResource::NotificationSink
00058                             _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00059 {
00060 
00061 public:
00062 
00068     class ResourceIterator : public DWFIterator<DWFResource*>
00069                              _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00070     {
00071 
00072     public:
00073 
00081         ResourceIterator( DWFResource::tMultiMap::iterator iBegin,
00082                           DWFResource::tMultiMap::iterator iEnd )
00083             throw()
00084             : _iBegin( iBegin )
00085             , _iEnd( iEnd )
00086             , _iCurrent( iBegin )
00087         {;}
00088 
00095         ResourceIterator( const ResourceIterator& i )
00096             throw()
00097             : _iBegin( i._iBegin )
00098             , _iEnd( i._iEnd )
00099             , _iCurrent( i._iCurrent )
00100         {;}
00101 
00108         ResourceIterator& operator=( const ResourceIterator& i )
00109             throw()
00110         {
00111             _iBegin = i._iBegin;
00112             _iEnd = i._iEnd;
00113             _iCurrent = i._iCurrent;
00114 
00115             return *this;
00116         }
00117 
00123         virtual ~ResourceIterator()
00124             throw()
00125         {;}
00126 
00130         void reset()
00131             throw()
00132         {
00133             _iCurrent = _iBegin;
00134         }
00135 
00139         bool valid()
00140             throw()
00141         {
00142             return (_iCurrent != _iEnd);
00143         }
00144 
00148         bool next()
00149             throw()
00150         {
00151             if (valid())
00152             {
00153                 _iCurrent++;
00154                 return valid();
00155             }
00156             else
00157             {
00158                 return false;
00159             }
00160         }
00161 
00165         DWFResource*& get()
00166             throw( DWFException )
00167         {
00168             if (valid())
00169             {
00170                 return _iCurrent->second;
00171             }
00172             else
00173             {
00174                 _DWFCORE_THROW( DWFDoesNotExistException, /*NOXLATE*/L"No more elements" );
00175             }
00176         }
00177 
00178     private:
00179 
00180         DWFResource::tMultiMap::iterator _iBegin;
00181         DWFResource::tMultiMap::iterator _iEnd;
00182         DWFResource::tMultiMap::iterator _iCurrent;
00183     };
00184 
00190     class ResourceKVIterator : public DWFKVIterator<const wchar_t*, DWFResource*>
00191                                _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00192     {
00193 
00194     public:
00195 
00203         ResourceKVIterator( DWFResource::tMultiMap::iterator iBegin,
00204                             DWFResource::tMultiMap::iterator iEnd )
00205             throw()
00206             : _iBegin( iBegin )
00207             , _iEnd( iEnd )
00208             , _iCurrent( iBegin )
00209         {;}
00210 
00217         ResourceKVIterator( const ResourceKVIterator& i )
00218             throw()
00219             : _iBegin( i._iBegin )
00220             , _iEnd( i._iEnd )
00221             , _iCurrent( i._iCurrent )
00222         {;}
00223 
00230         ResourceKVIterator& operator=( const ResourceKVIterator& i )
00231             throw()
00232         {
00233             _iBegin = i._iBegin;
00234             _iEnd = i._iEnd;
00235             _iCurrent = i._iCurrent;
00236 
00237             return *this;
00238         }
00239 
00245         virtual ~ResourceKVIterator()
00246             throw()
00247         {;}
00248 
00252         void reset()
00253             throw()
00254         {
00255             _iCurrent = _iBegin;
00256         }
00257 
00261         bool valid()
00262             throw()
00263         {
00264             return (_iCurrent != _iEnd);
00265         }
00266 
00270         bool next()
00271             throw()
00272         {
00273             if (valid())
00274             {
00275                 _iCurrent++;
00276                 return valid();
00277             }
00278             else
00279             {
00280                 return false;
00281             }
00282         }
00283 
00287         const wchar_t*& key()
00288             throw( DWFException )
00289         {
00290             if (valid())
00291             {
00292                 return (const wchar_t*&)(_iCurrent->first);
00293             }
00294             else
00295             {
00296                 _DWFCORE_THROW( DWFDoesNotExistException, /*NOXLATE*/L"No more elements" );
00297             }
00298         }
00299 
00303         DWFResource*& value()
00304             throw( DWFException )
00305         {
00306             if (valid())
00307             {
00308                 return _iCurrent->second;
00309             }
00310             else
00311             {
00312                 _DWFCORE_THROW( DWFDoesNotExistException, /*NOXLATE*/L"No more elements" );
00313             }
00314         }
00315 
00316     private:
00317 
00318         DWFResource::tMultiMap::iterator _iBegin;
00319         DWFResource::tMultiMap::iterator _iEnd;
00320         DWFResource::tMultiMap::iterator _iCurrent;
00321     };
00322 
00323 
00324 
00325 public:
00326 
00335     _DWFTK_API
00336     virtual ~DWFResourceContainer()
00337         throw();
00338 
00345     _DWFTK_API
00346     size_t resourceCount() const
00347         throw();
00348 
00359     _DWFTK_API
00360     DWFResource* findResourceByHREF( const DWFString& zHRef )
00361         throw();
00362 
00370     _DWFTK_API
00371     DWFResource* findResourceByObjectID( const DWFString& zObjectID)
00372         throw();
00373 
00374 
00387     _DWFTK_API
00388     ResourceIterator* findResourcesByRole( const DWFString& zRole )
00389         throw();
00390 
00403     _DWFTK_API
00404     ResourceIterator* findResourcesByMIME( const DWFString& zMIME )
00405         throw();
00406 
00422     _DWFTK_API
00423     ResourceKVIterator* getResourcesByHREF()
00424         throw();
00425 
00426     //
00427     // Returns all resources in a key-value iterator
00428     // where the key is the ObjectID of the resource
00429     //
00430     _DWFTK_API
00431     ResourceKVIterator* getResourcesByObjectID()
00432         throw();
00433 
00449     _DWFTK_API
00450     ResourceKVIterator* getResourcesByRole()
00451         throw();
00452 
00468     _DWFTK_API
00469     ResourceKVIterator* getResourcesByMIME()
00470         throw();
00471 
00488     _DWFTK_API
00489     DWFResource* removeResource( DWFResource& rResource,
00490                                  bool         bDeleteIfOwned )
00491         throw( DWFException );
00492 
00506     _DWFTK_API
00507     DWFResource* removeResourceByHREF( const DWFString& zHRef,
00508                                        bool             bDeleteIfOwned )
00509         throw( DWFException );
00510 
00511     //
00512     // Clears the resource from the container
00513     // The caller now owns the resource and is responsible for deleting it,
00514     // unless bDeleteIfOwned and this container does own the resource,
00515     // in which case, the pointer will be freed and NULL is returned
00516     //
00517     _DWFTK_API
00518     DWFResource* removeResourceByObjectID( const DWFString& zObjectID,
00519                                            bool             bDeleteIfOwned )
00520         throw( DWFException );
00521 
00535     _DWFTK_API
00536         virtual ResourceIterator* removeResourcesByRole( const DWFString& zRole,
00537                                              bool             bDeleteIfOwned )
00538         throw( DWFException );
00539 
00553     _DWFTK_API
00554     ResourceIterator* removeResourcesByMIME( const DWFString&   zMIME,
00555                                              bool               bDeleteIfOwned )
00556         throw( DWFException );
00557 
00577     _DWFTK_API
00578     virtual DWFResource* addResource( DWFResource*       pResource,
00579                                       bool               bOwnResource,
00580                                       bool               bReplace = true,
00581                                       bool               bDeleteReplacedIfOwned = true,
00582                                       const DWFResource* pParentResource = NULL )
00583         throw( DWFException );
00584 
00588     _DWFTK_API
00589     virtual void onBeforeResourceHRefChanged( DWFResource* pResource )
00590         throw();
00591 
00595     _DWFTK_API
00596     virtual void onAfterResourceHRefChanged( DWFResource* pResource )
00597         throw();
00598 
00599 
00600 #ifndef DWFTK_READ_ONLY
00601 
00609     DWFXMLSerializable& getSerializable() const
00610         throw()
00611     {
00612         return (DWFXMLSerializable&)_oSerializer;
00613     }
00614 
00615 #endif
00616 
00617 protected:
00618 
00624     _DWFTK_API
00625     DWFResourceContainer()
00626         throw();
00627 
00639     void rename( const DWFString& zName )
00640         throw()
00641     {
00642         _zName = zName;
00643     }
00644 
00648     _DWFTK_API
00649     virtual void notifyOwnerChanged( DWFOwnable& rOwnable )
00650         throw( DWFException );
00651 
00655     _DWFTK_API
00656     virtual void notifyOwnableDeletion( DWFOwnable& rOwnable )
00657         throw( DWFException );
00658 
00659 #ifndef DWFTK_READ_ONLY
00660 
00661 private:
00662 
00663     //
00664     // in order to avoid bizarre diamond patterns and
00665     // excessively overload base implementations,
00666     // all container classes must define and implementation this
00667     // internal [PRIVATE] class utility for serializing themselves into XML.
00668     //
00669     class _Serializer : public DWFXMLSerializable
00670                         _DWFTK_EXPORT_API_MEMORY_CONTROL_BASE_MEMBER
00671     {
00672 
00673     public:
00674 
00675         _Serializer()
00676             throw()
00677             : DWFXMLSerializable()
00678             , _pContainer( NULL )
00679         {;}
00680 
00681         virtual ~_Serializer()
00682             throw()
00683         {;}
00684 
00685         void is( DWFResourceContainer* pContainer )
00686         {
00687             _pContainer = pContainer;
00688         }
00689 
00690         //
00691         //
00692         //
00693         virtual void serializeXML( DWFXMLSerializer& rSerializer, unsigned int nFlags )
00694             throw( DWFException );
00695 
00696     private:
00697 
00698         DWFResourceContainer* _pContainer;
00699     };
00700 
00701 #endif
00702 
00703 
00704 protected:
00705 
00706     virtual DWFResource* _remove( DWFResource* pResource, bool bDeleteIfOwned )
00707         throw();
00708 
00709 protected:
00710 
00714     typedef std::multimap<const DWFResource*, DWFResource*> tResourcePointerMultiMap;
00715 
00719     DWFUUID                     _oUUID;
00723     DWFResource::tMap           _oResourcesByHREF;
00724     DWFResource::tMap           _oResourcesByObjectID;
00725     DWFResource::tMultiMap      _oResourcesByRole;
00729     DWFResource::tMultiMap      _oResourcesByMIME;
00733     tResourcePointerMultiMap    _oResourceHierarchy;
00734 
00735 private:
00736 
00737     DWFString                   _zName;
00738 
00739 #ifndef DWFTK_READ_ONLY
00740 
00741     _Serializer                 _oSerializer;
00742 
00743 #endif
00744 
00745 
00746 private:
00747 
00748     DWFResourceContainer( const DWFResourceContainer& );
00749     DWFResourceContainer& operator=( const DWFResourceContainer& );
00750 };
00751 
00752 }
00753 
00754 #endif

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