Savarese Software Research Corporation
VectorBlob.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2009 Savarese Software Research Corporation
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     https://www.savarese.com/software/ApacheLicense-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00022 #ifndef __SSRC_WSPR_DATABASE_VECTOR_BLOB
00023 #define __SSRC_WSPR_DATABASE_VECTOR_BLOB
00024 
00025 #include <ssrc/wispers/database/Database.h>
00026 
00027 #include <vector>
00028 #include <cstring>
00029 
00030 #include <boost/serialization/vector.hpp>
00031 
00032 __BEGIN_NS_SSRC_WSPR_DATABASE
00033 
00039 template<typename T>
00040 struct VectorBlob : public std::vector<T> {
00041   typedef NS_SSRC_WSPR_DATABASE::blob_type db_value_type;
00042   typedef std::vector<T> super;
00043   typedef typename super::value_type value_type;
00044 
00045   VectorBlob() { }
00046 
00047   VectorBlob(const db_value_type & blob) {
00048     if(blob.first && blob.second > 0) {
00049       super::resize(blob.second/sizeof(value_type));
00050       std::memcpy(&super::operator[](0), blob.first,
00051                   super::size()*sizeof(value_type));
00052     }
00053   }
00054 
00055   friend PreparedStatement & bind_column(PreparedStatement & statement, 
00056                                          const unsigned int index,
00057                                          const VectorBlob & vec)
00058   {
00059     if(vec.empty())
00060       return statement.bind(index, static_cast<const void *>(0), 0);
00061     else
00062       return statement.bind(index, static_cast<const void *>(&vec[0]),
00063                             vec.size()*sizeof(typename VectorBlob::value_type));
00064   }
00065 
00066 #if defined(BOOST_SERIALIZATION_ACCESS_HPP)
00067   template<class Archive>
00068   void serialize(Archive & ar, const unsigned int) {
00069     ar & boost::serialization::base_object<super>(*this);
00070   }
00071 #endif
00072 };
00073 
00074 __END_NS_SSRC_WSPR_DATABASE
00075 
00076 #endif

Savarese Software Research Corporation
Copyright © 2006-2011 Savarese Software Research Corporation. All rights reserved.