aboutsummaryrefslogtreecommitdiff
path: root/brep/package-traits.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-10-19 15:28:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-10-28 01:53:51 +0200
commit5b336ac46f60606cdcf77889d624ce15cdd62530 (patch)
tree469c0dd598b072d13b9a27f458c96c8353745638 /brep/package-traits.cxx
parent3e37999a5f9efd4caf44c40985b3e1254660a625 (diff)
Implement package search by terms
Diffstat (limited to 'brep/package-traits.cxx')
-rw-r--r--brep/package-traits.cxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/brep/package-traits.cxx b/brep/package-traits.cxx
new file mode 100644
index 0000000..cd30d81
--- /dev/null
+++ b/brep/package-traits.cxx
@@ -0,0 +1,70 @@
+// file : brep/package-traits.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <brep/package-traits>
+
+#include <string>
+#include <ostream>
+#include <sstream>
+#include <cstring> // memcpy
+
+#include <odb/pgsql/traits.hxx>
+
+using namespace std;
+
+namespace odb
+{
+ namespace pgsql
+ {
+ static inline void
+ to_pg_string (ostream& os, const string& s)
+ {
+ os << '"';
+
+ for (auto c: s)
+ {
+ if (c == '\\' || c == '"')
+ os << '\\';
+
+ os << c;
+ }
+
+ os << '"';
+ }
+
+ // Convert C++ weighted_text struct to PostgreSQL weighted_text
+ // composite type.
+ //
+ void value_traits<brep::weighted_text, id_string>::
+ set_image (details::buffer& b,
+ size_t& n,
+ bool& is_null,
+ const value_type& v)
+ {
+ is_null = v.a.empty () && v.b.empty () && v.c.empty () && v.d.empty ();
+
+ if (!is_null)
+ {
+ ostringstream o;
+ o << "(";
+ to_pg_string (o, v.a);
+ o << ",";
+ to_pg_string (o, v.b);
+ o << ",";
+ to_pg_string (o, v.c);
+ o << ",";
+ to_pg_string (o, v.d);
+ o << ")";
+
+ const string& s (o.str ());
+ n = s.size ();
+
+ if (n > b.capacity ())
+ b.capacity (n);
+
+ memcpy (b.data (), s.c_str (), n);
+ }
+ }
+ }
+}