初始化工程
This commit is contained in:
32
Config/Tools/Luban/Templates/cpp-rawptr-bin/bean.sbn
Normal file
32
Config/Tools/Luban/Templates/cpp-rawptr-bin/bean.sbn
Normal 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, {{__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}}
|
||||
45
Config/Tools/Luban/Templates/cpp-rawptr-bin/schema_cpp.sbn
Normal file
45
Config/Tools/Luban/Templates/cpp-rawptr-bin/schema_cpp.sbn
Normal file
@@ -0,0 +1,45 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
{{~if bean.is_abstract_type~}}
|
||||
bool {{make_cpp_name bean.full_name}}::deserialize{{bean.name}}(::luban::ByteBuf& _buf, {{make_cpp_name bean.full_name}}*& _out)
|
||||
{
|
||||
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 = LUBAN_NEW({{make_type_cpp_name child}}); if (_out->deserialize(_buf)) { return true; } else { _out = nullptr; return false;} }
|
||||
{{~end~}}
|
||||
default: { _out = nullptr; return false;}
|
||||
}
|
||||
}
|
||||
{{~else~}}
|
||||
bool {{make_cpp_name bean.full_name}}::deserialize{{bean.name}}(::luban::ByteBuf& _buf, {{make_cpp_name bean.full_name}}*& _out)
|
||||
{
|
||||
_out = LUBAN_NEW({{make_type_cpp_name bean}});
|
||||
return _out->deserialize(_buf);
|
||||
}
|
||||
{{~end~}}
|
||||
|
||||
{{~end~}}
|
||||
{{namespace_with_grace_end __top_module}}
|
||||
21
Config/Tools/Luban/Templates/cpp-rawptr-bin/schema_h.sbn
Normal file
21
Config/Tools/Luban/Templates/cpp-rawptr-bin/schema_h.sbn
Normal 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}}
|
||||
134
Config/Tools/Luban/Templates/cpp-rawptr-bin/table.sbn
Normal file
134
Config/Tools/Luban/Templates/cpp-rawptr-bin/table.sbn
Normal file
@@ -0,0 +1,134 @@
|
||||
{{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:
|
||||
~{{__name}}()
|
||||
{
|
||||
for (auto& _v : _dataList)
|
||||
{
|
||||
LUBAN_FREE(_v);
|
||||
}
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
{{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}};
|
||||
}
|
||||
|
||||
{{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~}}
|
||||
|
||||
{{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}}
|
||||
23
Config/Tools/Luban/Templates/cpp-rawptr-bin/tables.sbn
Normal file
23
Config/Tools/Luban/Templates/cpp-rawptr-bin/tables.sbn
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user