Author: brane
Date: Fri Dec 14 06:05:33 2012
New Revision: 1421679

URL: http://svn.apache.org/viewvc?rev=1421679&view=rev
Log:
Playing with the C++ bindings, restructure the code (and reformat to our
coding style guide) and set up namespaces for future version compatibility,
also according to our compat guidelines.

* build.conf (libsvncxxhl): Update build configuration.

[in subversion/bindings/cxxhl/]
* include/svncxxhl.hpp: New, top-level include file.
* include/svncxxhl/_compat.hpp: New; compatibility mode.
* include/svncxxhl/exception.hpp: New; exception wrappers for svn_error_t.
* include/svncxxhl/tristate.hpp: Renamed and modified from 
include/types/svn_cxxhl_tristate.h.
* include/types, include/svn_cxxhl_types.h: Removed.

* src/exception.cpp: New.
* src/tristate.cpp: Renamed and modified from src/types/tristate.cpp.

Added:
    subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/
    subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl.hpp
    subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/_compat.hpp
    subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
    subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/tristate.hpp
      - copied, changed from r1418979, 
subversion/trunk/subversion/bindings/cxxhl/include/types/svn_cxxhl_tristate.h
    subversion/trunk/subversion/bindings/cxxhl/src/exception.cpp
    subversion/trunk/subversion/bindings/cxxhl/src/tristate.cpp
      - copied, changed from r1420598, 
subversion/trunk/subversion/bindings/cxxhl/src/types/tristate.cpp
Removed:
    subversion/trunk/subversion/bindings/cxxhl/include/svn_cxxhl_types.h
    subversion/trunk/subversion/bindings/cxxhl/include/types/
    subversion/trunk/subversion/bindings/cxxhl/src/types/
Modified:
    subversion/trunk/build.conf

