Virtual Testbed
Ship dynamics simulator for extreme conditions
blob.hh
1 #ifndef VTESTBED_DB_BLOB_HH
2 #define VTESTBED_DB_BLOB_HH
3 
4 #include <sstream>
5 
6 #include <vtestbed/base/bstream.hh>
7 #include <sqlitex/statement.hh>
8 
9 namespace vtb {
10 
11  namespace db {
12 
13  template <class Object>
14  inline sqlite::blob
15  make_blob(const Object& object) {
16  std::stringbuf buf;
17  vtb::base::bstream str(&buf);
18  str << object;
19  return buf.str();
20  }
21 
22  template <class Object>
23  struct object_wrapper {
24  Object& _object;
25  };
26 
27  template <class Object>
28  inline sqlite::cstream&
29  operator>>(sqlite::cstream& in, const object_wrapper<Object>& rhs) {
30  sqlite::blob blob;
31  in >> blob;
32  if (!blob.empty()) {
33  std::stringbuf buf{blob};
34  vtb::base::bstream str{&buf};
35  str >> rhs._object;
36  }
37  return in;
38  }
39 
40  template <class Object>
41  inline object_wrapper<Object>
42  make_object(Object& object) {
43  return object_wrapper<Object>{object};
44  }
45 
46  }
47 
48 }
49 
50 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9