aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/qname.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-07 14:48:13 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-07 14:48:13 +0200
commit4f38adc11ab1a3a1ab2dd3f958c917182be7d71f (patch)
treefd4242b2fb5648536a6307a18442abfcaf280573 /libxsde/xsde/cxx/qname.cxx
parent0baca4b033509b6c4ebfabfb74bf6518c3b1182c (diff)
Implement generation of clone functions
New test: clone.
Diffstat (limited to 'libxsde/xsde/cxx/qname.cxx')
-rw-r--r--libxsde/xsde/cxx/qname.cxx118
1 files changed, 105 insertions, 13 deletions
diff --git a/libxsde/xsde/cxx/qname.cxx b/libxsde/xsde/cxx/qname.cxx
index be196be..f1e4238 100644
--- a/libxsde/xsde/cxx/qname.cxx
+++ b/libxsde/xsde/cxx/qname.cxx
@@ -10,11 +10,83 @@ namespace xsde
{
namespace cxx
{
-#ifndef XSDE_EXCEPTIONS
- qname::error qname::
+
+#ifdef XSDE_EXCEPTIONS
+
+ void qname::
+ prefix_copy (const char* prefix)
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete[] prefix_;
#else
+ cxx::free (prefix_);
+#endif
+
+ if (prefix)
+ prefix_ = strdupx (prefix);
+ else
+ prefix_ = 0;
+ }
+
void qname::
+ name_copy (const char* name)
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete[] name_;
+#else
+ cxx::free (name_);
+#endif
+
+ if (name)
+ name_ = strdupx (name);
+ else
+ name_ = 0;
+ }
+
+ struct qname_guard
+ {
+ qname_guard (qname* p) : p_ (p) {}
+
+ ~qname_guard ()
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete p_;
+#else
+ if (p_ != 0)
+ {
+ p_->~qname ();
+ cxx::free (p_);
+ }
#endif
+ }
+
+ void
+ release () { p_ = 0; }
+
+ private:
+ qname* p_;
+ };
+
+ qname* qname::
+ _clone () const
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ qname* c = new qname;
+#else
+ // Default qname c-tor cannot throw so we don't need alloc_guard.
+ //
+ qname* c = static_cast<qname*> (cxx::alloc (sizeof (qname)));
+ new (c) qname;
+#endif
+ qname_guard g (c);
+ _copy (*c);
+ g.release ();
+ return c;
+ }
+
+#else
+
+ qname::error qname::
prefix_copy (const char* prefix)
{
#ifndef XSDE_CUSTOM_ALLOCATOR
@@ -27,24 +99,16 @@ namespace xsde
{
prefix_ = strdupx (prefix);
-#ifndef XSDE_EXCEPTIONS
if (prefix_ == 0)
return error_no_memory;
-#endif
}
else
prefix_ = 0;
-#ifndef XSDE_EXCEPTIONS
return error_none;
-#endif
}
-#ifndef XSDE_EXCEPTIONS
qname::error qname::
-#else
- void qname::
-#endif
name_copy (const char* name)
{
#ifndef XSDE_CUSTOM_ALLOCATOR
@@ -57,17 +121,45 @@ namespace xsde
{
name_ = strdupx (name);
-#ifndef XSDE_EXCEPTIONS
if (name_ == 0)
return error_no_memory;
-#endif
}
else
name_ = 0;
-#ifndef XSDE_EXCEPTIONS
return error_none;
+ }
+
+ qname* qname::
+ _clone () const
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ qname* c = new qname;
+#else
+ qname* c = static_cast<qname*> (cxx::alloc (sizeof (qname)));
+#endif
+
+ if (c == 0)
+ return 0;
+
+#ifdef XSDE_CUSTOM_ALLOCATOR
+ new (c) qname;
#endif
+
+ if (!_copy (*c))
+ {
+#ifndef XSDE_CUSTOM_ALLOCATOR
+ delete c;
+#else
+ c->~qname ();
+ cxx::free (c);
+#endif
+ return 0;
+ }
+
+ return c;
}
+
+#endif
}
}