// file : odb/object-result.hxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #ifndef ODB_OBJECT_RESULT_HXX #define ODB_OBJECT_RESULT_HXX #include #include // std::ptrdiff_t #include // iterator categories #include #include #include #include namespace odb { // // object_result_impl // template class object_result_impl; template class polymorphic_object_result_impl; template class no_id_object_result_impl; // // object_result_impl_selector // template ::id_type, bool polymorphic = object_traits::polymorphic> struct object_result_impl_selector; template struct object_result_impl_selector { typedef object_result_impl type; }; template struct object_result_impl_selector { typedef polymorphic_object_result_impl type; }; template struct object_result_impl_selector { typedef no_id_object_result_impl type; }; // // result_iterator // template class object_result_iterator; template class result_iterator: public object_result_iterator< T, typename object_traits::id_type, object_traits::polymorphic> { public: typedef T value_type; typedef value_type& reference; typedef value_type* pointer; typedef std::ptrdiff_t difference_type; typedef std::input_iterator_tag iterator_category; // T can be const T while object_type is always non-const. // typedef object_result_iterator::id_type, object_traits::polymorphic> base_type; public: explicit result_iterator (typename base_type::result_impl_type* res = 0) : base_type (res) { } // Input iterator requirements. // public: reference operator* () const { return pointer_traits::get_ref (this->res_->current ()); } // Our value_type is already a pointer so return it instead of // a pointer to it (operator-> will just have to go one deeper // in the latter case). // pointer operator-> () const { return pointer_traits::get_ptr (this->res_->current ()); } result_iterator& operator++ () { this->res_->next (); return *this; } result_iterator operator++ (int) { // All non-end iterators for a result object move together. // this->res_->next (); return *this; } public: bool equal (result_iterator j) const { return (this->res_ ? this->res_->end () : true) == (j.res_ ? j.res_->end () : true); } private: // Use unrestricted pointer traits since that's what is returned by // result_impl. // typedef odb::pointer_traits< typename object_traits< typename base_type::object_type>::pointer_type> pointer_traits; }; // // template class result_base { public: typedef typename object_traits::pointer_type value_type; // T can be const T while object_type is always non-const. // typedef typename object_traits::object_type object_type; typedef typename object_result_impl_selector::type result_impl_type; }; } #include #endif // ODB_OBJECT_RESULT_HXX