1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// file : odb/sqlite/traits.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
#include <cstring> // std::memcpy, std::strlen
#include <odb/sqlite/traits.hxx>
using namespace std;
namespace odb
{
namespace sqlite
{
using details::buffer;
//
// default_value_traits<std::string>
//
void default_value_traits<string, id_text>::
set_image (buffer& b,
size_t& n,
bool& is_null,
const string& v)
{
is_null = false;
n = v.size ();
if (n > b.capacity ())
b.capacity (n);
if (n != 0)
memcpy (b.data (), v.c_str (), n);
}
//
// default_value_traits<const char*>
//
void default_value_traits<const char*, id_text>::
set_image (buffer& b,
size_t& n,
bool& is_null,
const char* v)
{
is_null = false;
n = strlen (v);
if (n > b.capacity ())
b.capacity (n);
if (n != 0)
memcpy (b.data (), v, n);
}
//
// default_value_traits<vector<char>, id_blob>
//
void default_value_traits<vector<char>, id_blob>::
set_image (details::buffer& b,
size_t& n,
bool& is_null,
const value_type& v)
{
is_null = false;
n = v.size ();
if (n > b.capacity ())
b.capacity (n);
// std::vector::data() may not be available in older compilers.
//
if (n != 0)
memcpy (b.data (), &v.front (), n);
}
}
}
|