subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1850390 - in /subversion/trunk/subversion/bindings/cxx/src: private/revision_private.hpp revision.cpp
Date Fri, 04 Jan 2019 15:15:23 GMT
Author: brane
Date: Fri Jan  4 15:15:22 2019
New Revision: 1850390

URL: http://svn.apache.org/viewvc?rev=1850390&view=rev
Log:
Make conversions between svn_opt_revision_kind and svn::revision::kind
compile-time constant expressions in SVN++.

[in subversion/bindings/cxx/src]
* private/revision_private.hpp: Include <stdexcept>. Don't include svn_types.h.
  (impl::convert): Implement here as inline constexpr functions.
* revision.cpp: Update include directives.
  (impl::convert): Remove implementation.

Modified:
    subversion/trunk/subversion/bindings/cxx/src/private/revision_private.hpp
    subversion/trunk/subversion/bindings/cxx/src/revision.cpp

Modified: subversion/trunk/subversion/bindings/cxx/src/private/revision_private.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/private/revision_private.hpp?rev=1850390&r1=1850389&r2=1850390&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/private/revision_private.hpp (original)
+++ subversion/trunk/subversion/bindings/cxx/src/private/revision_private.hpp Fri Jan  4 15:15:22
2019
@@ -24,9 +24,10 @@
 #ifndef SVNXX_PRIVATE_REVISION_HPP
 #define SVNXX_PRIVATE_REVISION_HPP
 
+#include <stdexcept>
+
 #include "svnxx/revision.hpp"
 
