2014-03-13 06:25:09 +08:00
|
|
|
// Aseprite Document Library
|
2015-01-19 09:05:33 +08:00
|
|
|
// Copyright (c) 2001-2015 David Capello
|
2014-03-13 06:25:09 +08:00
|
|
|
//
|
2014-03-30 07:08:05 +08:00
|
|
|
// This file is released under the terms of the MIT license.
|
|
|
|
|
// Read LICENSE.txt for more information.
|
2014-03-13 06:25:09 +08:00
|
|
|
|
|
|
|
|
#ifndef DOC_OBJECT_H_INCLUDED
|
|
|
|
|
#define DOC_OBJECT_H_INCLUDED
|
2014-03-30 06:40:17 +08:00
|
|
|
#pragma once
|
2014-03-13 06:25:09 +08:00
|
|
|
|
|
|
|
|
#include "doc/object_id.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/object_type.h"
|
2014-03-13 06:25:09 +08:00
|
|
|
|
|
|
|
|
namespace doc {
|
|
|
|
|
|
2015-04-08 04:53:31 +08:00
|
|
|
typedef uint32_t ObjectVersion;
|
|
|
|
|
|
2014-03-13 06:25:09 +08:00
|
|
|
class Object {
|
|
|
|
|
public:
|
2014-10-21 09:21:31 +08:00
|
|
|
Object(ObjectType type);
|
2015-01-19 09:05:33 +08:00
|
|
|
Object(const Object& other);
|
2014-07-29 11:53:24 +08:00
|
|
|
virtual ~Object();
|
2014-03-13 06:25:09 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
const ObjectType type() const { return m_type; }
|
2015-01-19 09:05:33 +08:00
|
|
|
const ObjectId id() const;
|
2015-04-08 04:53:31 +08:00
|
|
|
const ObjectVersion version() const { return m_version; }
|
2014-03-13 06:25:09 +08:00
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
void setId(ObjectId id);
|
2015-04-08 04:53:31 +08:00
|
|
|
void setVersion(ObjectVersion version);
|
|
|
|
|
|
|
|
|
|
void incrementVersion() {
|
|
|
|
|
++m_version;
|
|
|
|
|
}
|
2014-03-13 06:25:09 +08:00
|
|
|
|
2014-10-21 09:21:31 +08:00
|
|
|
// Returns the approximate amount of memory (in bytes) which this
|
|
|
|
|
// object use.
|
|
|
|
|
virtual int getMemSize() const;
|
|
|
|
|
|
2014-03-13 06:25:09 +08:00
|
|
|
private:
|
2014-10-21 09:21:31 +08:00
|
|
|
ObjectType m_type;
|
|
|
|
|
|
2014-03-13 06:25:09 +08:00
|
|
|
// Unique identifier for this object (it is assigned by
|
|
|
|
|
// Objects class).
|
2015-01-19 09:05:33 +08:00
|
|
|
mutable ObjectId m_id;
|
|
|
|
|
|
2015-04-08 04:53:31 +08:00
|
|
|
ObjectVersion m_version;
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
// Disable copy assignment
|
|
|
|
|
Object& operator=(const Object&);
|
2014-03-13 06:25:09 +08:00
|
|
|
};
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
Object* get_object(ObjectId id);
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
inline T* get(ObjectId id) {
|
|
|
|
|
return static_cast<T*>(get_object(id));
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 06:25:09 +08:00
|
|
|
} // namespace doc
|
|
|
|
|
|
|
|
|
|
#endif
|