初始化工程

This commit is contained in:
2025-07-15 15:33:35 +08:00
parent ead49da3e8
commit bbd78128d0
301 changed files with 23953 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
{{namespace_with_grace_begin __namespace}}
{{~if __this.comment != '' ~}}
/**
* {{escape_comment __this.comment}}
*/
{{~end~}}
struct {{__name}} : public{{if __parent_def_type}} {{make_cpp_name __parent_def_type.full_name}} {{else}} luban::CfgBean {{end}}
{
static bool deserialize{{__name}}(::luban::ByteBuf& _buf, ::luban::SharedPtr<{{__name}}>& _out);
virtual ~{{__name}}() {}
bool deserialize(::luban::ByteBuf& _buf);
{{~ for field in __export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{escape_comment field.comment}}
*/
{{~end~}}
{{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}};
{{~end~}}
{{~if !__this.is_abstract_type~}}
static constexpr int __ID__ = {{__this.id}};
int getTypeId() const override { return __ID__; }
{{~end~}}
};
{{namespace_with_grace_end __namespace}}

View File

@@ -0,0 +1,50 @@
#include "{{__schema_header_file}}"
{{namespace_with_grace_begin __top_module}}
{{~for bean in __beans~}}
bool {{make_cpp_name bean.full_name}}::deserialize(::luban::ByteBuf& _buf)
{
{{~if bean.parent_def_type~}}
if (!{{make_cpp_name bean.parent_def_type.full_name}}::deserialize(_buf))
{
return false;
}
{{~end~}}
{{~ for field in bean.export_fields ~}}
{{deserialize '_buf' (format_field_name __code_style field.name) field.ctype}}
{{~end~}}
return true;
}
bool {{make_cpp_name bean.full_name}}::deserialize{{bean.name}}(::luban::ByteBuf& _buf, ::luban::SharedPtr<{{make_cpp_name bean.full_name}}>& _out)
{
{{~if bean.is_abstract_type~}}
int32_t id;
if (!_buf.readInt(id)) return false;
switch (id)
{
{{~for child in bean.hierarchy_not_abstract_children~}}
case {{make_type_cpp_name child}}::__ID__: { _out.reset(LUBAN_NEW({{make_type_cpp_name child}})); if (_out->deserialize(_buf)) { return true; } else { _out.reset(); return false;} }
{{~end~}}
default: { _out = nullptr; return false;}
}
{{~else~}}
_out.reset(LUBAN_NEW({{make_type_cpp_name bean}}));
if (_out->deserialize(_buf))
{
return true;
}
else
{
_out.reset();
return false;
}
{{~end~}}
}
{{~end~}}
{{namespace_with_grace_end __top_module}}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <functional>
#include <algorithm>
#include "CfgBean.h"
{{namespace_with_grace_begin __top_module}}
{{__enum_codes~}}
{{~for b in __beans~}}
{{namespace_with_grace_begin b.namespace}} struct {{b.name}}; {{namespace_with_grace_end b.namespace}}
{{~end~}}
{{~__bean_codes~}}
{{~__table_codes~}}
{{__tables_code}}
{{namespace_with_grace_end __top_module}}

View File

@@ -0,0 +1,140 @@
{{namespace_with_grace_begin __namespace}}
{{~if __this.comment != '' ~}}
/**
* {{escape_comment __this.comment}}
*/
{{~end~}}
class {{__name}}
{
{{~if __this.is_map_table ~}}
private:
::luban::HashMap<{{declaring_type_name __key_type}}, {{declaring_type_name __value_type}}> _dataMap;
::luban::Vector<{{declaring_type_name __value_type}}> _dataList;
public:
bool load(::luban::ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
for(; n > 0 ; --n)
{
{{declaring_type_name __value_type}} _v;
{{deserialize '_buf' '_v' __value_type}}
_dataList.push_back(_v);
_dataMap[_v->{{format_field_name __code_style __this.index_field.name}}] = _v;
}
return true;
}
const ::luban::HashMap<{{declaring_type_name __key_type}}, {{declaring_type_name __value_type}}>& getDataMap() const { return _dataMap; }
const ::luban::Vector<{{declaring_type_name __value_type}}>& getDataList() const { return _dataList; }
{{make_type_cpp_name __value_type.def_bean}}* getRaw({{declaring_type_name __key_type}} key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second.get() : nullptr;
}
{{declaring_type_name __value_type}} get({{declaring_type_name __key_type}} key)
{
auto it = _dataMap.find(key);
return it != _dataMap.end() ? it->second : nullptr;
}
{{~else if __this.is_list_table~}}
private:
::luban::Vector<{{declaring_type_name __value_type}}> _dataList;
{{~if __this.is_union_index~}}
{{~else if !__this.index_list.empty?~}}
{{~for idx in __this.index_list~}}
::luban::HashMap<{{declaring_type_name idx.type}}, {{declaring_type_name __value_type}}> _dataMap_{{idx.index_field.name}};
{{~end~}}
{{~else~}}
{{~end~}}
public:
bool load(::luban::ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
for(; n > 0 ; --n)
{
{{declaring_type_name __value_type}} _v;
{{deserialize '_buf' '_v' __value_type}}
_dataList.push_back(_v);
{{~if __this.is_union_index~}}
{{~else if !__this.index_list.empty?~}}
{{~for idx in __this.index_list~}}
_dataMap_{{idx.index_field.name}}[_v->{{idx.index_field.name}}] = _v;
{{~end~}}
{{~else~}}
{{~end~}}
}
return true;
}
const ::luban::Vector<{{declaring_type_name __value_type}}>& getDataList() const { return _dataList; }
{{~if __this.is_union_index~}}
{{~else if !__this.index_list.empty?~}}
{{~for idx in __this.index_list~}}
::luban::HashMap<{{declaring_type_name idx.type}}, {{declaring_type_name __value_type}}>& getDataMapBy{{idx.index_field.name}}()
{
return _dataMap_{{idx.index_field.name}};
}
{{make_type_cpp_name __value_type.def_bean}}* getRawBy{{idx.index_field.name}}({{declaring_type_name idx.type}} key)
{
auto it = _dataMap_{{idx.index_field.name}}.find(key);
return it != _dataMap_{{idx.index_field.name}}.end() ? it->second.get() : nullptr;
}
{{declaring_type_name __value_type}} getBy{{idx.index_field.name}}({{declaring_type_name 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~}}
{{make_type_cpp_name __value_type.def_bean}}* getRaw(size_t index) const
{
return _dataList[index].get();
}
{{declaring_type_name __value_type}} get(size_t index) const
{
return _dataList[index];
}
{{~end~}}
{{~else~}}
private:
{{declaring_type_name __value_type}} _data;
public:
{{declaring_type_name __value_type}} data() const { return _data; }
bool load(::luban::ByteBuf& _buf)
{
int n;
if (!_buf.readSize(n)) return false;
if (n != 1) return false;
{{deserialize '_buf' '_data' __value_type}}
return true;
}
{{~ for field in __value_type.def_bean.hierarchy_export_fields ~}}
{{~if field.comment != '' ~}}
/**
* {{escape_comment field.comment}}
*/
{{~end~}}
{{declaring_type_name field.ctype}}& {{getter_name field.name}}() const { return _data->{{format_field_name __code_style field.name}}; }
{{~end~}}
{{~end~}}
};
{{namespace_with_grace_end __namespace}}

View File

@@ -0,0 +1,23 @@
class {{__name}}
{
public:
{{~for table in __tables ~}}
{{~if table.comment != '' ~}}
/**
* {{escape_comment table.comment}}
*/
{{~end~}}
{{make_cpp_name table.full_name}} {{table.name}};
{{~end~}}
bool load(::luban::Loader<::luban::ByteBuf> loader)
{
::luban::ByteBuf buf;
{{~for table in __tables~}}
buf.clear();
if (!loader(buf, "{{table.output_data_file}}")) return false;
if (!{{table.name}}.load(buf)) return false;
{{~end~}}
return true;
}
};