Web Wispers 1.2.2 C++ Unit Test Coverage |
|
|
|
|
Branch data Line data Source code
1 : : /*
2 : : * Copyright 2006-2009 Savarese Software Research Corporation
3 : : *
4 : : * Licensed under the Apache License, Version 2.0 (the "License");
5 : : * you may not use this file except in compliance with the License.
6 : : * You may obtain a copy of the License at
7 : : *
8 : : * https://www.savarese.com/software/ApacheLicense-2.0
9 : : *
10 : : * Unless required by applicable law or agreed to in writing, software
11 : : * distributed under the License is distributed on an "AS IS" BASIS,
12 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : : * See the License for the specific language governing permissions and
14 : : * limitations under the License.
15 : : */
16 : :
17 : : /**
18 : : * @file
19 : : * This header defines the VectorBlob class.
20 : : */
21 : :
22 : : #ifndef __SSRC_WSPR_DATABASE_VECTOR_BLOB
23 : : #define __SSRC_WSPR_DATABASE_VECTOR_BLOB
24 : :
25 : : #include <ssrc/wispers/database/Database.h>
26 : :
27 : : #include <vector>
28 : : #include <cstring>
29 : :
30 : : #include <boost/serialization/vector.hpp>
31 : :
32 : : __BEGIN_NS_SSRC_WSPR_DATABASE
33 : :
34 : : /**
35 : : * This class is intended only for use with primitive types or
36 : : * structures composed only of primitive types that don't define
37 : : * serialization functions.
38 : : */
39 : : template<typename T>
40 : 6 : struct VectorBlob : public std::vector<T> {
41 : : typedef NS_SSRC_WSPR_DATABASE::blob_type db_value_type;
42 : : typedef std::vector<T> super;
43 : : typedef typename super::value_type value_type;
44 : :
45 : 1 : VectorBlob() { }
46 : :
47 : 1 : VectorBlob(const db_value_type & blob) {
48 [ + - + - ]: 1 : if(blob.first && blob.second > 0) {
49 [ + - ]: 1 : super::resize(blob.second/sizeof(value_type));
50 [ + - + - ]: 1 : std::memcpy(&super::operator[](0), blob.first,
51 : : super::size()*sizeof(value_type));
52 : : }
53 : 1 : }
54 : :
55 : 1 : friend PreparedStatement & bind_column(PreparedStatement & statement,
56 : : const unsigned int index,
57 : : const VectorBlob & vec)
58 : : {
59 [ - + ]: 1 : if(vec.empty())
60 : 0 : return statement.bind(index, static_cast<const void *>(0), 0);
61 : : else
62 : : return statement.bind(index, static_cast<const void *>(&vec[0]),
63 : 1 : vec.size()*sizeof(typename VectorBlob::value_type));
64 : : }
65 : :
66 : : #if defined(BOOST_SERIALIZATION_ACCESS_HPP)
67 : : template<class Archive>
68 : : void serialize(Archive & ar, const unsigned int) {
69 : : ar & boost::serialization::base_object<super>(*this);
70 : : }
71 : : #endif
72 : : };
73 : :
74 : : __END_NS_SSRC_WSPR_DATABASE
75 : :
76 : : #endif
|
Copyright © 2017 Savarese Software Research Corporation. All rights reserved