aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-12-22 12:48:20 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-12-22 12:48:20 +0200
commit8fa47fed49fdb13b857c63f721edd9c55688a588 (patch)
treecaa89b95db49e9be8b5d930ddd28aa7ac83e2feb
parent0d59e889e52c9495e42492b74b99076e3b3f3361 (diff)
Truncate excess data instead of asserting, make small functions inline
-rw-r--r--odb/oracle/traits.cxx84
-rw-r--r--odb/oracle/traits.hxx61
2 files changed, 51 insertions, 94 deletions
diff --git a/odb/oracle/traits.cxx b/odb/oracle/traits.cxx
index 8c0f236..eabfe28 100644
--- a/odb/oracle/traits.cxx
+++ b/odb/oracle/traits.cxx
@@ -12,90 +12,6 @@ namespace odb
namespace oracle
{
//
- // string_value_traits
- //
-
- void string_value_traits::
- set_image (char* b,
- size_t c,
- size_t& n,
- bool& is_null,
- const string& v)
- {
- is_null = false;
- n = v.size ();
-
- assert (n <= c);
-
- if (n != 0 && n <= c)
- memcpy (b, v.c_str (), n);
- }
-
- //
- // c_string_value_traits
- //
-
- void c_string_value_traits::
- set_image (char* b,
- size_t c,
- size_t& n,
- bool& is_null,
- const char* v)
- {
- is_null = false;
- n = strlen (v);
-
- assert (n <= c);
-
- if (n != 0 && n <= c)
- memcpy (b, v, n);
- }
-
- //
- // default_value_traits<vector<char>, id_raw>
- //
-
- void default_value_traits<vector<char>, id_raw>::
- set_image (char* b,
- size_t c,
- size_t& n,
- bool& is_null,
- const value_type& v)
- {
- is_null = false;
- n = v.size ();
-
- assert (n <= c);
-
- // std::vector::data() may not be available in older compilers.
- //
- if (n != 0)
- memcpy (b, &v.front (), n);
- }
-
- //
- // default_value_traits<vector<unsigned char>, id_raw>
- //
-
- void default_value_traits<vector<unsigned char>, id_raw>::
- set_image (char* b,
- size_t c,
- size_t& n,
- bool& is_null,
- const value_type& v)
- {
- is_null = false;
- n = v.size ();
-
- assert (n <= c);
-
- // std::vector::data() may not be available in older compilers.
- //
- if (n != 0)
- memcpy (b, &v.front (), n);
- }
-
- //
// string_lob_value_traits
//
diff --git a/odb/oracle/traits.hxx b/odb/oracle/traits.hxx
index d060588..903502c 100644
--- a/odb/oracle/traits.hxx
+++ b/odb/oracle/traits.hxx
@@ -12,7 +12,6 @@
#include <vector>
#include <cstddef> // std::size_t
#include <cstring> // std::memcpy, std::memset, std::strlen
-#include <cassert>
#include <odb/traits.hxx>
#include <odb/wrapper-traits.hxx>
@@ -517,7 +516,17 @@ namespace odb
std::size_t c,
std::size_t& n,
bool& is_null,
- const std::string&);
+ const std::string& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > c)
+ n = c;
+
+ if (n != 0)
+ std::memcpy (b, v.c_str (), n);
+ }
};
template <>
@@ -546,11 +555,21 @@ namespace odb
typedef char* image_type;
static void
- set_image (char*,
+ set_image (char* b,
std::size_t c,
std::size_t& n,
bool& is_null,
- const char*);
+ const char* v)
+ {
+ is_null = false;
+ n = std::strlen (v);
+
+ if (n > c)
+ n = c;
+
+ if (n != 0)
+ std::memcpy (b, v, n);
+ }
};
template <>
@@ -611,7 +630,19 @@ namespace odb
std::size_t c,
std::size_t& n,
bool& is_null,
- const value_type& v);
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > c)
+ n = c;
+
+ // std::vector::data() may not be available in older compilers.
+ //
+ if (n != 0)
+ std::memcpy (b, &v.front (), n);
+ }
};
// std::vector<unsigned char> (buffer) specialization for RAW.
@@ -641,7 +672,19 @@ namespace odb
std::size_t c,
std::size_t& n,
bool& is_null,
- const value_type& v);
+ const value_type& v)
+ {
+ is_null = false;
+ n = v.size ();
+
+ if (n > c)
+ n = c;
+
+ // std::vector::data() may not be available in older compilers.
+ //
+ if (n != 0)
+ std::memcpy (b, &v.front (), n);
+ }
};
// char[n] (buffer) specialization for RAW.
@@ -670,8 +713,7 @@ namespace odb
const char* v)
{
is_null = false;
- n = N;
- assert (N <= c);
+ n = N < c ? N : c;
std::memcpy (b, v, n);
}
};
@@ -705,8 +747,7 @@ namespace odb
const unsigned char* v)
{
is_null = false;
- n = N;
- assert (N <= c);
+ n = N < c ? N : c;
std::memcpy (b, v, n);
}
};