You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2018/12/27 04:30:17 UTC

svn commit: r1849788 - in /subversion/trunk/subversion/bindings/cxx: include/svnxx/depth.hpp src/depth.cpp src/private.hpp src/private/depth-private.hpp src/private/strings-private.hpp tests/test_depth.cpp

Author: brane
Date: Thu Dec 27 04:30:16 2018
New Revision: 1849788

URL: http://svn.apache.org/viewvc?rev=1849788&view=rev
Log:
Add SVN++ encapsulation of svn_depth_t.

[in subversion/bindings/cxx]
* include/svnxx/depth.hpp: New file.
* src/depth.cpp: New; implementation of svn::depth conversions.

* src/private.hpp: Include depth-private.hpp and strings-private.hpp.
* private/depth-private.hpp: New file.
* private/strings-private.hpp: New; string conversions.

* tests/test_depth.cpp: New.

Added:
    subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp   (with props)
    subversion/trunk/subversion/bindings/cxx/src/depth.cpp   (with props)
    subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp   (with props)
    subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp   (with props)
    subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp   (with props)
Modified:
    subversion/trunk/subversion/bindings/cxx/src/private.hpp

Added: subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp?rev=1849788&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp (added)
+++ subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp Thu Dec 27 04:30:16 2018
@@ -0,0 +1,76 @@
+/**
+ * @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 SVNXX_DEPTH_HPP
+#define SVNXX_DEPTH_HPP
+
+#include <cstdint>
+#include <string>
+
+namespace apache {
+namespace subversion {
+namespace svnxx {
+
+/**
+ * @brief The concept of depth for directories (see @ref svn_depth_t).
+ */
+// NOTE: Keep these values identical to those in svn_depth_t!
+enum class depth : int8_t
+  {
+    unknown = -2,
+    exclude = -1,
+    empty = 0,
+    files = 1,
+    immediates = 2,
+    infinity = 3,
+  };
+
+/**
+ * @brief Converts a depth constant to its string representation.
+ * @see svn_depth_to_word()
+ */
+std::string to_string(depth);
+
+/**
+ * @brief Converts a depth constant to its wide-string representation.
+ * @see svn_depth_to_word()
+ */
+std::wstring to_wstring(depth);
+
+/**
+ * @brief Converts a depth constant to its UTF-16 string representation.
+ * @see svn_depth_to_word()
+ */
+std::u16string to_u16string(depth);
+
+/**
+ * @brief Converts a depth constant to its UTF-32 string representation.
+ * @see svn_depth_to_word()
+ */
+std::u32string to_u32string(depth);
+
+} // namespace svnxx
+} // namespace subversion
+} // namespace apache
+
+#endif  // SVNXX_CLIENT_HPP

