From ab9dec8671eeb90230064474cf86c49c69fd8e10 Mon Sep 17 00:00:00 2001
From: znone <glyc@sina.com.cn>
Date: Wed, 27 Jun 2018 06:54:45 +0000
Subject: [PATCH] 允许用字段名绑定数据(会影响性能) 允许对同一个数据结构进行不同的绑定
---
include/qtl_common.hpp | 73 ++++++++++++++++++++++++++++++++++--
1 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/include/qtl_common.hpp b/include/qtl_common.hpp
index e0eb972..eb616a1 100644
--- a/include/qtl_common.hpp
+++ b/include/qtl_common.hpp
@@ -218,6 +218,66 @@
fun(value, temp);
}
+template<typename Command, typename T, typename=typename std::enable_if<!std::is_reference<T>::value>::type>
+inline void bind_field(Command& command, const char* name, T&& value)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value=T();
+ else
+ command.bind_field(index, std::forward<T>(value));
+}
+
+template<typename Command, typename T>
+inline void bind_field(Command& command, const char* name, T& value)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value=T();
+ else
+ bind_field(command, index, std::forward<T>(value));
+}
+
+template<typename FieldType, typename Command, typename BindType>
+inline void bind_field(Command& command, const char* name, BindType& value)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value=BindType();
+ else
+ bind_field<FieldType>(command, index, value);
+}
+
+template<typename FieldType, typename Command, typename BindType, typename CastFun>
+inline void bind_field(Command& command, const char* name, BindType& value, CastFun&& fun)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value=BindType();
+ else
+ bind_field<FieldType>(command, index, value, fun);
+}
+
+template<typename Command>
+inline void bind_field(Command& command, const char* name, char* value, size_t length)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value[0]='\0';
+ else
+ command.bind_field(index, value, length);
+}
+
+template<typename Command>
+inline void bind_field(Command& command, const char* name, wchar_t* value, size_t length)
+{
+ size_t index=command.find_field(name);
+ if(index==-1)
+ value[0]='\0';
+ else
+ command.bind_field(index, value, length);
+}
+
namespace detail
{
@@ -404,7 +464,7 @@
void operator()(std::tuple<Types...>&& params) const
{
typedef typename std::remove_reference<typename std::tuple_element<0, tuple_type>::type>::type param_type;
- bind_field(m_command, 0, std::forward<param_type>(std::get<0>(std::forward<tuple_type>(params))));
+ bind_field(m_command, static_cast<size_t>(0), std::forward<param_type>(std::get<0>(std::forward<tuple_type>(params))));
}
private:
typedef std::tuple<Types...> tuple_type;
@@ -554,7 +614,7 @@
{
inline void operator()(Command& command, T&& value) const
{
- bind_field(command, 0, std::forward<typename std::remove_reference<T>::type>(value));
+ bind_field(command, static_cast<size_t>(0), std::forward<typename std::remove_reference<T>::type>(value));
}
};
@@ -573,11 +633,16 @@
{
void operator()(Command& command, std::pair<Type1, Type2>&& values) const
{
- bind_field(command, 0, std::forward<Type1>(values.first));
- bind_field(command, 1, std::forward<Type2>(values.second));
+ bind_field(command, static_cast<size_t>(0), std::forward<Type1>(values.first));
+ bind_field(command, static_cast<size_t>(1), std::forward<Type2>(values.second));
}
};
+template<typename T, typename Tag>
+struct record_with_tag : public T
+{
+};
+
template<typename Command, typename T>
inline void bind_record(Command& command, T&& value)
{
--
Gitblit v1.9.3