Modified: subversion/trunk/build.conf
URL: 
http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1421679&r1=1421678&r2=1421679&view=diff
==============================================================================
--- subversion/trunk/build.conf (original)
+++ subversion/trunk/build.conf Fri Dec 14 06:05:33 2012
@@ -38,8 +38,8 @@ private-includes =
         subversion/include/private/*.h
         subversion/bindings/swig/include/*.swg
         subversion/libsvn_delta/compose_delta.c
-        subversion/bindings/cxxhl/include/*.h
-        subversion/bindings/cxxhl/include/types/*.h
+        subversion/bindings/cxxhl/include/*.hpp
+        subversion/bindings/cxxhl/include/svncxxhl/*.hpp
 private-built-includes =
         subversion/svn_private_config.h
         subversion/libsvn_fs_fs/rep-cache-db.h
@@ -629,13 +629,14 @@ link-cmd = $(LINK_JAVAHL_CXX)
 #
 
 [libsvncxxhl]
-description = Subversion C++ HighLevel binding
+description = Subversion C++ HighLevel bindings
 type = lib
 path = subversion/bindings/cxxhl
 libs = libsvn_repos libsvn_client libsvn_wc libsvn_ra libsvn_delta libsvn_diff
        libsvn_subr libsvn_fs aprutil apriconv apr
-sources = src/*.cpp src/types/*.cpp
+sources = src/*.cpp
 install = cxxhl-lib
+msvc-static = yes
 compile-cmd = $(COMPILE_CXXHL_CXX)
 link-cmd = $(LINK_CXX_LIB)
 

Added: subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl.hpp
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl.hpp?rev=1421679&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl.hpp (added)
+++ subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl.hpp Fri Dec 14 
06:05:33 2012
@@ -0,0 +1,37 @@
+/**
+ * @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 __cplusplus
+#error "This is a C++ header file."
+#endif
+
+#ifndef SVN_CXXHL_HPP
+#define SVN_CXXHL_HPP
+
+// Expose the whole API and alias the default version namespace
+#include "svncxxhl/exception.hpp"
+#include "svncxxhl/tristate.hpp"
+
+namespace svn = ::subversion::cxxhl::version_1_9_dev;
+
+#endif  // SVN_CXXHL_HPP

Added: subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/_compat.hpp
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/_compat.hpp?rev=1421679&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/_compat.hpp 
(added)
+++ subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/_compat.hpp Fri 
Dec 14 06:05:33 2012
@@ -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
+ */
+
+#ifndef __cplusplus
+#error "This is a C++ header file."
+#endif
+
+#ifndef SVN_CXXHL_COMPAT_HPP
+#define SVN_CXXHL_COMPAT_HPP
+
+// Configuration test: std::shared_ptr<>
+// Currently detects: clang++, g++, msvc-2010+
+#ifndef SVN_CXXHL_HAVE_STD_SHARED_PTR
+#  if   (defined(__clang__) && __cplusplus >= 201103L) \
+     || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)) \
+     || (defined(_MSC_VER) && _MSC_VER >= 1600)
+#    define SVN_CXXHL_HAVE_STD_SHARED_PTR
+#  endif  // config test: std::shared_ptr<>
+#endif  // SVN_CXXHL_HAVE_STD_SHARED_PTR
+
+// Configuration test: std::tr1::shared_ptr<>
+// Currently detects: clang++, g++
+#ifndef SVN_CXXHL_HAVE_STD_SHARED_PTR
+#  ifndef SVN_CXXHL_HAVE_STD_TR1_SHARED_PTR
+#    if   defined(__GNUC__) \
+       && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#      define SVN_CXXHL_HAVE_STD_TR1_SHARED_PTR
+#    endif  // config test: std::tr1::shared_ptr<>
+#  endif  // SVN_CXXHL_HAVE_STD_TR1_SHARED_PTR
+#endif  // SVN_CXXHL_HAVE_STD_SHARED_PTR
+
+
+#if defined(SVN_CXXHL_HAVE_STD_SHARED_PTR)
+
+#include <memory>
+namespace subversion {
+namespace cxxhl {
+namespace compat {
+using std::shared_ptr;
+} // namespace compat
+} // namespace cxxhl
+} // namespace subversion
+
+#elif defined(SVN_CXXHL_HAVE_STD_TR1_SHARED_PTR)
+
+#include <tr1/memory>
+namespace subversion {
+namespace cxxhl {
+namespace compat {
+using std::tr1::shared_ptr;
+} // namespace compat
+} // namespace cxxhl
+} // namespace subversion
+
+#else
+// We need shared_ptr<> from somewhere. If we cannot find it in ::std
+// given known compiler characteristics, then try boost as a last
+// resort.
+
+#include <boost/shared_ptr.hpp>
+namespace subversion {
+namespace cxxhl {
+namespace compat {
+using boost::shared_ptr;
+} // namespace compat
+} // namespace cxxhl
+} // namespace subversion
+
+#endif  // SVN_CXXHL_HAVE_STD_SHARED_PTR
+
+#endif  // SVN_CXXHL_COMPAT_HPP

Added: subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp?rev=1421679&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp 
(added)
+++ subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/exception.hpp 
Fri Dec 14 06:05:33 2012
@@ -0,0 +1,86 @@
+/**
+ * @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 __cplusplus
+#error "This is a C++ header file."
+#endif
+
+#ifndef SVN_CXXHL_EXCEPTION_HPP
+#define SVN_CXXHL_EXCEPTION_HPP
+
+#include <exception>
+
+#include "svncxxhl/_compat.hpp"
+
+namespace subversion {
+namespace cxxhl {
+
+namespace compat {} // Announce the compat namespace for shared_ptr lookup
+
+namespace detail {
+struct error_description;
+} // namespace detail
+
+namespace version_1_9_dev {
+
+class error : public std::exception
+{
+public:
+  typedef compat::shared_ptr<error> shared_ptr;
+
+  error(const char* description, int errno);
+  error(const char* description, int errno, shared_ptr nested);
+
+  error(const error& that) throw();
+  error& operator=(const error& that) throw();
+  virtual ~error() throw();
+
+  virtual int code() const throw() { return m_errno; }
+  virtual const char* what() const throw();
+  virtual shared_ptr nested() const throw() { return m_nested; }
+
+private:
+  int m_errno;                ///< The (SVN or APR) error code
+  shared_ptr m_nested;        ///< Optional pointer to nessted error
+
+  /// Error message; will be @c NULL if this is a trace link.
+  detail::error_description* m_description;
+
+  /**
+   * The location of the error in @a m_loc_file at @a m_loc_line.
+   *
+   * @a m_loc_file will be @c NULL if the location is not available
+   * (i.e., if the wrapped Subversion library was not compiled in
+   * maintaner mode.
+   */
+  const char* m_loc_file;
+  int m_loc_line;
+};
+
+class canceled : public error {};
+
+} // namespace version_1_9_dev
+} // namespace cxxhl
+} // namespace subversion
+
+#endif  // SVN_CXXHL_EXCEPTION_HPP

