Changeset 229 for trunk/nv/resource.hh
- Timestamp:
- 05/06/14 04:59:23 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/resource.hh
r121 r229 23 23 { 24 24 public: 25 typedef std::shared_ptr< resource > ptr; 26 public: 25 resource() : m_size(0), m_rid(0), m_used(0), m_loaded(0), m_data(nullptr) {} 27 26 virtual bool load() = 0; 27 virtual bool initialize() { return true; }; 28 virtual bool destroy() { return true; }; 28 29 virtual bool unload() = 0; 29 30 bool is_loaded() const { return m_loaded; } 30 31 uid get_rid() const { return m_rid; } 31 32 uid get_size() const { return m_size; } 33 const void* get() { return m_data; } 34 void lock() { m_used++; } 35 void unlock() { m_used--; } 32 36 virtual ~resource() {} 33 37 private: 34 38 uint32 m_size; 35 39 uint32 m_rid; 40 uint32 m_used; 36 41 bool m_loaded; 42 void* m_data; 43 }; 44 45 template< class DATA > 46 class resource_type : public resource 47 { 48 public: 49 explicit resource_type( DATA* data ) : m_data( data ) {} 50 virtual bool load() { return true; }; 51 virtual bool unload() { return true; }; 52 ~resource_type() { delete data; } 53 }; 54 55 56 57 template< class DATA > 58 class resource_handle 59 { 60 public: 61 explicit resource_handle( resource_type< DATA >& m_resource ) 62 : m_resource( &a_resource ) { m_resource.lock(); } 63 void assign( resource_type< DATA >& a_resource ) 64 { 65 m_resource.unlock(); 66 m_resource = a_resource; 67 m_resource.lock(); 68 } 69 const DATA* operator->() const { return (const DATA*)m_resource.get(); } 70 ~resource_handle() { m_resource.unlock(); } 71 private: 72 resource& m_resource; 37 73 }; 38 74
Note: See TracChangeset
for help on using the changeset viewer.