up-to-date submodule(rive-cpp)
[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> bool is() const { return isTypeOf(T::typeKey); }
23                 template <typename T> T* as()
24                 {
25                         assert(is<T>());
26                         return reinterpret_cast<T*>(this);
27                 }
28
29                 template <typename T> const T* as() const
30                 {
31                         assert(is<T>());
32                         return reinterpret_cast<const T*>(this);
33                 }
34
35                 /// Called when the object is first added to the context, other objects
36                 /// may not have resolved their dependencies yet. This is an opportunity
37                 /// to look up objects referenced by id, but not assume that they in
38                 /// turn have resolved their references yet. Called during
39                 /// load/instance.
40                 virtual StatusCode onAddedDirty(CoreContext* context) = 0;
41
42                 /// Called when all the objects in the context have had onAddedDirty
43                 /// called. This is an opportunity to reference things referenced by
44                 /// dependencies. (A path should be able to find a Shape somewhere in
45                 /// its hierarchy, which may be multiple levels up).
46                 virtual StatusCode onAddedClean(CoreContext* context) = 0;
47
48                 virtual StatusCode import(ImportStack& importStack)
49                 {
50                         return StatusCode::Ok;
51                 }
52         };
53 } // namespace rive
54 #endif