Author: wyoung
Date: Fri Aug 10 21:20:45 2007
New Revision: 1744

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1744&view=rev
Log:
Folded contents of const_subscript_container template into those classes
that use it.  It was just a trivial collection of typedefs and syntactic
sugar functions, none of which was ever changed or overridden.  It was
a base class for Fields, Row, and Result, but only because it was a
mix-in class, not because we want to pass objects of these types around
polymorphically; a Field is-not-a Row, which is-not-a Result.  Not only
do these classes have no is-a relationship now, there will be even less
resemblance between them after changes soon to come.

Bottom line, this class was more problem than solution.

Modified:
    trunk/Wishlist
    trunk/lib/fields.h
    trunk/lib/resiter.h
    trunk/lib/result.h
    trunk/lib/row.h

Modified: trunk/Wishlist
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/Wishlist?rev=1744&r1=1743&r2=1744&view=diff
==============================================================================
--- trunk/Wishlist (original)
+++ trunk/Wishlist Fri Aug 10 21:20:45 2007
@@ -70,14 +70,17 @@
 
     o Rework elment access in subscript_iterator derivatives:
 
-      - Add a vector<ColData> to Row as a parallel to MYSQL_ROW, with
-        each element pointing into a MYSQL_FIELD.
-
-      - Change operator[] from value to reference semantics.  (This
-        isn't possible in Row without previous change.)
-
-      - Add operator->()  (Similar to above, it can't work when the
-        underlying container can only provide value semantics.)
+      - Change data management to work like ColData's new reference-
+        counted buffer mechanism where possible to avoid copying
+        large data blocks when returning things by value.
+
+      - Change operator[] from value to reference semantics every
+        place this is possible.
+
+      - Add operator->() whereever reference semantics are possible
+
+    o Sort out the ResUse::fetch_row() vs. Result::fetch_row() mess.
+      Probably ResUse can't really justify having this.
 
     o ColData and SQLString are inverses.  ColData is initialized
       with string data from SQL results and can convert it to typical

Modified: trunk/lib/fields.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/fields.h?rev=1744&r1=1743&r2=1744&view=diff
==============================================================================
--- trunk/lib/fields.h (original)
+++ trunk/lib/fields.h Fri Aug 10 21:20:45 2007
@@ -3,10 +3,10 @@
 /// fields.
 
 /***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -41,9 +41,55 @@
 /// \brief A container similar to \c std::vector for holding
 /// mysqlpp::Field records.
 
-class MYSQLPP_EXPORT Fields : public const_subscript_container<Fields, Field>
+class MYSQLPP_EXPORT Fields
 {
 public:
+       typedef int difference_type;                    ///< type for index 
differences
+       typedef unsigned int size_type;                 ///< type of returned 
sizes
+
+       typedef Field value_type;                               ///< type of 
data in container
+       typedef value_type& reference;                  ///< reference to 
value_type
+       typedef const value_type& const_reference;///< const ref to value_type
+       typedef value_type* pointer;                    ///< pointer to 
value_type
+       typedef const value_type* const_pointer;///< const pointer to value_type
+
+       /// \brief regular iterator type
+       ///
+       /// Note that this is the same as const_iterator; we don't have a
+       /// mutable iterator type.
+       typedef subscript_iterator<const Fields, const value_type, size_type,
+                       difference_type> iterator;      
+       typedef iterator const_iterator;                ///< constant iterator 
type
+
+       /// \brief mutable reverse iterator type
+       typedef const std::reverse_iterator<iterator> reverse_iterator;         
        
+
+       /// \brief const reverse iterator type
+       typedef const std::reverse_iterator<const_iterator> 
const_reverse_iterator;             
+
+       /// \brief Return maximum number of elements that can be stored
+       /// in container without resizing.
+       size_type max_size() const { return size(); }
+
+       /// \brief Returns true if container is empty
+       bool empty() const { return size() == 0; }
+
+       /// \brief Return iterator pointing to first element in the
+       /// container
+       iterator begin() const { return iterator(this, 0); }
+
+       /// \brief Return iterator pointing to one past the last element
+       /// in the container
+       iterator end() const { return iterator(this, size()); }
+
+       /// \brief Return reverse iterator pointing to first element in the
+       /// container
+       reverse_iterator rbegin() const { return reverse_iterator(end()); }
+
+       /// \brief Return reverse iterator pointing to one past the last
+       /// element in the container
+       reverse_iterator rend() const { return reverse_iterator(begin()); }
+
        /// \brief Default constructor
        Fields() { }
        
@@ -54,12 +100,12 @@
        }
 
        /// \brief Returns a field given its index.
-       const Field& at(int i) const;
+       const value_type& at(int i) const;
 
        /// \brief Returns a field given its index.
        ///
        /// Just a synonym for at()
-       const Field& operator [](int i) const { return at(i); }
+       const value_type& operator [](int i) const { return at(i); }
 
        size_type size() const; ///< get the number of fields
 

Modified: trunk/lib/resiter.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/resiter.h?rev=1744&r1=1743&r2=1744&view=diff
==============================================================================
--- trunk/lib/resiter.h (original)
+++ trunk/lib/resiter.h Fri Aug 10 21:20:45 2007
@@ -7,10 +7,10 @@
 /// mysqlpp::Fields and mysqlpp::Row classes.
 
 /***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -39,83 +39,12 @@
 
 namespace mysqlpp {
 
-template <class OnType, class ReturnType, class SizeType,
-       class DiffType> class subscript_iterator;
-
-/// \brief A base class that one derives from to become a random
-/// access container, which can be accessed with subscript notation.
-///
-/// OnType must have the member functions \c operator[](int) and
-// \c size() defined for it.
-
-template <class OnType,
-               class ValueType,
-               class ReturnType = const ValueType&,
-               class SizeType = unsigned int,
-               class DiffType = int>
-class const_subscript_container
-{
-public:
-       typedef const_subscript_container<OnType, ValueType, ReturnType,
-                       SizeType, DiffType> this_type; ///< this object's type
-       typedef subscript_iterator<const this_type, ReturnType, SizeType,
-                       DiffType> iterator;                     ///< mutable 
iterator type
-       typedef iterator const_iterator;        ///< constant iterator type
-       typedef const std::reverse_iterator<iterator>
-                       reverse_iterator;                       ///< mutable 
reverse iterator type
-       typedef const std::reverse_iterator<const_iterator>
-                       const_reverse_iterator;         ///< const reverse 
iterator type
-
-       typedef ValueType value_type;           ///< type of data stored in 
container
-       typedef value_type& reference;          ///< reference to value_type
-       typedef value_type& const_reference;///< const ref to value_type
-       typedef value_type* pointer;            ///< pointer to value_type
-       typedef value_type* const_pointer;      ///< const pointer to value_type
-
-       typedef DiffType difference_type;       ///< for index differences
-       typedef SizeType size_type;                     ///< for returned sizes
-
-       /// \brief Destroy object
-       virtual ~const_subscript_container() { }
-
-       /// \brief Return count of elements in container
-       virtual size_type size() const = 0;     
-
-       /// \brief Return element at given index in container
-       virtual ReturnType at(int i) const = 0;
-
-       /// \brief Return maximum number of elements that can be stored
-       /// in container without resizing.
-       size_type max_size() const { return size(); }
-
-       /// \brief Returns true if container is empty
-       bool empty() const { return size() == 0; }
-
-       /// \brief Return iterator pointing to first element in the
-       /// container
-       iterator begin() const { return iterator(this, 0); }
-
-       /// \brief Return iterator pointing to one past the last element
-       /// in the container
-       iterator end() const { return iterator(this, size()); }
-
-       /// \brief Return reverse iterator pointing to first element in the
-       /// container
-       reverse_iterator rbegin() const { return reverse_iterator(end()); }
-
-       /// \brief Return reverse iterator pointing to one past the last
-       /// element in the container
-       reverse_iterator rend() const { return reverse_iterator(begin()); }
-};
-
-
 /// \brief Iterator that can be subscripted.
 ///
-/// This is the type of iterator used by the const_subscript_container
-/// template.
-
-template <class OnType, class ReturnType, class SizeType,
-               class DiffType>
+/// This is the type of iterator offered by most of MySQL++'s
+/// container-like classes.
+
+template <class OnType, class ReturnType, class SizeType, class DiffType>
 class subscript_iterator : public std::iterator<ReturnType, SizeType>
 {
 public:
@@ -259,9 +188,8 @@
 };
 
 
-#if !defined(DOXYGEN_IGNORE)
-// Doxygen will not generate documentation for this section.
-
+/// \brief Add a constant to a subscript_iterator, returning a
+/// subscript_iterator offset by that amount
 template <class OnType, class ReturnType, class SizeType,
                class DiffType> 
 inline subscript_iterator<OnType, ReturnType, SizeType, DiffType>
@@ -271,8 +199,6 @@
        return y + x;
 }
 
-#endif // !defined(DOXYGEN_IGNORE)
-
 } // end namespace mysqlpp
 
 #endif

Modified: trunk/lib/result.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/result.h?rev=1744&r1=1743&r2=1744&view=diff
==============================================================================
--- trunk/lib/result.h (original)
+++ trunk/lib/result.h Fri Aug 10 21:20:45 2007
@@ -2,10 +2,10 @@
 /// \brief Declares classes for holding SQL query result sets.
 
 /***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -338,10 +338,55 @@
 /// provides a reverse random-access iterator in addition to the normal
 /// forward one.
 
-class MYSQLPP_EXPORT Result : public ResUse,
-               public const_subscript_container<Result, Row, const Row>
+class MYSQLPP_EXPORT Result : public ResUse
 {
 public:
+       typedef int difference_type;                    ///< type for index 
differences
+       typedef unsigned int size_type;                 ///< type of returned 
sizes
+
+       typedef Row value_type;                                 ///< type of 
data in container
+       typedef value_type& reference;                  ///< reference to 
value_type
+       typedef const value_type& const_reference;///< const ref to value_type
+       typedef value_type* pointer;                    ///< pointer to 
value_type
+       typedef const value_type* const_pointer;///< const pointer to value_type
+
+       /// \brief regular iterator type
+       ///
+       /// Note that this is the same as const_iterator; we don't have a
+       /// mutable iterator type.
+       typedef subscript_iterator<const Result, const value_type, size_type,
+                       difference_type> iterator;      
+       typedef iterator const_iterator;                ///< constant iterator 
type
+
+       /// \brief mutable reverse iterator type
+       typedef const std::reverse_iterator<iterator> reverse_iterator;         
        
+
+       /// \brief const reverse iterator type
+       typedef const std::reverse_iterator<const_iterator> 
const_reverse_iterator;             
+
+       /// \brief Return maximum number of elements that can be stored
+       /// in container without resizing.
+       size_type max_size() const { return size(); }
+
+       /// \brief Returns true if container is empty
+       bool empty() const { return size() == 0; }
+
+       /// \brief Return iterator pointing to first element in the
+       /// container
+       iterator begin() const { return iterator(this, 0); }
+
+       /// \brief Return iterator pointing to one past the last element
+       /// in the container
+       iterator end() const { return iterator(this, size()); }
+
+       /// \brief Return reverse iterator pointing to first element in the
+       /// container
+       reverse_iterator rbegin() const { return reverse_iterator(end()); }
+
+       /// \brief Return reverse iterator pointing to one past the last
+       /// element in the container
+       reverse_iterator rend() const { return reverse_iterator(begin()); }
+
        /// \brief Default constructor
        Result()
        {
@@ -355,8 +400,7 @@
 
        /// \brief Initialize object as a copy of another Result object
        Result(const Result& other) :
-       ResUse(other),
-       const_subscript_container<Result, Row, const Row>() // no copying here
+       ResUse(other)
        {
                conn_ = 0;
        }
@@ -369,7 +413,7 @@
        /// This is simply the const version of the same function in our
        /// \link mysqlpp::ResUse parent class \endlink . Why this cannot
        /// actually \e be in our parent class is beyond me.
-       const Row fetch_row() const
+       const value_type fetch_row() const
        {
                if (!result_) {
                        if (throw_exceptions()) {
@@ -420,7 +464,7 @@
        }
 
        /// \brief Get the row with an offset of i.
-       const Row at(int i) const
+       const value_type at(int i) const
        {
                data_seek(i);
                return fetch_row();
@@ -429,7 +473,7 @@
        /// \brief Get the row with an offset of i.
        ///
        /// Just a synonym for at()
-       const Row operator [](int i) const { return at(i); }
+       const value_type operator [](int i) const { return at(i); }
 };
 
 

Modified: trunk/lib/row.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/row.h?rev=1744&r1=1743&r2=1744&view=diff
==============================================================================
--- trunk/lib/row.h (original)
+++ trunk/lib/row.h Fri Aug 10 21:20:45 2007
@@ -2,10 +2,10 @@
 /// \brief Declares the classes for holding row data from a result set.
 
 /***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004-2007 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file.  See the CREDITS
- file in the top directory of the distribution for details.
+ Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
+ (c) 2004-2007 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS file in
+ the top directory of the distribution for details.
 
  This file is part of MySQL++.
 
@@ -47,11 +47,55 @@
 #endif
 
 /// \brief Manages rows from a result set.
-class MYSQLPP_EXPORT Row :
-               public const_subscript_container<Row, ColData, const ColData>,
-               public OptionalExceptions
+class MYSQLPP_EXPORT Row : public OptionalExceptions
 {
 public:
+       typedef int difference_type;                    ///< type for index 
differences
+       typedef unsigned int size_type;                 ///< type of returned 
sizes
+
+       typedef ColData value_type;                             ///< type of 
data in container
+       typedef value_type& reference;                  ///< reference to 
value_type
+       typedef const value_type& const_reference;///< const ref to value_type
+       typedef value_type* pointer;                    ///< pointer to 
value_type
+       typedef const value_type* const_pointer;///< const pointer to value_type
+
+       /// \brief regular iterator type
+       ///
+       /// Note that this is the same as const_iterator; we don't have a
+       /// mutable iterator type.
+       typedef subscript_iterator<const Row, const value_type, size_type,
+                       difference_type> iterator;      
+       typedef iterator const_iterator;                ///< constant iterator 
type
+
+       /// \brief mutable reverse iterator type
+       typedef const std::reverse_iterator<iterator> reverse_iterator;         
        
+
+       /// \brief const reverse iterator type
+       typedef const std::reverse_iterator<const_iterator> 
const_reverse_iterator;             
+
+       /// \brief Return maximum number of elements that can be stored
+       /// in container without resizing.
+       size_type max_size() const { return size(); }
+
+       /// \brief Returns true if container is empty
+       bool empty() const { return size() == 0; }
+
+       /// \brief Return iterator pointing to first element in the
+       /// container
+       iterator begin() const { return iterator(this, 0); }
+
+       /// \brief Return iterator pointing to one past the last element
+       /// in the container
+       iterator end() const { return iterator(this, size()); }
+
+       /// \brief Return reverse iterator pointing to first element in the
+       /// container
+       reverse_iterator rbegin() const { return reverse_iterator(end()); }
+
+       /// \brief Return reverse iterator pointing to one past the last
+       /// element in the container
+       reverse_iterator rend() const { return reverse_iterator(begin()); }
+
        /// \brief Default constructor
        Row() :
        res_(0),
@@ -118,7 +162,7 @@
        /// This function is rather inefficient.  If that is a concern for
        /// you, use at(), operator[](size_type) or the SSQLS mechanism'
        /// instead.
-       const ColData operator [](const char* field) const;
+       const value_type operator [](const char* field) const;
 
        /// \brief Get the value of a field given its index.
        ///
@@ -127,7 +171,7 @@
        /// \sa at() for the full documentation for this operator, and
        /// operator[](const char*) for further caveats about using this
        /// operator.
-       const ColData operator [](int i) const
+       const value_type operator [](int i) const
        {
                return at(i);
        }
@@ -143,7 +187,7 @@
        /// retrieving data from this row object.
        ///
        /// See operator[](const char*) for more caveats.
-       const ColData at(int i) const;
+       const value_type at(int i) const;
 
        /// \brief Return the value of a field as a C string given its
        /// index, in raw form.


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to