diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2017-04-29 23:55:46 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2017-04-30 23:57:17 +0300 |
commit | 8f3d3956b1e837c726859eb8bbe19dad79c54a42 (patch) | |
tree | 81ded52db212b12c7f685165702cce90aa0233cf /libbrep/package-traits.cxx | |
parent | ea60a6df471706a0eeb5ff1f774d69abe89e4bc9 (diff) |
Add hxx extension for headers and lib prefix for library dirs
Diffstat (limited to 'libbrep/package-traits.cxx')
-rw-r--r-- | libbrep/package-traits.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/libbrep/package-traits.cxx b/libbrep/package-traits.cxx new file mode 100644 index 0000000..a03cbac --- /dev/null +++ b/libbrep/package-traits.cxx @@ -0,0 +1,70 @@ +// file : libbrep/package-traits.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <libbrep/package-traits.hxx> + +#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); + } + } + } +} |