mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Start TEngine3.0
Start TEngine3.0
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
|
||||
#include "bright/serialization/ByteBuf.h"
|
||||
#include "bright/CfgBean.hpp"
|
||||
|
||||
using ByteBuf = ::bright::serialization::ByteBuf;
|
||||
|
||||
namespace {{assembly.top_module}}
|
||||
{
|
||||
|
||||
{{~for e in x.enum_codes~}}
|
||||
{{e}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for b in x.beans~}}
|
||||
{{b.cpp_namespace_begin}} class {{b.name}}; {{b.cpp_namespace_end}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for b in x.bean_codes~}}
|
||||
{{b}}
|
||||
{{~end~}}
|
||||
|
||||
{{~for t in x.table_codes~}}
|
||||
{{t}}
|
||||
{{~end~}}
|
||||
|
||||
{{x.tables_code}}
|
||||
|
||||
}
|
66
Luban/Luban.ClientServer/Templates/config/cpp_bin/bean.tpl
Normal file
66
Luban/Luban.ClientServer/Templates/config/cpp_bin/bean.tpl
Normal file
@@ -0,0 +1,66 @@
|
||||
{{x.cpp_namespace_begin}}
|
||||
|
||||
{{
|
||||
name = x.name
|
||||
parent_def_type = x.parent_def_type
|
||||
export_fields = x.export_fields
|
||||
hierarchy_export_fields = x.hierarchy_export_fields
|
||||
}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
class {{name}} : public {{if parent_def_type}} {{parent_def_type.cpp_full_name}} {{else}} bright::CfgBean {{end}}
|
||||
{
|
||||
public:
|
||||
|
||||
static bool deserialize{{name}}(ByteBuf& _buf, ::bright::SharedPtr<{{name}}>& _out);
|
||||
|
||||
{{name}}()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
{{~if !hierarchy_export_fields.empty?~}}
|
||||
{{name}}({{- for field in hierarchy_export_fields }}{{cpp_define_type field.ctype}} {{field.name}}{{if !for.last}},{{end}} {{end}})
|
||||
{{~if parent_def_type~}}
|
||||
: {{parent_def_type.cpp_full_name}}({{ for field in parent_def_type.hierarchy_export_fields }}{{field.name}}{{if !for.last}}, {{end}}{{end}})
|
||||
{{~end~}}
|
||||
{
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
this->{{field.convention_name}} = {{field.name}};
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
virtual ~{{name}}() {}
|
||||
|
||||
bool deserialize(ByteBuf& _buf);
|
||||
|
||||
{{~ for field in export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}} {{field.convention_name}};
|
||||
{{~if field.index_field~}}
|
||||
::bright::HashMap<{{cpp_define_type field.index_field.ctype}}, {{cpp_define_type field.ctype.element_type}}> {{field.convention_name}}_Index;
|
||||
{{~end~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{field.cpp_ref_validator_define}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
{{~if !x.is_abstract_type~}}
|
||||
static constexpr int __ID__ = {{x.id}};
|
||||
|
||||
int getTypeId() const { return __ID__; }
|
||||
{{~end~}}
|
||||
|
||||
virtual void resolve(::bright::HashMap<::bright::String, void*>& _tables);
|
||||
};
|
||||
|
||||
{{x.cpp_namespace_end}}
|
72
Luban/Luban.ClientServer/Templates/config/cpp_bin/stub.tpl
Normal file
72
Luban/Luban.ClientServer/Templates/config/cpp_bin/stub.tpl
Normal file
@@ -0,0 +1,72 @@
|
||||
#include <algorithm>
|
||||
#include "gen_types.h"
|
||||
|
||||
using ByteBuf = bright::serialization::ByteBuf;
|
||||
|
||||
namespace {{assembly.top_module}}
|
||||
{
|
||||
{{~for type in x.types~}}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize(ByteBuf& _buf)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
if (!{{type.parent_def_type.cpp_full_name}}::deserialize(_buf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{cpp_deserialize '_buf' field.convention_name field.ctype}}
|
||||
{{~if field.index_field ~}}
|
||||
for(auto& _v : this->{{field.convention_name}})
|
||||
{
|
||||
{{field.convention_name}}_Index.insert({_v->{{field.index_field.convention_name}}, _v});
|
||||
}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool {{type.cpp_full_name}}::deserialize{{type.name}}(ByteBuf& _buf, ::bright::SharedPtr<{{type.cpp_full_name}}>& _out)
|
||||
{
|
||||
{{~if type.is_abstract_type~}}
|
||||
int id;
|
||||
if (!_buf.readInt(id)) return false;
|
||||
switch (id)
|
||||
{
|
||||
{{~for child in type.hierarchy_not_abstract_children~}}
|
||||
case {{child.cpp_full_name}}::__ID__: { _out.reset(new {{child.cpp_full_name}}()); if (_out->deserialize(_buf)) { return true; } else { _out.reset(); return false;} }
|
||||
{{~end~}}
|
||||
default: { _out = nullptr; return false;}
|
||||
}
|
||||
{{~else~}}
|
||||
_out.reset(new {{type.cpp_full_name}}());
|
||||
if (_out->deserialize(_buf))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_out.reset();
|
||||
return false;
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
||||
|
||||
void {{type.cpp_full_name}}::resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
{{~if type.parent_def_type~}}
|
||||
{{type.parent_def_type.name}}::resolve(_tables);
|
||||
{{~end~}}
|
||||
{{~ for field in type.export_fields ~}}
|
||||
{{~if field.gen_ref~}}
|
||||
{{cpp_ref_validator_resolve field}}
|
||||
{{~else if field.has_recursive_ref~}}
|
||||
{{cpp_recursive_resolve field '_tables'}}
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
}
|
||||
{{~end~}}
|
||||
}
|
215
Luban/Luban.ClientServer/Templates/config/cpp_bin/table.tpl
Normal file
215
Luban/Luban.ClientServer/Templates/config/cpp_bin/table.tpl
Normal file
@@ -0,0 +1,215 @@
|
||||
{{x.cpp_namespace_begin}}
|
||||
|
||||
{{~
|
||||
name = x.name
|
||||
key_type = x.key_ttype
|
||||
key_type1 = x.key_ttype1
|
||||
key_type2 = x.key_ttype2
|
||||
value_type = x.value_ttype
|
||||
~}}
|
||||
|
||||
{{~if x.comment != '' ~}}
|
||||
/**
|
||||
* {{x.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
|
||||
{{~if x.is_list_table ~}}
|
||||
{{~if x.is_union_index~}}
|
||||
typedef struct t_{{name}}_MultiKey
|
||||
{
|
||||
{{~for idx in x.index_list~}}
|
||||
{{cpp_define_type idx.type}} {{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
bool operator==(const t_{{name}}_MultiKey& stOther) const
|
||||
{
|
||||
bool bEqual = true;
|
||||
{{~for idx in x.index_list~}}
|
||||
bEqual = bEqual && (stOther.{{idx.index_field.name}} == {{idx.index_field.name}});
|
||||
{{~end~}}
|
||||
return bEqual;
|
||||
}
|
||||
}t_{{name}}_MultiKey;
|
||||
|
||||
typedef struct t_{{name}}_MultiKey_HashFunc
|
||||
{
|
||||
std::size_t operator()(const t_{{name}}_MultiKey& stMK) const
|
||||
{
|
||||
std::size_t sHash = 0;
|
||||
{{~for idx in x.index_list~}}
|
||||
sHash ^= std::hash<{{cpp_define_type idx.type}}>()(stMK.{{idx.index_field.name}});
|
||||
{{~end~}}
|
||||
return sHash;
|
||||
}
|
||||
}t_{{name}}_MultiKey_HashFunc;
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
|
||||
|
||||
class {{name}}
|
||||
{
|
||||
{{~if x.is_map_table ~}}
|
||||
private:
|
||||
::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}> _dataMap;
|
||||
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
|
||||
|
||||
public:
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
for(; n > 0 ; --n)
|
||||
{
|
||||
{{cpp_define_type value_type}} _v;
|
||||
{{cpp_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.push_back(_v);
|
||||
_dataMap[_v->{{x.index_field.convention_name}}] = _v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const ::bright::HashMap<{{cpp_define_type key_type}}, {{cpp_define_type value_type}}>& getDataMap() const { return _dataMap; }
|
||||
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
|
||||
|
||||
{{value_type.bean.cpp_full_name}}* getRaw({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
|
||||
{{cpp_define_type value_type}} get({{cpp_define_type key_type}} key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
for(auto v : _dataList)
|
||||
{
|
||||
v->resolve(_tables);
|
||||
}
|
||||
}
|
||||
|
||||
{{~else if x.is_list_table~}}
|
||||
private:
|
||||
::bright::Vector<{{cpp_define_type value_type}}> _dataList;
|
||||
{{~if x.is_union_index~}}
|
||||
::bright::HashMapMultiKey<t_{{name}}_MultiKey, {{cpp_define_type value_type}}, t_{{name}}_MultiKey_HashFunc> _dataMap;
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
::bright::HashMap<{{cpp_define_type idx.type}}, {{cpp_define_type value_type}}> _dataMap_{{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
{{~end~}}
|
||||
|
||||
public:
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
for(; n > 0 ; --n)
|
||||
{
|
||||
{{cpp_define_type value_type}} _v;
|
||||
{{cpp_deserialize '_buf' '_v' value_type}}
|
||||
_dataList.push_back(_v);
|
||||
{{~if x.is_union_index~}}
|
||||
t_{{name}}_MultiKey stKey;
|
||||
{{~for idx in x.index_list~}}
|
||||
stKey.{{idx.index_field.name}} = _v->{{idx.index_field.name}};
|
||||
{{~end~}}
|
||||
_dataMap[stKey] = _v;
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
_dataMap_{{idx.index_field.name}}[_v->{{idx.index_field.name}}] = _v;
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
{{~end~}}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const ::bright::Vector<{{cpp_define_type value_type}}>& getDataList() const { return _dataList; }
|
||||
|
||||
{{~if x.is_union_index~}}
|
||||
::bright::HashMapMultiKey<t_{{name}}_MultiKey, {{cpp_define_type value_type}}, t_{{name}}_MultiKey_HashFunc>& getDataMap()
|
||||
{
|
||||
return _dataMap;
|
||||
}
|
||||
{{value_type.bean.cpp_full_name}}* getRaw(t_{{name}}_MultiKey& key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
{{cpp_define_type value_type}} get(t_{{name}}_MultiKey& key)
|
||||
{
|
||||
auto it = _dataMap.find(key);
|
||||
return it != _dataMap.end() ? it->second : nullptr;
|
||||
}
|
||||
{{~else if !x.index_list.empty?~}}
|
||||
{{~for idx in x.index_list~}}
|
||||
::bright::HashMap<{{cpp_define_type idx.type}}, {{cpp_define_type value_type}}>& getDataMapBy{{idx.index_field.name}}()
|
||||
{
|
||||
return _dataMap_{{idx.index_field.name}};
|
||||
}
|
||||
{{value_type.bean.cpp_full_name}}* getRawBy{{idx.index_field.name}}({{cpp_define_type idx.type}} key)
|
||||
{
|
||||
auto it = _dataMap_{{idx.index_field.name}}.find(key);
|
||||
return it != _dataMap_{{idx.index_field.name}}.end() ? it->second.get() : nullptr;
|
||||
}
|
||||
{{cpp_define_type value_type}} getBy{{idx.index_field.name}}({{cpp_define_type idx.type}} key)
|
||||
{
|
||||
auto it = _dataMap_{{idx.index_field.name}}.find(key);
|
||||
return it != _dataMap_{{idx.index_field.name}}.end() ? it->second : nullptr;
|
||||
}
|
||||
{{~end~}}
|
||||
{{~else~}}
|
||||
{{value_type.bean.cpp_full_name}}* getRaw(size_t index) const
|
||||
{
|
||||
return _dataList[index].get();
|
||||
}
|
||||
|
||||
{{cpp_define_type value_type}} get(size_t index) const
|
||||
{
|
||||
return _dataList[index];
|
||||
}
|
||||
{{~end~}}
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
for(auto v : _dataList)
|
||||
{
|
||||
v->resolve(_tables);
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
private:
|
||||
{{cpp_define_type value_type}} _data;
|
||||
|
||||
public:
|
||||
{{cpp_define_type value_type}} data() const { return _data; }
|
||||
|
||||
bool load(ByteBuf& _buf)
|
||||
{
|
||||
int n;
|
||||
if (!_buf.readSize(n)) return false;
|
||||
if (n != 1) return false;
|
||||
{{cpp_deserialize '_buf' '_data' value_type}}
|
||||
return true;
|
||||
}
|
||||
|
||||
void resolve(::bright::HashMap<::bright::String, void*>& _tables)
|
||||
{
|
||||
_data->resolve(_tables);
|
||||
}
|
||||
|
||||
{{~ for field in value_type.bean.hierarchy_export_fields ~}}
|
||||
{{~if field.comment != '' ~}}
|
||||
/**
|
||||
* {{field.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{cpp_define_type field.ctype}}& {{field.convention_getter_name}}() const { return _data->{{field.convention_name}}; }
|
||||
{{~end~}}
|
||||
{{~end~}}
|
||||
};
|
||||
{{x.cpp_namespace_end}}
|
33
Luban/Luban.ClientServer/Templates/config/cpp_bin/tables.tpl
Normal file
33
Luban/Luban.ClientServer/Templates/config/cpp_bin/tables.tpl
Normal file
@@ -0,0 +1,33 @@
|
||||
{{~
|
||||
tables = x.tables
|
||||
name = x.name
|
||||
~}}
|
||||
class {{name}}
|
||||
{
|
||||
public:
|
||||
{{~for table in tables ~}}
|
||||
{{~if table.comment != '' ~}}
|
||||
/**
|
||||
* {{table.escape_comment}}
|
||||
*/
|
||||
{{~end~}}
|
||||
{{table.cpp_full_name}} {{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
bool load(::bright::Loader<ByteBuf> loader)
|
||||
{
|
||||
::bright::HashMap<::bright::String, void*> __tables__;
|
||||
|
||||
ByteBuf buf;
|
||||
{{~for table in tables~}}
|
||||
if (!loader(buf, "{{table.output_data_file}}")) return false;
|
||||
if (!{{table.name}}.load(buf)) return false;
|
||||
__tables__["{{table.full_name}}"] = &{{table.name}};
|
||||
{{~end~}}
|
||||
|
||||
{{~for table in tables ~}}
|
||||
{{table.name}}.resolve(__tables__);
|
||||
{{~end~}}
|
||||
return true;
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user