Author: hwright
Date: Mon Oct  4 21:27:35 2010
New Revision: 1004438

URL: http://svn.apache.org/viewvc?rev=1004438&view=rev
Log:
On the object-model branch:
Parameterize the pool alloc function to return a buffer of a given type.
This prevents the need to add casts whenever grabbing bits of allocated memory.

* subversion/bindings/c++/include/Pool.h
  (Pool::alloc): Make a template function, and cast to the templated type.

* subversion/bindings/c++/include/Types.h
  (Version::dup): Use the improved pool alloc method.

* subversion/tests/libsvn++/util-test.cpp
  (test_pools): Alloc some more memory, using different template parameters.
 
* subversion/tests/libsvn++/client-test.cpp
  (get_client): Properly parameterize the pool alloc call.

Modified:
    subversion/branches/object-model/subversion/bindings/c++/include/Pool.h
    subversion/branches/object-model/subversion/bindings/c++/include/Types.h
    subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp
    subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp

Modified: 
subversion/branches/object-model/subversion/bindings/c++/include/Pool.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Pool.h?rev=1004438&r1=1004437&r2=1004438&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Pool.h 
(original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Pool.h Mon 
Oct  4 21:27:35 2010
@@ -53,10 +53,11 @@ namespace SVN
         svn_pool_destroy(m_pool);
       }
 
-      inline void *
+      template <typename T>
+      inline T *
       alloc(apr_size_t sz)
       {
-        return apr_palloc(m_pool, sz);
+        return reinterpret_cast<T *>(apr_palloc(m_pool, sz));
       }
 
       inline char *

Modified: 
subversion/branches/object-model/subversion/bindings/c++/include/Types.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/bindings/c%2B%2B/include/Types.h?rev=1004438&r1=1004437&r2=1004438&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/bindings/c++/include/Types.h 
(original)
+++ subversion/branches/object-model/subversion/bindings/c++/include/Types.h 
Mon Oct  4 21:27:35 2010
@@ -265,8 +265,7 @@ class Version
     inline static svn_version_t *
     dup(const svn_version_t *version, Pool &pool)
     {
-      svn_version_t *v =
-                    reinterpret_cast<svn_version_t *>(pool.alloc(sizeof(*v)));
+      svn_version_t *v = pool.alloc<svn_version_t>(sizeof(*v));
 
       v->major = version->major;
       v->minor = version->minor;

Modified: 
subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp
URL: 
http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/client-test.cpp?rev=1004438&r1=1004437&r2=1004438&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp 
(original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/client-test.cpp 
Mon Oct  4 21:27:35 2010
@@ -72,10 +72,10 @@ get_client(Pool &pool)
 {
   // We use placement new here to allocate the Client in the given pool.
   // We also register a function to destory the object on pool cleanup
-  void *buf = pool.alloc(sizeof(Client));
+  void *buf = pool.alloc<void>(sizeof(Client));
   Client *client = new (buf) Client();
 
-  buf = pool.alloc(sizeof(Notifier));
+  buf = pool.alloc<void>(sizeof(Notifier));
   Notifier *notifier = new (buf) Notifier();
   client->subscribeNotifier(notifier);
 

Modified: 
subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp
URL: 
http://svn.apache.org/viewvc/subversion/branches/object-model/subversion/tests/libsvn%2B%2B/util-test.cpp?rev=1004438&r1=1004437&r2=1004438&view=diff
==============================================================================
--- subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp 
(original)
+++ subversion/branches/object-model/subversion/tests/libsvn++/util-test.cpp 
Mon Oct  4 21:27:35 2010
@@ -42,7 +42,8 @@ test_pools(apr_pool_t *p)
   // We ignore the passed in pool, in favor of creating our own.
   Pool pool;
 
-  void *mem = pool.alloc(1000);
+  void *mem = pool.alloc<void>(1000);
+  const char *foo = pool.alloc<const char>(100);
 
   pool.clear();
 


Reply via email to