From commits-return-50173-archive-asf-public=cust-asf.ponee.io@subversion.apache.org Fri Jan 4 15:17:25 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4668F180660 for ; Fri, 4 Jan 2019 15:17:25 +0100 (CET) Received: (qmail 57506 invoked by uid 500); 4 Jan 2019 14:17:24 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 57496 invoked by uid 99); 4 Jan 2019 14:17:24 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jan 2019 14:17:24 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B9C413A27CC for ; Fri, 4 Jan 2019 14:17:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@subversion.apache.org From: brane@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190104141723.B9C413A27CC@svn01-us-west.apache.org> 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 . 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 +#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(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 -#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