diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-05-11 12:20:11 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-05-11 12:20:11 +0200 |
commit | 2e501c68a8641a2b3c430b55f13491a9c1c5d0f5 (patch) | |
tree | 49c2748443fe3c1f01108756b647440e0647a11b /xsde/cxx/hybrid/extraction-source.cxx | |
parent | 161beba6cdb0d91b15ad19fa8b3e51d986203915 (diff) |
Add support for custom allocators
New example: examples/cxx/hybrid/allocator.
Diffstat (limited to 'xsde/cxx/hybrid/extraction-source.cxx')
-rw-r--r-- | xsde/cxx/hybrid/extraction-source.cxx | 189 |
1 files changed, 147 insertions, 42 deletions
diff --git a/xsde/cxx/hybrid/extraction-source.cxx b/xsde/cxx/hybrid/extraction-source.cxx index 3b98100..1e2a602 100644 --- a/xsde/cxx/hybrid/extraction-source.cxx +++ b/xsde/cxx/hybrid/extraction-source.cxx @@ -239,15 +239,30 @@ namespace CXX { String fq (fq_name (t)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -354,15 +369,30 @@ namespace CXX { String fq (fq_name (t)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -423,15 +453,30 @@ namespace CXX { String fq (scope (a) + L"::" + etype (a)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -529,15 +574,30 @@ namespace CXX { String fq (fq_name (t)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -604,15 +664,30 @@ namespace CXX { String fq (scope (c) + L"::" + etype (c)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -681,15 +756,30 @@ namespace CXX { String fq (scope (c) + L"::" + etype (c)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) @@ -784,15 +874,30 @@ namespace CXX { String fq (scope (s) + L"::" + etype (s)); - if (exceptions) - os << "x." << name << " (new " << fq << ");"; + if (!custom_alloc) + os << fq << "* i = new " << fq << ";"; else - os << fq << "* i = new " << fq << ";" - << endl + os << fq << "* i = static_cast< " << fq << "* > (" << endl + << "::xsde::cxx::alloc (sizeof (" << fq << ")));"; + + if (!exceptions) + os << endl << "if (i == 0)" << endl << "return false;" - << endl - << "x." << name << " (i);"; + << endl; + + if (custom_alloc) + { + if (exceptions) + os << "::xsde::cxx::alloc_guard ig (i);"; + + os << "new (i) " << fq << ";"; + + if (exceptions) + os << "ig.release ();"; + } + + os << "x." << name << " (i);"; } if (exceptions) |