| 1 | // Aseprite Document Library |
| 2 | // Copyright (c) 2001-2015 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef DOC_OBJECT_H_INCLUDED |
| 8 | #define DOC_OBJECT_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "doc/object_id.h" |
| 12 | #include "doc/object_type.h" |
| 13 | #include "doc/object_version.h" |
| 14 | |
| 15 | namespace doc { |
| 16 | |
| 17 | class Object { |
| 18 | public: |
| 19 | Object(ObjectType type); |
| 20 | Object(const Object& other); |
| 21 | virtual ~Object(); |
| 22 | |
| 23 | const ObjectType type() const { return m_type; } |
| 24 | const ObjectId id() const; |
| 25 | const ObjectVersion version() const { return m_version; } |
| 26 | |
| 27 | void setId(ObjectId id); |
| 28 | void setVersion(ObjectVersion version); |
| 29 | |
| 30 | void incrementVersion() { |
| 31 | ++m_version; |
| 32 | } |
| 33 | |
| 34 | // Returns the approximate amount of memory (in bytes) which this |
| 35 | // object use. |
| 36 | virtual int getMemSize() const; |
| 37 | |
| 38 | private: |
| 39 | ObjectType m_type; |
| 40 | |
| 41 | // Unique identifier for this object (it is assigned by |
| 42 | // Objects class). |
| 43 | mutable ObjectId m_id; |
| 44 | |
| 45 | ObjectVersion m_version; |
| 46 | |
| 47 | // Disable copy assignment |
| 48 | Object& operator=(const Object&); |
| 49 | }; |
| 50 | |
| 51 | Object* get_object(ObjectId id); |
| 52 | |
| 53 | template<typename T> |
| 54 | inline T* get(ObjectId id) { |
| 55 | return static_cast<T*>(get_object(id)); |
| 56 | } |
| 57 | |
| 58 | } // namespace doc |
| 59 | |
| 60 | #endif |
| 61 | |