mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2025-05-10 21:52:08 +02:00
Started working on a new automatic resource serialization system. Only some layout work so far, with lots of comments. Need to think about it more.
This commit is contained in:
parent
b379829839
commit
29c27ab82a
@ -9,6 +9,7 @@ void Resource::from_json(const String &data) {
|
|||||||
Resource::Resource() :
|
Resource::Resource() :
|
||||||
Reference() {
|
Reference() {
|
||||||
id = 0;
|
id = 0;
|
||||||
|
dirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource::~Resource() {
|
Resource::~Resource() {
|
||||||
|
@ -1,28 +1,118 @@
|
|||||||
#ifndef RESOURCE_H
|
#ifndef RESOURCE_H
|
||||||
#define RESOURCE_H
|
#define RESOURCE_H
|
||||||
|
|
||||||
|
#include "core/containers/vector.h"
|
||||||
#include "core/string.h"
|
#include "core/string.h"
|
||||||
|
|
||||||
#include "reference.h"
|
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
#include "reference.h"
|
||||||
|
|
||||||
#if DATABASES_ENABLED
|
#if DATABASES_ENABLED
|
||||||
class Database;
|
class Database;
|
||||||
|
class QueryBuilder;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
class Resource : public Reference {
|
class Resource : public Reference {
|
||||||
RCPP_OBJECT(Resource, Reference);
|
RCPP_OBJECT(Resource, Reference);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
//uncomment!
|
||||||
|
//static ResourcePropertyDB properties;
|
||||||
|
|
||||||
int id;
|
int id;
|
||||||
|
//since we will need getters and setters, this should be added
|
||||||
|
bool dirty;
|
||||||
|
|
||||||
virtual String to_json(rapidjson::Document *into = nullptr);
|
virtual String to_json(rapidjson::Document *into = nullptr);
|
||||||
virtual void from_json(const String &data);
|
virtual void from_json(const String &data);
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
//Resource::register<T>() foreach parents cast call
|
||||||
|
//RBACRank::register()
|
||||||
|
|
||||||
Resource();
|
Resource();
|
||||||
~Resource();
|
~Resource();
|
||||||
|
|
||||||
|
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() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
7
core/resource_property_db.cpp
Normal file
7
core/resource_property_db.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "resource_property_db.h"
|
||||||
|
|
||||||
|
ResourcePropertyDB::ResourcePropertyDB() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourcePropertyDB::~ResourcePropertyDB() {
|
||||||
|
}
|
74
core/resource_property_db.h
Normal file
74
core/resource_property_db.h
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#ifndef RESOURCE_PROPERTY_DB_H
|
||||||
|
#define RESOURCE_PROPERTY_DB_H
|
||||||
|
|
||||||
|
#include "core/containers/vector.h"
|
||||||
|
#include "core/string.h"
|
||||||
|
|
||||||
|
struct ResourcePropertyBind {
|
||||||
|
enum PropertyBindType {
|
||||||
|
PROPERTY_TYPE_NONE = 0,
|
||||||
|
PROPERTY_TYPE_INT = 1,
|
||||||
|
PROPERTY_TYPE_REAL,
|
||||||
|
PROPERTY_TYPE_STRING,
|
||||||
|
PROPERTY_TYPE_RESOURCE,
|
||||||
|
PROPERTY_TYPE_INT_VECTOR,
|
||||||
|
PROPERTY_TYPE_REAL_VECTOR,
|
||||||
|
PROPERTY_TYPE_STRING_VECTOR,
|
||||||
|
PROPERTY_TYPE_RESOURCE_VECTOR,
|
||||||
|
};
|
||||||
|
|
||||||
|
PropertyBindType type;
|
||||||
|
String name;
|
||||||
|
|
||||||
|
//querybuilderhez?
|
||||||
|
virtual String get_value_as_string() { return ""; }
|
||||||
|
|
||||||
|
ResourcePropertyBind() {
|
||||||
|
type = PROPERTY_TYPE_NONE;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class ResourcePropertyDB {
|
||||||
|
public:
|
||||||
|
|
||||||
|
//add_int()
|
||||||
|
//add_string
|
||||||
|
//etc
|
||||||
|
//nem kell template
|
||||||
|
//eleg ha resourcekent adja vissya
|
||||||
|
//beassignolodik es jo lesz
|
||||||
|
//automata serializacios rendsyer
|
||||||
|
|
||||||
|
//get prop count
|
||||||
|
//get prop name index
|
||||||
|
|
||||||
|
|
||||||
|
ResourcePropertyDB();
|
||||||
|
~ResourcePropertyDB();
|
||||||
|
};
|
||||||
|
|
||||||
|
//qb save
|
||||||
|
|
||||||
|
//insert into table_name (where to store?)
|
||||||
|
//store default table -> + add support for table name param
|
||||||
|
|
||||||
|
//foreach props
|
||||||
|
//get name
|
||||||
|
//endforeach
|
||||||
|
|
||||||
|
//values
|
||||||
|
//fporeach propes
|
||||||
|
//get as string?
|
||||||
|
//vagy prop->add value to qb(qb)
|
||||||
|
|
||||||
|
//if array v resource tyr -> skip
|
||||||
|
|
||||||
|
//endforeach
|
||||||
|
|
||||||
|
//foreach props -> if array add to transact
|
||||||
|
|
||||||
|
//foreach again
|
||||||
|
//if resource -> add to transact etc
|
||||||
|
//if res arr foreach add to transact
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user