Propchange: subversion/trunk/subversion/bindings/cxx/include/svnxx/depth.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/trunk/subversion/bindings/cxx/src/depth.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/depth.cpp?rev=1849788&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/depth.cpp (added)
+++ subversion/trunk/subversion/bindings/cxx/src/depth.cpp Thu Dec 27 04:30:16 2018
@@ -0,0 +1,142 @@
+/**
+ * @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 <stdexcept>
+
+#include "svnxx/depth.hpp"
+#include "private.hpp"
+
+namespace apache {
+namespace subversion {
+namespace svnxx {
+
+std::string to_string(depth d)
+{
+  return std::string(svn_depth_to_word(detail::convert(d)));
+}
+
+std::wstring to_wstring(depth d)
+{
+  return detail::convert<wchar_t>(svn_depth_to_word(detail::convert(d)));
+}
+
+std::u16string to_u16string(depth d)
+{
+  return detail::convert<char16_t>(svn_depth_to_word(detail::convert(d)));
+}
+
+std::u32string to_u32string(depth d)
+{
+  return detail::convert<char32_t>(svn_depth_to_word(detail::convert(d)));
+}
+
+namespace detail {
+
+svn_depth_t convert(depth d)
+{
+#ifdef SVN_DEBUG
+  switch (d)
+    {
+    case depth::unknown:
+      if (d != svn_depth_unknown)
+        throw std::range_error("convert svn::depth::unknown");
+      break;
+
+    case depth::exclude:
+      if (d != svn_depth_exclude)
+        throw std::range_error("convert svn::depth::exclude");
+      break;
+
+    case depth::empty:
+      if (d != svn_depth_empty)
+        throw std::range_error("convert svn::depth::empty");
+      break;
+
+    case depth::files:
+      if (d != svn_depth_files)
+        throw std::range_error("convert svn::depth::files");
+      break;
+
+    case depth::immediates:
+      if (d != svn_depth_immediates)
+        throw std::range_error("convert svn::depth::immediates");
+      break;
+
+    case depth::infinity:
+      if (d != svn_depth_infinity)
+        throw std::range_error("convert svn::depth::infinity");
+      break;
+
+    default:
+      throw std::range_error("unknown svn::depth");
+    }
+#endif
+  return svn_depth_t(d);
+}
+
+depth convert(svn_depth_t d)
+{
+#ifdef SVN_DEBUG
+  switch (d)
+    {
+    case svn_depth_unknown:
+      if (d != depth::unknown)
+        throw std::range_error("convert svn_depth_unknown");
+      break;
+
+    case svn_depth_exclude:
+      if (d != depth::exclude)
+        throw std::range_error("convert svn_depth_exclude");
+      break;
+
+    case svn_depth_empty:
+      if (d != depth::empty)
+        throw std::range_error("convert svn_depth_empty");
+      break;
+
+    case svn_depth_files:
+      if (d != depth::files)
+        throw std::range_error("convert svn_depth_files");
+      break;
+
+    case svn_depth_immediates:
+      if (d != depth::immediates)
+        throw std::range_error("convert svn_depth_immediates");
+      break;
+
+    case svn_depth_infinity:
+      if (d != depth::infinity)
+        throw std::range_error("convert svn_depth_infinity");
+      break;
+
+    default:
+      throw std::range_error("unknown svn_depth_t");
+    }
+#endif
+  return depth(d);
+}
+
+} // namespace detail
+} // namespace svnxx
+} // namespace subversion
+} // namespace apache

Propchange: subversion/trunk/subversion/bindings/cxx/src/depth.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/trunk/subversion/bindings/cxx/src/private.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/private.hpp?rev=1849788&r1=1849787&r2=1849788&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/private.hpp (original)
+++ subversion/trunk/subversion/bindings/cxx/src/private.hpp Thu Dec 27 04:30:16 2018
@@ -24,7 +24,9 @@
 #ifndef SVNXX_PRIVATE_PRIVATE_HPP
 #define SVNXX_PRIVATE_PRIVATE_HPP
 
+#include "private/depth-private.hpp"
 #include "private/exception-private.hpp"
+#include "private/strings-private.hpp"
 #include "private/tristate-private.hpp"
 
 #endif // SVNXX_PRIVATE_PRIVATE_HPP

Added: subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp?rev=1849788&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp (added)
+++ subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp Thu Dec 27 04:30:16 2018
@@ -0,0 +1,51 @@
+/**
+ * @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 SVNXX_PRIVATE_DEPTH_HPP
+#define SVNXX_PRIVATE_DEPTH_HPP
+
+#include "svnxx/depth.hpp"
+
+#include "svn_types.h"
+
+namespace apache {
+namespace subversion {
+namespace svnxx {
+namespace detail {
+
+/**
+ * Convert @a d to an svn_depth_t.
+ */
+svn_depth_t convert(depth d);
+
+/**
+ * Convert @a d to an svn::depth.
+ */
+depth convert(svn_depth_t d);
+
+} // namespace detail
+} // namespace svnxx
+} // namespace subversion
+} // namespace apache
+
+#endif // SVNXX_PRIVATE_DEPTH_HPP

Propchange: subversion/trunk/subversion/bindings/cxx/src/private/depth-private.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp?rev=1849788&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp (added)
+++ subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp Thu Dec 27 04:30:16 2018
@@ -0,0 +1,106 @@
+/**
+ * @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 SVNXX_PRIVATE_STRINGS_HPP
+#define SVNXX_PRIVATE_STRINGS_HPP
+
+#include <codecvt>
+#include <cstdlib>
+#include <locale>
+#include <string>
+
+namespace apache {
+namespace subversion {
+namespace svnxx {
+namespace detail {
+
+namespace {
+// Define codecvt types for our various converters.
+template<typename C> struct codecvt;
+template<> struct codecvt<wchar_t> : public std::codecvt_utf8<wchar_t> {};
+template<> struct codecvt<char16_t> : public std::codecvt_utf8_utf16<char16_t> {};
+template<> struct codecvt<char32_t> : public std::codecvt_utf8<char32_t> {};
+
+template<typename C> using converter = std::wstring_convert<codecvt<C>, C>;
+} // anonymous namespace
+
+/**
+ * Convert a sequence of @c char's encoded as UTF-8 to a not-narroe string.
+ */
+template<typename C>
+inline std::basic_string<C> convert(const char* cstr, std::size_t size)
+{
+  return converter<C>().from_bytes(cstr, cstr + size);
+}
+
+/**
+ * Convert a nul-terminated string encoded as UTF-8 to a not-narrow string.
+ */
+template<typename C>
+inline std::basic_string<C> convert(const char* cstr)
+{
+  return converter<C>().from_bytes(cstr);
+}
+
+/**
+ * Convert a string encoded as UTF-8 to a not-narrow string.
+ */
+template<typename C>
+inline std::basic_string<C> convert(const std::string& str)
+{
+  return converter<C>().from_bytes(str);
+}
+
+/**
+ * Convert a sequence of @c C's to a string encoded as UTF-8.
+ */
+template<typename C>
+inline std::string convert(const C* cstr, std::size_t size)
+{
+  return converter<C>().to_bytes(cstr, size);
+}
+
+/**
+ * Convert a nul-terminated not-narrow string to a string encoded as UTF-8.
+ */
+template<typename C>
+inline std::string convert(const C* cstr)
+{
+  return converter<C>().to_bytes(cstr);
+}
+
+/**
+ * Convert a not-narrow string to a string encoded as UTF-8.
+ */
+template<typename C>
+inline std::string convert(const std::basic_string<C>& str)
+{
+  return converter<C>().to_bytes(str);
+}
+
+} // namespace detail
+} // namespace svnxx
+} // namespace subversion
+} // namespace apache
+
+#endif // SVNXX_PRIVATE_STRINGS_HPP

