templates.thrift_cpp.include.interface_erpc_output.body.vm Maven / Gradle / Ivy
#parse("thrift_cpp/include/cxx_schema_include.vm")
#parse("thrift_cpp/include/cxx.helper.vm")
#set( $output_basename = "${schemainfo.programName}_erpc_output")
#set( $output_filename = "${output_basename}.${source_type}")
## 当前代码名字空间
#set($source_namespace = "net.gdface.utils")
$codewriter.setCurrentCxxFilename($output_filename)
##############################
#define($out_field)
#if(${fieldMetadata.enum})
out << obj.m_$name##
#elseif(${fieldMetadata.canPrimitive})
out << obj.m_$name##
#elseif( $fieldMetadata.erpcType.protocolType.string && $fieldMetadata.preAlloc)
out << std::string((char*)obj.m_$name)##
#elseif( $fieldMetadata.erpcType.protocolType.string)
out << (obj.m_$name ? obj.m_$name : "")##
#elseif( $fieldMetadata.erpcType.protocolType.binary)
out << obj.m_$name##
#elseif($fieldMetadata.pointer)
out << obj.m_$name##
#else
out << obj.m_$name##
#end
#end
###############################
$header_begin
/**
* $interfaceName 接口数据类型与 eRPC 定义类型输出操作符(C++11)
* C++11 compiler or VS2015 or above required
* $GENERAED_BY
*/
#if( $source_type == "cpp" )
\#include
\#include
\#include "${output_basename}.h"
using namespace ${cxxhelper.cxxNamespace($source_namespace,true)};
#else
\#include
\#include
\#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.exception)
#if(${type.enum})
#set($thriftTypeMetadata = ${schemainfo.getThriftEnumMetadata($type.baseClass)})
#set($erpcClass = ${thriftTypeMetadata.enumName} )
#elseif(${schemainfo.isThriftStruct($type.baseClass)})
#set($thriftTypeMetadata = ${schemainfo.getThriftStructMetadata($type.baseClass)})
#set($erpcClass = ${thriftTypeMetadata.structName} )
#elseif(${schemainfo.isDecoratorType($type.baseClass)})
#set($thriftTypeMetadata = ${schemainfo.getThriftStructMetadata($type.decoratorClassName)})
#set($erpcClass = ${thriftTypeMetadata.structName} )
#end
#if(${type.enum})
// output operator for eRPC enum type(ref)
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const ${erpcClass}& obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
switch(obj){
#foreach($element in ${thriftTypeMetadata.extensiveItemsBefore})
#set($elementName = "${type.baseClass.simpleName}_${element.name}_c")
case ${elementName}:out << "$elementName";break;
#end
#foreach($element in ${thriftTypeMetadata.elementsDocumentation.keySet()})
#set($elementName = "${type.baseClass.simpleName}_${element.name()}_c")
case ${elementName}:out << "$elementName";break;
#end
#foreach($element in ${thriftTypeMetadata.extensiveItemsAfter})
#set($elementName = "${type.baseClass.simpleName}_${element.name}_c")
case ${elementName}:out << "$elementName";break;
#end
default:out << "${type.baseClass.simpleName}_Unknow_value"; break;
}
return out;
}
#end##if source_type
#else
// output operator for eRPC struct type(ref)
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const ${erpcClass}& obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
out << "${erpcClass}(";
#foreach($name in $type.fields)
#set($field = ${type.getField($name)})
#set($fieldMetadata = ${thriftTypeMetadata.getField($name)})
out <<#if($velocityCount >1)", " <<#end "m_${name}=["; $out_field;out << "]";
#end
out << ")";
return out;
}
#end##if source_type
#end###if(${type.enum})
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const ${erpcClass}* obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
if(obj){
out << *obj;
}else{
out << "";
}
return out;
}
#end##if source_type
#end###if(!$type.exception)
#end##foreach($type)
#end##foreach($entry)
#if( $source_type == "cpp" )
// output eRPC type(array)
template
void
printTo(std::ostream& out,const E*left, size_t count)
{
if (left ) {
out << "[";
for (auto i = 0; i < count; ++i) {
if (i > 0)out << ",";
out << left[i];
}
out << "]";
}
else {
out << "";
}
}
#end##if source_type
#### 结构列表 #####
///////////struct list type //////////////
#foreach($listType in ${schemainfo.collectionStructs})
#ifdef __cplusplus
// output operator for eRPC ${listType.ctype} struct type(ref)
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const ${listType.ctype} &obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
printTo(out,obj.elements, (size_t)obj.elementsCount);
return out;
}
#end##if source_type
#endif /** __cplusplus */
// output operator for eRPC ${listType.ctype} struct type(pointer)
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const ${listType.ctype} *obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
if (obj) {
out << *obj;
}
else {
out << "";
}
return out;
}
#end##if source_type
#end###foreach($listType in ${schemainfo.collectionStructs})
\#if _USE_BINARY
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const binary_t& obj)$method_declare_suffix
#if( $source_type == "cpp" )
{
if (obj.data) {
if (BINARY_OUTPUT_SIZE > 32 && obj.dataLength > BINARY_OUTPUT_SIZE) {
out << ::gdface::com_utilits::bytes_to_hex_string(obj.data, 16);
out << "...size:" << obj.dataLength << "...";
out << ::gdface::com_utilits::bytes_to_hex_string(obj.data + obj.dataLength - 16, 16);
}
else {
out << ::gdface::com_utilits::bytes_to_hex_string(obj.data, (size_t)obj.dataLength);
}
}else{
out << "";
}
return out;
}
#end##if source_type
std::ostream&
${ns_method_prefix}operator<<(std::ostream& out, const binary_t* obj)$method_declare_suffix
#if( $source_type == "cpp" ){
if (obj) {
out << *obj;
}
else {
out << "";
}
return out;
}
#end##if source_type
#endif /** _USE_BINARY */
#pkg_namespace_end()
$header_end
© 2015 - 2025 Weber Informatics LLC | Privacy Policy