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

templates.thrift_cpp.include.cxx.helper.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#macro(namespace_begin $type)
#if( $source_type == "h" )
$cxxhelper.namespaceBegin($type.baseClass,false)
#end
#end
#macro(namespace_end)
#if( $source_type == "h" )
$cxxhelper.namespaceEnd()
#end
#end
#################
#macro(pkg_namespace_begin $pkg)
#if( $source_type == "h" )
$cxxhelper.namespaceBegin($pkg,false)
#else
#set($source_namespace = $pkg)
#end
#end
#macro(pkg_namespace_end)
#if( $source_type == "h" )
$cxxhelper.namespaceEnd()
#end
#end
#################
#macro(pre_def_begin $type  )
#if( $source_type == "h" )
#### 增加类型定义标志,防止应用项目引用入多个拥有相同类型定义的库时的冲突
#set($PRE_CLASS_DEF =  "_DEFINED_${type.name.replaceAll('[\W]', '_')}" )
#if( $source_type == "h" )
#ifndef $PRE_CLASS_DEF
\#define $PRE_CLASS_DEF
#end
#end
#end
#macro(pre_def_end)
#if( $source_type == "h" )
#endif /** $PRE_CLASS_DEF */
#end
#end
####################
#macro(class_begin $type  )
#if( $source_type == "h" )
class ${DLL_DECL}${typeClass}#if($type.exception) : public std::exception#end {
#end
#end
#macro(class_end)
#if( $source_type == "h" )
};
#end
#end
############
#define($isset_type_name)_${typeClass}__isset#end
#define($ns_method_prefix)#if( $source_type == "cpp" )${cxxhelper.cxxNamespace($source_namespace,true)}::#end#end
#define($member_method_prefix)#if( $source_type == "cpp" )${cxxhelper.cxxClassName($type.baseClass,true)}::#end#end
#define($service_method_prefix)#if( $source_type == "cpp" )${cxxhelper.cxxNamespace($interfaceClass.package.name,true)}::${typeClass}::#end#end
#define($method_declare_suffix)#if( $source_type == "h" );
#end#end
#define($input_ref)#if($cxxType.date || $cxxType.uiType.byReference)&#end#end
#define($return_pointer)#if(!$cxxType.primitive)*#end#end
#define($const_if_byval)#if(${cxxType.uiType.byValue})const #end#end
#define($DLL_DECL)#if( $source_type == "h" )${UP_IF_NAME}_DLL_DECL #end#end
#################
#macro(def_struct_isset $type )
#if( $source_type == "cpp")
#if($type.sql2javaBean)
#ifndef __DEFINED_${isset_type_name}
\#define __DEFINED_${isset_type_name}
#set( $_field_bit_count = $type.fields.size())
const int ${type.baseClass.simpleName}_field_bit_count = $_field_bit_count;
#set( $_field_byte_count = ($type.fields.size()+7)/8)
const int ${type.baseClass.simpleName}_field_byte_count = $_field_byte_count;
typedef enum $isset_type_name {
  #join($type.fields '#field_index($type $e) = ${foreach.index}' ',
  ')

}$isset_type_name;
#endif /** __DEFINED_${isset_type_name} */
#end
#end
#if( $source_type == "h")
#if(!$type.sql2javaBean && $type.hasOptionalField)
#ifndef __DEFINED_${isset_type_name}
\#define __DEFINED_${isset_type_name}
typedef struct ${UP_IF_NAME}_DLL_DECL $isset_type_name {
  ${isset_type_name}() : #join($type.refFields '${e}(false)'  ', '){}
#join($type.refFields '  bool ${e} : 1;
' '')

}$isset_type_name;
#endif /** __DEFINED_${isset_type_name} */
#end##if(!$type.sql2javaBean && $type.hasOptionalField)
#end
#end
###################
#macro(def_class_fields $type)
#if( $source_type == "h" )
public:
#foreach($field in $type.fields)
$!{typeDoc.getFieldComment($field)}##
  ${type.getCxxField($field).uiType.type} $field;
#end
#if($type.sql2javaBean)
  bool _new;
  #bit_field_type(${type.getCxxField("initialized").uiType}) initialized;
  #bit_field_type(${type.getCxxField("modified").uiType}) modified;
#else
#if($type.hasOptionalField)
  $isset_type_name __isset;
#end##if($type.hasOptionalField)
#end##if($type.sql2javaBean)
#end##if( $source_type == "h" )
#end
###################
#macro(def_constructor $type)
#set($classname = $type.cxxType.uiType.type)
#if( $source_type == "h" )
public:
#end
  // copy constructor
  ${member_method_prefix}${typeClass}(const ${classname} & other)$method_declare_suffix
#if( $source_type == "cpp" )
  {
#join($type.fields '    $e = other.$e;
' '')
#if($type.sql2javaBean)
    _new = other._new;
    initialized = other.initialized;
    modified = other.initialized;
#elseif($type.hasOptionalField)
    __isset = other.__isset;
#end
  }
#end
#if(${type.hasCanMoveField})
  // move constructor
  ${member_method_prefix}${typeClass}(${classname} && other)$method_declare_suffix
#if( $source_type == "cpp" )
  {
#join($type.fields '    $e = std::move(other.$e);
' '')
#if($type.sql2javaBean)
    _new = other._new;
    initialized = other.initialized;
    modified = other.initialized;
#elseif($type.hasOptionalField)
    __isset = std::move(other.__isset);
#end##if($type.sql2javaBean)
  }
#end
#end##if ${type.hasCanMoveField}
  // default constructor
  ${member_method_prefix}${typeClass}()$method_declare_suffix
