aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/stack.cxx
blob: 936a732f1be1b3c20232c541ab1df7ffc04db83d (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
// file      : xsde/cxx/stack.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#include <string.h> // memcpy

#include <xsde/cxx/stack.hxx>

namespace xsde
{
  namespace cxx
  {
#ifdef XSDE_EXCEPTIONS
    void stack::
#else
    stack::error stack::
#endif
    grow ()
    {
      size_t c = capacity_ ? capacity_ * 2 : 8;
      char* d = new char[c * el_size_];

#ifndef XSDE_EXCEPTIONS
      if (d == 0)
        return error_no_memory;
#endif

      if (size_ > 1)
        memcpy (d, data_, (size_ - 1) * el_size_);

      delete[] data_;

      data_ = d;
      capacity_ = c;

#ifndef XSDE_EXCEPTIONS
      return error_none;
#endif
    }
  }
}