Copied: 
subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/tristate.hpp (from 
r1418979, 
subversion/trunk/subversion/bindings/cxxhl/include/types/svn_cxxhl_tristate.h)
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/tristate.hpp?p2=subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/tristate.hpp&p1=subversion/trunk/subversion/bindings/cxxhl/include/types/svn_cxxhl_tristate.h&r1=1418979&r2=1421679&rev=1421679&view=diff
==============================================================================
--- 
subversion/trunk/subversion/bindings/cxxhl/include/types/svn_cxxhl_tristate.h 
(original)
+++ subversion/trunk/subversion/bindings/cxxhl/include/svncxxhl/tristate.hpp 
Fri Dec 14 06:05:33 2012
@@ -1,4 +1,3 @@
-/* -*- C++ -*- */
 /**
  * @copyright
  * ====================================================================
@@ -26,32 +25,40 @@
 #error "This is a C++ header file."
 #endif
 
-#ifndef SVN_CXXHL_TYPES_TRISTATE_H
-#define SVN_CXXHL_TYPES_TRISTATE_H
+#ifndef SVN_CXXHL_TRISTATE_HPP
+#define SVN_CXXHL_TRISTATE_HPP
 
-namespace apache {
 namespace subversion {
 namespace cxxhl {
+namespace version_1_9_dev {
 
-class Tristate
+class tristate
 {
-  public:
-    Tristate(const Tristate& that) : m_value(that.m_value) {}
-
-    bool operator==(const Tristate& that) { return m_value == that.m_value; }
-    bool operator!=(const Tristate& that) { return !(*this == that); }
-
-    static const Tristate TRUE;
-    static const Tristate FALSE;
-    static const Tristate UNKNOWN;
-
-  private:
-    explicit Tristate(short value);
-    short m_value;
+public:
+  static const tristate TRUE;
+  static const tristate FALSE;
+  static const tristate UNKNOWN;
+
+  tristate(const tristate& that) throw()
+    : m_value(that.m_value)
+    {}
+
+  bool operator==(const tristate& that) const throw()
+    { return m_value == that.m_value; }
+
+  bool operator!=(const tristate& that) const throw()
+    { return !(*this == that); }
+
+  bool known() const throw()
+    { return *this != UNKNOWN; }
+
+private:
+  explicit tristate(short int value) throw();
+  short int m_value;
 };
 
+} // namespace version_1_9_dev
 } // namespace cxxhl
 } // namespace subversion
-} // namespace apache
 
-#endif  // SVN_CXXHL_TYPES_TRISTATE_H
+#endif  // SVN_CXXHL_TRISTATE_HPP

Added: subversion/trunk/subversion/bindings/cxxhl/src/exception.cpp
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/exception.cpp?rev=1421679&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/exception.cpp (added)
+++ subversion/trunk/subversion/bindings/cxxhl/src/exception.cpp Fri Dec 14 
06:05:33 2012
@@ -0,0 +1,118 @@
+/**
+ * @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 <csignal>
+#include <cstddef>
+#include <cstring>
+#include <new>
+
+#include "svncxxhl/exception.hpp"
+
+#include "svn_error.h"
+#undef TRUE
+#undef FALSE
+
+namespace subversion {
+namespace cxxhl {
+
+namespace detail {
+
+struct error_description
+{
+  volatile std::sig_atomic_t m_refcount;
+  char m_message[1];
+
+  static error_description* create(const char* message) throw(std::bad_alloc)
+    {
+      const std::size_t len = std::strlen(message);
+      void *memblock = ::operator new(len + sizeof(error_description));
+
+      error_description* err = new(memblock) error_description;
+      std::memcpy(err->m_message, message, len);
+      err->m_message[len] = 0;
+      err->m_refcount = 0;
+      return err;
+    }
+
+  static void destroy(error_description* message) throw()
+    {
+      // TODO: DEBUG assert(message->m_refcount == 0)
+      ::operator delete(message, std::nothrow);
+    }
+};
+
+} // namespace detail
+
+
+namespace version_1_9_dev {
+
+error::error(const char* description, int error_code)
+  : m_errno(error_code),
+    m_description(detail::error_description::create(description))
+{
+  ++m_description->m_refcount;
+}
+
+error::error(const char* description, int error_code,
+             error::shared_ptr nested_error)
+  : m_errno(error_code),
+    m_nested(nested_error),
+    m_description(detail::error_description::create(description))
+{
+  ++m_description->m_refcount;
+}
+
+error::error(const error& that) throw()
+  : m_errno(that.m_errno),
+    m_nested(that.m_nested),
+    m_description(that.m_description)
+{
+  ++m_description->m_refcount;
+}
+
+error& error::operator=(const error& that) throw()
+{
+  if (this == &that)
+    return *this;
+
+  // This in-place destroy+copy implementation of the assignment
+  // operator is safe because both the destructor and the copy
+  // constructor do not throw exceptions.
+  this->~error();
+  return *new(this) error(that);
+}
+
+error::~error() throw()
+{
+  if (!--m_description->m_refcount)
+    detail::error_description::destroy(m_description);
+}
+
+const char* error::what() const throw()
+{
+  return m_description->m_message;
+}
+
+} // namespace version_1_9_dev
+} // namespace cxxhl
+} // namespace subversion

Copied: subversion/trunk/subversion/bindings/cxxhl/src/tristate.cpp (from 
r1420598, subversion/trunk/subversion/bindings/cxxhl/src/types/tristate.cpp)
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/cxxhl/src/tristate.cpp?p2=subversion/trunk/subversion/bindings/cxxhl/src/tristate.cpp&p1=subversion/trunk/subversion/bindings/cxxhl/src/types/tristate.cpp&r1=1420598&r2=1421679&rev=1421679&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/cxxhl/src/types/tristate.cpp (original)
+++ subversion/trunk/subversion/bindings/cxxhl/src/tristate.cpp Fri Dec 14 
06:05:33 2012
@@ -21,22 +21,24 @@
  * @endcopyright
  */
 
-#include "types/svn_cxxhl_tristate.h"
+#include "svncxxhl/tristate.hpp"
 
 #include "svn_types.h"
 #undef TRUE
 #undef FALSE
 
-namespace apache {
 namespace subversion {
 namespace cxxhl {
+namespace version_1_9_dev {
 
-Tristate::Tristate(short value) : m_value(value) {}
+tristate::tristate(short value) throw()
+    : m_value(value)
+{}
 
-const Tristate Tristate::TRUE(svn_tristate_true);
-const Tristate Tristate::FALSE(svn_tristate_false);
-const Tristate Tristate::UNKNOWN(svn_tristate_unknown);
+const tristate tristate::TRUE = tristate(svn_tristate_true);
+const tristate tristate::FALSE = tristate(svn_tristate_false);
+const tristate tristate::UNKNOWN = tristate(svn_tristate_unknown);
 
+} // namespace version_1_9_dev
 } // namespace cxxhl
 } // namespace subversion
-} // namespace apache


Reply via email to