aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/any-type.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-14 12:21:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-14 12:21:35 +0200
commitb7197929af1cca15e490703ba3632ae52a348b60 (patch)
treee4ed9dc7cf2021d6ad398fade7fc8148ff982b16 /libxsde/xsde/cxx/hybrid/any-type.cxx
parent6f395f9f769866a04f6949cb7ed14f93d90cf728 (diff)
New mapping for anyType with support for polymorphism
Diffstat (limited to 'libxsde/xsde/cxx/hybrid/any-type.cxx')
-rw-r--r--libxsde/xsde/cxx/hybrid/any-type.cxx151
1 files changed, 150 insertions, 1 deletions
diff --git a/libxsde/xsde/cxx/hybrid/any-type.cxx b/libxsde/xsde/cxx/hybrid/any-type.cxx
index d4f257d..544e11b 100644
--- a/libxsde/xsde/cxx/hybrid/any-type.cxx
+++ b/libxsde/xsde/cxx/hybrid/any-type.cxx
@@ -3,6 +3,12 @@
// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
+#include <xsde/cxx/config.hxx>
+
+#ifdef XSDE_CUSTOM_ALLOCATOR
+# include <xsde/cxx/allocator.hxx>
+#endif
+
#include <xsde/cxx/hybrid/any-type.hxx>
namespace xsde
@@ -13,12 +19,155 @@ namespace xsde
{
// any_type
//
-#ifdef XSDE_POLYMORPHIC
any_type::
~any_type ()
{
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete data_;
+#else
+ if (data_ != 0)
+ {
+ data_->~data_sequence ();
+ cxx::free (data_);
+ }
+#endif
+ }
+
+#ifdef XSDE_EXCEPTIONS
+ void any_type::
+ allocate_custom_data ()
+ {
+ if (data_ != 0)
+ return;
+
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ data_ = new data_sequence;
+#else
+ // Default data_sequence c-tor cannot throw so we don't need a guard.
+ //
+ data_ = static_cast<data_sequence*> (
+ cxx::alloc (sizeof (data_sequence)));
+ new (data_) data_sequence;
+#endif
}
+ void any_type::
+ _copy (any_type& c) const
+ {
+ if (data_ != 0)
+ {
+ c.allocate_custom_data ();
+ data_->copy (c.custom_data ());
+ }
+ }
+
+ struct any_type_guard
+ {
+ any_type_guard (any_type* p) : p_ (p) {}
+
+ ~any_type_guard ()
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete p_;
+#else
+ if (p_ != 0)
+ {
+ p_->~any_type ();
+ cxx::free (p_);
+ }
+#endif
+ }
+
+ void
+ release () { p_ = 0; }
+
+ private:
+ any_type* p_;
+ };
+
+ any_type* any_type::
+ _clone () const
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ any_type* c = new any_type;
+#else
+ // Default any_type c-tor cannot throw so we don't need alloc_guard.
+ //
+ any_type* c = static_cast<any_type*> (cxx::alloc (sizeof (any_type)));
+ new (c) any_type;
+#endif
+ any_type_guard g (c);
+ _copy (*c);
+ g.release ();
+ return c;
+ }
+#else
+ bool any_type::
+ allocate_custom_data ()
+ {
+ if (data_ != 0)
+ return true;
+
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ data_ = new data_sequence;
+#else
+ data_ = static_cast<data_sequence*> (
+ cxx::alloc (sizeof (data_sequence)));
+#endif
+ if (data_ == 0)
+ return false;
+
+#ifdef XSDE_CUSTOM_ALLOCATOR
+ new (data_) data_sequence;
+#endif
+ return true;
+ }
+
+ bool
+ _copy (any_type&) const
+ {
+ if (data_ != 0)
+ {
+ if (!c.allocate_custom_data () ||
+ !data_.copy (c.custom_data ()))
+ return false;
+ }
+
+ return true;
+ }
+
+ any_type* any_type::
+ _clone () const
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ any_type* c = new any_type;
+#else
+ any_type* c = static_cast<any_type*> (cxx::alloc (sizeof (any_type)));
+#endif
+
+ if (c == 0)
+ return 0;
+
+#ifdef XSDE_CUSTOM_ALLOCATOR
+ new (c) any_type;
+#endif
+
+ if (!_copy (*c))
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete c;
+#else
+ c->~any_type ();
+ cxx::free (c);
+#endif
+ return 0;
+ }
+
+ return c;
+ }
+#endif
+
+#ifdef XSDE_POLYMORPHIC
#ifdef XSDE_STL
const std::string& any_type::
_dynamic_type () const