mirror of
https://github.com/Relintai/rcpp_framework.git
synced 2024-11-10 00:52:11 +01:00
Removed the properties, as this implementation did not work with polymorphism.
This commit is contained in:
parent
242412dd46
commit
b309705f10
@ -14,78 +14,6 @@
|
||||
#include "core/database/database_manager.h"
|
||||
#endif
|
||||
|
||||
//For properties
|
||||
|
||||
typedef std::string String;
|
||||
typedef std::vector<int> IntVector;
|
||||
typedef std::vector<float> FloatVector;
|
||||
typedef std::vector<std::string> StringVector;
|
||||
typedef std::vector<bool> BoolVector;
|
||||
typedef std::vector<Ref<Resource> > ResourceVector;
|
||||
|
||||
#define RESOURCE_PROPERTY_GET_IMPL(property_type, type_enum, default_value, func_name) \
|
||||
ResourcePropertyBase *p = _property_map[property]; \
|
||||
\
|
||||
if (!p) { \
|
||||
printf("ERROR Resource:: func_name property can't be found! %s\n", property.c_str()); \
|
||||
\
|
||||
return default_value; \
|
||||
} \
|
||||
\
|
||||
if (p->type != type_enum) { \
|
||||
/*If this happens property binding code in this class is incorrect*/ \
|
||||
printf("ERROR Resource:: func_name property's type is not property_type! %s\n", property.c_str()); \
|
||||
\
|
||||
return default_value; \
|
||||
} \
|
||||
\
|
||||
ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> > *pp = static_cast<ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> > *>(p); \
|
||||
\
|
||||
if (!pp) { \
|
||||
printf("ERROR Resource:: func_name dynamic cast failed! %s\n", property.c_str()); \
|
||||
\
|
||||
return default_value; \
|
||||
} \
|
||||
\
|
||||
return pp->getter(this);
|
||||
|
||||
#define RESOURCE_PROPERTY_SET_IMPL(property_type, type_enum, func_name) \
|
||||
ResourcePropertyBase *p = _property_map[property]; \
|
||||
\
|
||||
if (!p) { \
|
||||
printf("ERROR Resource:: func_name property can't be found! %s\n", property.c_str()); \
|
||||
\
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
if (p->type != type_enum) { \
|
||||
/*If this happens property binding code in this class is incorrect*/ \
|
||||
printf("ERROR Resource:: func_name property's type is not property_type! %s\n", property.c_str()); \
|
||||
\
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> > *pp = static_cast<ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> > *>(p); \
|
||||
\
|
||||
if (!pp) { \
|
||||
printf("ERROR Resource:: func_name dynamic cast failed! %s\n", property.c_str()); \
|
||||
\
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
return pp->setter(this, data);
|
||||
|
||||
#define RESOURCE_PROPERTY_ADD_IMPL(property_type, type_enum) \
|
||||
ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> > *prop = new ResourceProperty<std::function<property_type(Resource *)>, std::function<void(Resource *, property_type)> >(); \
|
||||
\
|
||||
prop->type = type_enum; \
|
||||
prop->getter = getter; \
|
||||
prop->setter = setter; \
|
||||
\
|
||||
_property_map[name] = prop;
|
||||
|
||||
//Properties stuff end
|
||||
|
||||
int Resource::get_id() {
|
||||
return _id;
|
||||
}
|
||||
@ -194,198 +122,16 @@ std::string Resource::file_get_base_path() {
|
||||
}
|
||||
|
||||
std::string Resource::to_json(rapidjson::Document *into) {
|
||||
rapidjson::Document *document;
|
||||
|
||||
if (into) {
|
||||
document = into;
|
||||
} else {
|
||||
document = new rapidjson::Document();
|
||||
}
|
||||
|
||||
document->SetObject();
|
||||
|
||||
std::map<std::string, ResourcePropertyBase *>::iterator it;
|
||||
|
||||
for (it = _property_map.begin(); it != _property_map.end(); it++) {
|
||||
std::string property_name = it->first;
|
||||
ResourcePropertyType property_type = it->second->type;
|
||||
|
||||
switch (property_type) {
|
||||
case TYPE_NULL:
|
||||
break;
|
||||
case TYPE_INT:
|
||||
document->AddMember(rapidjson::GenericStringRef<char>(property_name.c_str()), get_int(property_name), document->GetAllocator());
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
break;
|
||||
case TYPE_STRING:
|
||||
break;
|
||||
case TYPE_BOOL:
|
||||
break;
|
||||
case TYPE_RESOURCE:
|
||||
break;
|
||||
case TYPE_VECTOR_INT:
|
||||
break;
|
||||
case TYPE_VECTOR_FLOAT:
|
||||
break;
|
||||
case TYPE_VECTOR_STRING:
|
||||
break;
|
||||
case TYPE_VECTOR_BOOL:
|
||||
break;
|
||||
case TYPE_VECTOR_RESOURCE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
document->AddMember("name", rapidjson::Value(nameui.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("email", rapidjson::Value(emailui.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("rank", rank, document->GetAllocator());
|
||||
document->AddMember("pre_salt", rapidjson::Value(pre_salt.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("post_salt", rapidjson::Value(post_salt.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("password_hash", rapidjson::Value(password_hash.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("banned", banned, document->GetAllocator());
|
||||
document->AddMember("password_reset_token", rapidjson::Value(password_reset_token.c_str(), document->GetAllocator()), document->GetAllocator());
|
||||
document->AddMember("locked", locked, document->GetAllocator());
|
||||
|
||||
rapidjson::Value sa(rapidjson::Type::kArrayType);
|
||||
rapidjson::Document::AllocatorType &allocator = document->GetAllocator();
|
||||
|
||||
for (int i = 0; i < sessions.size(); i++) {
|
||||
sa.PushBack(rapidjson::Value(sessions[i].c_str(), document->GetAllocator()), allocator);
|
||||
}
|
||||
|
||||
document->AddMember("sessions", sa, document->GetAllocator());
|
||||
|
||||
*/
|
||||
|
||||
if (into) {
|
||||
return "";
|
||||
}
|
||||
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
document->Accept(writer);
|
||||
|
||||
std::string s = buffer.GetString();
|
||||
|
||||
delete document;
|
||||
|
||||
return s;
|
||||
return "";
|
||||
}
|
||||
void Resource::from_json(const std::string &data) {
|
||||
}
|
||||
|
||||
//properties
|
||||
|
||||
int Resource::get_int(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(int, TYPE_INT, 0, get_int);
|
||||
}
|
||||
float Resource::get_float(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(float, TYPE_FLOAT, 0, get_float);
|
||||
}
|
||||
std::string Resource::get_string(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(String, TYPE_STRING, "", get_string);
|
||||
}
|
||||
bool Resource::get_bool(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(bool, TYPE_BOOL, 0, get_bool);
|
||||
}
|
||||
Ref<Resource> Resource::get_resource(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(Ref<Resource>, TYPE_RESOURCE, Ref<Resource>(), get_resource);
|
||||
}
|
||||
|
||||
std::vector<int> Resource::get_int_vector(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(IntVector, TYPE_VECTOR_INT, IntVector(), get_int_vector);
|
||||
}
|
||||
std::vector<float> Resource::get_float_vector(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(FloatVector, TYPE_VECTOR_FLOAT, FloatVector(), get_float_vector);
|
||||
}
|
||||
std::vector<std::string> Resource::get_string_vector(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(StringVector, TYPE_VECTOR_STRING, StringVector(), get_string_vector);
|
||||
}
|
||||
std::vector<bool> Resource::get_bool_vector(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(BoolVector, TYPE_VECTOR_BOOL, BoolVector(), get_bool_vector);
|
||||
}
|
||||
std::vector<Ref<Resource> > Resource::get_resource_vector(const std::string &property) {
|
||||
RESOURCE_PROPERTY_GET_IMPL(ResourceVector, TYPE_VECTOR_RESOURCE, ResourceVector(), get_resource_vector);
|
||||
}
|
||||
|
||||
void Resource::set_int(const std::string &property, const int data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(int, TYPE_INT, set_int);
|
||||
}
|
||||
void Resource::set_float(const std::string &property, const float data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(float, TYPE_FLOAT, get_float);
|
||||
}
|
||||
void Resource::set_string(const std::string &property, const std::string &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(String, TYPE_STRING, get_string);
|
||||
}
|
||||
void Resource::set_bool(const std::string &property, const bool data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(bool, TYPE_BOOL, get_bool);
|
||||
}
|
||||
void Resource::set_resource(const std::string &property, const Ref<Resource> &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(Ref<Resource>, TYPE_RESOURCE, get_resource);
|
||||
}
|
||||
|
||||
void Resource::set_int_vector(const std::string &property, const std::vector<int> &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(IntVector, TYPE_VECTOR_INT, get_int_vector);
|
||||
}
|
||||
|
||||
void Resource::set_float_vector(const std::string &property, const std::vector<float> &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(FloatVector, TYPE_VECTOR_FLOAT, get_float_vector);
|
||||
}
|
||||
void Resource::set_string_vector(const std::string &property, const std::vector<std::string> &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(StringVector, TYPE_VECTOR_STRING, get_string_vector);
|
||||
}
|
||||
void Resource::set_bool_vector(const std::string &property, const std::vector<bool> &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(BoolVector, TYPE_VECTOR_BOOL, get_bool_vector);
|
||||
}
|
||||
void Resource::set_resource_vector(const std::string &property, const std::vector<Ref<Resource> > &data) {
|
||||
RESOURCE_PROPERTY_SET_IMPL(ResourceVector, TYPE_VECTOR_RESOURCE, get_resource_vector);
|
||||
}
|
||||
|
||||
void Resource::add_property_int(const std::string &name, std::function<int(Resource *)> getter, std::function<void(Resource *, int)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(int, TYPE_INT);
|
||||
}
|
||||
void Resource::add_property_float(const std::string &name, std::function<float(Resource *)> getter, std::function<void(Resource *, float)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(float, TYPE_FLOAT);
|
||||
}
|
||||
void Resource::add_property_string(const std::string &name, std::function<std::string(Resource *)> getter, std::function<void(Resource *, std::string)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(String, TYPE_STRING);
|
||||
}
|
||||
void Resource::add_property_bool(const std::string &name, std::function<bool(Resource *)> getter, std::function<void(Resource *, bool)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(bool, TYPE_BOOL);
|
||||
}
|
||||
void Resource::add_property_resource(const std::string &name, std::function<Ref<Resource>(Resource *)> getter, std::function<void(Resource *, Ref<Resource>)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(Ref<Resource>, TYPE_RESOURCE);
|
||||
}
|
||||
|
||||
void Resource::add_property_int_vector(const std::string &name, std::function<std::vector<int>(Resource *)> getter, std::function<void(Resource *, std::vector<int>)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(IntVector, TYPE_VECTOR_INT);
|
||||
}
|
||||
void Resource::add_property_float_vector(const std::string &name, std::function<std::vector<float>(Resource *)> getter, std::function<void(Resource *, std::vector<float>)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(FloatVector, TYPE_VECTOR_FLOAT);
|
||||
}
|
||||
void Resource::add_property_string_vector(const std::string &name, std::function<std::vector<std::string>(Resource *)> getter, std::function<void(Resource *, std::vector<std::string>)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(StringVector, TYPE_VECTOR_STRING);
|
||||
}
|
||||
void Resource::add_property_bool_vector(const std::string &name, std::function<std::vector<bool>(Resource *)> getter, std::function<void(Resource *, std::vector<bool>)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(BoolVector, TYPE_VECTOR_BOOL);
|
||||
}
|
||||
void Resource::add_property_resource_vector(const std::string &name, std::function<std::vector<Ref<Resource> >(Resource *)> getter, std::function<void(Resource *, std::vector<Ref<Resource> >)> setter, const int property_flags) {
|
||||
RESOURCE_PROPERTY_ADD_IMPL(ResourceVector, TYPE_VECTOR_RESOURCE);
|
||||
}
|
||||
|
||||
void Resource::register_properties() {
|
||||
add_property_int("id", &Resource::get_id, &Resource::set_id);
|
||||
}
|
||||
|
||||
Resource::Resource() :
|
||||
Reference() {
|
||||
_id = 0;
|
||||
_dirty = false;
|
||||
_resource_name = get_class();
|
||||
|
||||
register_properties();
|
||||
}
|
||||
|
||||
Resource::~Resource() {
|
||||
|
@ -65,45 +65,6 @@ public:
|
||||
std::string to_json(rapidjson::Document *into = nullptr);
|
||||
void from_json(const std::string &data);
|
||||
|
||||
//todo add a variant like class. (Or variant itself from godot.)
|
||||
int get_int(const std::string &property);
|
||||
float get_float(const std::string &property);
|
||||
std::string get_string(const std::string &property);
|
||||
bool get_bool(const std::string &property);
|
||||
Ref<Resource> get_resource(const std::string &property);
|
||||
|
||||
std::vector<int> get_int_vector(const std::string &property);
|
||||
std::vector<float> get_float_vector(const std::string &property);
|
||||
std::vector<std::string> get_string_vector(const std::string &property);
|
||||
std::vector<bool> get_bool_vector(const std::string &property);
|
||||
std::vector<Ref<Resource> > get_resource_vector(const std::string &property);
|
||||
|
||||
void set_int(const std::string &property, const int data);
|
||||
void set_float(const std::string &property, const float data);
|
||||
void set_string(const std::string &property, const std::string &data);
|
||||
void set_bool(const std::string &property, const bool data);
|
||||
void set_resource(const std::string &property, const Ref<Resource> &data);
|
||||
|
||||
void set_int_vector(const std::string &property, const std::vector<int> &data);
|
||||
void set_float_vector(const std::string &property, const std::vector<float> &data);
|
||||
void set_string_vector(const std::string &property, const std::vector<std::string> &data);
|
||||
void set_bool_vector(const std::string &property, const std::vector<bool> &data);
|
||||
void set_resource_vector(const std::string &property, const std::vector<Ref<Resource> > &data);
|
||||
|
||||
void add_property_int(const std::string &name, std::function<int(Resource *)> getter, std::function<void(Resource *, int)> setter, const int property_flags = 0);
|
||||
void add_property_float(const std::string &name, std::function<float(Resource *)> getter, std::function<void(Resource *, float)> setter, const int property_flags = 0);
|
||||
void add_property_string(const std::string &name, std::function<std::string(Resource *)> getter, std::function<void(Resource *, std::string)> setter, const int property_flags = 0);
|
||||
void add_property_bool(const std::string &name, std::function<bool(Resource *)> getter, std::function<void(Resource *, bool)> setter, const int property_flags = 0);
|
||||
void add_property_resource(const std::string &name, std::function<Ref<Resource>(Resource *)> getter, std::function<void(Resource *, Ref<Resource>)> setter, const int property_flags = 0);
|
||||
|
||||
void add_property_int_vector(const std::string &name, std::function<std::vector<int>(Resource *)> getter, std::function<void(Resource *, std::vector<int>)> setter, const int property_flags = 0);
|
||||
void add_property_float_vector(const std::string &name, std::function<std::vector<float>(Resource *)> getter, std::function<void(Resource *, std::vector<float>)> setter, const int property_flags = 0);
|
||||
void add_property_string_vector(const std::string &name, std::function<std::vector<std::string>(Resource *)> getter, std::function<void(Resource *, std::vector<std::string>)> setter, const int property_flags = 0);
|
||||
void add_property_bool_vector(const std::string &name, std::function<std::vector<bool>(Resource *)> getter, std::function<void(Resource *, std::vector<bool>)> setter, const int property_flags = 0);
|
||||
void add_property_resource_vector(const std::string &name, std::function<std::vector<Ref<Resource> >(Resource *)> getter, std::function<void(Resource *, std::vector<Ref<Resource> >)> setter, const int property_flags = 0);
|
||||
|
||||
virtual void register_properties();
|
||||
|
||||
Resource();
|
||||
~Resource();
|
||||
|
||||
|
@ -697,15 +697,6 @@ void User::create_validators() {
|
||||
}
|
||||
}
|
||||
|
||||
void User::register_properties() {
|
||||
Resource::register_properties();
|
||||
|
||||
//add_property_int("id", &Resource::get_id, &Resource::set_id);
|
||||
|
||||
//add_property_string("nameui", &User::get_name_ui, &User::set_name_ui);
|
||||
//add_property_string("nameui", &User::get_name_ui, &User::set_name_ui);
|
||||
}
|
||||
|
||||
User::User() :
|
||||
Resource() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user