[Adaptation Layer] Added rive-tizen adaptation layer class.
[platform/core/uifw/rive-tizen.git] / submodule / include / core.hpp
1 #ifndef _RIVE_CORE_HPP_
2 #define _RIVE_CORE_HPP_
3
4 #include "core/binary_reader.hpp"
5 #include "status_code.hpp"
6 #include <cassert>
7
8 namespace rive
9 {
10         class CoreContext;
11         class ImportStack;
12         class Core
13         {
14         public:
15                 static const int invalidPropertyKey = 0;
16                 virtual ~Core() {}
17                 virtual uint16_t coreType() const = 0;
18                 virtual bool isTypeOf(uint16_t typeKey) const = 0;
19                 virtual bool deserialize(uint16_t propertyKey,
20                                          BinaryReader& reader) = 0;
21
22                 template <typename T> inline bool is() const
23                 {
24                         return isTypeOf(T::typeKey);
25                 }
26                 template <typename T> inline T* as()
27                 {
28                         assert(is<T>());
29                         return reinterpret_cast<T*>(this);
30                 }
31
32                 virtual Core* clone() const { return nullptr; }
33
34                 template <typename T> inline const T* as() const
35                 {
36                         assert(is<T>());
37                         return reinterpret_cast<const T*>(this);
38                 }
39
40                 /// Called when the object is first added to the context, other objects
41                 /// may not have resolved their dependencies yet. This is an opportunity
42                 /// to look up objects referenced by id, but not assume that they in
43                 /// turn have resolved their references yet. Called during
44                 /// load/instance.
45                 virtual StatusCode onAddedDirty(CoreContext* context)
46                 {
47                         return StatusCode::Ok;
48                 }
49
50                 /// Called when all the objects in the context have had onAddedDirty
51                 /// called. This is an opportunity to reference things referenced by
52                 /// dependencies. (A path should be able to find a Shape somewhere in
53                 /// its hierarchy, which may be multiple levels up).
54                 virtual StatusCode onAddedClean(CoreContext* context)
55                 {
56                         return StatusCode::Ok;
57                 }
58
59                 virtual StatusCode import(ImportStack& importStack)
60                 {
61                         return StatusCode::Ok;
62                 }
63         };
64 } // namespace rive
65 #endif