Better support for boost::optional in database layer.
This commit is contained in:
parent
780d912cd1
commit
e4ccd93b09
4 changed files with 27 additions and 5 deletions
|
|
@ -26,14 +26,14 @@ namespace Pgsql {
|
|||
}
|
||||
|
||||
template <typename E, typename I>
|
||||
void getAsArray(I insert_iter, const E &value_for_nulls) const
|
||||
Col& getAsArray(I insert_iter, const E &value_for_nulls)
|
||||
{
|
||||
nextValue().getAsArray<E, I>(insert_iter, value_for_nulls);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename E, typename I>
|
||||
void getAsArrayOfOptional(I insert_iter) const
|
||||
Col& getAsArrayOfOptional(I insert_iter)
|
||||
{
|
||||
nextValue().getAsArrayOfOptional<E, I>(insert_iter);
|
||||
return *this;
|
||||
|
|
@ -50,6 +50,12 @@ namespace Pgsql {
|
|||
int col = -1;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
Col& operator>>(Col &c, std::vector<T> &s)
|
||||
{
|
||||
return c.getAsArray<T>(std::back_inserter(s));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
Col& operator>>(Col &c, T &s)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace Pgsql {
|
||||
|
||||
|
|
@ -149,10 +150,24 @@ namespace Pgsql {
|
|||
Oid m_typ;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void operator<<(boost::optional<T> &s, const Value &v)
|
||||
{
|
||||
if (v.null())
|
||||
s = boost::optional<T>();
|
||||
else
|
||||
*s << v;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator<<(std::vector<T> &s, const Value &v)
|
||||
{
|
||||
v.getAsArray(std::back_inserter(s));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void operator<<(T &s, const Value &v)
|
||||
{
|
||||
//s = static_cast<T>(v);
|
||||
s = v.operator T();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue