/* Copyright (C) 2004 Garrett A. Kajmowicz * * This file is part of the uClibc++ Library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #ifndef HEADER_STD_MEMORY #define HEADER_STD_MEMORY 1 #pragma GCC visibility push(default) extern "C++" { namespace std { template class allocator; // Specialize for void: template <> class _UCXXEXPORT allocator { public: typedef void* pointer; typedef const void* const_pointer; typedef void value_type; template struct rebind { typedef allocator other; }; }; template class _UCXXEXPORT allocator { public: typedef T value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; pointer address(reference r) const { return &r; } const_pointer address(const_reference r) const { return &r; } allocator() throw(){} template allocator(const allocator& ) throw(); ~allocator() throw(){} // Space for n Ts pointer allocate(size_type n, typename allocator::const_pointer = 0) { return (T*)(::operator new( n * sizeof(T) )); } void deallocate(pointer p, size_type) { ::operator delete(p); } // Use placement new to engage the constructor void construct(pointer p, const T& val) { new((void*)p) T(val); } void destroy(pointer p){ ((T*)p)->~T(); } //Call destructor size_type max_size() const throw(); template struct rebind { typedef allocator other; }; }; template class _UCXXEXPORT raw_storage_iterator : public iterator { Out p; public: explicit raw_storage_iterator(Out pp) : p (pp) { } raw_storage_iterator & operator*() { return *this; } raw_storage_iterator & operator=(const T& val) { T* pp = &*p; new(pp) T(val); return *this; } raw_storage_iterator & operator++() { ++p; return *this; } raw_storage_iterator operator++(int) { raw_storage_iterator t = *this; ++p; return t; } }; template _UCXXEXPORT pair get_temporary_buffer(ptrdiff_t n) { pair retval; retval.first = static_cast(malloc(n * sizeof(T))); if (retval.first == 0) { retval.second = 0; } else { retval.second = n; } return retval; } template _UCXXEXPORT void return_temporary_buffer(T* p) { free(p); } template class _UCXXEXPORT auto_ptr { private: T * object; template struct auto_ptr_ref { Y * p; }; public: typedef T element_type; explicit auto_ptr(T* p =0) throw() : object(p){ } auto_ptr(auto_ptr& p) throw() : object(p.release()){ } auto_ptr(auto_ptr_ref r) throw() : object(r.p) { r.p = 0; } template auto_ptr(auto_ptr& p) throw() : object(p.release()){ } auto_ptr& operator=(auto_ptr& p) throw() { if (&p == this) { return *this; } delete object; object = p.release(); return *this; } template auto_ptr& operator=(auto_ptr& p) throw() { if (&p == this) { return *this; } delete object; object = p.release(); return *this; } ~auto_ptr() { delete object; } T& operator*() const throw() { return *object; } T* operator->() const throw() { return object; } T* get() const throw() { return object; } T* release() throw() { T * temp(object); object = 0; return temp; } void reset(T * p=0) throw() { if(p != object) { delete object; object = p; } } template operator auto_ptr_ref() throw() { auto_ptr_ref retval; retval.p = object; object = 0; return retval; } template operator auto_ptr() throw() { auto_ptr retval(object); object = 0; return retval; } }; } // namespace std } // extern "C++" #pragma GCC visibility pop #endif