From 2d1104b1e3cfbf394981c39d8828598599dee5d6 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 21 Apr 2011 09:19:17 +0200 Subject: Add qt/container implementation --- odb/qt.options | 1 + odb/qt/basic/sqlite/default-mapping.hxx | 2 +- odb/qt/containers.options | 20 +++++ odb/qt/containers/qhash-traits.hxx | 129 +++++++++++++++++++++++++++++ odb/qt/containers/qlinked-list-traits.hxx | 74 +++++++++++++++++ odb/qt/containers/qlist-traits.hxx | 73 +++++++++++++++++ odb/qt/containers/qmap-traits.hxx | 130 ++++++++++++++++++++++++++++++ odb/qt/containers/qset-traits.hxx | 70 ++++++++++++++++ odb/qt/containers/qvector-traits.hxx | 73 +++++++++++++++++ odb/qt/date-time/sqlite/qdate-traits.hxx | 2 +- 10 files changed, 572 insertions(+), 2 deletions(-) create mode 100644 odb/qt/containers.options create mode 100644 odb/qt/containers/qhash-traits.hxx create mode 100644 odb/qt/containers/qlinked-list-traits.hxx create mode 100644 odb/qt/containers/qlist-traits.hxx create mode 100644 odb/qt/containers/qmap-traits.hxx create mode 100644 odb/qt/containers/qset-traits.hxx create mode 100644 odb/qt/containers/qvector-traits.hxx diff --git a/odb/qt.options b/odb/qt.options index a1360f2..542e3fe 100644 --- a/odb/qt.options +++ b/odb/qt.options @@ -4,5 +4,6 @@ # license : GNU GPL v2; see accompanying LICENSE file --profile qt/basic +--profile qt/containers --profile qt/date-time --profile qt/smart-ptr diff --git a/odb/qt/basic/sqlite/default-mapping.hxx b/odb/qt/basic/sqlite/default-mapping.hxx index ea8108e..7211700 100644 --- a/odb/qt/basic/sqlite/default-mapping.hxx +++ b/odb/qt/basic/sqlite/default-mapping.hxx @@ -14,7 +14,7 @@ // #pragma db value(QString) type("TEXT") -// Map QByteArray to SQLite TEXT by default. Allow NULL values by default as +// Map QByteArray to SQLite BLOB by default. Allow NULL values by default as // QByteArray provides a null representation. // #pragma db value(QByteArray) type("BLOB") diff --git a/odb/qt/containers.options b/odb/qt/containers.options new file mode 100644 index 0000000..3651b9e --- /dev/null +++ b/odb/qt/containers.options @@ -0,0 +1,20 @@ +# file : odb/qt/containers.options +# author : Constantin Michael +# copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +# licences : GNU GPL v2; see accompanying LICENSE file + +--profile qt/version + +--odb-epilogue '#include ' +--odb-epilogue '#include ' +--odb-epilogue '#include ' +--odb-epilogue '#include ' +--odb-epilogue '#include ' +--odb-epilogue '#include ' + +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' +--hxx-prologue '#include ' diff --git a/odb/qt/containers/qhash-traits.hxx b/odb/qt/containers/qhash-traits.hxx new file mode 100644 index 0000000..c34b768 --- /dev/null +++ b/odb/qt/containers/qhash-traits.hxx @@ -0,0 +1,129 @@ +// file : odb/qt/containers/qhash-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QHASH_TRAITS_HXX +#define ODB_QT_CONTAINER_QHASH_TRAITS_HXX + +#include + +#include +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static container_kind const kind = ck_map; + + typedef QHash container_type; + typedef Key key_type; + typedef T value_type; + + typedef map_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + key_type k; + value_type v; + more = f.load_all (k, v); + c.insert (k, v); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; + + // @@ QMultiHash guarantees elements to be stored in reverse order of + // insertion. The current implementation of the generated code does + // not guarantee this. + // + template + class access::container_traits > + { + public: + static container_kind const kind = ck_multimap; + + typedef QMultiHash container_type; + typedef Key key_type; + typedef T value_type; + + typedef map_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + key_type k; + value_type v; + more = f.load_all (k, v); + c.insert (k, v); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QHASH_TRAITS_HXX diff --git a/odb/qt/containers/qlinked-list-traits.hxx b/odb/qt/containers/qlinked-list-traits.hxx new file mode 100644 index 0000000..708e240 --- /dev/null +++ b/odb/qt/containers/qlinked-list-traits.hxx @@ -0,0 +1,74 @@ +// file : odb/qt/containers/qlinked-list-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QLINKED_LIST_TRAITS_HXX +#define ODB_QT_CONTAINER_QLINKED_LIST_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static container_kind const kind = ck_ordered; + + typedef QLinkedList container_type; + + typedef T value_type; + typedef typename container_type::size_type index_type; + + typedef ordered_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + index_type i (0); + for (typename container_type::const_iterator j (c.begin ()), + e (c.end ()); j != e; ++j) + f.insert_one (i++, *j); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + index_type dummy; + c.append (value_type ()); + more = f.load_all (dummy, c.back ()); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + index_type i (0); + for (typename container_type::const_iterator j (c.begin ()), + e (c.end ()); j != e; ++j) + f.insert_one (i++, *j); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QLINKED_LIST_TRAITS_HXX diff --git a/odb/qt/containers/qlist-traits.hxx b/odb/qt/containers/qlist-traits.hxx new file mode 100644 index 0000000..9ac7cbf --- /dev/null +++ b/odb/qt/containers/qlist-traits.hxx @@ -0,0 +1,73 @@ +// file : odb/qt/containers/qlist-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QLIST_TRAITS_HXX +#define ODB_QT_CONTAINER_QLIST_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static const container_kind kind = ck_ordered; + + typedef QList container_type; + + typedef T value_type; + typedef typename container_type::size_type index_type; + + typedef ordered_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + // Index based access is just as fast as iterator based access for + // QList. + // + for (index_type i (0), n (c.size ()); i < n; ++i) + f.insert_one (i, c[i]); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + index_type dummy; + c.append (value_type ()); + more = f.load_all (dummy, c.back ()); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (index_type i (0), n (c.size ()); i < n; ++i) + f.insert_one (i, c[i]); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QLIST_TRAITS_HXX diff --git a/odb/qt/containers/qmap-traits.hxx b/odb/qt/containers/qmap-traits.hxx new file mode 100644 index 0000000..854dc87 --- /dev/null +++ b/odb/qt/containers/qmap-traits.hxx @@ -0,0 +1,130 @@ +// file : odb/qt/containers/qmap-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QMAP_TRAITS_HXX +#define ODB_QT_CONTAINER_QMAP_TRAITS_HXX + +#include + +#include +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static const container_kind kind = ck_map; + + typedef QMap container_type; + + typedef Key key_type; + typedef T value_type; + + typedef map_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + key_type k; + value_type v; + more = f.load_all (k, v); + c.insert (k, v); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; + // @@ QMultiMap guarantees elements to be stored in reverse order of + // insertion. The current implementation of the generated code does + // not guarantee this. + // + template + class access::container_traits > + { + public: + static const container_kind kind = ck_multimap; + + typedef QMultiMap container_type; + + typedef Key key_type; + typedef T value_type; + + typedef map_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + key_type k; + value_type v; + more = f.load_all (k, v); + c.insert (k, v); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (i.key (), i.value ()); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QMAP_TRAITS_HXX diff --git a/odb/qt/containers/qset-traits.hxx b/odb/qt/containers/qset-traits.hxx new file mode 100644 index 0000000..13216b9 --- /dev/null +++ b/odb/qt/containers/qset-traits.hxx @@ -0,0 +1,70 @@ +// file : odb/qt/containers/qset-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QSET_TRAITS_HXX +#define ODB_QT_CONTAINER_QSET_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static const container_kind kind = ck_set; + + typedef QSet container_type; + typedef T value_type; + + typedef set_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (*i); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + value_type v; + more = f.load_all (v); + c.insert (v); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (typename container_type::const_iterator i (c.begin ()), + e (c.end ()); i != e; ++i) + f.insert_one (*i); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QSET_TRAITS_HXX diff --git a/odb/qt/containers/qvector-traits.hxx b/odb/qt/containers/qvector-traits.hxx new file mode 100644 index 0000000..c86aa01 --- /dev/null +++ b/odb/qt/containers/qvector-traits.hxx @@ -0,0 +1,73 @@ +// file : odb/qt/containers/qvector-traits.hxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_QT_CONTAINER_QVECTOR_TRAITS_HXX +#define ODB_QT_CONTAINER_QVECTOR_TRAITS_HXX + +#include + +#include + +#include + +namespace odb +{ + template + class access::container_traits > + { + public: + static const container_kind kind = ck_ordered; + + typedef QVector container_type; + + typedef T value_type; + typedef typename container_type::size_type index_type; + + typedef ordered_functions functions; + + public: + static void + persist (const container_type& c, const functions& f) + { + // Index based access is just as fast as iterator based access for + // QVector. + // + for (index_type i (0), n (c.size ()); i < n; ++i) + f.insert_one (i, c[i]); + } + + static void + load (container_type& c, bool more, const functions& f) + { + c.clear (); + + while (more) + { + index_type dummy; + c.append (value_type ()); + more = f.load_all (dummy, c.back ()); + } + } + + static void + update (const container_type& c, const functions& f) + { + f.delete_all (); + + for (index_type i (0), n (c.size ()); i < n; ++i) + f.insert_one (i, c[i]); + } + + static void + erase (const functions& f) + { + f.delete_all (); + } + }; +} + +#include + +#endif // ODB_QT_CONTAINER_QVECTOR_TRAITS_HXX diff --git a/odb/qt/date-time/sqlite/qdate-traits.hxx b/odb/qt/date-time/sqlite/qdate-traits.hxx index d8df614..16940c3 100644 --- a/odb/qt/date-time/sqlite/qdate-traits.hxx +++ b/odb/qt/date-time/sqlite/qdate-traits.hxx @@ -93,7 +93,7 @@ namespace odb { QDateTime dt; dt.setTimeSpec (Qt::UTC); - dt.setTime_t(static_cast (i)); + dt.setTime_t (static_cast (i)); v = dt.date (); } -- cgit v1.1