From a7880f755a4f48b2254616ff761ba5fecbf790a7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 May 2014 22:01:17 +0800 Subject: [PATCH] Usermode/libc++ - Starting on a hacky STL implementation - String is the most complete, list is hack central --- .../libc++.so_src/include_exp/algorithm | 42 ++++ .../libc++.so_src/include_exp/allocator | 61 +++++ .../libc++.so_src/include_exp/cstddef | 15 ++ .../libc++.so_src/include_exp/cstdint | 16 ++ .../libc++.so_src/include_exp/exception | 29 +++ .../Libraries/libc++.so_src/include_exp/list | 134 +++++++++++ .../libc++.so_src/include_exp/memory | 20 ++ .../libc++.so_src/include_exp/stdexcept | 41 ++++ .../libc++.so_src/include_exp/string | 219 ++++++++++++++++++ .../libc++.so_src/include_exp/vector | 0 10 files changed, 577 insertions(+) create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/algorithm create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/allocator create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/cstddef create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/cstdint create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/exception create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/list create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/memory create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/stdexcept create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/string create mode 100644 Usermode/Libraries/libc++.so_src/include_exp/vector diff --git a/Usermode/Libraries/libc++.so_src/include_exp/algorithm b/Usermode/Libraries/libc++.so_src/include_exp/algorithm new file mode 100644 index 00000000..b02f5b0d --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/algorithm @@ -0,0 +1,42 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * string (header) + * - C++'s String type + */ +#ifndef _LIBCXX_ALGORITHM_ +#define _LIBCXX_ALGORITHM_ + +namespace std { + +// Maximum +template +const T& max(const T& a, const T& b) +{ + return (a +const T& max(const T& a, const T& b, Compare comp) +{ + return comp(a, b) ? b : a; +} + +template +const T& min(const T& a, const T& b) +{ + return (a +const T& min(const T& a, const T& b, Compare comp) +{ + return comp(a, b) ? a : b; +} + +}; // namespace std + +#endif + +// vim: ft=cpp diff --git a/Usermode/Libraries/libc++.so_src/include_exp/allocator b/Usermode/Libraries/libc++.so_src/include_exp/allocator new file mode 100644 index 00000000..0bb12ea2 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/allocator @@ -0,0 +1,61 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * string (header) + * - C++'s String type + */ +#ifndef _LIBCXX_ALLOCATOR_ +#define _LIBCXX_ALLOCATOR_ + +#include "cstddef" + +namespace std { + +template class allocator +{ +public: + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef const T* const_pointer; + typedef const T& const_reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + template + struct rebind + { + typedef allocator other; + }; + + allocator() throw() { + } + allocator(const allocator& alloc) throw() { + } + template + allocator(const allocator& alloc) throw() { + } + ~allocator() throw() { + } + + pointer address(reference x) const { + return &x; + } + const_pointer address(const_reference x) const { + return &x; + } + pointer allocate(size_type n, const void* hint=0) { + ::operator new (n * sizeof(value_type)); + } + void deallocate(pointer p, size_type n) { + ::operator delete(p); + } +}; + +}; + +#endif + +// vim: ft=cpp + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/cstddef b/Usermode/Libraries/libc++.so_src/include_exp/cstddef new file mode 100644 index 00000000..b7b0c136 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/cstddef @@ -0,0 +1,15 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * cstddef (header) + * - C++ wrapper around stddef.h + */ +#ifndef _LIBCXX_CSTDDEF_ +#define _LIBCXX_CSTDDEF_ + +extern "C" { +#include +}; + +#endif diff --git a/Usermode/Libraries/libc++.so_src/include_exp/cstdint b/Usermode/Libraries/libc++.so_src/include_exp/cstdint new file mode 100644 index 00000000..c5575d9f --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/cstdint @@ -0,0 +1,16 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * cstdint (header) + * - C++ wrapper around stdint.h + */ +#ifndef _LIBCXX_CSTDINT_ +#define _LIBCXX_CSTDINT_ + +extern "C" { +#include +}; + +#endif + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/exception b/Usermode/Libraries/libc++.so_src/include_exp/exception new file mode 100644 index 00000000..6edf82b8 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/exception @@ -0,0 +1,29 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * exception (header) + * - C++'s base exception type + */ +#ifndef _LIBCXX_EXCEPTION_ +#define _LIBCXX_EXCEPTION_ + +#define noexcept throw() + +namespace std { + +class exception +{ +public: + exception() noexcept; + exception(const exception& e) noexcept; + exception& operator= (const exception& e) noexcept; + virtual ~exception() noexcept; + virtual const char* what() const noexcept; +}; + +}; // namespace std + +#endif +// vim: ft=cpp + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/list b/Usermode/Libraries/libc++.so_src/include_exp/list new file mode 100644 index 00000000..602d2ae4 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/list @@ -0,0 +1,134 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * list (header) + * - List container + */ +#ifndef _LIBCXX_LIST_ +#define _LIBCXX_LIST_ + +#include + +namespace std { + +namespace _bits { +template class list_iterator; +template class list_item; +} + +template +class list +{ + friend class ::std::_bits::list_iterator; + + typedef ::std::_bits::list_item item_type; + item_type *m_start; + item_type *m_end; +public: + typedef T value_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef _bits::list_iterator iterator; + typedef _bits::list_iterator const_iterator; + + list(): + m_start(0), m_end(0) + { + } + list(size_t n, const value_type& val = value_type()); + list(const list& x); + ~list() { + clear(); + } + + list& operator =(const list& x); + + iterator begin() { + return iterator(m_start); + } + const_iterator begin() const { + return const_iterator(m_start); + } + + iterator end() { + return iterator(0); + } + const_iterator end() const { + return const_iterator(0); + } + + bool empty() const { + return !m_start; + } + size_t size() const; + size_t max_size() const; + + T& front(); + const T& front() const; + T& back(); + const T& back() const; + + void clear() { + while( m_start ) { + item_type* item = m_start; + m_start = m_start->next; + delete item; + } + } +}; + + +namespace _bits { + +template +struct list_item +{ + list_item *next; + list_item *prev; + T value; +}; + +template +class list_iterator//: + //public bidirectional_iterator_tag; +{ + friend class list; + + list_item *cur; +public: + bool operator == (const list_iterator& other) const { + return cur == other.cur; + } + bool operator != (const list_iterator& other) const { + return cur != other.cur; + } + + T& operator * () { + return cur->value; + } + T& operator -> () { + return cur->value; + } + list_iterator& operator ++ () { + cur = cur->next; + } + list_iterator& operator -- () { + cur = cur->prev; + } + +private: + list_iterator(list_item *item): + cur(item) + { + } +}; + +}; // namespace _bits + +}; // namespace std + +#endif + +// vim: ft=cpp + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/memory b/Usermode/Libraries/libc++.so_src/include_exp/memory new file mode 100644 index 00000000..b604fbe8 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/memory @@ -0,0 +1,20 @@ + +#ifndef _LIBCXX_MEMORY_ +#define _LIBCXX_MEMORY_ + +namespace std { + +template <> +class allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + template struct rebind { typedef allocator other; }; +}; + +} + +#endif + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/stdexcept b/Usermode/Libraries/libc++.so_src/include_exp/stdexcept new file mode 100644 index 00000000..f9e3e3e8 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/stdexcept @@ -0,0 +1,41 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * string (header) + * - C++'s String type + */ +#ifndef _LIBCXX_STDEXCEPT_ +#define _LIBCXX_STDEXCEPT_ + +#include "exception" + +namespace std { + +class logic_error: + public exception +{ +public: + explicit logic_error(const basic_string& what_arg); +}; + +class runtime_error: + public exception +{ +public: + explicit runtime_error(const basic_string& what_arg); +}; + +class out_of_range: + public logic_error +{ +public: + explicit out_of_range(const string& what_arg); +}; + +} // namespace std + +#endif + +// vim: ft=cpp + diff --git a/Usermode/Libraries/libc++.so_src/include_exp/string b/Usermode/Libraries/libc++.so_src/include_exp/string new file mode 100644 index 00000000..73262176 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/string @@ -0,0 +1,219 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * string (header) + * - C++'s String type + */ +#ifndef _LIBCXX_STRING_ +#define _LIBCXX_STRING_ + +#include + +namespace std { + +template +struct char_traits +{ +}; + +template <> +struct char_traits +{ + typedef char char_type; + typedef int int_type; + //typedef streamoff off_type; + //typedef streampos pos_type; + //typedef mbstate_t state_type; + + static bool eq(const char_type& c, const char_type& d) { + return c == d; + } + static bool lt(const char_type& c, const char_type& d) { + return c < d; + } + static size_t length(const char_type* s) { + size_t ret = 0; + while(*s++) ret ++; + return ret; + } +}; + +template <> +struct char_traits +{ + typedef wchar_t char_type; + typedef int int_type; + //typedef streamoff off_type; + //typedef streampos pos_type; + //typedef mbstate_t state_type; + + static size_t length(const char_type* s) { + size_t ret = 0; + while(*s++) ret ++; + return ret; + } + static bool eq(const char_type& c, const char_type& d) { + return c == d; + } + static bool lt(const char_type& c, const char_type& d) { + return c < d; + } +}; + +template < class charT, class traits=char_traits, class Alloc=allocator > +class basic_string; + +typedef basic_string string; + +}; // namespace std + +#include + +namespace std { + +template < class charT, class traits, class Alloc > +class basic_string +{ +public: + typedef traits traits_type; + typedef Alloc allocator_type; + typedef charT value_type; + typedef typename allocator_type::reference reference; + typedef typename allocator_type::const_reference const_reference; + typedef size_t size_type; + + basic_string(const allocator_type& alloc = allocator_type()): + m_allocator(alloc), + m_capacity(0), + m_length(0), + m_data(0) + { + } + basic_string(const basic_string& str): + basic_string(str, allocator_type()) + { + } + basic_string(const basic_string& str, const allocator_type& alloc): + basic_string(str, 0, str.length(), alloc) + { + } + basic_string(const basic_string& str, size_type pos, size_type len = npos, const allocator_type& alloc = allocator_type()): + basic_string(alloc) + { + if( pos < str.length() ) + { + if( len > str.length() - pos ) + len = str.length() - pos; + reserve(len); + for( size_type i = 0; i < len; i ++ ) + m_data[i] = str.m_data[pos+i]; + m_length = len; + } + } + basic_string(const charT *s, const allocator_type& alloc = allocator_type()): + basic_string(s, traits::length(s), alloc) + { + } + basic_string(const charT *s, size_type n, const allocator_type& alloc = allocator_type()): + basic_string(alloc) + { + if( n > 0 ) + { + reserve(n); + for( size_type i = 0; i < n; i ++ ) + m_data[i] = s[i]; + m_length = n; + } + } + basic_string(size_type n, charT c, const allocator_type& alloc = allocator_type()): + basic_string(alloc) + { + if( n > 0 ) + { + reserve(n); + for( size_type i = 0; i < n; i ++ ) + m_data[i] = c; + m_length = n; + } + } + + // iterators + + // capacity + size_type size() const { + return m_size; + } + size_type length() const { + return size(); + } + size_type max_size() const { + return -1; + } + void resize(size_type size, charT c = 0) { + reserve(size); + if( m_size < size ) { + for( size_type ofs = m_size; ofs < size; ofs ++ ) + m_data[ofs] = c; + } + m_size = size; + m_data[m_size] = 0; + } + size_type capacity() const { + return m_capacity; + } + void reserve(size_type size) { + size = (size+1 + 31) & ~31; + if( size > m_capacity ) { + auto new_area = m_allocator.allocate(size); + for( size_type i = 0; i < m_length; i ++ ) + new_area[i] = m_data[i]; + m_allocator.deallocate(m_data, m_capacity); + m_data = new_area; + m_capacity = size; + } + } + void clear() { + m_size = 0; + } + bool empty() const { + return length() == 0; + } + + // Access + reference operator[] (size_type pos) { + return m_data[pos]; + } + const_reference operator[] (size_type pos) const { + return m_data[pos]; + } + reference at(size_type pos) { + if(pos >= m_size) throw ::std::out_of_range("basic_string - at"); + return m_data[pos]; + } + const_reference at(size_type pos) const { + if(pos >= m_size) throw ::std::out_of_range("basic_string - at"); + return m_data[pos]; + } + + // Modifiers + basic_string& operator +=(const basic_string& str); + basic_string& operator +=(const charT* s); + basic_string& operator +=(charT c); + + static const size_type npos = -1; +private: + allocator_type m_allocator; + size_type m_capacity; + size_type m_size; + size_type m_length; + typename allocator_type::pointer m_data; +}; + +}; + +#include + +#endif + +// vim: ft=cpp diff --git a/Usermode/Libraries/libc++.so_src/include_exp/vector b/Usermode/Libraries/libc++.so_src/include_exp/vector new file mode 100644 index 00000000..e69de29b -- 2.20.1