#if( $source_type == "cpp" )#if(!$type.fields.empty)   : #join($type.fields '$e()' ',')#end#if($type.sql2javaBean),_new(true),initialized(#bit_field_size($type)),modified(#bit_field_size($type))#end
  {
  }

#end
  // destructor
  ${virtual_modifier}${member_method_prefix}~${typeClass}()$method_declare_suffix
#if( $source_type == "cpp" )
  {
  }

#end
  // copy assignment operator
  ${classname}& ${member_method_prefix}operator=(const ${classname} & rhs)$method_declare_suffix
#if( $source_type == "cpp" )
  {
#join($type.fields '    $e = rhs.$e;
' '')
#if($type.sql2javaBean)
    _new = rhs._new;
    initialized = rhs.initialized;
    modified = rhs.initialized;
#else
#if($type.hasOptionalField)
    __isset = rhs.__isset;
#end
#end##if($type.sql2javaBean)
    return *this;
  }

#end
#if($type.sql2javaBean)
  bool ${member_method_prefix}_be_initialized(int index)const $method_declare_suffix
#if( $source_type == "cpp" )
  {
#if( $type.sql2java4x)
    return bit_check(initialized,index);
#else
    return (initialized & (1 << index)) != 0;
#end
  }
#end
  bool ${member_method_prefix}_be_modified(int index)const $method_declare_suffix
#if( $source_type == "cpp" )
  {
#if( $type.sql2java4x)
    return bit_check(modified,index);
#else
    return (modified & (1 << index)) != 0;
#end
  }
#end
#end###if($type.sql2javaBean)
#if(${type.hasCanMoveField})
  // move assignment operator
  ${classname}& ${member_method_prefix}operator=(const ${classname} && rhs)$method_declare_suffix
#if( $source_type == "cpp" )
  {
#join($type.fields '    $e = std::move(rhs.$e);
' '')
#if($type.sql2javaBean)
    _new = rhs._new;
    initialized = rhs.initialized;
    modified = rhs.initialized;
#else
#if($type.hasOptionalField)
    __isset = std::move(rhs.__isset);
#end
#end##if($type.sql2javaBean)
    return *this;
  }

#end
#end##if ${type.hasCanMoveField}
  // == operator 
  bool ${member_method_prefix}operator==(const ${classname} & rhs) const $method_declare_suffix
#if( $source_type == "cpp" )
  {
#if($type.sql2javaBean)
#join($type.fields '    if(#if(!$type.getCxxField($e).primitive)(_be_initialized(#field_index($type $e)) != rhs._be_initialized(#field_index($type $e))) || #end!(#equal_express(${type.getCxxField($e).uiType} "$e" "rhs.$e")))return false;
' '')
#else
#join($type.fields '    if(#if(!$type.getCxxField($e).primitive)__isset.$e != rhs.__isset.$e || #end!(#equal_express(${type.getCxxField($e).uiType} "$e" "rhs.$e")))return false;
' '')
#end##if($type.sql2javaBean)
    return true;
  }

#end
  // != operator
  bool ${member_method_prefix}operator!=(const ${classname} & rhs) const $method_declare_suffix
#if( $source_type == "cpp" )
  {
    return !(*this == rhs);
  }

#end
  // < operator 
  bool ${member_method_prefix}operator<(const ${classname} & rhs) const $method_declare_suffix
#if( $source_type == "cpp" )
  {
    return false;
  }

#end
#if( $source_type == "h" && $type.exception)
  virtual char const* what() const noexcept
  {
    return message.empty()? "Unknown exception" : message.c_str();
  }
#end
#end##macro def_constructor
#####################
#macro(cxxStubType $type)${cxxhelper.getCxxType($type).stubType.type}#end
#macro(cxxUiType $type)${cxxhelper.getCxxType($type).uiType.type}#end 
#define($service_method_return)##
#if(!$TOOL.isVoid($method.genericReturnType))##
#if(!${cxxhelper.getCxxType($method.genericReturnType).stubType.canMove})##
return ##
#end##
#end##
#end
 ###################
#define($header_begin)
#if( $source_type == "h" )
#set($PRE_H =  ${output_filename.replaceAll("[A-Z]+","_$0").toUpperCase().replaceAll("[\W]", "_")} )
#ifndef $PRE_H
\#define $PRE_H#end#end##define
#define($header_end)#if( $source_type == "h" )#endif /** $PRE_H */#end#end
#define($public_modifier)#if( $source_type == "h" )public:#end#end
#define($private_modifier)#if( $source_type == "h" )private:#end#end
#define($virtual_modifier)#if( $source_type == "h" )virtual #end#end
#macro(input_param $typemeta $name)#if($typemeta.byValue)${typemeta.type} $name#{else}const ${typemeta.type}& $name#end#end
#macro(input_param_r $typemeta $name)#if($typemeta.byValue)${typemeta.type} $name#{else}${typemeta.type}&& $name#end#end
#macro(equal_express $typemeta $left $right)#if($typemeta.type=="std::tm")tm_eq($left,$right)#else$left == $right#end#end
#macro(field_index $type $field)${type.baseClass.simpleName}_${field}_index#end
#macro(check_isset $type $field)#if($type.sql2javaBean)_be_modified(#field_index($type $field))#{else}__isset.${field}#end#end
#macro(bit_field_type $typemeta)#if($typemeta.byValue)${typemeta.type}#{else}std::vector#end#end
#macro(bit_field_size $type)#if($type.sql2java4x)${type.baseClass.simpleName}_field_byte_count#{else}0#end#end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy