Author: wyoung
Date: Tue Nov 20 00:15:25 2007
New Revision: 1865

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1865&view=rev
Log:
- Added a few overloads for SQLTypeAdapter::assign(), like those in
  std::string
- Removed a few of SQLTypeAdapter's operator='s since they're redundant
  with respect to the conversion ctors.  C++ can do an implicit
  conversion on assignment for any type we previously supported
  explicitly, and buffer sharing keeps it reasonably efficient.

Modified:
    trunk/lib/stadapter.cpp
    trunk/lib/stadapter.h

Modified: trunk/lib/stadapter.cpp
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.cpp?rev=1865&r1=1864&r2=1865&view=diff
==============================================================================
--- trunk/lib/stadapter.cpp (original)
+++ trunk/lib/stadapter.cpp Tue Nov 20 00:15:25 2007
@@ -319,6 +319,39 @@
 buffer_(new RefCountedBuffer(null_str, typeid(void), true)),
 is_processed_(false)
 {
+}
+
+SQLTypeAdapter&
+SQLTypeAdapter::assign(const SQLTypeAdapter& sta)
+{
+       dec_ref_count();
+       buffer_ = sta.buffer_;
+       buffer_->attach();
+       is_processed_ = false;
+       return *this;
+}
+
+SQLTypeAdapter&
+SQLTypeAdapter::assign(const char* pc, int len)
+{
+       if (len < 0) {
+               len = strlen(pc);
+       }
+
+       dec_ref_count();
+       buffer_ = new RefCountedBuffer(pc, len,
+                       mysql_type_info::string_type, false);
+       is_processed_ = false;
+       return *this;
+}
+
+SQLTypeAdapter&
+SQLTypeAdapter::assign(const null_type& n)
+{ 
+       dec_ref_count();
+       buffer_ = new RefCountedBuffer(null_str, typeid(void), true);
+       is_processed_ = false;
+       return *this;
 }
 
 char
@@ -411,62 +444,13 @@
 SQLTypeAdapter&
 SQLTypeAdapter::operator =(const SQLTypeAdapter& rhs)
 {
-       dec_ref_count();
-       buffer_ = rhs.buffer_;
-       buffer_->attach();
-       is_processed_ = false;
-       return *this;
-}
-
-SQLTypeAdapter&
-SQLTypeAdapter::operator =(const String& rhs)
-{
-       dec_ref_count();
-       buffer_ = rhs.buffer_;
-       buffer_->attach();
-       is_processed_ = false;
-       return *this;
-}
-
-SQLTypeAdapter&
-SQLTypeAdapter::operator =(const char* str)
-{
-       dec_ref_count();
-       buffer_ = new RefCountedBuffer(str, strlen(str),
-                       mysql_type_info::string_type, false);
-       is_processed_ = false;
-       return *this;
-}
-
-SQLTypeAdapter&
-SQLTypeAdapter::operator =(const std::string& str)
-{
-       dec_ref_count();
-       buffer_ = new RefCountedBuffer(str,
-                       mysql_type_info::string_type, false);
-       is_processed_ = false;
-       return *this;
-}
-
-SQLTypeAdapter&
-SQLTypeAdapter::operator =(const Null<std::string>& str)
-{
-       dec_ref_count();
-       buffer_ = new RefCountedBuffer(
-                       str.is_null ? null_str : str.data,
-                       str.is_null ? typeid(void) : typeid(str.data),
-                       str.is_null);
-       is_processed_ = false;
-       return *this;
+       return assign(rhs);
 }
 
 SQLTypeAdapter&
 SQLTypeAdapter::operator =(const null_type& n)
 { 
-       dec_ref_count();
-       buffer_ = new RefCountedBuffer(null_str, typeid(void), true);
-       is_processed_ = false;
-       return *this;
+       return assign(n);
 }
 
 bool

Modified: trunk/lib/stadapter.h
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/stadapter.h?rev=1865&r1=1864&r2=1865&view=diff
==============================================================================
--- trunk/lib/stadapter.h (original)
+++ trunk/lib/stadapter.h Tue Nov 20 00:15:25 2007
@@ -160,27 +160,50 @@
 
        /// \brief Standard assignment operator
        ///
+       /// \see assign(const SQLTypeAdapter&) for details
+       SQLTypeAdapter& operator =(const SQLTypeAdapter& rhs);
+
+       /// \brief Replace contents of object with a SQL null
+       ///
+       /// \see assign(const null_type&) for details
+       SQLTypeAdapter& operator =(const null_type& n);
+
+       /// \brief Returns a const char pointer to the object's raw data
+       operator cchar*() const { return data(); }
+
+       /// \brief Copies another SQLTypeAdapter's data buffer into this
+       /// object.
+       ///
+       /// \param sta Other object to copy
+       ///
+       /// \retval *this
+       ///
        /// Detaches this object from its internal buffer and attaches
        /// itself to the other object's buffer, with reference counting
-       /// on each side.  If you need a deep copy, assign a string instead.
-       SQLTypeAdapter& operator =(const SQLTypeAdapter& rhs);
-
-       /// \brief Share a buffer with a String object
-       ///
-       /// Detaches this object from its internal buffer and attaches
-       /// itself to the other object's buffer, with reference counting
-       /// on each side.  If you need a deep copy, assign a string instead.
-       SQLTypeAdapter& operator =(const String& rhs);
-
-       /// \brief Copy a C string into this object
-       SQLTypeAdapter& operator =(const char* str);
-
-       /// \brief Copy a C++ \c string into this object
-       SQLTypeAdapter& operator =(const std::string& str);
-
-       /// \brief Returns a const char pointer to the object's raw data
-       operator cchar*() const { return data(); }
+       /// on each side.  If you need a deep copy, call one of the
+       /// assign() overloads taking a C or C++ string instead.
+       SQLTypeAdapter& assign(const SQLTypeAdapter& sta);
        
+       /// \brief Copies a C string or a raw buffer into this object.
+       ///
+       /// \param pc Pointer to char buffer to copy
+       /// \param len Number of characters to copy; default tells function
+       /// to use the return value of strlen() instead.
+       ///
+       /// \retval *this
+       ///
+       /// If you give the len parameter, this function will treat pc as a
+       /// pointer to an array of char, not as a C string.  It only treats
+       /// null characters as special when you leave len at its default.
+       SQLTypeAdapter& assign(const char* pc, int len = -1);
+
+       /// \brief Replaces contents of object with a SQL null
+       ///
+       /// \param n typically, the MySQL++ global object mysqlpp::null
+       ///
+       /// \retval *this
+       SQLTypeAdapter& assign(const null_type& n);
+
        /// \brief Returns the character at a given position within the
        /// string buffer.
        ///
@@ -269,7 +292,6 @@
        SQLTypeAdapter(const Null<DateTime>& dt);
        SQLTypeAdapter(const Null<Time>& t);
        SQLTypeAdapter& operator =(const Null<std::string>& str);
-       SQLTypeAdapter& operator =(const null_type& n);
 #endif // !defined(DOXYGEN_IGNORE)
 
 private:


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

Reply via email to