subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1502137 - in /subversion/trunk/subversion/bindings/cxxhl/src/aprwrap: array.hpp hash.hpp impl.cpp
Date Thu, 11 Jul 2013 07:47:40 GMT
Author: brane
Date: Thu Jul 11 07:47:40 2013
New Revision: 1502137

URL: http://svn.apache.org/r1502137
Log:
Minor enhancements to C++HL infrastructure.

* subversion/bindings/cxxhl/src/aprwrap/array.hpp
  (Array::Array): When constructing an array proxy from an APR array,
   double-check that the element size and value type match.
  (ConstArray::ConstArray): Likewise.

* subversion/bindings/cxxhl/src/aprwrap/hash.hpp
  (Hash<void,void>::iterate): Move declaration to the top of the class.
  (Hash<void,void>::Key): Constrain friendshipt to Hash::iterate.
  (Hash::Key::Key): Replace private constructor with a
   downcast conversion constructor.
  (Hash::Iteration::operator()): Use the new conversion constructor.

* subversion/bindings/cxxhl/src/aprwrap/impl.cpp
  (Hash<void,void>::iterate): Rename argument 'pool' to 'scratch_pool'.

Modified:
    subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/array.hpp
    subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp
    subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/impl.cpp

Modified: subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/array.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/array.hpp?rev=1502137&r1=1502136&r2=1502137&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/array.hpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/array.hpp Thu Jul 11 07:47:40 2013
@@ -67,9 +67,13 @@ public:
   /**
    * Create a new proxy for the APR array @a array.
    */
-  explicit Array(apr_array_header_t* array) throw()
+  explicit Array(apr_array_header_t* array) throw(std::invalid_argument)
     : m_array(array)
-    {}
+    {
+      if (m_array->elt_size != sizeof(value_type))
+        throw std::invalid_argument(
+            _("APR array element size does not match template parameter"));
+    }
 
   /**
    * @return The wrapped APR array.
@@ -223,7 +227,8 @@ public:
   /**
    * Create a new proxy for the APR array @a array.
    */
-  explicit ConstArray(const apr_array_header_t* array) throw()
+  explicit ConstArray(const apr_array_header_t* array)
+    throw(std::invalid_argument)
     : inherited(const_cast<apr_array_header_t*>(array))
     {}
 

Modified: subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp?rev=1502137&r1=1502136&r2=1502137&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/hash.hpp Thu Jul 11 07:47:40 2013
@@ -44,6 +44,16 @@ template<>
 class Hash<void, void>
 {
 public:
+  struct Iteration;
+
+  /**
+   * Iterate over all the key-value pairs in the hash table, invoking
+   * @a callback for each pair.
+   * Uses @a scratch_pool for temporary allocations.
+   */
+  void iterate(Iteration& callback, const Pool& scratch_pool);
+
+public:
   /**
    * Proxy for a key in an APR hash table.
    * This is a template specialization for the default hash key type.
@@ -83,7 +93,7 @@ public:
     /**
      * The hash table wrapper must be able to call the protected constructor.
      */
-    friend class Hash;
+    friend void Hash::iterate(Hash::Iteration&, const Pool&);
 
   private:
     const key_type m_key;       ///< Immutable reference to the key
@@ -164,13 +174,6 @@ public:
     virtual bool operator() (const Key& key, value_type value) = 0;
   };
 
-  /**
-   * Iterate over all the key-value pairs in the hash table, invoking
-   * @a callback for each pair.
-   * Uses @a scratch_pool for temporary allocations.
-   */
-  void iterate(Iteration& callback, const Pool& scratch_pool);
-
 protected:
   typedef const void* const_value_type;
 
@@ -213,6 +216,12 @@ public:
   {
     typedef Hash<void, void>::Key inherited;
 
+    /**
+     * The wrapper must be able to call the private constructor and
+     * convert references to the base class.
+     */
+    friend class Hash;
+
   public:
     typedef const K* key_type;
     typedef inherited::size_type size_type;
@@ -239,17 +248,11 @@ public:
 
   private:
     /**
-     * Constructor used by the hash table wrapper.
-     * Does not make assumptions about the key size.
+     * Conversion constructor used by the derived iteration class.
      */
-    Key(key_type key, size_type size) throw()
-      : inherited(key, size)
+    explicit Key(const inherited::Key& that) throw()
+      : inherited(that)
       {}
-
-    /**
-     * The hash table wrapper must be able to call the private constructor.
-     */
-    friend class Hash;
   };
 
 public:
@@ -335,9 +338,7 @@ public:
     virtual bool operator() (const inherited::Key& raw_key,
                              inherited::value_type raw_value)
       {
-        return (*this)(
-            Key(static_cast<key_type>(raw_key.get()), raw_key.size()),
-            static_cast<value_type>(raw_value));
+        return (*this)(Key(raw_key), static_cast<value_type>(raw_value));
       }
   };
 

Modified: subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/impl.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/impl.cpp?rev=1502137&r1=1502136&r2=1502137&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/impl.cpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/src/aprwrap/impl.cpp Thu Jul 11 07:47:40 2013
@@ -89,9 +89,9 @@ apr_pool_t* Pool::get_root_pool() throw(
 //
 
 void Hash<void, void>::iterate(Hash<void, void>::Iteration& callback,
-                               const Pool& pool)
+                               const Pool& scratch_pool)
 {
-  for (apr_hash_index_t* hi = apr_hash_first(pool.get(), m_hash);
+  for (apr_hash_index_t* hi = apr_hash_first(scratch_pool.get(), m_hash);
        hi; hi = apr_hash_next(hi))
     {
       key_type key;



Mime
View raw message