diff options
Diffstat (limited to 'libxsde')
-rw-r--r-- | libxsde/xsde/cxx/hashmap.hxx | 4 | ||||
-rw-r--r-- | libxsde/xsde/cxx/stack.cxx | 42 | ||||
-rw-r--r-- | libxsde/xsde/cxx/stack.hxx | 83 | ||||
-rw-r--r-- | libxsde/xsde/cxx/stack.ixx | 86 | ||||
-rw-r--r-- | libxsde/xsde/makefile | 2 |
5 files changed, 213 insertions, 4 deletions
diff --git a/libxsde/xsde/cxx/hashmap.hxx b/libxsde/xsde/cxx/hashmap.hxx index 29c47e7..8554327 100644 --- a/libxsde/xsde/cxx/hashmap.hxx +++ b/libxsde/xsde/cxx/hashmap.hxx @@ -73,9 +73,7 @@ namespace xsde private: hashmap (hashmap&); - - hashmap& - operator= (hashmap&); + hashmap& operator= (hashmap&); public: void diff --git a/libxsde/xsde/cxx/stack.cxx b/libxsde/xsde/cxx/stack.cxx new file mode 100644 index 0000000..a27acc8 --- /dev/null +++ b/libxsde/xsde/cxx/stack.cxx @@ -0,0 +1,42 @@ +// file : xsde/cxx/stack.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 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 + } + } +} diff --git a/libxsde/xsde/cxx/stack.hxx b/libxsde/xsde/cxx/stack.hxx new file mode 100644 index 0000000..f58b1c7 --- /dev/null +++ b/libxsde/xsde/cxx/stack.hxx @@ -0,0 +1,83 @@ +// file : xsde/cxx/stack.hxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#ifndef XSDE_CXX_STACK_HXX +#define XSDE_CXX_STACK_HXX + +#include <stddef.h> // size_t + +#include <xsde/cxx/config.hxx> + +namespace xsde +{ + namespace cxx + { + // POD stack with pre-allocated first element. You may + // need to pad your elements to get the proper alignment. + // + struct stack + { +#ifndef XSDE_EXCEPTIONS + enum error + { + error_none, + error_no_memory + }; +#endif + + ~stack (); + stack (size_t element_size, void* first_element); + + private: + stack (stack&); + stack& operator= (stack&); + + public: + void + pop (); + +#ifdef XSDE_EXCEPTIONS + void +#else + error +#endif + push (); + + void* + top (); + + void + clear (); + + bool + empty () const; + + size_t + size () const; + + size_t + element_size () const; + + private: +#ifdef XSDE_EXCEPTIONS + void +#else + error +#endif + grow (); + + private: + size_t el_size_; + void* first_; + char* data_; + size_t size_; + size_t capacity_; + }; + } +} + +#include <xsde/cxx/stack.ixx> + +#endif // XSDE_CXX_STACK_HXX diff --git a/libxsde/xsde/cxx/stack.ixx b/libxsde/xsde/cxx/stack.ixx new file mode 100644 index 0000000..b0e81ff --- /dev/null +++ b/libxsde/xsde/cxx/stack.ixx @@ -0,0 +1,86 @@ +// file : xsde/cxx/stack.ixx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +namespace xsde +{ + namespace cxx + { + inline stack:: + ~stack () + { + delete[] data_; + } + + inline stack:: + stack (size_t el_size, void* first_el) + : el_size_ (el_size), + first_ (first_el), + data_ (0), + size_ (0), + capacity_ (0) + { + } + + inline void stack:: + pop () + { + --size_; + } + +#ifdef XSDE_EXCEPTIONS + inline void stack:: +#else + inline stack::error stack:: +#endif + push () + { + if (size_ > capacity_) + { +#ifdef XSDE_EXCEPTIONS + grow (); +#else + if (error e = grow ()) + return e; +#endif + } + + ++size_; + +#ifndef XSDE_EXCEPTIONS + return error_none; +#endif + } + + inline void* stack:: + top () + { + return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_; + } + + inline void stack:: + clear () + { + size_ = 0; + } + + inline bool stack:: + empty () const + { + return size_ == 0; + } + + inline size_t stack:: + size () const + { + return size_; + } + + inline size_t stack:: + element_size () const + { + return el_size_; + } + } +} diff --git a/libxsde/xsde/makefile b/libxsde/xsde/makefile index d42fabf..b9b3884 100644 --- a/libxsde/xsde/makefile +++ b/libxsde/xsde/makefile @@ -5,7 +5,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make -cxx_tun := cxx/string.cxx cxx/ro-string.cxx +cxx_tun := cxx/string.cxx cxx/ro-string.cxx cxx/stack.cxx ifeq ($(xsde_stl),n) cxx_tun += cxx/strdupx.cxx |