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

templates.includes.tostring.body.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/generic.include.vm")
#init_qualifier($source_type)
#if( $source_type == "cpp" )
\#include "${C_TOSTRING}.h"
\#include "Judge.h"
#else
#pragma once
\#include 
\#include 
\#include 
\#include 
\#include 
\#include 
#INCLUDE_BEANCLASS()
\#include "FaceUtilits.h"
#end
#if( $source_type != "cpp" )
/**
 * 用于调试的工具函数族
 * 实现 webservice 所有引用类型输出到std::basic_ostream及到std::string的转换,以及对应的<<操作符重载函数 
 * 指针类型(std::shared_ptr)的成员如果为null,则不转换 
 * 数组类型(std::vector)的成员如果为空,则不转换
 * $GENERAED_BY
 */
#end
namespace net
{
	namespace gdface
	{
		namespace utils
		{
#if ($source_type != "cpp")
#USING_BEANCLASSES("		")
#end
#foreach( $refClass in $beanClasses)
## 异常类没有tostring函数
			// $refClass.simpleName输出到stream
			template
			$!{INLINE}std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const $refClass.simpleName& _src)#if( $source_type == "h" );
#else{
				int col=0;
				stream<<"{";
## propertyDescriptor:java.beans.PropertyDescriptor
#foreach( $propertyDescriptor in $TOOL.sortBy($refClassPropertiesMap[$refClass].values(),"name") )
## 引用类型中的属性类型(java.lang.Class)
#set($propClass=$gsoapHelper.getClassOfProperty($propertyDescriptor))
#if($propClass.primitive||$TOOL.isString($propClass))
				if(col++>0)stream<<",";
				stream<<"$propertyDescriptor.name=";
				tostream(stream,_src.${propertyDescriptor.readMethod.name}());
#elseif($propClass.array&&(!$TOOL.isArrayOfbyte($propClass)))
## 数组类型(std::vector)的成员如果为空,则不转换
				if(!Judge::isEmpty(_src.${propertyDescriptor.readMethod.name}())){
					if(col++>0)stream<<",";
					stream<<"$propertyDescriptor.name=";
					tostream(stream,_src.${propertyDescriptor.readMethod.name}());
				}
#else
## 指针类型(std::shared_ptr)的成员如果为null,则不转换
				if(!Judge::isNull(_src.${propertyDescriptor.readMethod.name}())){
					if(col++>0)stream<<",";
					stream<<"$propertyDescriptor.name=";
					tostream(stream,_src.${propertyDescriptor.readMethod.name}());
				}
#end
#end ## end of foreach
				stream<<"}";
				return stream;			
			}
#end## tostream函数结束
#end
#if( $source_type != "cpp" )
			// 字节数组转为hex字符串输出到stream
			// 大于limit的数组只显示长度,limit为0时全部显示 
			template
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const std::vector& _src, size_t limit = 64){
				if(_src.empty())return stream;
				else if(0==limit||_src.size()<=limit) return (stream << net::gdface::utils::FaceUtilits::toHex(_src));
				else return (stream<< "..." <<_src.size() << "bytes");
			}
			// bool 类型输出到stream
			template
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,bool _src){
				return (stream<< (_src?"true":"false"));				
			}
			// std::string 类型输出到stream
			template
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const std::string& _src){
				return (stream<<"\""<<_src<<"\"");
			}
			// 算术类型输出到stream
			template
			inline typename std::enable_if::value, std::basic_ostream<_Elem, _Traits>&>::type 
			tostream(std::basic_ostream<_Elem, _Traits>& stream,T _src){
				return (stream<<_src);
			}
			// 时间对象(tm)输出到stream
			template
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const tm& _src){
				auto time=mktime(&const_cast(_src));
				return (stream<
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const std::shared_ptr& _src){
				return nullptr==_src?(stream<<"null"):tostream(stream,*_src);				
			}
			// 算术类型数组(std::vector)输出到stream
			template
			inline typename std::enable_if::value, std::basic_ostream<_Elem, _Traits>&>::type
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const std::vector& _src){
				stream<<"{";
				for(decltype(_src.size()) i=0,end_i=_src.size();i>输出到stream
			template::value>
			inline std::basic_ostream<_Elem, _Traits>&
			tostream(std::basic_ostream<_Elem, _Traits>& stream,const std::vector>& _src){
				stream<<"{";
				if(!IS_ARITHMETIC)stream<<"\n";
				for(decltype(_src.size()) i=0,end_i=_src.size();i0)if(IS_ARITHMETIC)stream<<","; else stream<(tostream(stream,_src)).str();
			}
#end## tostring函数结束
#end
			// 字节数组(std::vector)转hex字符串(std::string) 
			// 大于limit的数组只显示长度,limit为0时全部显示 
			$!{INLINE}std::string tostring(const std::vector& _src, size_t _limit#defaultParamValue(0))#if( $source_type == "h" );
#else{
				std::ostringstream stream;
				return dynamic_cast(tostream(stream,_src,_limit)).str();
			}
#end
			// 时间对象(tm)转std::string 
			$!{INLINE}std::string tostring(const tm& _src)#if( $source_type == "h" );
#else{
				std::ostringstream stream;
				return dynamic_cast(tostream(stream,_src)).str();
			}
#end
#if( $source_type != "cpp" )
			// std::shared_ptr对象转std::string
			template
			inline std::string tostring(const std::shared_ptr& _src){
				std::ostringstream stream;
				return dynamic_cast(tostream(stream,_src)).str();
			}
			// 算术类型数组(std::vector)转std::string
			template
			inline typename std::enable_if::value, std::string>::type 
			tostring(const std::vector& _src){
				std::ostringstream stream;
				return dynamic_cast(tostream(stream,_src)).str();
			}
			// std::vector>类型转std::string
			template
			inline std::string 
			tostring(const std::vector>& _src){
				std::ostringstream stream;
				return dynamic_cast(tostream(stream,_src)).str();
			}
#end
		} /* namespace utils */
	} /* namespace gdface */
} /* namespace net */
#if( $source_type != "cpp" )
###foreach( $refClass in $beanClasses)
##// 支持$gsoapHelper.toCppFullName($refClass)的<<操作符重载函数 
##template
##inline std::basic_ostream<_Elem, _Traits>& operator<<(std::basic_ostream<_Elem, _Traits>& _Out,const $gsoapHelper.toCppFullName($refClass)& _src)
##{	
##	return net::gdface::utils::tostream(_Out,_src);
##}
##// 支持std::vector>的<<操作符重载函数 
##template
##inline std::basic_ostream<_Elem, _Traits>& operator<<(std::basic_ostream<_Elem, _Traits>& _Out,const std::vector>& _src)
##{	
##	return net::gdface::utils::tostream(_Out,_src);
##}
###end
// 支持所有bean引用类型的<<操作符重载函数模板 
template
inline
typename std::enable_if<
#join($beanClasses,'	std::is_base_of<$gsoapHelper.toCppFullName($e),T>::value','||
')

	,std::basic_ostream<_Elem, _Traits>&>::type
operator<<(std::basic_ostream<_Elem, _Traits>& _Out,const T& _src)
{	
	return net::gdface::utils::tostream(_Out,_src);
}
// 支持std::vector>的<<操作符重载函数模板 
// T 为所有bean引用类型
template
inline
typename std::enable_if<
#join($beanClasses '	std::is_base_of<$gsoapHelper.toCppFullName($e),T>::value' '||
')

	,std::basic_ostream<_Elem, _Traits>&>::type
operator<<(std::basic_ostream<_Elem, _Traits>& _Out,const std::vector>& _src)
{	
	return net::gdface::utils::tostream(_Out,_src);
}
#end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy