hecl
High-Level Extensible Combiner Language and Resource Database
HECLRuntime.hpp
1 #ifndef HECLRUNTIME_HPP
2 #define HECLRUNTIME_HPP
3 
4 #include <memory>
5 #include <vector>
6 #include <atomic>
7 
8 #include "HECL.hpp"
9 
10 namespace HECL
11 {
12 namespace Runtime
13 {
14 
15 class Entity
16 {
17 public:
18  enum Type
19  {
20  ENTITY_NONE,
21  ENTITY_OBJECT,
22  ENTITY_GROUP
23  };
24 
25 private:
26  Type m_type;
27  const std::string& m_path;
28  bool m_loaded = false;
29 
30  friend class Group;
31  friend class ObjectBase;
32  Entity(Type type, const std::string& path)
33  : m_type(type), m_path(path) {}
34 
35 public:
40  inline Type getType() const {return m_type;}
41 
46  inline const std::string& getPath() const {return m_path;}
47 
52  inline bool isLoaded() const {return m_loaded;}
53 };
54 
68 class Group : public Entity
69 {
70 public:
71  typedef std::vector<std::weak_ptr<const class RuntimeObjectBase>> GroupObjectsVector;
72 private:
73  friend class HECLRuntime;
74  GroupObjectsVector m_objects;
75  Group(const std::string& path)
76  : Entity(ENTITY_GROUP, path) {}
77 public:
78  inline const GroupObjectsVector& getObjects() const {return m_objects;}
79 };
80 
90 class ObjectBase : public Entity
91 {
92  std::shared_ptr<const Group> m_parent;
93 protected:
94 
101  virtual bool _objectFinishedLoading(const void* data, size_t len)
102  {(void)data;(void)len;return true;}
103 
107  virtual void _objectWillUnload() {}
108 
109 public:
110  ObjectBase(const Group* group, const std::string& path)
111  : Entity(ENTITY_OBJECT, path), m_parent(group) {}
112 
117  inline const Group* getParentGroup() {return m_parent.get();}
118 };
119 
128 class Runtime
129 {
130 public:
135  Runtime(const SystemString& hlpkDirectory);
136  ~Runtime();
137 
142  {
143  std::atomic_bool done;
144  std::atomic_size_t completedObjects;
145  std::atomic_size_t totalObjects;
146  };
147 
156  std::shared_ptr<Entity> loadSync(const Hash& pathHash);
157 
167  std::shared_ptr<Entity> loadAsync(const Hash& pathHash,
168  SGroupLoadStatus* statusOut=NULL);
169 
170 };
171 
172 }
173 }
174 
175 #endif // HECLRUNTIME_HPP
std::shared_ptr< Entity > loadSync(const Hash &pathHash)
Begin a synchronous group-load transaction.
virtual bool _objectFinishedLoading(const void *data, size_t len)
Optional subclass method called on background thread or in response to interrupt when data is ready...
Definition: HECLRuntime.hpp:101
HLPK Runtime data-management root.
Definition: HECLRuntime.hpp:128
Base object to subclass for integrating with key runtime operations.
Definition: HECLRuntime.hpp:90
const Group * getParentGroup()
Get parent group of object.
Definition: HECLRuntime.hpp:117
std::shared_ptr< Entity > loadAsync(const Hash &pathHash, SGroupLoadStatus *statusOut=NULL)
Begin an asynchronous group-load transaction.
Type getType() const
Get type of runtime object.
Definition: HECLRuntime.hpp:40
Runtime(const SystemString &hlpkDirectory)
Constructs the HECL runtime root.
virtual void _objectWillUnload()
Optional subclass method called in response to reference-count dropping to 0.
Definition: HECLRuntime.hpp:107
Definition: HECLRuntime.hpp:15
Definition: HECL.hpp:24
Structure indicating the load status of an object group.
Definition: HECLRuntime.hpp:141
const std::string & getPath() const
Get database entity path.
Definition: HECLRuntime.hpp:46
bool isLoaded() const
Determine if object is fully loaded and constructed.
Definition: HECLRuntime.hpp:52
Interface representing a load-ordered group of runtime objects.
Definition: HECLRuntime.hpp:68
Hash representation used for all storable and comparable objects.
Definition: HECL.hpp:257