subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1850365 - in /subversion/trunk/subversion/bindings/cxx/src: depth.cpp private/depth_private.hpp
Date Fri, 04 Jan 2019 14:17:23 GMT
Author: brane
Date: Fri Jan  4 14:17:23 2019
New Revision: 1850365

URL: http://svn.apache.org/viewvc?rev=1850365&view=rev
Log:
Make conversions between svn_depth_t and svn::depth compile-time
constant expressions in SVN++.

[in subversion/bindings/cxx/src]
* private/depth_private.hpp: Include <stdexcept>. Do not include svn_types.h.
  (impl::convert): Implement here as inline constexpr functions.
* depth.cpp: Update include directives.
  (impl::convert): Remove implementation.

Modified:
    subversion/trunk/subversion/bindings/cxx/src/depth.cpp
    subversion/trunk/subversion/bindings/cxx/src/private/depth_private.hpp

Modified: subversion/trunk/subversion/bindings/cxx/src/depth.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/depth.cpp?rev=1850365&r1=1850364&r2=1850365&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/depth.cpp (original)
+++ subversion/trunk/subversion/bindings/cxx/src/depth.cpp Fri Jan  4 14:17:23 2019
@@ -21,10 +21,10 @@
  * @endcopyright
  */
 
-#include <stdexcept>
+#include "private/depth_private.hpp"
+#include "private/strings_private.hpp"
 
-#include "svnxx/depth.hpp"
-#include "private.hpp"
+#include "svn_types.h"
 
 namespace apache {
 namespace subversion {
@@ -50,93 +50,6 @@ std::u32string to_u32string(depth d)
   return impl::convert<char32_t>(svn_depth_to_word(impl::convert(d)));
 }
 
-namespace impl {
-
-svn_depth_t convert(depth d)
-{
-#ifdef SVN_DEBUG
-  switch (d)
-    {
-    case depth::unknown:
-      if (svn_depth_t(d) != svn_depth_unknown)
-        throw std::range_error("convert svn::depth::unknown");
-      break;
-
-    case depth::exclude:
-      if (svn_depth_t(d) != svn_depth_exclude)
-        throw std::range_error("convert svn::depth::exclude");
-      break;
-
-    case depth::empty:
-      if (svn_depth_t(d) != svn_depth_empty)
-        throw std::range_error("convert svn::depth::empty");
-      break;
-
-    case depth::files:
-      if (svn_depth_t(d) != svn_depth_files)
-        throw std::range_error("convert svn::depth::files");
-      break;
-
-    case depth::immediates:
-      if (svn_depth_t(d) != svn_depth_immediates)
-        throw std::range_error("convert svn::depth::immediates");
-      break;
-
-    case depth::infinity:
-      if (svn_depth_t(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 != svn_depth_t(depth::unknown))
-        throw std::range_error("convert svn_depth_unknown");
-      break;
-
-    case svn_depth_exclude:
-      if (d != svn_depth_t(depth::exclude))
-        throw std::range_error("convert svn_depth_exclude");
-      break;
-
-    case svn_depth_empty:
-      if (d != svn_depth_t(depth::empty))
-        throw std::range_error("convert svn_depth_empty");
-      break;
-
-    case svn_depth_files:
-      if (d != svn_depth_t(depth::files))
-        throw std::range_error("convert svn_depth_files");
-      break;
-
-    case svn_depth_immediates:
-      if (d != svn_depth_t(depth::immediates))
-        throw std::range_error("convert svn_depth_immediates");
-      break;
-
-    case svn_depth_infinity:
-      if (d != svn_depth_t(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 impl
 } // namespace svnxx
 } // namespace subversion
 } // namespace apache

Modified: 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=1850365&r1=1850364&r2=1850365&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/private/depth_private.hpp (original)
+++ subversion/trunk/subversion/bindings/cxx/src/private/depth_private.hpp Fri Jan  4 14:17:23
2019
@@ -24,9 +24,9 @@
 #ifndef SVNXX_PRIVATE_DEPTH_HPP
 #define SVNXX_PRIVATE_DEPTH_HPP
 
-#include "svnxx/depth.hpp"
+#include <stdexcept>
 
-#include "svn_types.h"
+#include "svnxx/depth.hpp"
 
 namespace apache {
 namespace subversion {
@@ -36,12 +36,90 @@ namespace impl {
 /**
  * Convert @a d to an svn_depth_t.
  */
-svn_depth_t convert(depth d);
+inline constexpr svn_depth_t convert(depth d)
+{
+#ifndef SVN_DEBUG
+  return svn_depth_t(d);
+#else
+  // switch in constexpr is allowed in C++14 but not in C++11, so we
+  // have to use a series of ternary operators.
+  return (d == depth::unknown
+          ? (svn_depth_t(d) != svn_depth_unknown
+             ? throw std::range_error("convert(svn::depth::unknown)")
+             : svn_depth_t(d))
+          :
+          d == depth::exclude
+          ? (svn_depth_t(d) != svn_depth_exclude
+             ? throw std::range_error("convert(svn::depth::exclude)")
+             : svn_depth_t(d))
+          :
+          d == depth::empty
+          ? (svn_depth_t(d) != svn_depth_empty
+             ? throw std::range_error("convert(svn::depth::empty)")
+             : svn_depth_t(d))
+          :
+          d == depth::files
+          ? (svn_depth_t(d) != svn_depth_files
+             ? throw std::range_error("convert(svn::depth::files)")
+             : svn_depth_t(d))
+          :
+          d == depth::immediates
+          ? (svn_depth_t(d) != svn_depth_immediates
+             ? throw std::range_error("convert(svn::depth::immediates)")
+             : svn_depth_t(d))
+          :
+          d == depth::infinity
+          ? (svn_depth_t(d) != svn_depth_infinity
+             ? throw std::range_error("convert(svn::depth::infinity)")
+             : svn_depth_t(d))
+          :
+          throw std::range_error("convert: unknown svn::depth"));
+#endif
+}
 
 /**
  * Convert @a d to an svn::depth.
  */
-depth convert(svn_depth_t d);
+inline constexpr depth convert(svn_depth_t d)
+{
+#ifndef SVN_DEBUG
+  return depth(d);
+#else
+  // switch in constexpr is allowed in C++14 but not in C++11, so we
+  // have to use a series of ternary operators.
+  return (d == svn_depth_unknown
+          ? (d != svn_depth_t(depth::unknown)
+             ? throw std::range_error("convert(svn_depth_unknown)")
+             : depth(d))
+          :
+          d == svn_depth_exclude
+          ? (d != svn_depth_t(depth::exclude)
+             ? throw std::range_error("convert(svn_depth_exclude)")
+             : depth(d))
+          :
+          d == svn_depth_empty
+          ? (d != svn_depth_t(depth::empty)
+             ? throw std::range_error("convert(svn_depth_empty)")
+             : depth(d))
+          :
+          d == svn_depth_files
+          ? (d != svn_depth_t(depth::files)
+             ? throw std::range_error("convert(svn_depth_files)")
+             : depth(d))
+          :
+          d == svn_depth_immediates
+          ? (d != svn_depth_t(depth::immediates)
+             ? throw std::range_error("convert(svn_depth_immediates)")
+             : depth(d))
+          :
+          d == svn_depth_infinity
+          ? (d != svn_depth_t(depth::infinity)
+             ? throw std::range_error("convert(svn_depth_infinity)")
+             : depth(d))
+          :
+          throw std::range_error("convert: unknown svn_depth_t"));
+#endif
+}
 
 } // namespace impl
 } // namespace svnxx



Mime
View raw message