Update spec
parent
4d231ab05b
commit
8b81559ada
|
@ -15,6 +15,7 @@ namespace sirEdit::data {
|
|||
|
||||
class Tool;
|
||||
class Type;
|
||||
class Field;
|
||||
struct FieldType {
|
||||
enum struct TYPE_COMBINATION {
|
||||
SINGLE_TYPE,
|
||||
|
@ -29,11 +30,27 @@ namespace sirEdit::data {
|
|||
TYPE_COMBINATION combination;
|
||||
uint64_t arraySize;
|
||||
};
|
||||
struct FieldMeta {
|
||||
enum struct META_TYPE {
|
||||
NORMAL,
|
||||
CUSTOME,
|
||||
VIEW,
|
||||
ENUM_INSTANCE
|
||||
};
|
||||
META_TYPE type;
|
||||
bool isAuto;
|
||||
std::string customeLanguage;
|
||||
std::string customeTypename;
|
||||
std::unordered_map<std::string, std::vector<std::string>> customeOptions;
|
||||
Field* view;
|
||||
std::vector<Field*> viewInverse; // TODO: Use it!
|
||||
};
|
||||
class Field {
|
||||
private:
|
||||
std::string __name;
|
||||
std::string __comment;
|
||||
FieldType __type;
|
||||
FieldMeta __meta;
|
||||
std::unordered_map<std::string, std::vector<std::string>> __hints;
|
||||
std::unordered_map<std::string, std::vector<std::string>> __restrictions;
|
||||
|
||||
|
@ -44,11 +61,13 @@ namespace sirEdit::data {
|
|||
const std::string& getName() const { return this->__name; }
|
||||
const std::string& getComment() const { return this->__comment; }
|
||||
const FieldType& getType() const { return this->__type; }
|
||||
const FieldMeta& getMeta() const { return this->__meta; }
|
||||
const std::unordered_map<std::string, std::vector<std::string>>& getHints() const { return this->__hints; }
|
||||
const std::unordered_map<std::string, std::vector<std::string>>& getRestrictions() const { return this->__restrictions; }
|
||||
std::string& getName() { return this->__name; }
|
||||
std::string& getComment() { return this->__comment; }
|
||||
FieldType& getType() { return this->__type; }
|
||||
FieldMeta& getMeta() { return this->__meta; }
|
||||
std::unordered_map<std::string, std::vector<std::string>>& getHints() { return this->__hints; }
|
||||
std::unordered_map<std::string, std::vector<std::string>>& getRestrictions() { return this->__restrictions; }
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <sirEdit/data/types.hpp>
|
||||
|
@ -13,9 +16,9 @@ namespace sirEdit::data {
|
|||
class Transactions;
|
||||
class Serializer {
|
||||
private:
|
||||
std::vector<Type*> types;
|
||||
std::vector<Type*> baseTypes;
|
||||
std::vector<Tool*> tools;
|
||||
std::vector<Type*> __types;
|
||||
std::vector<Type*> __baseTypes;
|
||||
std::vector<Tool*> __tools;
|
||||
|
||||
void updateTypeInfo(Type* type) {
|
||||
// Base types
|
||||
|
@ -24,7 +27,7 @@ namespace sirEdit::data {
|
|||
if(tmp != nullptr)
|
||||
tmp->getSubTypes().push_back(type);
|
||||
else
|
||||
this->baseTypes.push_back(type);
|
||||
this->__baseTypes.push_back(type);
|
||||
}
|
||||
|
||||
// Interfaces
|
||||
|
@ -36,24 +39,26 @@ namespace sirEdit::data {
|
|||
void updateRelationships() {
|
||||
// Get data
|
||||
{
|
||||
this->types.clear();
|
||||
this->__types.clear();
|
||||
this->getBaseTypes([this](Type* type) -> void {
|
||||
this->types.push_back(type);
|
||||
this->__types.push_back(type);
|
||||
type->getSubTypes().clear();
|
||||
});
|
||||
this->tools.clear();
|
||||
this->__tools.clear();
|
||||
this->getBaseTools([this](Tool* tool) -> void {
|
||||
this->tools.push_back(tool);
|
||||
this->__tools.push_back(tool);
|
||||
});
|
||||
}
|
||||
|
||||
// Create new subtype information
|
||||
for(auto& i : this->types)
|
||||
for(auto& i : this->__types)
|
||||
this->updateTypeInfo(i);
|
||||
}
|
||||
|
||||
virtual void addBaseType(Type* type) = 0;
|
||||
virtual void removeBaseType(Type* type) = 0;
|
||||
virtual void addBaseTool(Tool* tool) = 0;
|
||||
virtual void removeBaseTool(Tool* tool) = 0;
|
||||
virtual void getBaseTypes(std::function<void(Type*)> callbackFunc) = 0;
|
||||
virtual void getBaseTools(std::function<void(Tool*)> callbackFunc) = 0;
|
||||
public:
|
||||
|
@ -61,25 +66,31 @@ namespace sirEdit::data {
|
|||
virtual ~Serializer() {}
|
||||
|
||||
void addType(Type* type) {
|
||||
this->types.push_back(type);
|
||||
this->__types.push_back(type);
|
||||
this->updateTypeInfo(type);
|
||||
this->addBaseType(type);
|
||||
}
|
||||
void removeType(Type* type) {
|
||||
throw; // TODO
|
||||
}
|
||||
void addTool(Tool* tool) {
|
||||
this->tools.push_back(tool);
|
||||
this->__tools.push_back(tool);
|
||||
this->addBaseTool(tool);
|
||||
}
|
||||
void removeTool(Tool* tool) {
|
||||
throw;// TODO
|
||||
}
|
||||
virtual void prepareSave() = 0;
|
||||
virtual void save() = 0;
|
||||
|
||||
const std::vector<Type*>& getTypes() const {
|
||||
return this->types;
|
||||
return this->__types;
|
||||
}
|
||||
const std::vector<Type*>& getBaseTypes() const {
|
||||
return this->baseTypes;
|
||||
return this->__baseTypes;
|
||||
}
|
||||
const std::vector<Tool*>& getTools() const {
|
||||
return this->tools;
|
||||
return this->__tools;
|
||||
}
|
||||
|
||||
friend Transactions;
|
||||
|
@ -89,8 +100,11 @@ namespace sirEdit::data {
|
|||
|
||||
class Transactions {
|
||||
private:
|
||||
Serializer& serializer;
|
||||
std::vector<std::function<void()>> change_callback;
|
||||
Serializer& __serializer;
|
||||
std::list<std::tuple<std::function<void(bool)>>> __history;
|
||||
std::unordered_map<const Tool*, std::list<uint64_t>> __tool_history;
|
||||
uint64_t __current_history = 0;
|
||||
std::vector<std::function<void()>> __change_callback;
|
||||
|
||||
template<class T>
|
||||
inline void updateCall(T& list) {
|
||||
|
@ -125,20 +139,20 @@ namespace sirEdit::data {
|
|||
}
|
||||
|
||||
public:
|
||||
Transactions(Serializer& serializer) : serializer(serializer) {}
|
||||
Transactions(Serializer& serializer) : __serializer(serializer) {}
|
||||
|
||||
void addChangeCallback(std::function<void()> func) {
|
||||
this->change_callback.push_back(std::move(func));
|
||||
this->__change_callback.push_back(std::move(func));
|
||||
}
|
||||
|
||||
const Serializer& getData() const {
|
||||
return this->serializer;
|
||||
return this->__serializer;
|
||||
}
|
||||
|
||||
const Tool* addTool(Tool tool) {
|
||||
Tool* tmp = new Tool(std::move(tool));
|
||||
this->serializer.addTool(tmp);
|
||||
updateCall(this->change_callback);
|
||||
this->__serializer.addTool(tmp);
|
||||
updateCall(this->__change_callback);
|
||||
return tmp;
|
||||
}
|
||||
void setFieldStatus(const Tool& tool, const Type& type, const Field& field, FIELD_STATE state, const std::function<void(const Type&, const Field&, FIELD_STATE, FIELD_STATE)>& callback_field, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
|
@ -155,7 +169,7 @@ namespace sirEdit::data {
|
|||
for(auto& i : field.getType().types)
|
||||
this->updateParentTypes(tool, *i, callback_type);
|
||||
this->updateParentTypes(tool, type, callback_type);
|
||||
updateCall(this->change_callback);
|
||||
updateCall(this->__change_callback);
|
||||
}
|
||||
void setTypeStatus(const Tool& tool, const Type& type, TYPE_STATE state, const std::function<void(const Type&, TYPE_STATE, TYPE_STATE)>& callback_type) {
|
||||
// Set type state
|
||||
|
@ -169,7 +183,7 @@ namespace sirEdit::data {
|
|||
// Update sub classes
|
||||
updateSubtypes(tool, type, callback_type);
|
||||
}
|
||||
updateCall(this->change_callback);
|
||||
updateCall(this->__change_callback);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -110,6 +110,42 @@ namespace sirEdit::data
|
|||
std::vector<TypeInterface*>& getInterfaces() { return this->__interfaces; }
|
||||
Type*& getSuper() { return this->__super; }
|
||||
};
|
||||
class TypeEnum : public TypeWithFields {
|
||||
private:
|
||||
std::vector<std::string> __instances;
|
||||
Type* __super;
|
||||
|
||||
public:
|
||||
TypeEnum(std::string name, std::string comment, std::vector<Field> fields, std::vector<std::string> instances, Type* super) : TypeWithFields(std::move(name), std::move(comment), std::move(fields)), __instances(std::move(instances)), __super(super) {
|
||||
this->getMetaTypeName() = "ENUM";
|
||||
}
|
||||
TypeEnum(const Type& type, std::vector<Field> fields, std::vector<std::string> instances, Type* super) : TypeWithFields(std::move(type), std::move(fields)), __instances(std::move(instances)), __super(super) {
|
||||
this->getMetaTypeName() = "ENUM";
|
||||
}
|
||||
TypeEnum(const TypeWithFields& fields, std::vector<std::string> instances, Type* super) : TypeWithFields(std::move(fields)), __instances(std::move(instances)), __super(super) {
|
||||
this->getMetaTypeName() = "ENUM";
|
||||
}
|
||||
|
||||
const std::vector<std::string>& getInterfaces() const { return this->__instances; }
|
||||
const Type* getSuper() const { return this->__super; }
|
||||
std::vector<std::string>& getInstances() { return this->__instances; }
|
||||
Type*& getSuper() { return this->__super; }
|
||||
};
|
||||
class TypeTypedef : public Type {
|
||||
private:
|
||||
const Type* __reference;
|
||||
|
||||
public:
|
||||
TypeTypedef(const Type& type, const Type* reference) : Type(type), __reference(reference) {
|
||||
this->getMetaTypeName() = "TYPEDEF";
|
||||
}
|
||||
TypeTypedef(std::string name, std::string comment, const Type* reference) : Type(std::move(name), std::move(comment)), __reference(reference) {
|
||||
this->getMetaTypeName() = "TYPEDEF";
|
||||
}
|
||||
|
||||
const Type* getReference() const { return this->__reference; }
|
||||
const Type*& getReference() { return this->__reference; }
|
||||
};
|
||||
|
||||
template<class FUNC_BASE, class FUNC_INTERFACE, class FUNC_CLASS>
|
||||
inline decltype((*static_cast<FUNC_BASE*>(nullptr))()) doBaseType(const Type* type, FUNC_BASE funcBase, FUNC_INTERFACE funcInterface, FUNC_CLASS funcClass) {
|
||||
|
|
|
@ -418,10 +418,16 @@ namespace {
|
|||
void addBaseType(Type* type) {
|
||||
throw; // TODO:
|
||||
}
|
||||
void removeBaseType(Type* type) {
|
||||
throw; // TODO:
|
||||
}
|
||||
void addBaseTool(Tool* tool) {
|
||||
auto tmp = this->sf->Tool->add();
|
||||
this->tools[tool] = tmp;
|
||||
}
|
||||
void removeBaseTool(Tool* tool) {
|
||||
throw; // TODO:
|
||||
}
|
||||
void getBaseTypes(std::function<void(Type*)> callbackFunc) {
|
||||
for(auto& i : this->types)
|
||||
callbackFunc(i.first);
|
||||
|
|
Loading…
Reference in New Issue