aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/any-type-pimpl.cxx
blob: 811566702a6541cb1ebf2d1a5b738a781165f2d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// file      : xsde/cxx/hybrid/any-type-pimpl.cxx
// copyright : Copyright (c) 2005-2011 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-pimpl.hxx>

namespace xsde
{
  namespace cxx
  {
    namespace hybrid
    {
      any_type_pimpl::
      ~any_type_pimpl ()
      {
        if (!base_ && val_)
        {
#ifndef XSDE_CUSTOM_ALLOCATOR
          delete val_;
#else
          val_->~any_type ();
          cxx::free (val_);
#endif
        }
      }

      void any_type_pimpl::
      _reset ()
      {
        any_type_pskel::_reset ();

        if (!base_ && val_)
        {
#ifndef XSDE_CUSTOM_ALLOCATOR
          delete val_;
#else
          val_->~any_type ();
          cxx::free (val_);
#endif
          val_ = 0;
        }
      }

      any_type_pimpl::
      any_type_pimpl (bool base)
          : base_ (base), val_ (0)
      {
      }

      void any_type_pimpl::
      pre_impl (any_type* qn)
      {
        val_ = qn;
      }

      void any_type_pimpl::
      _pre ()
      {
        if (val_ == 0)
        {
#ifndef XSDE_CUSTOM_ALLOCATOR
          val_ = new any_type ();
#else
          val_ = static_cast<any_type*> (alloc (sizeof (any_type)));

#ifdef XSDE_EXCEPTIONS
          alloc_guard ag (val_);
          new (val_) any_type ();
          ag.release ();
#else
          if (val_)
            new (val_) any_type ();
#endif
#endif

#ifndef XSDE_EXCEPTIONS
          if (val_ == 0)
          {
            _sys_error (sys_error::no_memory);
            return;
          }
#endif
        }
      }

      any_type* any_type_pimpl::
      post_any_type ()
      {
        any_type* r = val_;
        val_ = 0;
        return r;
      }
    }
  }
}