subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1545925 - in /subversion/trunk/subversion/bindings/javahl/native: Utility.cpp Utility.hpp org_apache_subversion_javahl_util_SubstLib.cpp
Date Wed, 27 Nov 2013 04:59:22 GMT
Author: brane
Date: Wed Nov 27 04:59:21 2013
New Revision: 1545925

URL: http://svn.apache.org/r1545925
Log:
Add common utilities for JavaHL new-style map iterations.

* subversion/bindings/javahl/native/Utility.hpp,
  subversion/bindings/javahl/native/Utility.cpp: New files.
  (JavaHL::Util::make_keyword_hash, JavaHL::Util::make_property_hash):
   New utility functions for iterating over a Java::Map.

* subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
  (KeywordHashBuilder, make_keywords_hash): Removed.
  (translate_stream_common): Use JavaHL::Util::make_keyword_hash instead.

Added:
    subversion/trunk/subversion/bindings/javahl/native/Utility.cpp   (with props)
    subversion/trunk/subversion/bindings/javahl/native/Utility.hpp   (with props)
Modified:
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp

Added: subversion/trunk/subversion/bindings/javahl/native/Utility.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/Utility.cpp?rev=1545925&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/Utility.cpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/Utility.cpp Wed Nov 27 04:59:21 2013
@@ -0,0 +1,91 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#include <string>
+#include <apr_strings.h>
+
+#include "svn_string.h"
+
+#include "jniwrapper/jni_array.hpp"
+#include "jniwrapper/jni_string.hpp"
+#include "jniwrapper/jni_string_map.hpp"
+
+#include "Utility.hpp"
+
+
+namespace JavaHL {
+namespace Util {
+
+namespace {
+class MapToHashIteration
+{
+public:
+  explicit MapToHashIteration(const svn_string_t* default_value,
+                              apr_pool_t* pool)
+    : m_pool(pool),
+      m_hash(apr_hash_make(pool)),
+      m_default(default_value)
+    {}
+
+  void operator()(const std::string& key, const Java::ByteArray& value)
+    {
+      const char* const safe_key =
+        apr_pstrmemdup(m_pool, key.c_str(), key.size() + 1);
+      if (!value.get())
+        apr_hash_set(m_hash, safe_key, key.size(), m_default);
+      else
+        {
+          Java::ByteArray::Contents val(value);
+          apr_hash_set(m_hash, safe_key, key.size(), val.get_string(m_pool));
+        }
+    }
+
+  apr_hash_t* get() const
+    {
+      return m_hash;
+    }
+
+private:
+  apr_pool_t* const m_pool;
+  apr_hash_t* const m_hash;
+  const svn_string_t* const m_default;
+};
+} // anonymous namespace
+
+apr_hash_t*
+make_keyword_hash(::Java::Env env, jobject jkeywords, apr_pool_t* pool)
+{
+  const svn_string_t* const empty = svn_string_create_empty(pool);
+  const ::Java::Map< ::Java::ByteArray, jbyteArray> keywords(env, jkeywords);
+  return keywords.for_each(MapToHashIteration(empty, pool)).get();
+}
+
+apr_hash_t*
+make_property_hash(::Java::Env env, jobject jproperties, apr_pool_t* pool)
+{
+  const ::Java::Map< ::Java::ByteArray, jbyteArray> props(env, jproperties);
+  return props.for_each(MapToHashIteration(NULL, pool)).get();
+}
+
+} // namespace Util
+} // namespace JavaHL

