All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.thrift_cpp.include.interface_erpc_cast.body.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("thrift_cpp/include/cxx_schema_include.vm")
#parse("thrift_cpp/include/cxx.helper.vm")
#set( $output_basename = "${schemainfo.programName}_erpc_cast")
#set( $output_filename = "${output_basename}.${source_type}")
## 当前代码名字空间
#set($source_namespace = "net.gdface.utils")
$codewriter.setCurrentCxxFilename($output_filename)
#define($use_pointer)#if($fieldMetadata.pointer && !$fieldMetadata.erpcType.protocolType.string)*#end#end
#define($max_size_macro_name)${type.baseClass.simpleName}_${name}_MAX_SIZE#end
## 返回正确的thrift 类型
#define($str_max_length)#if($fieldMetadata.erpcType.protocolType.string && $type.lengthLimitOf($field)),${max_size_macro_name}#end#end
#### eRPC类型字段数据有效性检查 ##################
#define($validcheck)
#set($beginvalidcheck = false)
#if(   !$type.invalidValueOf($field) && $fieldMetadata.pointer)if(left.m_${name}){##
#set($beginvalidcheck = true)
#elseif($type.invalidValueOf($field))
## eRPC类型字段无效值定义
#set($iv_ = $type.invalidValueOf($field))
#if($fieldMetadata.canPrimitive)if(left.m_${name} != $iv_){##
#set($beginvalidcheck = true)
#elseif($fieldMetadata.erpcType.protocolType.string && $fieldMetadata.preAlloc)if(std::strcmp((char*)left.m_${name},"$iv_")){##
#set($beginvalidcheck = true)
#elseif($fieldMetadata.erpcType.protocolType.string)if(left.m_${name} && std::strcmp(left.m_${name},"$iv_")){##
#set($beginvalidcheck = true)
#elseif($fieldMetadata.erpcType.protocolType.binary && $fieldMetadata.typePrefix.empty)if(left.m_${name}.data && std::memcmp(left.m_${name}.data,"$iv_",std::strlen("$iv_"))){##
#set($beginvalidcheck = true)
#elseif($fieldMetadata.erpcType.protocolType.binary)if(left->m_${name}.data && std::memcmp(left->m_${name}.data,"$iv_",std::strlen("$iv_"))){##
#set($beginvalidcheck = true)
#end
#end###if($iv_)
#end###define($validcheck)
#### eRPC类型字段数据有效性检查 ##################
#define($endvalidcheck)
#if($beginvalidcheck)
#if($type.sql2javaBean)right.initialized |= (1 << $foreach.index);#end
}##
#end###if($beginvalidcheck)
#end###define($endvalidcheck)
##### thrift stub类型字段有效性检查 #########################
#define($stub_issetcheck)
#if(${cxxType.enum} && !${type.isRequired($name)})if(left.__isset.$name)##
#elseif(!${cxxType.enum} && !${cxxType.primitive})if(left.__isset.$name)##
#end
#end###define($stub_issetcheck)
##############################
$header_begin
/**
 * $interfaceName 接口数据类型与 eRPC 定义类型转换(C++11) 
* C++11 compiler or VS2015 or above required
* $GENERAED_BY
*/ #if( $source_type == "cpp" ) \#include \#include "${output_basename}.h" \#include "${schemainfo.programName}_erpc_mem.h" \#if _EXISTS_LIST_STRING \#include #endif /** _EXISTS_LIST_STRING */ using namespace ${cxxhelper.cxxNamespace($source_namespace,true)}; #else \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include \#include "${interfaceName}_types.h" \#include "${schemainfo.programName}.h" \#include "${schemainfo.programName}_constant.h" #end #if( $source_type == "h" ) #pkg_namespace_begin($source_namespace) #end##if source_type ////////////////define transformer for types///////////////////// #foreach($entry in $structGenseqMap.entries()) #set($package = $entry.key) #foreach($type in $entry.value) #if($type.bean && !$type.extThriftStruct) #if(${schemainfo.isThriftStruct($type.baseClass)}) #set($thriftTypeMetadata = ${schemainfo.getThriftStructMetadata($type.baseClass)}) #elseif(${schemainfo.isDecoratorType($type.baseClass)}) #set($thriftTypeMetadata = ${schemainfo.getThriftStructMetadata($type.decoratorClassName)}) #end #set($erpcClass = ${thriftTypeMetadata.structName} ) #set($thriftStub = ${schemainfo.toStubCxxType($type.baseClass)}) ######## thrift stub type to eRPC type ########## // thrift stub type(ref) to eRPC type(ref) void ${ns_method_prefix}cast(const ${thriftStub}& left,${erpcClass}&right)$method_declare_suffix #if( $source_type == "cpp" ) { init_${erpcClass}_ref(right); #foreach($name in $type.fields) #set($field = ${type.getField($name)}) #set($fieldMetadata = ${thriftTypeMetadata.getField($name)}) #set ($cxxType = $type.getCxxField($name)) #if($fieldMetadata.pointer && $fieldMetadata.erpcType.protocolType.string) ${stub_issetcheck}right.m_$name = cast(left.$name,right.m_$name,left.${name}.size()); #else ${stub_issetcheck}cast(left.$name,right.m_$name$str_max_length); #end #end##foreach name #if($type.sql2javaBean) right.m__new = left._new; #end##if($type.sql2javaBean) } #end##if source_type // thrift stub type(ref) to eRPC type(ponter) ${erpcClass} ${ns_method_prefix}cast(const ${thriftStub}& left,${erpcClass} *)$method_declare_suffix #if( $source_type == "cpp" ) { ${erpcClass} right; cast(left,right); return right; } #end##if source_type // eRPC type(ref) to thrift stub type(ref) void ${ns_method_prefix}cast(const ${erpcClass}& left,${thriftStub} &right)$method_declare_suffix #if( $source_type == "cpp" ) { #if($type.sql2javaBean) right.initialized = 0; #end##if($type.sql2javaBean) #foreach($name in $type.fields) #set($field = ${type.getField($name)}) #set($fieldMetadata = ${thriftTypeMetadata.getField($name)}) #set ($cxxType = $type.getCxxField($name)) ${validcheck}right.__set_$name(cast(${use_pointer}left.m_${name}$str_max_length,(typename std::add_pointer::type)nullptr));$endvalidcheck #end##foreach name #if($type.sql2javaBean) right._new = left.m__new; right.modified = right.initialized; #end##if($type.sql2javaBean) } #end##if source_type // eRPC type(ref) to thrift stub type(pointer) ${thriftStub} ${ns_method_prefix}cast(const ${erpcClass}& left,${thriftStub} *)$method_declare_suffix #if( $source_type == "cpp" ) { ${thriftStub} right; cast(left,right); return right; } #end##if source_type // eRPC type(pointer) to thrift stub type(pointer) ${thriftStub} ${ns_method_prefix}cast(const ${erpcClass}* left,${thriftStub} *)$method_declare_suffix #if( $source_type == "cpp" ) { if(left){ return cast(*left,(${thriftStub}*)nullptr); }else{ return ${thriftStub}(); } } #end##if source_type #end###if($type.bean && !$type.extThriftStruct) #end##foreach($type) #end##foreach($entry) \#if _USE_STRING void ${ns_method_prefix}cast(const char* left, std::string &right)$method_declare_suffix #if( $source_type == "cpp" ) { if (left) { right = left; } else { right = ""; } } #end##if source_type void ${ns_method_prefix}cast(const int8_t* left, std::string &right)$method_declare_suffix #if( $source_type == "cpp" ) { cast((char*)left, right); } #end##if source_type std::string ${ns_method_prefix}cast(const char* left, std::string*)$method_declare_suffix #if( $source_type == "cpp" ) { std::string r; cast(left, r); return r; } #end##if source_type std::string ${ns_method_prefix}cast(const int8_t* left, std::string*)$method_declare_suffix #if( $source_type == "cpp" ) { return cast((char*)left, (std::string*)nullptr); } #end##if source_type void ${ns_method_prefix}cast(const char* left, size_t size, std::string &right)$method_declare_suffix #if( $source_type == "cpp" ) { if (left) { auto c = std::strlen(left); if (c > size && size > 0) { c = size; } right = std::string(left, c); } else { right = ""; } } #end##if source_type void ${ns_method_prefix}cast(const int8_t* left, size_t size, std::string &right)$method_declare_suffix #if( $source_type == "cpp" ) { cast((char*)left, size, right); } #end##if source_type std::string ${ns_method_prefix}cast(const char* left, size_t size, std::string *)$method_declare_suffix #if( $source_type == "cpp" ) { std::string right; cast(left, size, right); return std::move(right); } #end##if source_type std::string ${ns_method_prefix}cast(const int8_t* left, size_t size, std::string *)$method_declare_suffix #if( $source_type == "cpp" ) { return cast((char*)left, size,(std::string*)nullptr); } #end##if source_type char* ${ns_method_prefix}cast(const std::string &left, char* right, size_t size)$method_declare_suffix #if( $source_type == "cpp" ) { if (!right && left.size()) { size = left.size() + 1; right = (char*)malloc(size); throw_except_if_false(std::bad_alloc, right); } if (right && size) { auto c = left.size(); if (c > size) { c = size; } memcpy(right, left.data(), c); right[size - 1] = '\0'; } return right; } #end##if source_type int8_t* ${ns_method_prefix}cast(const std::string &left, int8_t* right, size_t size)$method_declare_suffix #if( $source_type == "cpp" ) { return (int8_t*)cast(left, (char*)right, size); } #end##if source_type #endif /** _USE_STRING */ \#if _USE_BINARY void ${ns_method_prefix}cast(const std::string &left, binary_t &right)$method_declare_suffix #if( $source_type == "cpp" ) { alloc_binary_t_ref(right, left.size()); throw_except_if_false(std::bad_alloc, (nullptr != right.data) && (left.size() == (size_t)right.dataLength)); if (right.data) { std::memcpy(right.data, left.data(), (size_t)right.dataLength); } } #end##if source_type void ${ns_method_prefix}cast(const binary_t &left, std::string&right)$method_declare_suffix #if( $source_type == "cpp" ) { if (left.data && left.dataLength > 0) { right = std::string((char*)left.data, (size_t)left.dataLength); } else { right = ""; } } #end##if source_type std::string ${ns_method_prefix}cast(const binary_t &left, std::string*)$method_declare_suffix #if( $source_type == "cpp" ) { std::string r; cast(left, r); return r; } #end##if source_type std::string ${ns_method_prefix}cast(const binary_t *left, std::string*)$method_declare_suffix #if( $source_type == "cpp" ) { if (left) { return cast(*left, (std::string*)nullptr); } else { return std::string(); } } #end##if source_type #endif /** _USE_BINARY */ \#if _EXISTS_LIST_STRING // thrift stub type to eRPC list string (ref) void ${ns_method_prefix}cast(const std::vector& left, list_string_1_t &right)$method_declare_suffix #if( $source_type == "cpp" ) { right.elements = (decltype(right.elements))std::malloc(sizeof(char*)*left.size()); throw_except_if_false(std::bad_alloc, right.elements); if (right.elements) { std::memset(right.elements, 0, sizeof(char*)*left.size()); for (int i = 0; i < left.size(); ++i) { if (left[i].size()) { auto &l = left[i]; right.elements[i] = (char*)std::malloc(l.size() + 1); throw_except_if_false(std::bad_alloc, right.elements[i]); std::memcpy(right.elements[i], l.data(), l.size()); right.elements[i][l.size()] = '\0'; } } right.elementsCount = (decltype(right.elementsCount))left.size(); } } #end##if source_type #endif /** _EXISTS_LIST_STRING */ #pkg_namespace_end() #if( $source_type == "h" ) \#include #end $header_end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy