Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# deResource_Helper.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deResource_Helper.hpp
    00003 ///
    00004 /// @brief Global resource handler, inline implementation header
    00005 ///
    00006 /// @author Assassin
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date May 2004
    00023 /// @author Assassin
    00024 /// @remarks Creation
    00025 ///
    00026 ///////////////////////////////////////////////////////////////////////////////
    00027
    00028 #ifndef DERESOURCE_HELPER_HPP
    00029 #define DERESOURCE_HELPER_HPP
    00030
    00031 #include "deResource.hpp"
    00032
    00033 //=================================================================================
    00034 // deResourceBase Class
    00035 //
    00036 // Middle-man class which all resource handling classes must derive from
    00037 //=================================================================================
    00038
    00039 /// inherit from this class instead of IdeResourceBase to get basic functionality implemented
    00040 class deResourceBase : virtual public IdeResourceBase, public deRefCountBase
    00041 {
    00042 public:
    00043     deBoolean IsDirty(void)
    00044     { return m_Dirty; }
    00045     const char * GetFilename(void)
    00046     { return m_Filename; }
    00047     void GetFilenameBuffer(char * buffer, long buffersize)
    00048     { int len = min(255,buffersize); memcpy(buffer, m_Filename, len); buffer[len] = '\0';}
    00049
    00050     // pure virtual must be overridden
    00051     IdeResourceBase * MakeCopy() = 0;
    00052
    00053     void * GetRscInterface(long interface_id)
    00054     { if (interface_id == 0) { return (IdeResourceBase*)(this); } DEBUGRETURN(NULL, "base GetRscInterface called\nyou need to implement a derived version"); }
    00055 protected:
    00056     virtual ~deResourceBase(void)
    00057     { RemoveMe(); m_HashTable = NULL; }
    00058     deResourceBase(const char * filename)
    00059         : m_Dirty(deFALSE), m_HashTable(NULL), m_Manager(NULL)
    00060     {
    00061         int i;
    00062         for (i = 0; i < 255 && filename[i]; i++)
    00063             m_Filename[i] = filename[i];
    00064         m_Filename[i] = '\0';
    00065     }
    00066     deResourceBase()
    00067         : m_Dirty(deTRUE), m_HashTable(NULL), m_Manager(NULL)
    00068     { m_Filename[0] = '\0'; }
    00069     void SetDirty()
    00070     { m_Dirty = DE_TRUE; }
    00071     deBoolean RemoveMe(void)
    00072     { if (m_Manager) { if(!m_Manager->RemoveResource(this)) return deFALSE;} return deTRUE;  }
    00073
    00074 private:
    00075     char m_Filename[256];
    00076     deBoolean m_Dirty;
    00077     void * m_HashTable;
    00078     IdeResourceManager * m_Manager;
    00079
    00080 private:
    00081     void SetHash(void *HashTable)
    00082     { m_HashTable = HashTable; }
    00083     void SetManager(IdeResourceManager *Manager)
    00084     { m_Manager = Manager; }
    00085     void *GetHash(void)
    00086     { return m_HashTable; }
    00087     IdeResourceManager *GetManager(void)
    00088     { return m_Manager; }
    00089 };
    00090
    00091 #endif  //End: DERESOURCE_HELPER_HPP