aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-04-18 18:45:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-04-18 18:45:35 +0200
commit1e1a40eb86919a19b0c6738741be50ec084be596 (patch)
tree1a7736c1fe2a18a1968bcaff7d4bea9fea3e8193
parent0a3be5b5025ed61b58fea316aec4150a79865722 (diff)
Get rid of image type argument in value_traits
-rw-r--r--odb/mysql/query.hxx50
-rw-r--r--odb/mysql/traits.hxx121
2 files changed, 118 insertions, 53 deletions
diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx
index d58fb30..f4845cf 100644
--- a/odb/mysql/query.hxx
+++ b/odb/mysql/query.hxx
@@ -1030,7 +1030,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, signed char, id_tiny>::set_image (image_, dummy, v);
+ value_traits<T, id_tiny>::set_image (image_, dummy, v);
}
private:
@@ -1063,7 +1063,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, unsigned char, id_utiny>::set_image (image_, dummy, v);
+ value_traits<T, id_utiny>::set_image (image_, dummy, v);
}
private:
@@ -1098,7 +1098,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, short, id_short>::set_image (image_, dummy, v);
+ value_traits<T, id_short>::set_image (image_, dummy, v);
}
private:
@@ -1131,8 +1131,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, unsigned short, id_ushort>::set_image (
- image_, dummy, v);
+ value_traits<T, id_ushort>::set_image (image_, dummy, v);
}
private:
@@ -1167,7 +1166,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, int, id_long>::set_image (image_, dummy, v);
+ value_traits<T, id_long>::set_image (image_, dummy, v);
}
private:
@@ -1200,7 +1199,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, unsigned int, id_ulong>::set_image (image_, dummy, v);
+ value_traits<T, id_ulong>::set_image (image_, dummy, v);
}
private:
@@ -1235,7 +1234,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, long long, id_longlong>::set_image (image_, dummy, v);
+ value_traits<T, id_longlong>::set_image (image_, dummy, v);
}
private:
@@ -1268,8 +1267,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, unsigned long long, id_ulonglong>::set_image (
- image_, dummy, v);
+ value_traits<T, id_ulonglong>::set_image (image_, dummy, v);
}
private:
@@ -1304,7 +1302,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, float, id_float>::set_image (image_, dummy, v);
+ value_traits<T, id_float>::set_image (image_, dummy, v);
}
private:
@@ -1339,7 +1337,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, double, id_double>::set_image (image_, dummy, v);
+ value_traits<T, id_double>::set_image (image_, dummy, v);
}
private:
@@ -1375,8 +1373,7 @@ namespace odb
{
bool dummy;
std::size_t size, cap (buffer_.capacity ());
- value_traits<T, details::buffer, id_decimal>::set_image (
- buffer_, size, dummy, v);
+ value_traits<T, id_decimal>::set_image (buffer_, size, dummy, v);
size_ = static_cast<unsigned long> (size);
return cap != buffer_.capacity ();
}
@@ -1413,7 +1410,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, MYSQL_TIME, id_date>::set_image (image_, dummy, v);
+ value_traits<T, id_date>::set_image (image_, dummy, v);
}
private:
@@ -1447,7 +1444,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, MYSQL_TIME, id_time>::set_image (image_, dummy, v);
+ value_traits<T, id_time>::set_image (image_, dummy, v);
}
private:
@@ -1481,7 +1478,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, MYSQL_TIME, id_datetime>::set_image (image_, dummy, v);
+ value_traits<T, id_datetime>::set_image (image_, dummy, v);
}
private:
@@ -1515,8 +1512,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, MYSQL_TIME, id_timestamp>::set_image (
- image_, dummy, v);
+ value_traits<T, id_timestamp>::set_image (image_, dummy, v);
}
private:
@@ -1551,7 +1547,7 @@ namespace odb
init (const T& v)
{
bool dummy;
- value_traits<T, short, id_year>::set_image (image_, dummy, v);
+ value_traits<T, id_year>::set_image (image_, dummy, v);
}
private:
@@ -1587,8 +1583,7 @@ namespace odb
{
bool dummy;
std::size_t size, cap (buffer_.capacity ());
- value_traits<T, details::buffer, id_string>::set_image (
- buffer_, size, dummy, v);
+ value_traits<T, id_string>::set_image (buffer_, size, dummy, v);
size_ = static_cast<unsigned long> (size);
return cap != buffer_.capacity ();
}
@@ -1627,8 +1622,7 @@ namespace odb
{
bool dummy;
std::size_t size, cap (buffer_.capacity ());
- value_traits<T, details::buffer, id_blob>::set_image (
- buffer_, size, dummy, v);
+ value_traits<T, id_blob>::set_image (buffer_, size, dummy, v);
size_ = static_cast<unsigned long> (size);
return cap != buffer_.capacity ();
}
@@ -1668,7 +1662,7 @@ namespace odb
{
bool dummy;
std::size_t size;
- value_traits<T, details::buffer, id_bit>::set_image (
+ value_traits<T, id_bit>::set_image (
buffer_, sizeof (buffer_), size, dummy, v);
size_ = static_cast<unsigned long> (size);
}
@@ -1709,8 +1703,7 @@ namespace odb
{
bool dummy;
std::size_t size, cap (buffer_.capacity ());
- value_traits<T, details::buffer, id_enum>::set_image (
- buffer_, size, dummy, v);
+ value_traits<T, id_enum>::set_image (buffer_, size, dummy, v);
size_ = static_cast<unsigned long> (size);
return cap != buffer_.capacity ();
}
@@ -1749,8 +1742,7 @@ namespace odb
{
bool dummy;
std::size_t size, cap (buffer_.capacity ());
- value_traits<T, details::buffer, id_set>::set_image (
- buffer_, size, dummy, v);
+ value_traits<T, id_set>::set_image (buffer_, size, dummy, v);
size_ = static_cast<unsigned long> (size);
return cap != buffer_.capacity ();
}
diff --git a/odb/mysql/traits.hxx b/odb/mysql/traits.hxx
index 63673ff..5418fa1 100644
--- a/odb/mysql/traits.hxx
+++ b/odb/mysql/traits.hxx
@@ -54,26 +54,99 @@ namespace odb
};
//
+ // image_traits
+ //
+
+ template <database_type_id>
+ struct image_traits;
+
+ template <>
+ struct image_traits<id_tiny> {typedef signed char image_type;};
+
+ template <>
+ struct image_traits<id_utiny> {typedef unsigned char image_type;};
+
+ template <>
+ struct image_traits<id_short> {typedef short image_type;};
+
+ template <>
+ struct image_traits<id_ushort> {typedef unsigned short image_type;};
+
+ template <>
+ struct image_traits<id_long> {typedef int image_type;};
+
+ template <>
+ struct image_traits<id_ulong> {typedef unsigned int image_type;};
+
+ template <>
+ struct image_traits<id_longlong> {typedef long long image_type;};
+
+ template <>
+ struct image_traits<id_ulonglong> {typedef unsigned long long image_type;};
+
+ template <>
+ struct image_traits<id_float> {typedef float image_type;};
+
+ template <>
+ struct image_traits<id_double> {typedef double image_type;};
+
+ template <>
+ struct image_traits<id_decimal> {typedef details::buffer image_type;};
+
+ template <>
+ struct image_traits<id_date> {typedef MYSQL_TIME image_type;};
+
+ template <>
+ struct image_traits<id_time> {typedef MYSQL_TIME image_type;};
+
+ template <>
+ struct image_traits<id_datetime> {typedef MYSQL_TIME image_type;};
+
+ template <>
+ struct image_traits<id_timestamp> {typedef MYSQL_TIME image_type;};
+
+ template <>
+ struct image_traits<id_year> {typedef short image_type;};
+
+ template <>
+ struct image_traits<id_string> {typedef details::buffer image_type;};
+
+ template <>
+ struct image_traits<id_blob> {typedef details::buffer image_type;};
+
+ template <>
+ struct image_traits<id_bit> {typedef unsigned char* image_type;};
+
+ // Note: default mapping is to integer. Alternative mapping is to
+ // string.
+ //
+ template <>
+ struct image_traits<id_enum> {typedef unsigned short image_type;};
+
+ template <>
+ struct image_traits<id_set> {typedef details::buffer image_type;};
+
+ //
// value_traits
//
- template <typename T, typename I, database_type_id>
+ template <typename T, database_type_id>
struct default_value_traits;
- template <typename T, typename I, database_type_id ID>
- class value_traits: public default_value_traits<T, I, ID>
+ template <typename T, database_type_id ID>
+ class value_traits: public default_value_traits<T, ID>
{
};
- template <typename T, typename I, database_type_id>
+ template <typename T, database_type_id ID>
struct default_value_traits
{
typedef T value_type;
typedef T query_type;
- typedef I image_type;
+ typedef typename image_traits<ID>::image_type image_type;
static void
- set_value (T& v, I i, bool is_null)
+ set_value (T& v, const image_type& i, bool is_null)
{
if (!is_null)
v = T (i);
@@ -82,10 +155,10 @@ namespace odb
}
static void
- set_image (I& i, bool& is_null, T v)
+ set_image (image_type& i, bool& is_null, T v)
{
is_null = false;
- i = I (v);
+ i = image_type (v);
}
};
@@ -118,26 +191,26 @@ namespace odb
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- std::string, details::buffer, id_string>: string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_string>:
+ string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- std::string, details::buffer, id_decimal>: string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_decimal>:
+ string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- std::string, details::buffer, id_enum>: string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_enum>:
+ string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- std::string, details::buffer, id_set>: string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<std::string, id_set>:
+ string_value_traits
{
};
@@ -162,26 +235,26 @@ namespace odb
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- const char*, details::buffer, id_string>: c_string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_string>:
+ c_string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- const char*, details::buffer, id_decimal>: c_string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_decimal>:
+ c_string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- const char*, details::buffer, id_enum>: c_string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_enum>:
+ c_string_value_traits
{
};
template <>
- struct LIBODB_MYSQL_EXPORT default_value_traits<
- const char*, details::buffer, id_set>: c_string_value_traits
+ struct LIBODB_MYSQL_EXPORT default_value_traits<const char*, id_set>:
+ c_string_value_traits
{
};