2021-08-21 13:53:23 +02:00
|
|
|
#ifndef RESOURCE_H
|
|
|
|
#define RESOURCE_H
|
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
#include "core/containers/vector.h"
|
2021-11-01 19:53:35 +01:00
|
|
|
#include "core/string.h"
|
2021-08-21 14:40:30 +02:00
|
|
|
|
2021-08-21 17:12:48 +02:00
|
|
|
#include "rapidjson/document.h"
|
2021-11-13 11:19:05 +01:00
|
|
|
#include "reference.h"
|
2021-08-21 17:12:48 +02:00
|
|
|
|
2021-08-21 14:40:30 +02:00
|
|
|
#if DATABASES_ENABLED
|
|
|
|
class Database;
|
2021-11-13 11:19:05 +01:00
|
|
|
class QueryBuilder;
|
2021-08-21 14:40:30 +02:00
|
|
|
#endif
|
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
//Based on Godot Engine's object method_bind initializers
|
|
|
|
#define RCPP_RESOURCE(m_class, m_inherits) \
|
|
|
|
public: \
|
|
|
|
static ResourcePropertyDB properties; \
|
|
|
|
\
|
|
|
|
static void initialize_class(ResourcePropertyDB *pdb = nullptr) { \
|
|
|
|
\
|
|
|
|
if (pdb == nullptr) { \
|
|
|
|
pdb = &m_class::properties; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
m_inherits::initialize_class(pdb); \
|
|
|
|
\
|
|
|
|
if (m_class::_get_bind_properties() != m_inherits::_get_bind_properties()) { \
|
|
|
|
_bind_properties(pdb); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
protected: \
|
|
|
|
inline static void (*_get_bind_properties())() { \
|
|
|
|
return &m_class::_bind_properties; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
private:
|
|
|
|
|
|
|
|
//add db_get etc templates to this
|
|
|
|
|
|
|
|
//#if DATABASES_ENABLED
|
|
|
|
//static Ref<RBACRank> db_get(const int id) {
|
|
|
|
// return Resource::db_get<RBACRank>(id);
|
|
|
|
//}
|
|
|
|
//#endif
|
|
|
|
|
|
|
|
//etc
|
|
|
|
|
|
|
|
//ResourcePropertyDB * -> bind properties param
|
|
|
|
|
2021-08-21 13:53:23 +02:00
|
|
|
class Resource : public Reference {
|
|
|
|
RCPP_OBJECT(Resource, Reference);
|
|
|
|
|
|
|
|
public:
|
2021-11-13 11:19:05 +01:00
|
|
|
//uncomment!
|
|
|
|
//static ResourcePropertyDB properties;
|
|
|
|
|
2021-08-22 20:57:37 +02:00
|
|
|
int id;
|
2021-11-13 11:19:05 +01:00
|
|
|
//since we will need getters and setters, this should be added
|
|
|
|
bool dirty;
|
2021-08-21 14:40:30 +02:00
|
|
|
|
2021-11-01 19:53:35 +01:00
|
|
|
virtual String to_json(rapidjson::Document *into = nullptr);
|
|
|
|
virtual void from_json(const String &data);
|
2021-08-21 14:40:30 +02:00
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
virtual String to_ini() { return ""; }
|
|
|
|
virtual void from_ini(const String &data) {}
|
|
|
|
|
|
|
|
#if DATABASES_ENABLED
|
|
|
|
virtual void db_load() {}
|
|
|
|
//should use transactions if a resource has subresources, when qg is null it should start and end a transaction.
|
|
|
|
virtual void db_save(QueryBuilder *qb = nullptr) {}
|
|
|
|
|
|
|
|
//these could be a template, so just every subclass can return itself with these. Also these could use transactions
|
|
|
|
template <class T>
|
|
|
|
static Ref<T> db_get(const int id);
|
|
|
|
static Ref<Resource> db_get_all();
|
|
|
|
static void db_save_all(const Vector<Ref<Resource> > &resources);
|
|
|
|
#endif
|
|
|
|
|
2021-11-16 17:34:01 +01:00
|
|
|
//add serialization to and from requests
|
|
|
|
//could also build a form validator automatically using the property registration api
|
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
//Resource::register<T>() foreach parents cast call
|
|
|
|
//RBACRank::register()
|
|
|
|
|
2021-08-21 13:53:23 +02:00
|
|
|
Resource();
|
|
|
|
~Resource();
|
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
protected:
|
|
|
|
inline static void (*_get_bind_properties())() {
|
|
|
|
return &Resource::_bind_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
//add ResourcePropertyDB *pdb param
|
|
|
|
//register id
|
|
|
|
static void _bind_properties() {}
|
|
|
|
|
|
|
|
public: //should be protected, but bug in clang++
|
|
|
|
//init like the macro
|
|
|
|
static void initialize_class() {}
|
|
|
|
|
2021-08-21 13:53:23 +02:00
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2021-11-13 11:19:05 +01:00
|
|
|
//minden resource derivaltnak:
|
|
|
|
//PropertyDB db;
|
|
|
|
//minden benne van
|
|
|
|
|
|
|
|
//RBACRanks::PropertyDB -> minden benne van, osclass is
|
|
|
|
//RBACPermission::PropertyDB -> minden bene van osok is
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
Ref<T> Resource::db_get(const int id) {
|
|
|
|
Ref<T> data;
|
|
|
|
data.instance();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-08-21 13:53:23 +02:00
|
|
|
#endif
|