From b9d18e76f95a9a231cc4a8a9aea5bf1bad942c9a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 22 Sep 2011 11:02:08 +0200 Subject: Make common result implementation instead of separate for views and objects --- odb/object-result.hxx | 155 +------------------------------------------------- 1 file changed, 3 insertions(+), 152 deletions(-) (limited to 'odb/object-result.hxx') diff --git a/odb/object-result.hxx b/odb/object-result.hxx index b4ef810..4c25962 100644 --- a/odb/object-result.hxx +++ b/odb/object-result.hxx @@ -27,8 +27,8 @@ namespace odb ~result_impl (); protected: - friend class result; - friend class result; + friend class result; + friend class result; friend class result_iterator; friend class result_iterator; @@ -206,167 +206,18 @@ namespace odb result_impl_type* res_; }; - // Input iterator requirements. - // - template - inline bool - operator== (result_iterator i, - result_iterator j) - { - return i.equal (j); - } - - template - inline bool - operator!= (result_iterator i, - result_iterator j) - { - return !i.equal (j); - } - // // template - class result + class result_base { public: typedef typename object_traits::pointer_type value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - typedef result_iterator iterator; - - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; // T can be const T while object_type is always non-const. // typedef typename object_traits::object_type object_type; typedef result_impl result_impl_type; - - public: - result () - { - } - - explicit - result (details::shared_ptr impl) - : impl_ (impl) - { - } - - // Copying or assignment of a result object leads to one instance - // being an alias for another. Think of copying a result as copying - // a file handle -- the file you access through either of them is - // still the same. - // - public: - result (const result& r) - : impl_ (r.impl_) - { - } - - result& - operator= (const result& r) - { - if (impl_ != r.impl_) - impl_ = r.impl_; - - return *this; - } - - // Conversion from result to result. - // - template - result (const result& r) - // - // If you get a compiler error pointing to the line below saying - // that the impl_ member is inaccessible, then you are most likely - // trying to perform an illegal result conversion, for example, - // from result to result. - // - : impl_ (r.impl_) - { - } - - template - result& - operator= (const result& r) - { - // If you get a compiler error pointing to the line below saying - // that the impl_ member is inaccessible, then you are most likely - // trying to perform an illegal result conversion, for example, - // from result to result. - // - if (impl_ != r.impl_) - impl_ = r.impl_; - - return *this; - } - - void - swap (result& r) - { - // @@ add swap() to shared_ptr. - // - details::shared_ptr p (impl_); - impl_ = r.impl_; - r.impl_ = p; - } - - public: - iterator - begin () - { - if (impl_) - impl_->begin (); - - return iterator (impl_.get ()); - } - - iterator - end () - { - return iterator (); - } - - // Cache the result instead of fetching the data from the database - // one object at a time. This is necessary if you plan on performing - // database operations while iterating over the result. - // - public: - void - cache () - { - if (impl_) - impl_->cache (); - } - - public: - bool - empty () const - { - if (impl_ == 0) - return true; - - impl_->begin (); - return impl_->end (); - } - - // Size is only known in cached results. - // - size_type - size () const - { - return impl_ ? impl_->size () : 0; - } - - private: - friend class result; - - details::shared_ptr impl_; }; } -- cgit v1.1