-#include "svn_types.h"
 #include "svn_opt.h"
 
 namespace apache {
@@ -37,12 +38,110 @@ namespace impl {
 /**
  * Convert @a kind to an svn_opt_revision_kind.
  */
-svn_opt_revision_kind convert(revision::kind kind);
+inline constexpr svn_opt_revision_kind convert(revision::kind kind)
+{
+#ifndef SVN_DEBUG
+  return svn_opt_revision_kind(kind);
+#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 (kind == revision::kind::unspecified
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_unspecified
+             ? throw std::range_error("convert(svn::revision::kind::unspecified)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::number
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_number
+             ? throw std::range_error("convert(svn::revision::kind::number)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::date
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_date
+             ? throw std::range_error("convert(svn::revision::kind::date)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::committed
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_committed
+             ? throw std::range_error("convert(svn::revision::kind::committed)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::previous
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_previous
+             ? throw std::range_error("convert(svn::revision::kind::previous)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::base
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_base
+             ? throw std::range_error("convert(svn::revision::kind::base)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::working
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_working
+             ? throw std::range_error("convert(svn::revision::kind::working)")
+             : svn_opt_revision_kind(kind))
+          :
+          kind == revision::kind::head
+          ? (svn_opt_revision_kind(kind) != svn_opt_revision_head
+             ? throw std::range_error("convert(svn::revision::kind::head)")
+             : svn_opt_revision_kind(kind))
+          :
+          throw std::range_error("convert: unknown svn::revision::kind"));
+#endif
+}
 
 /**
  * Convert @a kind to an svn::revision::kind.
  */
-revision::kind convert(svn_opt_revision_kind kind);
+inline constexpr revision::kind convert(svn_opt_revision_kind kind)
+{
+#ifndef SVN_DEBUG
+  return revision::kind(kind);
+#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 (kind ==svn_opt_revision_unspecified
+          ? (kind != svn_opt_revision_kind(revision::kind::unspecified)
+             ? throw std::range_error("convert(svn_opt_revision_unspecified)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_number
+          ? (kind != svn_opt_revision_kind(revision::kind::number)
+             ? throw std::range_error("convert(svn_opt_revision_number)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_date
+          ? (kind != svn_opt_revision_kind(revision::kind::date)
+             ? throw std::range_error("convert(svn_opt_revision_date)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_committed
+          ? (kind != svn_opt_revision_kind(revision::kind::committed)
+             ? throw std::range_error("convert(svn_opt_revision_committed)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_previous
+          ? (kind != svn_opt_revision_kind(revision::kind::previous)
+             ? throw std::range_error("convert(svn_opt_revision_previous)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_base
+          ? (kind != svn_opt_revision_kind(revision::kind::base)
+             ? throw std::range_error("convert(svn_opt_revision_base)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_working
+          ? (kind != svn_opt_revision_kind(revision::kind::working)
+             ? throw std::range_error("convert(svn_opt_revision_working)")
+             : revision::kind(kind))
+          :
+          kind == svn_opt_revision_head
+          ? (kind != svn_opt_revision_kind(revision::kind::head)
+             ? throw std::range_error("convert(svn_opt_revision_head)")
+             : revision::kind(kind))
+          :
+          throw std::range_error("convert: unknown svn_opt_revision_kind"));
+#endif
+}
 
 /**
  * Convert @a rev to an svn_opt_revision_t.

Modified: subversion/trunk/subversion/bindings/cxx/src/revision.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxx/src/revision.cpp?rev=1850390&r1=1850389&r2=1850390&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxx/src/revision.cpp (original)
+++ subversion/trunk/subversion/bindings/cxx/src/revision.cpp Fri Jan  4 15:15:22 2019
@@ -21,8 +21,6 @@
  * @endcopyright
  */
 
-#include <stdexcept>
-
 #include "private/revision_private.hpp"
 
 namespace apache {
@@ -30,110 +28,6 @@ namespace subversion {
 namespace svnxx {
 namespace impl {
 
-svn_opt_revision_kind convert(revision::kind kind)
-{
-#ifdef SVN_DEBUG
-  switch (kind)
-    {
-    case revision::kind::unspecified:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_unspecified)
-        throw std::range_error("convert svn::revision::kind::unspecified");
-      break;
-
-    case revision::kind::number:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_number)
-        throw std::range_error("convert svn::revision::kind::number");
-      break;
-
-    case revision::kind::date:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_date)
-        throw std::range_error("convert svn::revision::kind::date");
-      break;
-
-    case revision::kind::committed:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_committed)
-        throw std::range_error("convert svn::revision::kind::committed");
-      break;
-
-    case revision::kind::previous:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_previous)
-        throw std::range_error("convert svn::revision::kind::previous");
-      break;
-
-    case revision::kind::base:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_base)
-        throw std::range_error("convert svn::revision::kind::base");
-      break;
-
-    case revision::kind::working:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_working)
-        throw std::range_error("convert svn::revision::kind::working");
-      break;
-
-    case revision::kind::head:
-      if (svn_opt_revision_kind(kind) != svn_opt_revision_head)
-        throw std::range_error("convert svn::revision::kind::head");
-      break;
-
-    default:
-      throw std::range_error("unknown svn::revision::kind");
-    }
-#endif
-  return svn_opt_revision_kind(kind);
-}
-
-revision::kind convert(svn_opt_revision_kind kind)
-{
-#ifdef SVN_DEBUG
-  switch (kind)
-    {
-    case svn_opt_revision_unspecified:
-      if (kind != svn_opt_revision_kind(revision::kind::unspecified))
-        throw std::range_error("convert svn_opt_revision_unspecified");
-      break;
-
-    case svn_opt_revision_number:
-      if (kind != svn_opt_revision_kind(revision::kind::number))
-        throw std::range_error("convert svn_opt_revision_number");
-      break;
-
-    case svn_opt_revision_date:
-      if (kind != svn_opt_revision_kind(revision::kind::date))
-        throw std::range_error("convert svn_opt_revision_date");
-      break;
-
-    case svn_opt_revision_committed:
-      if (kind != svn_opt_revision_kind(revision::kind::committed))
-        throw std::range_error("convert svn_opt_revision_committed");
-      break;
-
-    case svn_opt_revision_previous:
-      if (kind != svn_opt_revision_kind(revision::kind::previous))
-        throw std::range_error("convert svn_opt_revision_previous");
-      break;
-
-    case svn_opt_revision_base:
-      if (kind != svn_opt_revision_kind(revision::kind::base))
-        throw std::range_error("convert svn_opt_revision_base");
-      break;
-
-    case svn_opt_revision_working:
-      if (kind != svn_opt_revision_kind(revision::kind::working))
-        throw std::range_error("convert svn_opt_revision_working");
-      break;
-
-    case svn_opt_revision_head:
-      if (kind != svn_opt_revision_kind(revision::kind::head))
-        throw std::range_error("convert svn_opt_revision_head");
-      break;
-
-    default:
-      throw std::range_error("unknown svn_opt_revision_kind");
-    }
-#endif
-  return revision::kind(kind);
-}
-
 svn_opt_revision_t convert(const revision& rev)
 {
   svn_opt_revision_t result;



Mime
View raw message