22 #ifndef STARK_RESOURCES_RESOURCE_H 23 #define STARK_RESOURCES_RESOURCE_H 25 #include "common/array.h" 26 #include "common/str.h" 33 class ResourceSerializer;
73 kAnimSoundTrigger = 36,
79 Type(ResourceType type);
81 ResourceType
get()
const;
82 const char *getName()
const;
84 bool operator==(
const Type &other)
const {
85 return other._type == _type;
88 bool operator!=(
const Type &other)
const {
89 return other._type != _type;
92 bool operator==(
const Type::ResourceType other)
const {
93 return other == _type;
96 bool operator!=(
const Type::ResourceType other)
const {
97 return other != _type;
184 virtual void onPostRead();
191 virtual void onAllLoaded();
196 virtual void onEnterLocation();
201 virtual void onGameLoop();
206 virtual void onEnginePause(
bool pause);
211 virtual void onExitLocation();
216 virtual void onPreDestroy();
222 static T *cast(
Object *resource);
229 Object *findChildWithIndex(
Type type, uint16 index,
int subType = -1)
const;
232 Object *findChildWithOrder(
Type type, uint16 order,
int subType = -1)
const;
239 T *findChild(
bool mustBeUnique =
true)
const;
243 T *findChildWithSubtype(
int subType,
bool mustBeUnique =
true)
const;
247 T *findChildWithIndex(uint16 index,
int subType = -1)
const;
251 T *findChildWithOrder(uint16 order,
int subType = -1)
const;
255 T *findChildWithName(
const Common::String &name,
int subType = -1)
const;
266 void addChild(
Object *child);
269 virtual void print(uint depth = 0);
274 void printWithDepth(uint depth,
const Common::String &
string)
const;
275 void printDescription(uint depth)
const;
276 virtual void printData();
300 void printData()
override;
308 if (resource && resource->_type != T::TYPE) {
309 error(
"Unexpected resource type when casting resource %s instead of %s",
310 resource->_type.getName(),
Type(T::TYPE).getName());
313 return (T *) resource;
320 T *Object::findParent() {
321 if (getType() == T::TYPE) {
322 return cast<T>(
this);
323 }
else if (!_parent) {
331 Object *Object::findParent();
337 for (uint i = 0; i < _children.size(); i++) {
338 if (_children[i]->getType() == T::TYPE
339 && (_children[i]->getSubType() == subType || subType == -1)) {
341 list.
push_back(Object::cast<T>(_children[i]));
352 for (uint i = 0; i < _children.size(); i++) {
353 if (_children[i]->getType() == T::TYPE
354 && (_children[i]->getSubType() == subType || subType == -1)) {
356 list.
push_back(Object::cast<T>(_children[i]));
360 list.
push_back(_children[i]->listChildrenRecursive<T>(subType));
370 T *Object::findChild(
bool mustBeUnique)
const {
371 return findChildWithSubtype<T>(-1, mustBeUnique);
375 T *Object::findChildWithSubtype(
int subType,
bool mustBeUnique)
const {
382 if (list.
size() > 1 && mustBeUnique) {
383 error(
"Several children resources matching criteria type = %s, subtype = %d",
Type(T::TYPE).getName(), subType);
390 T *Object::findChildWithIndex(uint16 index,
int subType)
const {
391 return Object::cast<T>(findChildWithIndex(T::TYPE, index, subType));
395 T *Object::findChildWithOrder(uint16 order,
int subType)
const {
396 return Object::cast<T>(findChildWithOrder(T::TYPE, order, subType));
401 return Object::cast<T>(findChildWithName(T::TYPE, name, subType));
407 #endif // STARK_RESOURCES_RESOURCE_H
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Common::String getIndexAsString() const
Definition: object.h:157
Common::String getName() const
Definition: object.h:160
T & front()
Definition: array.h:217
bool empty() const
Definition: array.h:351
void push_back(const T &element)
Definition: array.h:180
T * findParent()
Definition: object.h:320
size_type size() const
Definition: array.h:315
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
byte getSubType() const
Definition: object.h:151
Type getType() const
Definition: object.h:148
Definition: stateprovider.h:51
uint16 getIndex() const
Definition: object.h:154