Propchange: subversion/trunk/subversion/bindings/cxx/src/private/strings-private.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp?rev=1849788&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp (added)
+++ subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp Thu Dec 27 04:30:16 2018
@@ -0,0 +1,91 @@
+/*
+ * ====================================================================
+ *    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.
+ * ====================================================================
+ */
+
+#include <boost/test/unit_test.hpp>
+
+#include "../src/private/depth-private.hpp"
+
+namespace svn = ::apache::subversion::svnxx;
+namespace detail = ::apache::subversion::svnxx::detail;
+
+BOOST_AUTO_TEST_SUITE(depth);
+
+BOOST_AUTO_TEST_CASE(convert_to)
+{
+  BOOST_TEST((detail::convert(svn::depth::unknown)    == svn_depth_unknown));
+  BOOST_TEST((detail::convert(svn::depth::exclude)    == svn_depth_exclude));
+  BOOST_TEST((detail::convert(svn::depth::empty)      == svn_depth_empty));
+  BOOST_TEST((detail::convert(svn::depth::files)      == svn_depth_files));
+  BOOST_TEST((detail::convert(svn::depth::immediates) == svn_depth_immediates));
+  BOOST_TEST((detail::convert(svn::depth::infinity)   == svn_depth_infinity));
+}
+
+BOOST_AUTO_TEST_CASE(convert_from)
+{
+  BOOST_TEST((detail::convert(svn_depth_unknown)    == svn::depth::unknown));
+  BOOST_TEST((detail::convert(svn_depth_exclude)    == svn::depth::exclude));
+  BOOST_TEST((detail::convert(svn_depth_empty)      == svn::depth::empty));
+  BOOST_TEST((detail::convert(svn_depth_files)      == svn::depth::files));
+  BOOST_TEST((detail::convert(svn_depth_immediates) == svn::depth::immediates));
+  BOOST_TEST((detail::convert(svn_depth_infinity)   == svn::depth::infinity));
+}
+
+BOOST_AUTO_TEST_CASE(char_names)
+{
+  BOOST_TEST((to_string(svn::depth::unknown)    == "unknown"));
+  BOOST_TEST((to_string(svn::depth::exclude)    == "exclude"));
+  BOOST_TEST((to_string(svn::depth::empty)      == "empty"));
+  BOOST_TEST((to_string(svn::depth::files)      == "files"));
+  BOOST_TEST((to_string(svn::depth::immediates) == "immediates"));
+  BOOST_TEST((to_string(svn::depth::infinity)   == "infinity"));
+}
+
+BOOST_AUTO_TEST_CASE(wchar_names)
+{
+  BOOST_TEST((to_wstring(svn::depth::unknown)    == L"unknown"));
+  BOOST_TEST((to_wstring(svn::depth::exclude)    == L"exclude"));
+  BOOST_TEST((to_wstring(svn::depth::empty)      == L"empty"));
+  BOOST_TEST((to_wstring(svn::depth::files)      == L"files"));
+  BOOST_TEST((to_wstring(svn::depth::immediates) == L"immediates"));
+  BOOST_TEST((to_wstring(svn::depth::infinity)   == L"infinity"));
+}
+
+BOOST_AUTO_TEST_CASE(char16_names)
+{
+  BOOST_TEST((to_u16string(svn::depth::unknown)    == u"unknown"));
+  BOOST_TEST((to_u16string(svn::depth::exclude)    == u"exclude"));
+  BOOST_TEST((to_u16string(svn::depth::empty)      == u"empty"));
+  BOOST_TEST((to_u16string(svn::depth::files)      == u"files"));
+  BOOST_TEST((to_u16string(svn::depth::immediates) == u"immediates"));
+  BOOST_TEST((to_u16string(svn::depth::infinity)   == u"infinity"));
+}
+
+BOOST_AUTO_TEST_CASE(char32_names)
+{
+  BOOST_TEST((to_u32string(svn::depth::unknown)    == U"unknown"));
+  BOOST_TEST((to_u32string(svn::depth::exclude)    == U"exclude"));
+  BOOST_TEST((to_u32string(svn::depth::empty)      == U"empty"));
+  BOOST_TEST((to_u32string(svn::depth::files)      == U"files"));
+  BOOST_TEST((to_u32string(svn::depth::immediates) == U"immediates"));
+  BOOST_TEST((to_u32string(svn::depth::infinity)   == U"infinity"));
+}
+
+BOOST_AUTO_TEST_SUITE_END();

Propchange: subversion/trunk/subversion/bindings/cxx/tests/test_depth.cpp
------------------------------------------------------------------------------
    svn:eol-style = native