Removed resource properties, and most things from the base resource.

This commit is contained in:
Relintai 2022-02-04 05:16:40 +01:00
parent 6416ecc5e0
commit 5d75c5bda7
6 changed files with 2 additions and 182 deletions

View File

@ -1,11 +1,5 @@
#include "resource.h"
String Resource::to_json(rapidjson::Document *into) {
return "";
}
void Resource::from_json(const String &data) {
}
Resource::Resource() :
Reference() {
id = 0;

View File

@ -4,7 +4,6 @@
#include "core/containers/vector.h"
#include "core/string.h"
#include "rapidjson/document.h"
#include "reference.h"
#if DATABASES_ENABLED
@ -12,110 +11,17 @@ class Database;
class QueryBuilder;
#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 {
RCPP_OBJECT(Resource, Reference);
public:
//uncomment!
//static ResourcePropertyDB properties;
int id;
//since we will need getters and setters, this should be added
bool dirty;
virtual String to_json(rapidjson::Document *into = nullptr);
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
//add serialization to and from requests
//could also build a form validator automatically using the property registration api
//Resource::register<T>() foreach parents cast call
//RBACRank::register()
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:
};
//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

View File

@ -1,7 +0,0 @@
#include "resource_property_db.h"
ResourcePropertyDB::ResourcePropertyDB() {
}
ResourcePropertyDB::~ResourcePropertyDB() {
}

View File

@ -1,74 +0,0 @@
#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

View File

@ -4,7 +4,7 @@
#include "core/string.h"
#include "core/resource.h"
#include "rapidjson/document.h"
#include <mutex>
class Request;

View File

@ -8,6 +8,7 @@
#include "user.h"
#include "core/http/middleware.h"
#include "libs/rapidjson/rapidjson.h"
class Request;
class FormValidator;