SmartHandle.h

Go to the documentation of this file.
00001 //
00002 // Copyright 2010 Autodesk, Inc.  All rights reserved.
00003 //
00004 // Use of this software is subject to the terms of the Autodesk license
00005 // agreement provided at the time of installation or download, or which 
00006 // otherwise accompanies this software in either electronic or hard copy form.   
00007 //
00008 //
00009 
00010 #pragma once
00011 
00012 #include "./GraphicsDriverExport.h"
00013 #include "./Types.h"
00014 
00015 #include "../MaxHeap.h"
00016 #include "../Noncopyable.h"
00017 
00018 namespace MaxSDK { namespace Graphics {
00019 
00027 class SmartHandle : public MaxSDK::Util::Noncopyable
00028 {
00029 public:
00032     GraphicsDriverAPI virtual ~SmartHandle();
00033 
00037     GraphicsDriverAPI bool IsValid() const;
00038     
00042     GraphicsDriverAPI void Release();
00043 
00046     GraphicsDriverAPI Identifier GetObjectID() const;
00047 
00048     // This function is internally used only.
00049     GraphicsDriverAPI void SetPointer(void* pObject);
00050 
00053     GraphicsDriverAPI void* GetPointer() const;
00054 
00055     // comparison operators
00056     inline bool operator == (const SmartHandle& rhs) const {
00057         return mpObject == rhs.mpObject;
00058     }
00059 
00060     inline bool operator != (const SmartHandle& rhs) const {
00061         return mpObject != rhs.mpObject;
00062     }
00063 
00064     inline bool operator < (const SmartHandle& rhs) const {
00065         return mpObject < rhs.mpObject;
00066     }
00067 
00068     inline bool operator <= (const SmartHandle& rhs) const {
00069         return mpObject <= rhs.mpObject;
00070     }
00071 
00072     inline bool operator > (const SmartHandle& rhs) const {
00073         return mpObject > rhs.mpObject;
00074     }
00075 
00076     inline bool operator >= (const SmartHandle& rhs) const {
00077         return mpObject >= rhs.mpObject;
00078     }
00079 
00080 protected:
00081     // protected to keep the class from getting created directly. handle defaults to undefined
00082     GraphicsDriverAPI SmartHandle();
00083 
00084     // the object that this interface reference to. It is used to avoid accessing driver
00085     // every time you want to modify the object.
00086     void* mpObject;
00087 
00088 private:
00089     SmartHandle(const SmartHandle&);
00090     SmartHandle& operator = (const SmartHandle&);
00091 
00092     void AddRef();
00093 };
00094 
00095 } } // end namespace