Johannes Lochmann
2012-03-05 15:12:30 UTC
Hi list,
in case anybody besides me should find this useful.
HAND
Johannes
#include <string>
#include <sstream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
namespace pqxx {
template<> PQXX_LIBEXPORT struct string_traits<boost::uuids::uuid> {
static const char *name() {
return "boost::uuids::uuid";
}
static bool has_null() {
return false;
}
static bool is_null(const boost::uuids::uuid &) {
return false;
}
static boost::uuids::uuid null() {
internal::throw_null_conversion(name());
boost::uuids::nil_generator gen;
boost::uuids::uuid u = gen();
return u;
}
static void from_string(const char Str[], boost::uuids::uuid &Obj) {
std::stringstream ss;
ss << std::string(Str);
ss >> Obj;
}
static PGSTD::string to_string(const boost::uuids::uuid &Obj) {
std::stringstream ss;
ss << Obj;
return ss.str();
}
};
template<> PQXX_LIBEXPORT struct string_traits<boost::posix_time::ptime> {
static const char *name() {
return "boost::posix_time::ptime";
}
static bool has_null() {
return false;
}
static bool is_null(const boost::posix_time::ptime &) {
return false;
}
static boost::posix_time::ptime null() {
return boost::posix_time::ptime();
}
static void from_string(const char Str[], boost::posix_time::ptime
&Obj) {
Obj = boost::posix_time::time_from_string(std::string(Str));
}
static PGSTD::string to_string(const boost::posix_time::ptime &Obj) {
std::stringstream ss;
ss << Obj;
return ss.str();
}
};
}
in case anybody besides me should find this useful.
HAND
Johannes
#include <string>
#include <sstream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
namespace pqxx {
template<> PQXX_LIBEXPORT struct string_traits<boost::uuids::uuid> {
static const char *name() {
return "boost::uuids::uuid";
}
static bool has_null() {
return false;
}
static bool is_null(const boost::uuids::uuid &) {
return false;
}
static boost::uuids::uuid null() {
internal::throw_null_conversion(name());
boost::uuids::nil_generator gen;
boost::uuids::uuid u = gen();
return u;
}
static void from_string(const char Str[], boost::uuids::uuid &Obj) {
std::stringstream ss;
ss << std::string(Str);
ss >> Obj;
}
static PGSTD::string to_string(const boost::uuids::uuid &Obj) {
std::stringstream ss;
ss << Obj;
return ss.str();
}
};
template<> PQXX_LIBEXPORT struct string_traits<boost::posix_time::ptime> {
static const char *name() {
return "boost::posix_time::ptime";
}
static bool has_null() {
return false;
}
static bool is_null(const boost::posix_time::ptime &) {
return false;
}
static boost::posix_time::ptime null() {
return boost::posix_time::ptime();
}
static void from_string(const char Str[], boost::posix_time::ptime
&Obj) {
Obj = boost::posix_time::time_from_string(std::string(Str));
}
static PGSTD::string to_string(const boost::posix_time::ptime &Obj) {
std::stringstream ss;
ss << Obj;
return ss.str();
}
};
}