Propchange: subversion/trunk/subversion/bindings/javahl/native/Utility.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/trunk/subversion/bindings/javahl/native/Utility.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/Utility.hpp?rev=1545925&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/Utility.hpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/Utility.hpp Wed Nov 27 04:59:21 2013
@@ -0,0 +1,90 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#ifndef SVN_JAVAHL_UTILITY_HPP
+#define SVN_JAVAHL_UTILITY_HPP
+
+#include <apr_hash.h>
+
+#include "Pool.h"
+
+namespace JavaHL {
+namespace Util {
+
+/**
+ * Converts keyword/valuue pairs in the the Java map @a jkeywords to
+ * an APR hash table allocated in @a pool. The keys in the resulting
+ * table are @c const @c char*, the values are @c svn_string_t*. Null
+ * values in the Java map are converted to empty strings.
+ *
+ * @since New in 1.9.
+ */
+apr_hash_t*
+make_keyword_hash(::Java::Env env, jobject jkeywords, apr_pool_t* pool);
+
+/**
+ * Converts keyword/valuue pairs in the the Java map @a jkeywords to
+ * an APR hash table allocated in @a pool. The keys in the resulting
+ * table are @c const @c char*, the values are @c svn_string_t*. Null
+ * values in the Java map are converted to empty strings.
+ *
+ * @since New in 1.9.
+ */
+inline apr_hash_t*
+make_keyword_hash(::Java::Env env, jobject jkeywords,
+                   const ::SVN::Pool& pool)
+{
+  return make_keyword_hash(env, jkeywords, pool.getPool());
+}
+
+
+/**
+ * Converts property/value pairs the Java map @a jkeywords to an APR
+ * hash table allocated in @a pool. The keys in the resulting table
+ * are @c const @c char*, the values are @c svn_string_t*. Null values
+ * in the Java map will not appear in the converted map.
+ *
+ * @since New in 1.9.
+ */
+apr_hash_t*
+make_property_hash(::Java::Env env, jobject jproperties, apr_pool_t* pool);
+
+/**
+ * Converts property/value pairs the Java map @a jkeywords to an APR
+ * hash table allocated in @a pool. The keys in the resulting table
+ * are @c const @c char*, the values are @c svn_string_t*. Null values
+ * in the Java map will not appear in the converted map.
+ *
+ * @since New in 1.9.
+ */
+inline apr_hash_t*
+make_property_hash(::Java::Env env, jobject jproperties,
+                   const ::SVN::Pool& pool)
+{
+  return make_property_hash(env, jproperties, pool.getPool());
+}
+
+} // namespace Util
+} // namespace JavaHL
+
+#endif // SVN_JAVAHL_JNI_UTILITY_HPP

Propchange: subversion/trunk/subversion/bindings/javahl/native/Utility.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp?rev=1545925&r1=1545924&r2=1545925&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
(original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_SubstLib.cpp
Wed Nov 27 04:59:21 2013
@@ -36,8 +36,8 @@
 
 #include "JNIUtil.h"
 #include "NativeStream.hpp"
+#include "Utility.hpp"
 
-#include <apr_strings.h>
 #include <apr_hash.h>
 
 #include "svn_subst.h"
@@ -81,46 +81,6 @@ build_keywords_common(Java::Env env, con
   return kw;
 }
 
-class KeywordHashBuilder
-{
-public:
-  explicit KeywordHashBuilder(const SVN::Pool& pool)
-    : m_pool(pool),
-      m_hash(apr_hash_make(pool.getPool())),
-      m_empty(svn_string_create_empty(pool.getPool()))
-    {}
-
-  void operator()(const std::string& key, const Java::ByteArray& value)
-    {
-      const char* const safe_key =
-        apr_pstrmemdup(m_pool.getPool(), key.c_str(), key.size() + 1);
-      if (!value.get())
-        apr_hash_set(m_hash, safe_key, key.size(), m_empty);
-      else
-        {
-          Java::ByteArray::Contents val(value);
-          apr_hash_set(m_hash, safe_key, key.size(), val.get_string(m_pool));
-        }
-    }
-
-  apr_hash_t* get() const
-    {
-      return m_hash;
-    }
-
-private:
-  const SVN::Pool& m_pool;
-  apr_hash_t* const m_hash;
-  svn_string_t* const m_empty;
-};
-
-inline apr_hash_t*
-make_keywords_hash(Java::Env env, const SVN::Pool& pool, jobject jkeywords)
-{
-  const Java::Map<Java::ByteArray, jbyteArray> keywords(env, jkeywords);
-  return keywords.for_each(KeywordHashBuilder(pool)).get();
-}
-
 svn_stream_t*
 translate_stream_common(Java::Env env, const SVN::Pool& pool,
                         svn_stream_t* stream,
@@ -133,7 +93,7 @@ translate_stream_common(Java::Env env, c
 {
   apr_hash_t* const keywords =
     (juse_keywords
-     ? make_keywords_hash(env, pool, jkeywords)
+     ? JavaHL::Util::make_keyword_hash(env, jkeywords, pool)
      : build_keywords_common(
          env, pool, jkeywords_value, jrevision,
          jurl, jrepos_root_url, jdate, jauthor));



Mime
View raw message