-
-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[change] cpp-bin目标改名为cpp-sharedptr-bin
- Loading branch information
Showing
28 changed files
with
484 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Luban.CodeTarget; | ||
using Luban.Cpp.TemplateExtensions; | ||
using Scriban; | ||
|
||
namespace Luban.Cpp.CodeTarget; | ||
|
||
[CodeTarget("cpp-sharedptr-bin")] | ||
public class CppBinSharedptrCodeTarget : CppCodeTargetBase | ||
{ | ||
protected override void OnCreateTemplateContext(TemplateContext ctx) | ||
{ | ||
base.OnCreateTemplateContext(ctx); | ||
ctx.PushGlobal(new CppSharedptrBinTemplateExtension()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
src/Luban.Cpp/TemplateExtensions/CppBinTemplateExtension.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/Luban.Cpp/TemplateExtensions/CppRawptrBinTemplateExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Luban.Cpp.TypeVisitors; | ||
using Luban.Types; | ||
using Scriban.Runtime; | ||
|
||
namespace Luban.Cpp.TemplateExtensions; | ||
|
||
public class CppRawptrBinTemplateExtension : ScriptObject | ||
{ | ||
public static string Deserialize(string bufName, string fieldName, TType type) | ||
{ | ||
return type.Apply(CppRawptrDeserializeVisitor.Ins, bufName, fieldName); | ||
} | ||
|
||
public static string DeclaringTypeName(TType type) | ||
{ | ||
return type.Apply(CppRawptrDeclaringTypeNameVisitor.Ins); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Luban.Cpp/TemplateExtensions/CppSharedptrBinTemplateExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Luban.Cpp.TypeVisitors; | ||
using Luban.Types; | ||
using Scriban.Runtime; | ||
|
||
namespace Luban.Cpp.TemplateExtensions; | ||
|
||
public class CppSharedptrBinTemplateExtension : ScriptObject | ||
{ | ||
public static string Deserialize(string bufName, string fieldName, TType type) | ||
{ | ||
return type.Apply(CppSharedptrDeserializeVisitor.Ins, bufName, fieldName); | ||
} | ||
|
||
public static string DeclaringTypeName(TType type) | ||
{ | ||
return type.Apply(CppSharedptrDeclaringTypeNameVisitor.Ins); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.