summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-11-02 16:35:37 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-11-02 16:35:37 +0000
commit93e2ebb1e771bf5a4bfd250def96f61b3df91b04 (patch)
tree35260ec9ddc4541943a2106fed7ec8fc63e472b1 /misc
parent95682a5d15e5cb99ad3ff1713b2313ac81f4e125 (diff)
downloadpx4-nuttx-93e2ebb1e771bf5a4bfd250def96f61b3df91b04.tar.gz
px4-nuttx-93e2ebb1e771bf5a4bfd250def96f61b3df91b04.tar.bz2
px4-nuttx-93e2ebb1e771bf5a4bfd250def96f61b3df91b04.zip
More uClibc++ build fixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5299 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'misc')
-rw-r--r--misc/uClibc++/include/uClibc++/deque1912
-rw-r--r--misc/uClibc++/include/uClibc++/string1981
-rw-r--r--misc/uClibc++/libxx/uClibc++/Make.defs17
-rw-r--r--misc/uClibc++/libxx/uClibc++/eh_terminate.cxx4
-rw-r--r--misc/uClibc++/libxx/uClibc++/func_exception.cxx16
-rw-r--r--misc/uClibc++/libxx/uClibc++/stdexcept.cxx93
-rw-r--r--misc/uClibc++/libxx/uClibc++/string.cxx128
7 files changed, 2311 insertions, 1840 deletions
diff --git a/misc/uClibc++/include/uClibc++/deque b/misc/uClibc++/include/uClibc++/deque
index ff07ab51c..19be5c8bb 100644
--- a/misc/uClibc++/include/uClibc++/deque
+++ b/misc/uClibc++/include/uClibc++/deque
@@ -1,22 +1,21 @@
-/* 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
+/* 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 <memory>
#include <iterator>
#include <stdexcept>
@@ -26,854 +25,1039 @@
#ifndef __STD_HEADER_DEQUE
#define __STD_HEADER_DEQUE
-
-namespace std{
- template <class T, class Allocator = allocator<T> > class deque;
- template <class T, class Allocator> bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> void swap(deque<T,Allocator>& x, deque<T,Allocator>& y);
-
- template <class T, class Allocator> class _UCXXEXPORT deque {
- public:
- friend bool operator==<>(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
- friend class deque_iter;
- friend class deque_citer;
- class deque_iter;
- class deque_citer;
-
- typedef typename Allocator::reference reference;
- typedef typename Allocator::const_reference const_reference;
- typedef deque_iter iterator;
- typedef deque_citer const_iterator;
- typedef typename Allocator::size_type size_type;
- typedef typename Allocator::difference_type difference_type;
- typedef T value_type;
- typedef Allocator allocator_type;
- typedef typename Allocator::pointer pointer;
- typedef typename Allocator::const_pointer const_pointer;
- typedef std::reverse_iterator<iterator> reverse_iterator;
- typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-
- explicit deque(const Allocator& al = Allocator());
- explicit deque(size_type n, const T& value = T(), const Allocator& al = Allocator());
- template <class InputIterator> deque(InputIterator first, InputIterator last, const Allocator& = Allocator());
- deque(const deque<T,Allocator>& x);
- ~deque();
-
- deque<T,Allocator>& operator=(const deque<T,Allocator>& x);
- template <class InputIterator> void assign(InputIterator first, InputIterator last);
- template <class Size, class U> void assign(Size n, const U& u = U());
- allocator_type get_allocator() const;
-
- iterator begin();
- const_iterator begin() const;
- iterator end();
- const_iterator end() const;
- reverse_iterator rbegin();
- const_reverse_iterator rbegin() const;
- reverse_iterator rend();
- const_reverse_iterator rend() const;
-
- size_type size() const;
- size_type max_size() const;
- void resize(size_type sz, T c = T());
- bool empty() const;
-
- reference operator[](size_type n);
- const_reference operator[](size_type n) const;
- reference at(size_type n);
- const_reference at(size_type n) const;
- reference front();
- const_reference front() const;
- reference back();
- const_reference back() const;
-
- void push_front(const T& x);
- void push_back(const T& x);
- iterator insert(iterator position, const T& x = T());
- void insert(iterator position, size_type n, const T& x);
- template <class InputIterator> void insert (iterator position, InputIterator first, InputIterator last);
- void pop_front();
- void pop_back();
-
- iterator erase(iterator position);
- iterator erase(iterator first, iterator last);
- void swap(deque<T,Allocator>&);
- void clear();
-
- protected:
- void reserve(size_type n);
- inline size_type array_element(size_type deque_element) const{
- if(deque_element < (data_size - first_element)){
- return first_element + deque_element;
- }
- return deque_element - (data_size - first_element);
- }
- inline size_type first_subtract(size_type sub_size) const{
- if(sub_size > first_element){
- return (data_size - first_element) - sub_size;
- }
- return first_element - sub_size;
- }
-
- T * data;
- size_type data_size; //Physical size of array
- size_type elements; //Elements in array
- size_type first_element; //Element number of array 0..n
- size_type last_element; //Element number of array 0..n
- Allocator a;
-
- };
-
-
- template<class T, class Allocator> class _UCXXEXPORT deque<T, Allocator>::deque_iter
- : public std::iterator<
- random_access_iterator_tag,
- T,
- typename Allocator::difference_type,
- typename Allocator::pointer,
- typename Allocator::reference
- >
- {
- friend class deque<T, Allocator>;
- protected:
- deque<T, Allocator> * container;
- typename Allocator::size_type element;
-
- public:
- deque_iter() : container(0), element(0) { }
- deque_iter(const deque_iter & d) : container (d.container), element(d.element) { }
- deque_iter(deque<T, Allocator> * c, typename Allocator::size_type e)
- : container(c), element(e)
- {
- return;
- }
- ~deque_iter() { }
- deque_iter & operator=(const deque_iter & d){
- container = d.container;
- element = d.element;
- return *this;
- }
- T & operator*(){
- return container->data[container->array_element(element)];
- }
- T * operator->(){
- return container->data + container->array_element(element);
- }
- const T & operator*() const{
- return container->data[container->array_element(element)];
- }
- const T * operator->() const{
- return container->data + container->array_element(element);
- }
- bool operator==(const deque_iter & d) const{
- if(container == d.container && element == d.element){
- return true;
- }
- return false;
- }
- bool operator==(const deque_citer & d) const{
- if(container == d.container && element == d.element){
- return true;
- }
- return false;
- }
- bool operator!=(const deque_iter & d) const{
- if(container != d.container || element != d.element){
- return true;
- }
- return false;
- }
- bool operator!=(const deque_citer & d) const{
- if(container != d.container || element != d.element){
- return true;
- }
- return false;
- }
- bool operator<(const deque_iter & d) const{
- if(element < d.element){
- return true;
- }
- return false;
- }
- bool operator<(const deque_citer & d) const{
- if(element < d.element){
- return true;
- }
- return false;
- }
- bool operator<=(const deque_iter & d) const{
- if(element <= d.element){
- return true;
- }
- return false;
- }
- bool operator<=(const deque_citer & d) const{
- if(element <= d.element){
- return true;
- }
- return false;
- }
- bool operator>(const deque_iter & d) const{
- if(element > d.element){
- return true;
- }
- return false;
- }
- bool operator>(const deque_citer & d) const{
- if(element > d.element){
- return true;
- }
- return false;
- }
- bool operator>=(const deque_iter & d) const{
- if(element >= d.element){
- return true;
- }
- return false;
- }
- bool operator>=(const deque_citer & d) const{
- if(element >= d.element){
- return true;
- }
- return false;
- }
- deque_iter & operator++(){
- ++element;
- return *this;
- }
- deque_iter operator++(int){
- deque_iter temp(container, element);
- ++element;
- return temp;
- }
- deque_iter operator+(typename Allocator::size_type n){
- deque_iter temp(container, element + n);
- return temp;
- }
- deque_iter & operator+=(typename Allocator::size_type n){
- element += n;
- return *this;
- }
- deque_iter & operator--(){
- --element;
- return *this;
- }
- deque_iter operator--(int){
- deque_iter temp(container, element);
- --element;
- return temp;
- }
- deque_iter operator-(typename Allocator::size_type n){
- deque_iter temp(container, element - n);
- return temp;
- }
- deque_iter & operator-=(typename Allocator::size_type n){
- element -= n;
- return *this;
- }
- typename Allocator::size_type operator-(const deque_iter & d){
- return element - d.element;
- }
-
- };
-
- template<class T, class Allocator> class _UCXXEXPORT deque<T, Allocator>::deque_citer
- : public std::iterator<
- random_access_iterator_tag,
- T,
- typename Allocator::difference_type,
- typename Allocator::const_pointer,
- typename Allocator::const_reference
- >
- {
- friend class deque<T, Allocator>;
- protected:
- const deque<T, Allocator> * container;
- typename Allocator::size_type element;
-
- public:
- deque_citer() : container(0), element(0) { }
- deque_citer(const deque_citer & d) : container (d.container), element(d.element) { }
- deque_citer(const deque_iter & d) : container (d.container), element(d.element) { }
- deque_citer(const deque<T, Allocator> * c, typename Allocator::size_type e)
- : container(c), element(e)
- {
- return;
- }
- ~deque_citer() { }
- deque_citer & operator=(const deque_iter & d){
- container = d.container;
- element = d.element;
- return *this;
- }
- const T & operator*() const{
- return container->data[container->array_element(element)];
- }
- const T * operator->() const{
- return container->data + container->array_element(element);
- }
- bool operator==(const deque_citer & d) const{
- if(container == d.container && element == d.element){
- return true;
- }
- return false;
- }
- bool operator==(const deque_iter & d) const{
- if(container == d.container && element == d.element){
- return true;
- }
- return false;
- }
- bool operator!=(const deque_citer & d) const{
- if(container != d.container || element != d.element){
- return true;
- }
- return false;
- }
- bool operator!=(const deque_iter & d) const{
- if(container != d.container || element != d.element){
- return true;
- }
- return false;
- }
- bool operator<(const deque_citer & d) const{
- if(element < d.element){
- return true;
- }
- return false;
- }
- bool operator<(const deque_iter & d) const{
- if(element < d.element){
- return true;
- }
- return false;
- }
- bool operator<=(const deque_citer & d) const{
- if(element <= d.element){
- return true;
- }
- return false;
- }
- bool operator<=(const deque_iter & d) const{
- if(element <= d.element){
- return true;
- }
- return false;
- }
- bool operator>(const deque_citer & d) const{
- if(element > d.element){
- return true;
- }
- return false;
- }
- bool operator>(const deque_iter & d) const{
- if(element > d.element){
- return true;
- }
- return false;
- }
- bool operator>=(const deque_citer & d){
- if(element >= d.element){
- return true;
- }
- return false;
- }
- bool operator>=(const deque_iter & d){
- if(element >= d.element){
- return true;
- }
- return false;
- }
- deque_citer & operator++(){
- ++element;
- return *this;
- }
- deque_citer operator++(int){
- deque_citer temp(container, element);
- ++element;
- return temp;
- }
- deque_citer operator+(typename Allocator::size_type n){
- deque_citer temp(container, element + n);
- return temp;
- }
- deque_citer & operator+=(typename Allocator::size_type n){
- element += n;
- return *this;
- }
- deque_citer & operator--(){
- --element;
- return *this;
- }
- deque_citer operator--(int){
- deque_citer temp(container, element);
- --element;
- return temp;
- }
- deque_citer operator-(typename Allocator::size_type n){
- deque_citer temp(container, element - n);
- return temp;
- }
- deque_citer & operator-=(typename Allocator::size_type n){
- element -= n;
- return *this;
- }
- typename Allocator::size_type operator-(const deque_citer & d){
- return element - d.element;
- }
-
- };
-
- template<class T, class Allocator> deque<T, Allocator>::deque(const Allocator& al)
- : data(0),
- data_size(0), elements(0), first_element(0), last_element(0), a(al)
- {
- data_size = __UCLIBCXX_STL_BUFFER_SIZE__;
- data = a.allocate(data_size);
- first_element = data_size /2;
- last_element = first_element;
- }
-
-
- template<class T, class Allocator> deque<T, Allocator>::deque(
- size_type n, const T& value, const Allocator& al)
- : data(0),
- elements(n), first_element(0), last_element(0), a(al)
- {
- data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__;
- data = a.allocate(data_size);
- first_element = (data_size - elements) / 2;
- last_element = first_element;
-
- for(n=first_element ; n < last_element; ++n ){
- a.construct(data+n, value);
- }
- }
-
-
- template<class T, class Allocator> template <class InputIterator>
- deque<T, Allocator>::deque(InputIterator first, InputIterator last, const Allocator& al)
- : data(0),
- data_size(0), elements(0), first_element(0), last_element(0), a(al)
- {
- data_size = __UCLIBCXX_STL_BUFFER_SIZE__;
- data = a.allocate(data_size);
- first_element = data_size / 4; //Note sure how big, but let's add a little space...
- last_element = first_element;
- while(first != last){
- push_back(*first);
- ++first;
- }
- }
-
-
- template<class T, class Allocator> deque<T, Allocator>::deque(const deque<T,Allocator>& x)
- : data(0),
- elements(0), first_element(0), last_element(0), a(x.a)
- {
- data_size = x.elements + __UCLIBCXX_STL_BUFFER_SIZE__;
- data = a.allocate(data_size);
- first_element = (data_size - x.elements) / 2;
- last_element = first_element;
- for(size_type i=0; i < x.elements; ++i){
- push_back(x[i]);
- }
- }
-
-
- template<class T, class Allocator> deque<T, Allocator>::~deque(){
- clear();
- a.deallocate(data, data_size);
- }
-
- template<class T, class Allocator> deque<T,Allocator>& deque<T, Allocator>::
- operator=(const deque<T,Allocator>& x)
- {
- if(&x == this){
- return *this;
- }
- resize(x.elements);
- for(size_t i = 0; i < elements; ++i){
- data[array_element(i)] = x[i];
- }
- return *this;
- }
-
-
- template<class T, class Allocator> template <class InputIterator> void
- deque<T, Allocator>::assign(InputIterator first, InputIterator last)
- {
- clear();
- while(first !=last){
- push_back(*first);
- ++first;
- }
- }
-
-
- template<class T, class Allocator> template <class Size, class U> void
- deque<T, Allocator>::assign(Size n, const U& u)
- {
- if(&u == this){
- return;
- }
- clear();
- for(size_type i = 0; i < n; ++i){
- push_back(u);
- }
- }
-
-
- template<class T, class Allocator> typename deque<T, Allocator>::allocator_type
- deque<T, Allocator>::get_allocator() const
- {
- return a;
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::iterator deque<T, Allocator>::begin()
- {
- return deque_iter(this, 0);
- }
-
-
- template<class T, class Allocator> typename deque<T, Allocator>::const_iterator
- deque<T, Allocator>::begin() const
- {
- return deque_citer(this, 0);
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::iterator deque<T, Allocator>::end()
- {
- return deque_iter(this, elements);
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_iterator deque<T, Allocator>::end() const
- {
- return deque_citer(this, elements);
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reverse_iterator deque<T, Allocator>::rbegin()
- {
- return reverse_iterator(end());
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reverse_iterator deque<T, Allocator>::rbegin() const
- {
- return const_reverse_iterator(end());
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reverse_iterator deque<T, Allocator>::rend()
- {
- return reverse_iterator(begin());
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reverse_iterator deque<T, Allocator>::rend() const
- {
- return const_reverse_iterator(begin());
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::size_type deque<T, Allocator>::size() const
- {
- return elements;
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::size_type deque<T, Allocator>::max_size() const
- {
- return ((size_type)(-1)) / sizeof(T);
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::resize(size_type sz, T c){
- reserve(sz);
- while(sz > size()){
- push_back(c);
- }
- while(sz < size()){
- pop_back();
- }
- }
-
- template<class T, class Allocator> bool deque<T, Allocator>::empty() const{
- return (elements == 0);
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reference deque<T, Allocator>::operator[](size_type n)
- {
- return data[array_element(n)];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reference deque<T, Allocator>::operator[](size_type n) const
- {
- return data[array_element(n)];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reference deque<T, Allocator>::at(size_type n)
- {
- if(n > elements){
- __throw_out_of_range("Out of deque range");
- }
- return data[array_element(n)];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reference deque<T, Allocator>::at(size_type n) const
- {
- if(n > elements){
- __throw_out_of_range("Out of deque range");
- }
- return data[array_element(n)];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reference deque<T, Allocator>::front()
- {
- return data[first_element];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reference deque<T, Allocator>::front() const
- {
- return data[first_element];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::reference deque<T, Allocator>::back()
- {
- return data[array_element(elements-1)];
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::const_reference deque<T, Allocator>::back() const
- {
- return data[array_element(elements-1)];
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::push_front(const T& x){
- reserve(elements + 1);
- first_element = first_subtract(1);
- a.construct(data + first_element, x);
- ++elements;
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::push_back(const T& x){
- reserve(elements + 1);
- a.construct(data + last_element, x);
- ++elements;
- last_element = array_element(elements);
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::iterator deque<T, Allocator>::insert(iterator position, const T& x)
- {
- reserve(elements+1);
- if(position.element > (elements/2)){
- //Push all elements back 1
- push_back(x);
- for(size_type i = elements-1; i > position.element; --i){
- at(i) = at(i-1);
- }
- }else{
- //Push all elements forward 1
- push_front(x);
- for(size_type i = 0; i < position.element; ++i){
- at(i) = at(i+1);
- }
- }
- at(position.element) = x;
- return deque_iter(this, position.element);
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::
- insert(typename deque<T, Allocator>::iterator position, size_type n, const T& x)
- {
- reserve(elements + n);
- for(size_t i =0; i < n; ++i){
- position = insert(position, x);
- }
- }
-
- template<class T, class Allocator> template <class InputIterator>
- void deque<T, Allocator>::insert (iterator position, InputIterator first, InputIterator last)
- {
- while(first != last){
- position = insert(position, *first);
- ++first;
- }
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::pop_front(){
- if(elements == 0){
- __throw_out_of_range("deque pop_front");
- }
- a.destroy(data + first_element);
- first_element = array_element(1);
- --elements;
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::pop_back(){
- last_element = array_element(elements - 1);
- a.destroy(data + last_element);
- --elements;
- }
-
- template<class T, class Allocator> typename
- deque<T, Allocator>::iterator deque<T, Allocator>::erase(typename deque<T, Allocator>::iterator position)
- {
- if(position.element > (elements /2)){
- for(size_type i = position.element; i < elements - 1; ++i){
- at(i) = at(i+1);
- }
- pop_back();
- }else{
- for(size_type i = position.element; i > 0; --i){
- at(i) = at(i-1);
- }
- pop_front();
- }
- return deque_iter(this, position.element);
- }
-
- template<class T, class Allocator> typename deque<T, Allocator>::iterator
- deque<T, Allocator>::
- erase(typename deque<T, Allocator>::iterator first, typename deque<T, Allocator>::iterator last)
- {
- //Shift backwards
- size_type num_move = last.element - first.element;
- if( first.element > (elements - last.element) ){
- for(size_type i = last.element; i < elements ; ++i){
- at(i-num_move) = at(i);
- }
- for(size_type i = 0; i < num_move ; ++i){
- pop_back();
- }
- }else{
- for(size_type i = 0; i < first.element ; ++i){
- at(last.element - i - 1) = at(first.element - i - 1);
- }
- for(size_type i = 0; i < num_move ; ++i){
- pop_front();
- }
- }
- return deque_iter(this, first.element);
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::swap(deque<T,Allocator>& x)
- {
- T * temp_data;
- typename deque<T,Allocator>::size_type temp_size;
-
- //Swap data pointers
- temp_data = x.data;
- x.data = data;
- data = temp_data;
-
- //Swap array sizes
- temp_size = x.data_size;
- x.data_size = data_size;
- data_size = temp_size;
-
- //Swap num array elements
- temp_size = x.elements;
- x.elements = elements;
- elements = temp_size;
-
- //Swap first_pointer
- temp_size = x.first_element;
- x.first_element = first_element;
- first_element = temp_size;
-
- //Swap last_pointer
- temp_size = x.last_element;
- x.last_element = last_element;
- last_element = temp_size;
- }
-
- template<class T, class Allocator> void deque<T, Allocator>::clear()
- {
- while(elements > 0 ){
- pop_back();
- }
- }
-
-
- template<class T, class Allocator> void deque<T, Allocator>::reserve(typename deque<T, Allocator>::size_type n)
- {
- if(data_size >= n){
- return;
- }
-
- size_type size_temp;
- size_type first_temp;
- T * data_temp;
- size_temp = n + __UCLIBCXX_STL_BUFFER_SIZE__; //Reserve extra 'cause we can
- data_temp = a.allocate(size_temp);
-
- first_temp = (size_temp - elements) / 2;
- for(size_type i = 0; i < elements; ++i){
- a.construct(data_temp + first_temp + i, data[array_element(i)]);
- a.destroy(data + array_element(i));
- }
-
- //Now shuffle pointers
- a.deallocate(data, data_size);
- data = data_temp;
- data_size = size_temp;
- first_element = first_temp;
- last_element = first_element + elements;
- }
-
-
- template <class T, class Allocator> _UCXXEXPORT
- bool
- operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y)
- {
- if(x.elements != y.elements){
- return false;
- }
- for(typename deque<T,Allocator>::size_type i = 0; i < x.elements; ++i){
- if(x[i] < y[i] || y[i] < x[i]){
- return false;
- }
- }
- return true;
- }
-
- template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> _UCXXEXPORT
- bool
- operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y)
- {
- if(x == y){
- return false;
- }
- return true;
- }
- template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
- template <class T, class Allocator> _UCXXEXPORT void swap(deque<T,Allocator>& x, deque<T,Allocator>& y){
- x.swap(y);
- }
-
-
-
-}
+namespace std
+{
+ template <class T, class Allocator = allocator<T> > class deque;
+ template <class T, class Allocator> bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> void swap(deque<T,Allocator>& x, deque<T,Allocator>& y);
+
+ template <class T, class Allocator> class _UCXXEXPORT deque {
+ public:
+ friend bool operator==<>(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
+ friend class deque_iter;
+ friend class deque_citer;
+ class deque_iter;
+ class deque_citer;
+
+ typedef typename Allocator::reference reference;
+ typedef typename Allocator::const_reference const_reference;
+ typedef deque_iter iterator;
+ typedef deque_citer const_iterator;
+ typedef typename Allocator::size_type size_type;
+ typedef typename Allocator::difference_type difference_type;
+ typedef T value_type;
+ typedef Allocator allocator_type;
+ typedef typename Allocator::pointer pointer;
+ typedef typename Allocator::const_pointer const_pointer;
+ typedef std::reverse_iterator<iterator> reverse_iterator;
+ typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+
+ explicit deque(const Allocator& al = Allocator());
+ explicit deque(size_type n, const T& value = T(), const Allocator& al = Allocator());
+ template <class InputIterator> deque(InputIterator first, InputIterator last, const Allocator& = Allocator());
+ deque(const deque<T,Allocator>& x);
+ ~deque();
+
+ deque<T,Allocator>& operator=(const deque<T,Allocator>& x);
+ template <class InputIterator> void assign(InputIterator first, InputIterator last);
+ template <class Size, class U> void assign(Size n, const U& u = U());
+ allocator_type get_allocator() const;
+
+ iterator begin();
+ const_iterator begin() const;
+ iterator end();
+ const_iterator end() const;
+ reverse_iterator rbegin();
+ const_reverse_iterator rbegin() const;
+ reverse_iterator rend();
+ const_reverse_iterator rend() const;
+
+ size_type size() const;
+ size_type max_size() const;
+ void resize(size_type sz, T c = T());
+ bool empty() const;
+
+ reference operator[](size_type n);
+ const_reference operator[](size_type n) const;
+ reference at(size_type n);
+ const_reference at(size_type n) const;
+ reference front();
+ const_reference front() const;
+ reference back();
+ const_reference back() const;
+
+ void push_front(const T& x);
+ void push_back(const T& x);
+ iterator insert(iterator position, const T& x = T());
+ void insert(iterator position, size_type n, const T& x);
+ template <class InputIterator> void insert (iterator position, InputIterator first, InputIterator last);
+ void pop_front();
+ void pop_back();
+
+ iterator erase(iterator position);
+ iterator erase(iterator first, iterator last);
+ void swap(deque<T,Allocator>&);
+ void clear();
+
+ protected:
+ void reserve(size_type n);
+
+ inline size_type array_element(size_type deque_element) const
+ {
+ if (deque_element < (data_size - first_element))
+ {
+ return first_element + deque_element;
+ }
+ return deque_element - (data_size - first_element);
+ }
+
+ inline size_type first_subtract(size_type sub_size) const
+ {
+ if (sub_size > first_element)
+ {
+ return (data_size - first_element) - sub_size;
+ }
+ return first_element - sub_size;
+ }
+
+ T * data;
+ size_type data_size; //Physical size of array
+ size_type elements; //Elements in array
+ size_type first_element; //Element number of array 0..n
+ size_type last_element; //Element number of array 0..n
+ Allocator a;
+
+ };
+
+ template<class T, class Allocator> class _UCXXEXPORT deque<T, Allocator>::deque_iter
+ : public std::iterator<
+ random_access_iterator_tag,
+ T,
+ typename Allocator::difference_type,
+ typename Allocator::pointer,
+ typename Allocator::reference
+ >
+ {
+ friend class deque<T, Allocator>;
+ protected:
+ deque<T, Allocator> * container;
+ typename Allocator::size_type element;
+
+ public:
+ deque_iter() : container(0), element(0) { }
+ deque_iter(const deque_iter & d) : container (d.container), element(d.element) { }
+
+ deque_iter(deque<T, Allocator> * c, typename Allocator::size_type e)
+ : container(c), element(e)
+ {
+ return;
+ }
+
+ ~deque_iter() { }
+
+ deque_iter & operator=(const deque_iter & d)
+ {
+ container = d.container;
+ element = d.element;
+ return *this;
+ }
+
+ T & operator*()
+ {
+ return container->data[container->array_element(element)];
+ }
+
+ T * operator->()
+ {
+ return container->data + container->array_element(element);
+ }
+
+ const T & operator*() const
+ {
+ return container->data[container->array_element(element)];
+ }
+
+ const T * operator->() const
+ {
+ return container->data + container->array_element(element);
+ }
+
+ bool operator==(const deque_iter & d) const
+ {
+ if (container == d.container && element == d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool operator==(const deque_citer & d) const
+ {
+ if (container == d.container && element == d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator!=(const deque_iter & d) const
+ {
+ if (container != d.container || element != d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator!=(const deque_citer & d) const
+ {
+ if (container != d.container || element != d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<(const deque_iter & d) const
+ {
+ if (element < d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<(const deque_citer & d) const
+ {
+ if (element < d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<=(const deque_iter & d) const
+ {
+ if (element <= d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<=(const deque_citer & d) const
+ {
+ if (element <= d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator>(const deque_iter & d) const
+ {
+ if (element > d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool operator>(const deque_citer & d) const
+ {
+ if (element > d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool operator>=(const deque_iter & d) const
+ {
+ if (element >= d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool operator>=(const deque_citer & d) const
+ {
+ if (element >= d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ deque_iter & operator++()
+ {
+ ++element;
+ return *this;
+ }
+
+ deque_iter operator++(int)
+ {
+ deque_iter temp(container, element);
+ ++element;
+ return temp;
+ }
+
+ deque_iter operator+(typename Allocator::size_type n)
+ {
+ deque_iter temp(container, element + n);
+ return temp;
+ }
+
+ deque_iter & operator+=(typename Allocator::size_type n)
+ {
+ element += n;
+ return *this;
+ }
+
+ deque_iter & operator--()
+ {
+ --element;
+ return *this;
+ }
+
+ deque_iter operator--(int)
+ {
+ deque_iter temp(container, element);
+ --element;
+ return temp;
+ }
+
+ deque_iter operator-(typename Allocator::size_type n)
+ {
+ deque_iter temp(container, element - n);
+ return temp;
+ }
+
+ deque_iter & operator-=(typename Allocator::size_type n)
+ {
+ element -= n;
+ return *this;
+ }
+
+ typename Allocator::size_type operator-(const deque_iter & d)
+ {
+ return element - d.element;
+ }
+
+ };
+
+ template<class T, class Allocator> class _UCXXEXPORT deque<T, Allocator>::deque_citer
+ : public std::iterator<
+ random_access_iterator_tag,
+ T,
+ typename Allocator::difference_type,
+ typename Allocator::const_pointer,
+ typename Allocator::const_reference
+ >
+ {
+ friend class deque<T, Allocator>;
+ protected:
+ const deque<T, Allocator> * container;
+ typename Allocator::size_type element;
+
+ public:
+ deque_citer() : container(0), element(0) { }
+ deque_citer(const deque_citer & d) : container (d.container), element(d.element) { }
+ deque_citer(const deque_iter & d) : container (d.container), element(d.element) { }
+
+ deque_citer(const deque<T, Allocator> * c, typename Allocator::size_type e)
+ : container(c), element(e)
+ {
+ return;
+ }
+
+ ~deque_citer() { }
+
+ deque_citer & operator=(const deque_iter & d)
+ {
+ container = d.container;
+ element = d.element;
+ return *this;
+ }
+
+ const T & operator*() const
+ {
+ return container->data[container->array_element(element)];
+ }
+
+ const T * operator->() const
+ {
+ return container->data + container->array_element(element);
+ }
+
+ bool operator==(const deque_citer & d) const
+ {
+ if (container == d.container && element == d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator==(const deque_iter & d) const
+ {
+ if (container == d.container && element == d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator!=(const deque_citer & d) const
+ {
+ if (container != d.container || element != d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator!=(const deque_iter & d) const
+ {
+ if (container != d.container || element != d.element)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ bool operator<(const deque_citer & d) const
+ {
+ if (element < d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<(const deque_iter & d) const
+ {
+ if (element < d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<=(const deque_citer & d) const
+ {
+ if (element <= d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator<=(const deque_iter & d) const
+ {
+ if (element <= d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator>(const deque_citer & d) const
+ {
+ if (element > d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator>(const deque_iter & d) const
+ {
+ if (element > d.element){
+ return true;
+ }
+ return false;
+ }
+
+ bool operator>=(const deque_citer & d)
+ {
+ if (element >= d.element)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ bool operator>=(const deque_iter & d)
+ {
+ if (element >= d.element){
+ return true;
+ }
+ return false;
+ }
+
+ deque_citer & operator++()
+ {
+ ++element;
+ return *this;
+ }
+
+ deque_citer operator++(int)
+ {
+ deque_citer temp(container, element);
+ ++element;
+ return temp;
+ }
+
+ deque_citer operator+(typename Allocator::size_type n)
+ {
+ deque_citer temp(container, element + n);
+ return temp;
+ }
+
+ deque_citer & operator+=(typename Allocator::size_type n)
+ {
+ element += n;
+ return *this;
+ }
+
+ deque_citer & operator--()
+ {
+ --element;
+ return *this;
+ }
+
+ deque_citer operator--(int)
+ {
+ deque_citer temp(container, element);
+ --element;
+ return temp;
+ }
+
+ deque_citer operator-(typename Allocator::size_type n)
+ {
+ deque_citer temp(container, element - n);
+ return temp;
+ }
+
+ deque_citer & operator-=(typename Allocator::size_type n)
+ {
+ element -= n;
+ return *this;
+ }
+
+ typename Allocator::size_type operator-(const deque_citer & d)
+ {
+ return element - d.element;
+ }
+
+ };
+
+ template<class T, class Allocator> deque<T, Allocator>::deque(const Allocator& al)
+ : data(0),
+ data_size(0), elements(0), first_element(0), last_element(0), a(al)
+ {
+ data_size = __UCLIBCXX_STL_BUFFER_SIZE__;
+ data = a.allocate(data_size);
+ first_element = data_size /2;
+ last_element = first_element;
+ }
+
+
+ template<class T, class Allocator> deque<T, Allocator>::deque(
+ size_type n, const T& value, const Allocator& al)
+ : data(0),
+ elements(n), first_element(0), last_element(0), a(al)
+ {
+ data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__;
+ data = a.allocate(data_size);
+ first_element = (data_size - elements) / 2;
+ last_element = first_element;
+
+ for (n=first_element ; n < last_element; ++n)
+ {
+ a.construct(data+n, value);
+ }
+ }
+
+
+ template<class T, class Allocator> template <class InputIterator>
+ deque<T, Allocator>::deque(InputIterator first, InputIterator last, const Allocator& al)
+ : data(0),
+ data_size(0), elements(0), first_element(0), last_element(0), a(al)
+ {
+ data_size = __UCLIBCXX_STL_BUFFER_SIZE__;
+ data = a.allocate(data_size);
+ first_element = data_size / 4; //Note sure how big, but let's add a little space...
+ last_element = first_element;
+ while (first != last)
+ {
+ push_back(*first);
+ ++first;
+ }
+ }
+
+
+ template<class T, class Allocator> deque<T, Allocator>::deque(const deque<T,Allocator>& x)
+ : data(0),
+ elements(0), first_element(0), last_element(0), a(x.a)
+ {
+ data_size = x.elements + __UCLIBCXX_STL_BUFFER_SIZE__;
+ data = a.allocate(data_size);
+ first_element = (data_size - x.elements) / 2;
+ last_element = first_element;
+ for (size_type i=0; i < x.elements; ++i)
+ {
+ push_back(x[i]);
+ }
+ }
+
+
+ template<class T, class Allocator> deque<T, Allocator>::~deque()
+ {
+ clear();
+ a.deallocate(data, data_size);
+ }
+
+ template<class T, class Allocator> deque<T,Allocator>& deque<T, Allocator>::
+ operator=(const deque<T,Allocator>& x)
+ {
+ if (&x == this)
+ {
+ return *this;
+ }
+
+ resize(x.elements);
+ for (size_t i = 0; i < elements; ++i)
+ {
+ data[array_element(i)] = x[i];
+ }
+ return *this;
+ }
+
+ template<class T, class Allocator> template <class InputIterator> void
+ deque<T, Allocator>::assign(InputIterator first, InputIterator last)
+ {
+ clear();
+ while (first !=last)
+ {
+ push_back(*first);
+ ++first;
+ }
+ }
+
+ template<class T, class Allocator> template <class Size, class U> void
+ deque<T, Allocator>::assign(Size n, const U& u)
+ {
+ if (&u == this)
+ {
+ return;
+ }
+
+ clear();
+ for (size_type i = 0; i < n; ++i)
+ {
+ push_back(u);
+ }
+ }
+
+ template<class T, class Allocator> typename deque<T, Allocator>::allocator_type
+ deque<T, Allocator>::get_allocator() const
+ {
+ return a;
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::iterator deque<T, Allocator>::begin()
+ {
+ return deque_iter(this, 0);
+ }
+
+ template<class T, class Allocator> typename deque<T, Allocator>::const_iterator
+ deque<T, Allocator>::begin() const
+ {
+ return deque_citer(this, 0);
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::iterator deque<T, Allocator>::end()
+ {
+ return deque_iter(this, elements);
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_iterator deque<T, Allocator>::end() const
+ {
+ return deque_citer(this, elements);
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reverse_iterator deque<T, Allocator>::rbegin()
+ {
+ return reverse_iterator(end());
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reverse_iterator deque<T, Allocator>::rbegin() const
+ {
+ return const_reverse_iterator(end());
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reverse_iterator deque<T, Allocator>::rend()
+ {
+ return reverse_iterator(begin());
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reverse_iterator deque<T, Allocator>::rend() const
+ {
+ return const_reverse_iterator(begin());
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::size_type deque<T, Allocator>::size() const
+ {
+ return elements;
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::size_type deque<T, Allocator>::max_size() const
+ {
+ return ((size_type)(-1)) / sizeof(T);
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::resize(size_type sz, T c)
+ {
+ reserve(sz);
+ while (sz > size())
+ {
+ push_back(c);
+ }
+
+ while (sz < size())
+ {
+ pop_back();
+ }
+ }
+
+ template<class T, class Allocator> bool deque<T, Allocator>::empty() const
+ {
+ return (elements == 0);
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reference deque<T, Allocator>::operator[](size_type n)
+ {
+ return data[array_element(n)];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reference deque<T, Allocator>::operator[](size_type n) const
+ {
+ return data[array_element(n)];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reference deque<T, Allocator>::at(size_type n)
+ {
+ if (n > elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range("Out of deque range");
+#else
+ std::terminate();
+#endif
+ }
+ return data[array_element(n)];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reference deque<T, Allocator>::at(size_type n) const
+ {
+ if (n > elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range("Out of deque range");
+#else
+ std::terminate();
+#endif
+ }
+ return data[array_element(n)];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reference deque<T, Allocator>::front()
+ {
+ return data[first_element];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reference deque<T, Allocator>::front() const
+ {
+ return data[first_element];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::reference deque<T, Allocator>::back()
+ {
+ return data[array_element(elements-1)];
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::const_reference deque<T, Allocator>::back() const
+ {
+ return data[array_element(elements-1)];
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::push_front(const T& x)
+ {
+ reserve(elements + 1);
+ first_element = first_subtract(1);
+ a.construct(data + first_element, x);
+ ++elements;
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::push_back(const T& x)
+ {
+ reserve(elements + 1);
+ a.construct(data + last_element, x);
+ ++elements;
+ last_element = array_element(elements);
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::iterator deque<T, Allocator>::insert(iterator position, const T& x)
+ {
+ reserve(elements+1);
+ if (position.element > (elements/2))
+ {
+ //Push all elements back 1
+
+ push_back(x);
+ for (size_type i = elements-1; i > position.element; --i)
+ {
+ at(i) = at(i-1);
+ }
+ }
+ else
+ {
+ //Push all elements forward 1
+
+ push_front(x);
+ for (size_type i = 0; i < position.element; ++i){
+ at(i) = at(i+1);
+ }
+ }
+
+ at(position.element) = x;
+ return deque_iter(this, position.element);
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::
+ insert(typename deque<T, Allocator>::iterator position, size_type n, const T& x)
+ {
+ reserve(elements + n);
+ for (size_t i =0; i < n; ++i){
+ position = insert(position, x);
+ }
+ }
+
+ template<class T, class Allocator> template <class InputIterator>
+ void deque<T, Allocator>::insert (iterator position, InputIterator first, InputIterator last)
+ {
+ while (first != last){
+ position = insert(position, *first);
+ ++first;
+ }
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::pop_front()
+ {
+ if (elements == 0)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range("deque pop_front");
+#else
+ std::terminate();
+#endif
+ }
+ a.destroy(data + first_element);
+ first_element = array_element(1);
+ --elements;
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::pop_back()
+ {
+ last_element = array_element(elements - 1);
+ a.destroy(data + last_element);
+ --elements;
+ }
+
+ template<class T, class Allocator> typename
+ deque<T, Allocator>::iterator deque<T, Allocator>::erase(typename deque<T, Allocator>::iterator position)
+ {
+ if (position.element > (elements /2))
+ {
+ for (size_type i = position.element; i < elements - 1; ++i)
+ {
+ at(i) = at(i+1);
+ }
+ pop_back();
+ }
+ else
+ {
+ for (size_type i = position.element; i > 0; --i)
+ {
+ at(i) = at(i-1);
+ }
+ pop_front();
+ }
+ return deque_iter(this, position.element);
+ }
+
+ template<class T, class Allocator> typename deque<T, Allocator>::iterator
+ deque<T, Allocator>::
+ erase(typename deque<T, Allocator>::iterator first, typename deque<T, Allocator>::iterator last)
+ {
+ //Shift backwards
+ size_type num_move = last.element - first.element;
+ if (first.element > (elements - last.element))
+ {
+ for (size_type i = last.element; i < elements ; ++i)
+ {
+ at(i-num_move) = at(i);
+ }
+
+ for (size_type i = 0; i < num_move ; ++i)
+ {
+ pop_back();
+ }
+ }
+ else
+ {
+ for (size_type i = 0; i < first.element ; ++i)
+ {
+ at(last.element - i - 1) = at(first.element - i - 1);
+ }
+
+ for (size_type i = 0; i < num_move ; ++i)
+ {
+ pop_front();
+ }
+ }
+ return deque_iter(this, first.element);
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::swap(deque<T,Allocator>& x)
+ {
+ T * temp_data;
+ typename deque<T,Allocator>::size_type temp_size;
+
+ //Swap data pointers
+
+ temp_data = x.data;
+ x.data = data;
+ data = temp_data;
+
+ //Swap array sizes
+
+ temp_size = x.data_size;
+ x.data_size = data_size;
+ data_size = temp_size;
+
+ //Swap num array elements
+
+ temp_size = x.elements;
+ x.elements = elements;
+ elements = temp_size;
+
+ //Swap first_pointer
+
+ temp_size = x.first_element;
+ x.first_element = first_element;
+ first_element = temp_size;
+
+ //Swap last_pointer
+
+ temp_size = x.last_element;
+ x.last_element = last_element;
+ last_element = temp_size;
+ }
+
+ template<class T, class Allocator> void deque<T, Allocator>::clear()
+ {
+ while (elements > 0)
+ {
+ pop_back();
+ }
+ }
+
+
+ template<class T, class Allocator> void deque<T, Allocator>::reserve(typename deque<T, Allocator>::size_type n)
+ {
+ if (data_size >= n)
+ {
+ return;
+ }
+
+ size_type size_temp;
+ size_type first_temp;
+ T * data_temp;
+ size_temp = n + __UCLIBCXX_STL_BUFFER_SIZE__; //Reserve extra 'cause we can
+ data_temp = a.allocate(size_temp);
+
+ first_temp = (size_temp - elements) / 2;
+ for (size_type i = 0; i < elements; ++i)
+ {
+ a.construct(data_temp + first_temp + i, data[array_element(i)]);
+ a.destroy(data + array_element(i));
+ }
+
+ //Now shuffle pointers
+
+ a.deallocate(data, data_size);
+ data = data_temp;
+ data_size = size_temp;
+ first_element = first_temp;
+ last_element = first_element + elements;
+ }
+
+ template <class T, class Allocator> _UCXXEXPORT
+ bool
+ operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y)
+ {
+ if (x.elements != y.elements){
+ return false;
+ }
+ for (typename deque<T,Allocator>::size_type i = 0; i < x.elements; ++i){
+ if (x[i] < y[i] || y[i] < x[i]){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ template <class T, class Allocator> bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> _UCXXEXPORT
+ bool
+ operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y)
+ {
+ if (x == y){
+ return false;
+ }
+ return true;
+ }
+
+ template <class T, class Allocator> bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
+ template <class T, class Allocator> _UCXXEXPORT void swap(deque<T,Allocator>& x, deque<T,Allocator>& y){
+ x.swap(y);
+ }
+} // namespace
#pragma GCC visibility pop
diff --git a/misc/uClibc++/include/uClibc++/string b/misc/uClibc++/include/uClibc++/string
index d04579414..f128e7e5a 100644
--- a/misc/uClibc++/include/uClibc++/string
+++ b/misc/uClibc++/include/uClibc++/string
@@ -1,21 +1,21 @@
-/* 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
-*/
+/* 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 <cstdbool>
#include <basic_definitions>
@@ -25,7 +25,6 @@
#include <memory>
#include <vector>
-
#ifdef __UCLIBCXX_HAS_WCHAR__
#include <cwchar>
#include <cwctype>
@@ -36,979 +35,1278 @@
#pragma GCC visibility push(default)
-namespace std{
-
- //Basic basic_string
-
- template<class Ch, class Tr = char_traits<Ch>, class A = allocator<Ch> > class basic_string;
-
- typedef basic_string<char> string;
- #ifdef __UCLIBCXX_HAS_WCHAR__
- typedef basic_string<wchar_t> wstring;
- #endif
+namespace std
+{
+ // Basic basic_string
+ template<class Ch, class Tr = char_traits<Ch>, class A = allocator<Ch> > class basic_string;
+ typedef basic_string<char> string;
+ #ifdef __UCLIBCXX_HAS_WCHAR__
+ typedef basic_string<wchar_t> wstring;
+ #endif
//template<class Ch, class Tr = char_traits<Ch>, class A = allocator<Ch> > class _UCXXEXPORT basic_string
template<class Ch, class Tr, class A> class basic_string
- : public std::vector<Ch, A>
+ : public std::vector<Ch, A>
{
public:
- typedef Tr traits_type;
- typedef typename Tr::char_type value_type;
- typedef A allocator_type;
- typedef typename A::size_type size_type;
- typedef typename A::difference_type difference_type;
-
- typedef typename A::reference reference;
- typedef typename A::const_reference const_reference;
- typedef typename A::pointer pointer;
- typedef typename A::const_pointer const_pointer;
-
- typedef typename vector<Ch, A>::iterator iterator;
- typedef typename vector<Ch, A>::const_iterator const_iterator;
-
- typedef typename vector<Ch, A>::reverse_iterator reverse_iterator;
- typedef typename vector<Ch, A>::const_reverse_iterator const_reverse_iterator;
-
- static const size_type npos = (size_type)-1;
-
- explicit _UCXXEXPORT basic_string(const A& al = A()) : vector<Ch, A>(al){ return; }
-
- _UCXXEXPORT basic_string(const basic_string& str, size_type pos = 0, size_type n = npos, const A& al = A()); //Below
-
- _UCXXEXPORT basic_string(const Ch* s, size_type n, const A& al = A())
- : vector<Ch, A>(al)
- {
- if(n == npos){
- __throw_out_of_range();
- }
- if(s > 0){
- resize(n);
- Tr::copy(vector<Ch, A>::data, s, vector<Ch, A>::elements);
- }
- }
-
- _UCXXEXPORT basic_string(const Ch* s, const A& al = A()); //Below
-
- _UCXXEXPORT basic_string(size_type n, Ch c, const A& al = A())
- : vector<Ch, A>(n, c, al)
- {
- }
-
- template<class InputIterator> _UCXXEXPORT basic_string(InputIterator begin, InputIterator end, const A& a = A())
- :vector<Ch, A>(begin, end)
- {
-
- }
-
- _UCXXEXPORT ~basic_string() {
- return;
- }
-
- _UCXXEXPORT basic_string& operator=(const basic_string& str); //Below
-
- _UCXXEXPORT basic_string& operator=(const Ch* s){
- vector<Ch, A>::clear();
- if(s!=0){
- size_type len = Tr::length(s);
- resize(len);
- Tr::copy( vector<Ch, A>::data, s, len);
- }
- return *this;
- }
-
- _UCXXEXPORT basic_string& operator=(Ch c){
- vector<Ch, A>::clear();
- vector<Ch, A>::push_back(c);
- return *this;
- }
-
- inline _UCXXEXPORT size_type length() const { return vector<Ch, A>::size(); }
-
- void _UCXXEXPORT resize(size_type n, Ch c = Ch()){
- vector<Ch, A>::resize(n, c);
- }
-
- _UCXXEXPORT basic_string& operator+=(const basic_string& str){
- return append(str);
- }
-
- _UCXXEXPORT basic_string& operator+=(const Ch * s){
- return append(s);
- }
-
- _UCXXEXPORT basic_string& operator+=(Ch c){
- vector<Ch, A>::push_back(c);
- return *this;
- }
-
- _UCXXEXPORT basic_string& append(const basic_string& str){
- size_t temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + str.elements);
- Tr::copy( vector<Ch, A>::data + temp, str.vector<Ch, A>::data, str.elements);
-
- return *this;
- }
-
- _UCXXEXPORT basic_string& append(const basic_string& str, size_type pos, size_type n){
- if(pos > str.size()){
- __throw_out_of_range();
- }
-
- size_type rlen = str.elements - pos;
- if(rlen > n){
- rlen = n;
- }
- if(vector<Ch, A>::elements > npos - rlen){
- __throw_length_error();
- }
- size_t temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + rlen);
- Tr::copy( vector<Ch, A>::data + temp, str.vector<Ch, A>::data + pos, rlen);
- return *this;
- }
-
- _UCXXEXPORT basic_string& append(const Ch* s, size_type n){
- size_t temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + n);
- Tr::copy( vector<Ch, A>::data + temp, s, n);
- return *this;
- }
-
- _UCXXEXPORT basic_string& append(const Ch* s){
- size_type strLen = Tr::length(s);
- size_t temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + strLen);
- Tr::copy( vector<Ch, A>::data + temp, s, strLen);
- return *this;
- }
-
- _UCXXEXPORT basic_string& append(size_type n, Ch c){
- vector<Ch, A>::resize(vector<Ch, A>::elements + n, c);
- return *this;
- }
-
- _UCXXEXPORT basic_string& assign(const basic_string& str){
- operator=(str);
- return *this;
- }
-
- _UCXXEXPORT basic_string& assign(const basic_string& str, size_type pos, size_type n){
- if(pos > str.elements){
- __throw_out_of_range();
- }
- size_type r = str.elements - pos;
- if(r > n){
- r = n;
- }
- resize(r);
- Tr::copy(vector<Ch, A>::data, str.vector<Ch, A>::data + pos, r);
- return *this;
- }
-
- _UCXXEXPORT basic_string& assign(const Ch* s, size_type n){
- resize(n);
- Tr::copy(vector<Ch, A>::data, s, n);
- return *this;
- }
-
- _UCXXEXPORT basic_string& assign(const Ch* s){
- size_type len = Tr::length(s);
- return assign(s, len);
- }
-
- _UCXXEXPORT basic_string& assign(size_type n, Ch c){
- vector<Ch, A>::clear();
- vector<Ch, A>::resize(n, Ch() );
- return *this;
- }
-
- template<class InputIterator> _UCXXEXPORT basic_string& assign(InputIterator first, InputIterator last){
- vector<Ch, A>::resize(0, Ch());
- while (first != last){
- append(*first);
- ++first;
- }
- return *this;
- }
-
- _UCXXEXPORT basic_string& insert(size_type pos1, const basic_string& str, size_type pos2=0, size_type n=npos){
- if(pos1 > vector<Ch, A>::elements || pos2 > str.elements){
- __throw_out_of_range();
- }
- size_type r = str.elements - pos2;
- if( r > n){
- r = n;
- }
- if(vector<Ch, A>::elements > npos - r){
- __throw_length_error();
- }
- size_type temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + r);
- Tr::move(vector<Ch, A>::data + pos1 + r, vector<Ch, A>::data + pos1, temp - pos1);
- Tr::copy(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, r);
- return *this;
- }
-
- _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s, size_type n){
- if(pos > vector<Ch, A>::elements){
- __throw_out_of_range();
- }
- if(vector<Ch, A>::elements > npos - n){
- __throw_length_error();
- }
- size_type temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + n);
- Tr::move(vector<Ch, A>::data + pos + n, vector<Ch, A>::data + pos, temp - pos);
- Tr::copy(vector<Ch, A>::data + pos, s, n);
- return *this;
- }
-
- inline _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s){
- size_type len = Tr::length(s);
- return insert(pos, s, len);
- }
-
- _UCXXEXPORT basic_string& insert(size_type pos, size_type n, Ch c){
- if(pos > vector<Ch, A>::elements){
- __throw_out_of_range();
- }
- if(vector<Ch, A>::elements > npos - n){
- __throw_length_error();
- }
- size_type temp = vector<Ch, A>::elements;
- resize(vector<Ch, A>::elements + n);
- Tr::move(vector<Ch, A>::data + pos + n, vector<Ch, A>::data + pos, temp - pos);
- Tr::assign(vector<Ch, A>::data + pos, n, c);
- return *this;
- }
-
- using vector<Ch, A>::insert;
-// void insert(iterator p, size_type n, charT c);
-// template<class InputIterator> void insert(iterator p, InputIterator first, InputIterator last);
-
- _UCXXEXPORT basic_string& erase(size_type pos = 0, size_type n = npos){
- size_type xlen = vector<Ch, A>::elements - pos;
-
- if(xlen > n){
- xlen = n;
- }
- size_type temp = vector<Ch, A>::elements;
-
- Tr::move(vector<Ch, A>::data + pos, vector<Ch, A>::data + pos + xlen, temp - pos - xlen);
- resize(temp - xlen);
- return *this;
- }
-
- _UCXXEXPORT iterator erase(iterator position){
- if(position == vector<Ch, A>::end()){
- return position;
- }
-
- ++position;
-
- iterator temp = position;
-
- while(position != vector<Ch, A>::end()){
- *(position-1) = *position;
- ++position;
- }
- vector<Ch, A>::pop_back();
- return temp;
- }
-
- _UCXXEXPORT iterator erase(iterator first, iterator last){
- size_t count = last - first;
-
- iterator temp = last;
-
- while(last != vector<Ch, A>::end()){
- *(last - count) = *last;
- ++last;
- }
-
- resize( vector<Ch, A>::elements-count);
-
- return temp;
- }
-
- _UCXXEXPORT basic_string&
- replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2=0, size_type n2=npos)
- {
- if(pos1 > vector<Ch, A>::elements){
- __throw_out_of_range();
- }
- size_type xlen = vector<Ch, A>::elements - pos1;
- if(xlen > n1){
- xlen = n1;
- }
- size_type rlen = str.elements - pos2;
- if(rlen > n2){
- rlen = n2;
- }
- if((vector<Ch, A>::elements - xlen) >= (npos - rlen)){
- __throw_length_error();
- }
-
- size_t temp = vector<Ch, A>::elements;
-
- if(rlen > xlen){ //Only if making larger
- resize(temp - xlen + rlen);
- }
-
- //Final length = vector<Ch, A>::elements - xlen + rlen
- //Initial block is of size pos1
- //Block 2 is of size len
-
- Tr::move(vector<Ch, A>::data + pos1 + rlen, vector<Ch, A>::data + pos1 + xlen, temp - pos1 - xlen);
- Tr::copy(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, rlen);
- resize(temp - xlen + rlen);
- return *this;
- }
-
- _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s, size_type n2){
- return replace(pos,n1,basic_string<Ch,Tr,A>(s,n2));
-
- }
-
- inline _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s){
- return replace(pos,n1,basic_string<Ch,Tr,A>(s));
- }
-
- _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, size_type n2, Ch c){
- return replace(pos,n1,basic_string<Ch, Tr, A>(n2,c));
- }
-// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const basic_string& str);
-// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s, size_type n);
-// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s);
-// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, size_type n, Ch c);
-/* template<class InputIterator> _UCXXEXPORT basic_string& replace(iterator i1, iterator i2,
- InputIterator j1, InputIterator j2);*/
-
- size_type _UCXXEXPORT copy(Ch* s, size_type n, size_type pos = 0) const{
- if(pos > vector<Ch, A>::elements){
- __throw_out_of_range();
- }
- size_type r = vector<Ch, A>::elements - pos;
- if(r > n){
- r = n;
- }
- Tr::copy(s, vector<Ch, A>::data + pos, r);
- return r;
- }
-
- _UCXXEXPORT void swap(basic_string<Ch,Tr,A>& s){
- //Data pointers
-
- vector<Ch, A>::swap(s);
- }
-
- _UCXXEXPORT const Ch* c_str() const{
- const_cast<basic_string<Ch,Tr,A> *>(this)->reserve(vector<Ch, A>::elements+1);
- vector<Ch, A>::data[vector<Ch, A>::elements] = 0; //Add 0 at the end
- return vector<Ch, A>::data;
- }
-
- _UCXXEXPORT const Ch* data() const{
- return vector<Ch, A>::data;
- }
- _UCXXEXPORT allocator_type get_allocator() const{
- return vector<Ch, A>::a;
- }
-
- _UCXXEXPORT size_type find (const basic_string& str, size_type pos = 0) const; //Below
-
- _UCXXEXPORT size_type find (const Ch* s, size_type pos, size_type n) const{
- return find(basic_string<Ch, Tr, A>(s,n), pos);
- }
- _UCXXEXPORT size_type find (const Ch* s, size_type pos = 0) const{
- return find(basic_string<Ch, Tr, A>(s), pos);
- }
- _UCXXEXPORT size_type find (Ch c, size_type pos = 0) const{
- for(size_type i = pos; i < length(); ++i){
- if(this->operator[](i) == c){
- return i;
- }
- }
- return npos;
- }
- _UCXXEXPORT size_type rfind(const basic_string& str, size_type pos = npos) const{
- if(pos >= length()){
- pos = length();
- }
- for(size_type i = pos; i > 0; --i){
- if(str == substr(i-1, str.length())){
- return i-1;
- }
- }
- return npos;
- }
- _UCXXEXPORT size_type rfind(const Ch* s, size_type pos, size_type n) const{
- return rfind(basic_string<Ch, Tr, A>(s,n),pos);
- }
- _UCXXEXPORT size_type rfind(const Ch* s, size_type pos = npos) const{
- return rfind(basic_string<Ch, Tr, A>(s),pos);
- }
- _UCXXEXPORT size_type rfind(Ch c, size_type pos = npos) const{
- return rfind(basic_string<Ch, Tr, A>(1,c),pos);
- }
-
- _UCXXEXPORT size_type find_first_of(const basic_string& str, size_type pos = 0) const{
- for(size_type i = pos; i < length(); ++i){
- for(size_type j = 0; j < str.length() ; ++j){
- if( Tr::eq(str[j], this->operator[](i)) ){
- return i;
- }
- }
- }
- return npos;
- }
-
- _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos, size_type n) const{
- return find_first_of(basic_string<Ch, Tr, A>(s,n),pos);
- }
- _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos = 0) const{
- return find_first_of(basic_string<Ch, Tr, A>(s),pos);
- }
- _UCXXEXPORT size_type find_first_of(Ch c, size_type pos = 0) const{
- for(size_type i = pos; i< length(); ++i){
- if( Tr::eq(this->operator[](i), c) ){
- return i;
- }
- }
- return npos;
- }
-
- _UCXXEXPORT size_type find_last_of (const basic_string& str, size_type pos = npos) const{
- if(pos > length()){
- pos = length();
- }
- for(size_type i = pos; i >0 ; --i){
- for(size_type j = 0 ; j < str.length(); ++j){
- if( Tr::eq(this->operator[](i-1), str[j]) ){
- return i-1;
- }
- }
- }
- return npos;
- }
- _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos, size_type n) const{
- return find_last_of(basic_string<Ch, Tr, A>(s,n),pos);
- }
- _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos = npos) const{
- return find_last_of(basic_string<Ch, Tr, A>(s),pos);
- }
- _UCXXEXPORT size_type find_last_of (Ch c, size_type pos = npos) const{
- if(pos > length()){
- pos = length();
- }
- for(size_type i = pos; i >0 ; --i){
- if( Tr::eq(this->operator[](i-1), c) ){
- return i-1;
- }
- }
- return npos;
- }
-
- _UCXXEXPORT size_type find_first_not_of(const basic_string& str, size_type pos = 0) const{
- bool foundCharacter;
- for(size_type i = pos; i < length(); ++i){
- foundCharacter = false;
- for(size_type j = 0; j < str.length() ; ++j){
- if( Tr::eq(str[j], this->operator[](i)) ){
- foundCharacter = true;
- }
- }
- if(foundCharacter == false){
- return i;
- }
- }
- return npos;
- }
-
- _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos, size_type n) const{
- return find_first_not_of(basic_string<Ch, Tr, A>(s,n),pos);
- }
- _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos = 0) const{
- return find_first_not_of(basic_string<Ch, Tr, A>(s),pos);
- }
- _UCXXEXPORT size_type find_first_not_of(Ch c, size_type pos = 0) const{
- for(size_type i = pos; i < length() ; ++i){
- if(this->operator[](i) != c){
- return i;
- }
- }
- return npos;
- }
- _UCXXEXPORT size_type find_last_not_of (const basic_string& str, size_type pos = npos) const{
- size_type xpos(length() - 1);
- if(xpos > pos){
- xpos = pos;
- }
-
- while(xpos != npos && npos != str.find_first_of(this->at(xpos))){
- --xpos;
- }
-
- return xpos;
- }
-
- _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos, size_type n) const{
- return find_last_not_of(basic_string<Ch, Tr, A>(s,n),pos);
- }
- _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos = npos) const{
- return find_last_not_of(basic_string<Ch, Tr, A>(s),pos);
- }
- _UCXXEXPORT size_type find_last_not_of (Ch c, size_type pos = npos) const{
- size_type xpos(length() - 1);
- if(xpos > pos){
- xpos = pos;
- }
- while(xpos != npos && Tr::eq(this->at(xpos), c)){
- --xpos;
- }
- return xpos;
-
- }
-
- _UCXXEXPORT basic_string substr(size_type pos = 0, size_type n = npos) const;
-
- _UCXXEXPORT int compare(const basic_string& str) const{
- size_type rlen = vector<Ch, A>::elements;
- if(rlen > str.elements){
- rlen = str.elements;
- }
- int retval = Tr::compare(vector<Ch, A>::data, str.vector<Ch, A>::data, rlen);
- if(retval == 0){
- if(vector<Ch, A>::elements < str.elements){
- retval = -1;
- }
- if(vector<Ch, A>::elements > str.elements){
- retval = 1;
- }
- }
- return retval;
- }
-
- _UCXXEXPORT int compare(size_type pos1, size_type n1, const basic_string& str,
- size_type pos2=0, size_type n2=npos) const{
- size_type len1 = vector<Ch, A>::elements - pos1;
- if(len1 > n1){
- len1 = n1;
- }
- size_type len2 = str.vector<Ch, A>::elements - pos2;
- if(len2 > n2){
- len2 = n2;
- }
- size_type rlen = len1;
- if(rlen > len2){
- rlen = len2;
- }
- int retval = Tr::compare(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, rlen);
- if(retval == 0){
- if(len1 < len2){
- retval = -1;
- }
- if(len1 > len2){
- retval = 1;
- }
- }
- return retval;
- }
-
- _UCXXEXPORT int compare(const Ch* s) const{
- size_type slen = Tr::length(s);
- size_type rlen = slen;
- if(rlen > vector<Ch, A>::elements){
- rlen=vector<Ch, A>::elements;
- }
- int retval = Tr::compare(vector<Ch, A>::data, s, rlen);
- if(retval==0){
- if(vector<Ch, A>::elements < slen){
- retval = -1;
- }
- if(vector<Ch, A>::elements > slen){
- retval = 1;
- }
- }
- return retval;
- }
-
- _UCXXEXPORT int compare(size_type pos1, size_type n1, const Ch* s, size_type n2 = npos) const{
- size_type len1 = vector<Ch, A>::elements - pos1;
- if(len1 > n1){
- len1 = n1;
- }
- size_type slen = Tr::length(s);
- size_type len2 = slen;
- if(len2 > n2){
- len2 = n2;
- }
- size_type rlen = len1;
- if(rlen > len2){
- rlen = len2;
- }
- int retval = Tr::compare(vector<Ch, A>::data + pos1, s, rlen);
- if(retval == 0){
- if(len1 < len2){
- retval = -1;
- }
- if(len1 > len2){
- retval = 1;
- }
- }
- return retval;
- }
-
+ typedef Tr traits_type;
+ typedef typename Tr::char_type value_type;
+ typedef A allocator_type;
+ typedef typename A::size_type size_type;
+ typedef typename A::difference_type difference_type;
+
+ typedef typename A::reference reference;
+ typedef typename A::const_reference const_reference;
+ typedef typename A::pointer pointer;
+ typedef typename A::const_pointer const_pointer;
+
+ typedef typename vector<Ch, A>::iterator iterator;
+ typedef typename vector<Ch, A>::const_iterator const_iterator;
+
+ typedef typename vector<Ch, A>::reverse_iterator reverse_iterator;
+ typedef typename vector<Ch, A>::const_reverse_iterator const_reverse_iterator;
+
+ static const size_type npos = (size_type)-1;
+
+ explicit _UCXXEXPORT basic_string(const A& al = A()) : vector<Ch, A>(al){ return; }
+
+ _UCXXEXPORT basic_string(const basic_string& str, size_type pos = 0, size_type n = npos, const A& al = A()); //Below
+
+ _UCXXEXPORT basic_string(const Ch* s, size_type n, const A& al = A())
+ : vector<Ch, A>(al)
+ {
+ if (n == npos)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ if (s > 0)
+ {
+ resize(n);
+ Tr::copy(vector<Ch, A>::data, s, vector<Ch, A>::elements);
+ }
+ }
+
+ _UCXXEXPORT basic_string(const Ch* s, const A& al = A()); //Below
+
+ _UCXXEXPORT basic_string(size_type n, Ch c, const A& al = A())
+ : vector<Ch, A>(n, c, al)
+ {
+ }
+
+ template<class InputIterator> _UCXXEXPORT basic_string(InputIterator begin, InputIterator end, const A& a = A())
+ :vector<Ch, A>(begin, end)
+ {
+
+ }
+
+ _UCXXEXPORT ~basic_string()
+ {
+ return;
+ }
+
+ _UCXXEXPORT basic_string& operator=(const basic_string& str); // Below
+
+ _UCXXEXPORT basic_string& operator=(const Ch* s)
+ {
+ vector<Ch, A>::clear();
+ if (s != 0)
+ {
+ size_type len = Tr::length(s);
+ resize(len);
+ Tr::copy(vector<Ch, A>::data, s, len);
+ }
+
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& operator=(Ch c)
+ {
+ vector<Ch, A>::clear();
+ vector<Ch, A>::push_back(c);
+ return *this;
+ }
+
+ inline _UCXXEXPORT size_type length() const { return vector<Ch, A>::size(); }
+
+ void _UCXXEXPORT resize(size_type n, Ch c = Ch())
+ {
+ vector<Ch, A>::resize(n, c);
+ }
+
+ _UCXXEXPORT basic_string& operator+=(const basic_string& str)
+ {
+ return append(str);
+ }
+
+ _UCXXEXPORT basic_string& operator+=(const Ch * s)
+ {
+ return append(s);
+ }
+
+ _UCXXEXPORT basic_string& operator+=(Ch c)
+ {
+ vector<Ch, A>::push_back(c);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& append(const basic_string& str)
+ {
+ size_t temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + str.elements);
+ Tr::copy(vector<Ch, A>::data + temp, str.vector<Ch, A>::data, str.elements);
+
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& append(const basic_string& str, size_type pos, size_type n)
+ {
+ if (pos > str.size())
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type rlen = str.elements - pos;
+ if (rlen > n)
+ {
+ rlen = n;
+ }
+
+ if (vector<Ch, A>::elements > npos - rlen)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_length_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_t temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + rlen);
+ Tr::copy(vector<Ch, A>::data + temp, str.vector<Ch, A>::data + pos, rlen);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& append(const Ch* s, size_type n)
+ {
+ size_t temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + n);
+ Tr::copy(vector<Ch, A>::data + temp, s, n);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& append(const Ch* s)
+ {
+ size_type strLen = Tr::length(s);
+ size_t temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + strLen);
+ Tr::copy(vector<Ch, A>::data + temp, s, strLen);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& append(size_type n, Ch c)
+ {
+ vector<Ch, A>::resize(vector<Ch, A>::elements + n, c);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& assign(const basic_string& str)
+ {
+ operator=(str);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& assign(const basic_string& str, size_type pos, size_type n)
+ {
+ if (pos > str.elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type r = str.elements - pos;
+ if (r > n)
+ {
+ r = n;
+ }
+
+ resize(r);
+ Tr::copy(vector<Ch, A>::data, str.vector<Ch, A>::data + pos, r);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& assign(const Ch* s, size_type n)
+ {
+ resize(n);
+ Tr::copy(vector<Ch, A>::data, s, n);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& assign(const Ch* s)
+ {
+ size_type len = Tr::length(s);
+ return assign(s, len);
+ }
+
+ _UCXXEXPORT basic_string& assign(size_type n, Ch c)
+ {
+ vector<Ch, A>::clear();
+ vector<Ch, A>::resize(n, Ch());
+ return *this;
+ }
+
+ template<class InputIterator> _UCXXEXPORT basic_string& assign(InputIterator first, InputIterator last)
+ {
+ vector<Ch, A>::resize(0, Ch());
+ while (first != last)
+ {
+ append(*first);
+ ++first;
+ }
+
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& insert(size_type pos1, const basic_string& str, size_type pos2=0, size_type n=npos)
+ {
+ if (pos1 > vector<Ch, A>::elements || pos2 > str.elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type r = str.elements - pos2;
+ if (r > n)
+ {
+ r = n;
+ }
+
+ if (vector<Ch, A>::elements > npos - r)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_length_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + r);
+ Tr::move(vector<Ch, A>::data + pos1 + r, vector<Ch, A>::data + pos1, temp - pos1);
+ Tr::copy(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, r);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s, size_type n)
+ {
+ if (pos > vector<Ch, A>::elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ if (vector<Ch, A>::elements > npos - n)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_length_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + n);
+ Tr::move(vector<Ch, A>::data + pos + n, vector<Ch, A>::data + pos, temp - pos);
+ Tr::copy(vector<Ch, A>::data + pos, s, n);
+ return *this;
+ }
+
+ inline _UCXXEXPORT basic_string& insert(size_type pos, const Ch* s)
+ {
+ size_type len = Tr::length(s);
+ return insert(pos, s, len);
+ }
+
+ _UCXXEXPORT basic_string& insert(size_type pos, size_type n, Ch c)
+ {
+ if (pos > vector<Ch, A>::elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ if (vector<Ch, A>::elements > npos - n)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_length_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type temp = vector<Ch, A>::elements;
+ resize(vector<Ch, A>::elements + n);
+ Tr::move(vector<Ch, A>::data + pos + n, vector<Ch, A>::data + pos, temp - pos);
+ Tr::assign(vector<Ch, A>::data + pos, n, c);
+ return *this;
+ }
+
+ using vector<Ch, A>::insert;
+// void insert(iterator p, size_type n, charT c);
+// template<class InputIterator> void insert(iterator p, InputIterator first, InputIterator last);
+
+ _UCXXEXPORT basic_string& erase(size_type pos = 0, size_type n = npos)
+ {
+ size_type xlen = vector<Ch, A>::elements - pos;
+
+ if (xlen > n)
+ {
+ xlen = n;
+ }
+
+ size_type temp = vector<Ch, A>::elements;
+
+ Tr::move(vector<Ch, A>::data + pos, vector<Ch, A>::data + pos + xlen, temp - pos - xlen);
+ resize(temp - xlen);
+ return *this;
+ }
+
+ _UCXXEXPORT iterator erase(iterator position)
+ {
+ if (position == vector<Ch, A>::end())
+ {
+ return position;
+ }
+
+ ++position;
+
+ iterator temp = position;
+
+ while (position != vector<Ch, A>::end())
+ {
+ *(position-1) = *position;
+ ++position;
+ }
+
+ vector<Ch, A>::pop_back();
+ return temp;
+ }
+
+ _UCXXEXPORT iterator erase(iterator first, iterator last)
+ {
+ size_t count = last - first;
+
+ iterator temp = last;
+
+ while (last != vector<Ch, A>::end())
+ {
+ *(last - count) = *last;
+ ++last;
+ }
+
+ resize(vector<Ch, A>::elements-count);
+
+ return temp;
+ }
+
+ _UCXXEXPORT basic_string&
+ replace(size_type pos1, size_type n1, const basic_string& str, size_type pos2=0, size_type n2=npos)
+ {
+ if (pos1 > vector<Ch, A>::elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type xlen = vector<Ch, A>::elements - pos1;
+ if (xlen > n1)
+ {
+ xlen = n1;
+ }
+
+ size_type rlen = str.elements - pos2;
+ if (rlen > n2)
+ {
+ rlen = n2;
+ }
+
+ if ((vector<Ch, A>::elements - xlen) >= (npos - rlen))
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_length_error();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_t temp = vector<Ch, A>::elements;
+
+ if (rlen > xlen)
+ {
+ //Only if making larger
+
+ resize(temp - xlen + rlen);
+ }
+
+ //Final length = vector<Ch, A>::elements - xlen + rlen
+ //Initial block is of size pos1
+ //Block 2 is of size len
+
+ Tr::move(vector<Ch, A>::data + pos1 + rlen, vector<Ch, A>::data + pos1 + xlen, temp - pos1 - xlen);
+ Tr::copy(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, rlen);
+ resize(temp - xlen + rlen);
+ return *this;
+ }
+
+ _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s, size_type n2)
+ {
+ return replace(pos,n1,basic_string<Ch,Tr,A>(s,n2));
+ }
+
+ inline _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s)
+ {
+ return replace(pos,n1,basic_string<Ch,Tr,A>(s));
+ }
+
+ _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, size_type n2, Ch c)
+ {
+ return replace(pos,n1,basic_string<Ch, Tr, A>(n2,c));
+ }
+
+// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const basic_string& str);
+// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s, size_type n);
+// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, const Ch* s);
+// _UCXXEXPORT basic_string& replace(iterator i1, iterator i2, size_type n, Ch c);
+/* template<class InputIterator> _UCXXEXPORT basic_string& replace(iterator i1, iterator i2,
+ InputIterator j1, InputIterator j2);*/
+
+ size_type _UCXXEXPORT copy(Ch* s, size_type n, size_type pos = 0) const
+ {
+ if (pos > vector<Ch, A>::elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type r = vector<Ch, A>::elements - pos;
+ if (r > n)
+ {
+ r = n;
+ }
+
+ Tr::copy(s, vector<Ch, A>::data + pos, r);
+ return r;
+ }
+
+ _UCXXEXPORT void swap(basic_string<Ch,Tr,A>& s)
+ {
+ //Data pointers
+
+ vector<Ch, A>::swap(s);
+ }
+
+ _UCXXEXPORT const Ch* c_str() const
+ {
+ const_cast<basic_string<Ch,Tr,A> *>(this)->reserve(vector<Ch, A>::elements+1);
+ vector<Ch, A>::data[vector<Ch, A>::elements] = 0; //Add 0 at the end
+ return vector<Ch, A>::data;
+ }
+
+ _UCXXEXPORT const Ch* data() const
+ {
+ return vector<Ch, A>::data;
+ }
+
+ _UCXXEXPORT allocator_type get_allocator() const
+ {
+ return vector<Ch, A>::a;
+ }
+
+ _UCXXEXPORT size_type find (const basic_string& str, size_type pos = 0) const; //Below
+
+ _UCXXEXPORT size_type find (const Ch* s, size_type pos, size_type n) const
+ {
+ return find(basic_string<Ch, Tr, A>(s,n), pos);
+ }
+
+ _UCXXEXPORT size_type find (const Ch* s, size_type pos = 0) const
+ {
+ return find(basic_string<Ch, Tr, A>(s), pos);
+ }
+
+ _UCXXEXPORT size_type find (Ch c, size_type pos = 0) const
+ {
+ for (size_type i = pos; i < length(); ++i)
+ {
+ if (this->operator[](i) == c)
+ {
+ return i;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type rfind(const basic_string& str, size_type pos = npos) const
+ {
+ if (pos >= length())
+ {
+ pos = length();
+ }
+
+ for (size_type i = pos; i > 0; --i)
+ {
+ if (str == substr(i-1, str.length()))
+ {
+ return i-1;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type rfind(const Ch* s, size_type pos, size_type n) const
+ {
+ return rfind(basic_string<Ch, Tr, A>(s,n),pos);
+ }
+
+ _UCXXEXPORT size_type rfind(const Ch* s, size_type pos = npos) const
+ {
+ return rfind(basic_string<Ch, Tr, A>(s),pos);
+ }
+
+ _UCXXEXPORT size_type rfind(Ch c, size_type pos = npos) const
+ {
+ return rfind(basic_string<Ch, Tr, A>(1,c),pos);
+ }
+
+ _UCXXEXPORT size_type find_first_of(const basic_string& str, size_type pos = 0) const
+ {
+ for (size_type i = pos; i < length(); ++i)
+ {
+ for (size_type j = 0; j < str.length() ; ++j)
+ {
+ if (Tr::eq(str[j], this->operator[](i)))
+ {
+ return i;
+ }
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos, size_type n) const
+ {
+ return find_first_of(basic_string<Ch, Tr, A>(s,n),pos);
+ }
+
+ _UCXXEXPORT size_type find_first_of(const Ch* s, size_type pos = 0) const
+ {
+ return find_first_of(basic_string<Ch, Tr, A>(s),pos);
+ }
+
+ _UCXXEXPORT size_type find_first_of(Ch c, size_type pos = 0) const
+ {
+ for (size_type i = pos; i< length(); ++i)
+ {
+ if (Tr::eq(this->operator[](i), c))
+ {
+ return i;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_last_of (const basic_string& str, size_type pos = npos) const
+ {
+ if (pos > length())
+ {
+ pos = length();
+ }
+
+ for (size_type i = pos; i >0 ; --i)
+ {
+ for (size_type j = 0 ; j < str.length(); ++j)
+ {
+ if (Tr::eq(this->operator[](i-1), str[j]))
+ {
+ return i-1;
+ }
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos, size_type n) const
+ {
+ return find_last_of(basic_string<Ch, Tr, A>(s,n),pos);
+ }
+
+ _UCXXEXPORT size_type find_last_of (const Ch* s, size_type pos = npos) const
+ {
+ return find_last_of(basic_string<Ch, Tr, A>(s),pos);
+ }
+
+ _UCXXEXPORT size_type find_last_of (Ch c, size_type pos = npos) const
+ {
+ if (pos > length())
+ {
+ pos = length();
+ }
+
+ for (size_type i = pos; i >0 ; --i)
+ {
+ if (Tr::eq(this->operator[](i-1), c))
+ {
+ return i-1;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_first_not_of(const basic_string& str, size_type pos = 0) const
+ {
+ bool foundCharacter;
+ for (size_type i = pos; i < length(); ++i)
+ {
+ foundCharacter = false;
+ for (size_type j = 0; j < str.length() ; ++j)
+ {
+ if (Tr::eq(str[j], this->operator[](i)))
+ {
+ foundCharacter = true;
+ }
+ }
+
+ if (foundCharacter == false)
+ {
+ return i;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos, size_type n) const
+ {
+ return find_first_not_of(basic_string<Ch, Tr, A>(s,n),pos);
+ }
+
+ _UCXXEXPORT size_type find_first_not_of(const Ch* s, size_type pos = 0) const
+ {
+ return find_first_not_of(basic_string<Ch, Tr, A>(s),pos);
+ }
+
+ _UCXXEXPORT size_type find_first_not_of(Ch c, size_type pos = 0) const
+ {
+ for (size_type i = pos; i < length() ; ++i)
+ {
+ if (this->operator[](i) != c)
+ {
+ return i;
+ }
+ }
+
+ return npos;
+ }
+
+ _UCXXEXPORT size_type find_last_not_of (const basic_string& str, size_type pos = npos) const
+ {
+ size_type xpos(length() - 1);
+ if (xpos > pos)
+ {
+ xpos = pos;
+ }
+
+ while (xpos != npos && npos != str.find_first_of(this->at(xpos)))
+ {
+ --xpos;
+ }
+
+ return xpos;
+ }
+
+ _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos, size_type n) const
+ {
+ return find_last_not_of(basic_string<Ch, Tr, A>(s,n),pos);
+ }
+
+ _UCXXEXPORT size_type find_last_not_of (const Ch* s, size_type pos = npos) const
+ {
+ return find_last_not_of(basic_string<Ch, Tr, A>(s),pos);
+ }
+
+ _UCXXEXPORT size_type find_last_not_of (Ch c, size_type pos = npos) const
+ {
+ size_type xpos(length() - 1);
+ if (xpos > pos)
+ {
+ xpos = pos;
+ }
+
+ while (xpos != npos && Tr::eq(this->at(xpos), c))
+ {
+ --xpos;
+ }
+
+ return xpos;
+ }
+
+ _UCXXEXPORT basic_string substr(size_type pos = 0, size_type n = npos) const;
+
+ _UCXXEXPORT int compare(const basic_string& str) const
+ {
+ size_type rlen = vector<Ch, A>::elements;
+ if (rlen > str.elements)
+ {
+ rlen = str.elements;
+ }
+
+ int retval = Tr::compare(vector<Ch, A>::data, str.vector<Ch, A>::data, rlen);
+ if (retval == 0)
+ {
+ if (vector<Ch, A>::elements < str.elements)
+ {
+ retval = -1;
+ }
+
+ if (vector<Ch, A>::elements > str.elements)
+ {
+ retval = 1;
+ }
+ }
+
+ return retval;
+ }
+
+ _UCXXEXPORT int compare(size_type pos1, size_type n1, const basic_string& str,
+ size_type pos2=0, size_type n2=npos) const
+ {
+ size_type len1 = vector<Ch, A>::elements - pos1;
+ if (len1 > n1)
+ {
+ len1 = n1;
+ }
+
+ size_type len2 = str.vector<Ch, A>::elements - pos2;
+ if (len2 > n2)
+ {
+ len2 = n2;
+ }
+
+ size_type rlen = len1;
+ if (rlen > len2)
+ {
+ rlen = len2;
+ }
+
+ int retval = Tr::compare(vector<Ch, A>::data + pos1, str.vector<Ch, A>::data + pos2, rlen);
+ if (retval == 0)
+ {
+ if (len1 < len2)
+ {
+ retval = -1;
+ }
+
+ if (len1 > len2)
+ {
+ retval = 1;
+ }
+ }
+
+ return retval;
+ }
+
+ _UCXXEXPORT int compare(const Ch* s) const
+ {
+ size_type slen = Tr::length(s);
+ size_type rlen = slen;
+ if (rlen > vector<Ch, A>::elements)
+ {
+ rlen=vector<Ch, A>::elements;
+ }
+
+ int retval = Tr::compare(vector<Ch, A>::data, s, rlen);
+ if (retval==0)
+ {
+ if (vector<Ch, A>::elements < slen)
+ {
+ retval = -1;
+ }
+
+ if (vector<Ch, A>::elements > slen)
+ {
+ retval = 1;
+ }
+ }
+
+ return retval;
+ }
+
+ _UCXXEXPORT int compare(size_type pos1, size_type n1, const Ch* s, size_type n2 = npos) const
+ {
+ size_type len1 = vector<Ch, A>::elements - pos1;
+ if (len1 > n1)
+ {
+ len1 = n1;
+ }
+
+ size_type slen = Tr::length(s);
+ size_type len2 = slen;
+ if (len2 > n2)
+ {
+ len2 = n2;
+ }
+
+ size_type rlen = len1;
+ if (rlen > len2)
+ {
+ rlen = len2;
+ }
+
+ int retval = Tr::compare(vector<Ch, A>::data + pos1, s, rlen);
+ if (retval == 0)
+ {
+ if (len1 < len2)
+ {
+ retval = -1;
+ }
+
+ if (len1 > len2)
+ {
+ retval = 1;
+ }
+ }
+
+ return retval;
+ }
};
//Functions
template<class Ch,class Tr,class A> _UCXXEXPORT basic_string<Ch,Tr,A>::basic_string(const Ch* s, const A& al)
- : vector<Ch, A>(al)
+ : vector<Ch, A>(al)
{
- if(s!=0){
- size_type temp = Tr::length(s);
- append(s, temp);
- }
+ if (s!=0)
+ {
+ size_type temp = Tr::length(s);
+ append(s, temp);
+ }
}
template<class Ch,class Tr,class A> _UCXXEXPORT basic_string<Ch,Tr,A>::
- basic_string(const basic_string& str, size_type pos, size_type n, const A& al)
- : vector<Ch, A>(al)
+ basic_string(const basic_string& str, size_type pos, size_type n, const A& al)
+ : vector<Ch, A>(al)
{
- if(pos>str.size()){
- __throw_out_of_range();
- }
- size_type rlen = str.size() - pos;
- if( rlen > n){
- rlen = n;
- }
- resize(rlen);
- Tr::copy(vector<Ch, A>::data, str.vector<Ch, A>::data + pos, vector<Ch, A>::elements);
+ if (pos>str.size())
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+
+ size_type rlen = str.size() - pos;
+ if (rlen > n)
+ {
+ rlen = n;
+ }
+
+ resize(rlen);
+ Tr::copy(vector<Ch, A>::data, str.vector<Ch, A>::data + pos, vector<Ch, A>::elements);
}
template<class Ch,class Tr,class A> _UCXXEXPORT basic_string<Ch,Tr,A>&
- basic_string<Ch,Tr,A>::operator=(const basic_string<Ch,Tr,A> & str)
+ basic_string<Ch,Tr,A>::operator=(const basic_string<Ch,Tr,A> & str)
{
- if(&str == this){ //Check if we are doing a=a
- return *this;
- }
- vector<Ch, A>::clear();
- resize(str.elements);
- Tr::copy( vector<Ch, A>::data, str.vector<Ch, A>::data, str.elements);
- return *this;
-}
+ if (&str == this)
+ {
+ //Check if we are doing a=a
+ return *this;
+ }
+
+ vector<Ch, A>::clear();
+ resize(str.elements);
+ Tr::copy(vector<Ch, A>::data, str.vector<Ch, A>::data, str.elements);
+ return *this;
+}
template<class Ch,class Tr,class A> _UCXXEXPORT typename basic_string<Ch,Tr,A>::size_type
- basic_string<Ch,Tr,A>::find (const basic_string<Ch,Tr,A>& str, size_type pos) const
+ basic_string<Ch,Tr,A>::find (const basic_string<Ch,Tr,A>& str, size_type pos) const
{
- if(str.length() > length()){
- return npos;
- }
- size_type max_string_start = 1 + length() - str.length();
- for(size_type i = pos; i < max_string_start; ++i){
- if(str == substr(i, str.length())){
- return i;
- }
- }
- return npos;
+ if (str.length() > length())
+ {
+ return npos;
+ }
+
+ size_type max_string_start = 1 + length() - str.length();
+ for (size_type i = pos; i < max_string_start; ++i)
+ {
+ if (str == substr(i, str.length()))
+ {
+ return i;
+ }
+ }
+
+ return npos;
}
-
template<class Ch,class Tr,class A>
- _UCXXEXPORT basic_string<Ch, Tr, A> basic_string<Ch,Tr,A>::substr(size_type pos, size_type n) const
+ _UCXXEXPORT basic_string<Ch, Tr, A> basic_string<Ch,Tr,A>::substr(size_type pos, size_type n) const
{
- if(pos > vector<Ch, A>::elements){
- __throw_out_of_range();
- }
- size_type rlen = vector<Ch, A>::elements - pos;
- if(rlen > n){
- rlen = n;
- }
- return basic_string<Ch,Tr,A>(vector<Ch, A>::data + pos,rlen);
-}
-
+ if (pos > vector<Ch, A>::elements)
+ {
+#ifdef CONFIG_UCLIBCXX_EXCEPTION
+ __throw_out_of_range();
+#else
+ std::terminate();
+#endif
+ }
+ size_type rlen = vector<Ch, A>::elements - pos;
+ if (rlen > n)
+ {
+ rlen = n;
+ }
+ return basic_string<Ch,Tr,A>(vector<Ch, A>::data + pos,rlen);
+}
#ifdef __UCLIBCXX_EXPAND_STRING_CHAR__
#ifndef __UCLIBCXX_COMPILE_STRING__
-
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
- template <> _UCXXEXPORT string::basic_string(const allocator<char> &);
- template <> _UCXXEXPORT string::basic_string(size_type n, char c, const allocator<char> & );
- template <> _UCXXEXPORT string::basic_string(const char* s, const allocator<char>& al);
- template <> _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator<char>& al);
- template <> _UCXXEXPORT string::~basic_string();
+ template <> _UCXXEXPORT string::basic_string(const allocator<char> &);
+ template <> _UCXXEXPORT string::basic_string(size_type n, char c, const allocator<char> &);
+ template <> _UCXXEXPORT string::basic_string(const char* s, const allocator<char>& al);
+ template <> _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator<char>& al);
+ template <> _UCXXEXPORT string::~basic_string();
#endif
- template <> _UCXXEXPORT string & string::append(const char * s, size_type n);
-
+ template <> _UCXXEXPORT string & string::append(const char * s, size_type n);
- template <> _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find (char c, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find (char c, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const;
- template <> _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const;
- template <> _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const;
- template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const;
+ template <> _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const;
+ template <> _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const;
- template <> _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const;
- template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const;
- template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const;
- template <> _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const;
+ template <> _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const;
- template <> _UCXXEXPORT int string::compare(const string & str) const;
- template <> _UCXXEXPORT int string::compare(
- size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const;
+ template <> _UCXXEXPORT int string::compare(const string & str) const;
+ template <> _UCXXEXPORT int string::compare(
+ size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const;
- template <> _UCXXEXPORT string string::substr(size_type pos, size_type n) const;
+ template <> _UCXXEXPORT string string::substr(size_type pos, size_type n) const;
- template <> _UCXXEXPORT string & string::operator=(const string & str);
- template <> _UCXXEXPORT string & string::operator=(const char * s);
+ template <> _UCXXEXPORT string & string::operator=(const string & str);
+ template <> _UCXXEXPORT string & string::operator=(const char * s);
#endif
#endif
-
-
-
//typedef basic_string<char> string;
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_string<charT,traits,Allocator>
- operator+(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator+(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- temp.append(rhs);
- return temp;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ temp.append(rhs);
+ return temp;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_string<charT,traits,Allocator>
- operator+(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator+(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- temp.append(rhs);
- return temp;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ temp.append(rhs);
+ return temp;
}
-
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_string<charT,traits,Allocator>
- operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(1, lhs);
- temp.append(rhs);
- return temp;
+ basic_string<charT,traits,Allocator> temp(1, lhs);
+ temp.append(rhs);
+ return temp;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_string<charT,traits,Allocator>
- operator+(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator+(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- temp.append(rhs);
- return temp;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ temp.append(rhs);
+ return temp;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT basic_string<charT,traits,Allocator>
- operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs)
+ operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- temp+=rhs;
- return temp;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ temp+=rhs;
+ return temp;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator==(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator==(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) == 0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) == 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator==(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator==(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(rhs.compare(lhs) == 0){
- return true;
- }
- return false;
+ if (rhs.compare(lhs) == 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- if(lhs.compare(rhs)==0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs)==0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator!=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator!=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) !=0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) !=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator!=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator!=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- return (temp != rhs);
+ basic_string<charT,traits,Allocator> temp(lhs);
+ return (temp != rhs);
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator!=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator!=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(rhs);
- return (lhs != temp);
+ basic_string<charT,traits,Allocator> temp(rhs);
+ return (lhs != temp);
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator< (const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator< (const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) < 0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) < 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator< (const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator< (const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(rhs);
- if(lhs.compare(rhs) < 0){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(rhs);
+ if (lhs.compare(rhs) < 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator< (const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator< (const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- if(temp.compare(rhs) < 0){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ if (temp.compare(rhs) < 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator> (const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator> (const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) > 0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) > 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator> (const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator> (const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(rhs);
- if(lhs.compare(rhs) > 0){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(rhs);
+ if (lhs.compare(rhs) > 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator> (const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator> (const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- if(temp.compare(rhs) > 0){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ if (temp.compare(rhs) > 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator<=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator<=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) <=0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) <=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator<=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator<=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(rhs);
- if(lhs.compare(temp) <=0 ){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(rhs);
+ if (lhs.compare(temp) <=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator<=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator<=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- if(temp.compare(rhs) <= 0){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ if (temp.compare(rhs) <= 0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator>=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator>=(const basic_string<charT,traits,Allocator>& lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- if(lhs.compare(rhs) >=0){
- return true;
- }
- return false;
+ if (lhs.compare(rhs) >=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator>=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
+ operator>=(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs)
{
- basic_string<charT,traits,Allocator> temp(rhs);
- if(lhs.compare(temp) >=0 ){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(rhs);
+ if (lhs.compare(temp) >=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT bool
- operator>=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
+ operator>=(const charT* lhs, const basic_string<charT,traits,Allocator>& rhs)
{
- basic_string<charT,traits,Allocator> temp(lhs);
- if(temp.compare(rhs) >=0 ){
- return true;
- }
- return false;
+ basic_string<charT,traits,Allocator> temp(lhs);
+ if (temp.compare(rhs) >=0)
+ {
+ return true;
+ }
+
+ return false;
}
template<class charT, class traits, class Allocator> _UCXXEXPORT void
- swap(basic_string<charT,traits,Allocator>& lhs, basic_string<charT,traits,Allocator>& rhs)
+ swap(basic_string<charT,traits,Allocator>& lhs, basic_string<charT,traits,Allocator>& rhs)
{
- lhs.swap(rhs);
+ lhs.swap(rhs);
}
/*template<class charT, class traits, class Allocator> _UCXXEXPORT basic_ostream<charT, traits>&
- operator<<(basic_ostream<charT, traits>& os, const basic_string<charT,traits,Allocator>& str)
+ operator<<(basic_ostream<charT, traits>& os, const basic_string<charT,traits,Allocator>& str)
{
- return os.write(str.data(), str.length());
+ return os.write(str.data(), str.length());
}*/
#ifdef __UCLIBCXX_EXPAND_STRING_CHAR__
@@ -1031,12 +1329,9 @@ template <> _UCXXEXPORT string operator+(const string & lhs, const string & rhs)
template <> _UCXXEXPORT bool operator> (const string & lhs, const string & rhs);
template <> _UCXXEXPORT bool operator< (const string & lhs, const string & rhs);
-
#endif
#endif
-
-
-}
+} // namespace
#pragma GCC visibility pop
diff --git a/misc/uClibc++/libxx/uClibc++/Make.defs b/misc/uClibc++/libxx/uClibc++/Make.defs
index 2a877ee3e..b8f7a7092 100644
--- a/misc/uClibc++/libxx/uClibc++/Make.defs
+++ b/misc/uClibc++/libxx/uClibc++/Make.defs
@@ -37,13 +37,16 @@
CXXSRCS += algorithm.cxx associative_base.cxx bitset.cxx char_traits.cxx
CXXSRCS += complex.cxx del_op.cxx del_opnt.cxx del_opv.cxx del_opvnt.cxx
-CXXSRCS += deque.cxx exception.cxx fstream.cxx func_exception.cxx
-CXXSRCS += iomanip.cxx ios.cxx iostream.cxx istream.cxx iterator.cxx
-CXXSRCS += limits.cxx list.cxx locale.cxx map.cxx new_handler.cxx
-CXXSRCS += new_op.cxx new_opnt.cxx new_opv.cxx new_opvnt.cxx numeric.cxx
-CXXSRCS += ostream.cxx queue.cxx set.cxx sstream.cxx stack.cxx
-CXXSRCS += stdexcept.cxx streambuf.cxx string.cxx typeinfo.cxx utility.cxx
-CXXSRCS += valarray.cxx vector.cxx
+CXXSRCS += deque.cxx fstream.cxx iomanip.cxx ios.cxx iostream.cxx
+CXXSRCS += istream.cxx iterator.cxx limits.cxx list.cxx locale.cxx
+CXXSRCS += map.cxx new_handler.cxx new_op.cxx new_opnt.cxx new_opv.cxx
+CXXSRCS += new_opvnt.cxx numeric.cxx ostream.cxx queue.cxx set.cxx
+CXXSRCS += sstream.cxx stack.cxx streambuf.cxx string.cxx typeinfo.cxx
+CXXSRCS += utility.cxx valarray.cxx vector.cxx
+
+ifeq ($(CONFIG_UCLIBCXX_EXCEPTION),y)
+CXXSRCS += exception.cxx func_exception.cxx stdexcept.cxx
+endif
ifneq ($(CONFIG_UCLIBCXX_HAVE_LIBSUPCXX),y)
CXXSRCS += eh_alloc.cxx eh_globals.cxx eh_terminate.cxx
diff --git a/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx b/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx
index f64be60d9..1d1aa9eb7 100644
--- a/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx
+++ b/misc/uClibc++/libxx/uClibc++/eh_terminate.cxx
@@ -20,8 +20,6 @@
#include <cstdlib>
#include <exception>
-#ifdef CONFIG_UCLIBCXX_EXCEPTION
-
namespace std
{
_UCXXEXPORT static terminate_handler __terminate_handler = abort;
@@ -71,5 +69,3 @@ namespace std
terminate();
}
}
-
-#endif
diff --git a/misc/uClibc++/libxx/uClibc++/func_exception.cxx b/misc/uClibc++/libxx/uClibc++/func_exception.cxx
index 9971871ef..d5bbe001f 100644
--- a/misc/uClibc++/libxx/uClibc++/func_exception.cxx
+++ b/misc/uClibc++/libxx/uClibc++/func_exception.cxx
@@ -22,8 +22,8 @@
#include <stdexcept>
#include <cstdlib>
-namespace std{
-
+namespace std
+{
#ifdef CONFIG_UCLIBCXX_EXCEPTION
_UCXXEXPORT void __throw_bad_alloc()
@@ -33,7 +33,7 @@ _UCXXEXPORT void __throw_bad_alloc()
_UCXXEXPORT void __throw_out_of_range(const char * message)
{
- if(message == 0)
+ if (message == 0)
{
throw out_of_range();
}
@@ -43,7 +43,7 @@ _UCXXEXPORT void __throw_out_of_range(const char * message)
_UCXXEXPORT void __throw_overflow_error(const char * message)
{
- if(message == 0)
+ if (message == 0)
{
throw overflow_error();
}
@@ -53,7 +53,7 @@ _UCXXEXPORT void __throw_overflow_error(const char * message)
_UCXXEXPORT void __throw_length_error(const char * message)
{
- if(message == 0)
+ if (message == 0)
{
throw length_error();
}
@@ -63,7 +63,7 @@ _UCXXEXPORT void __throw_length_error(const char * message)
_UCXXEXPORT void __throw_invalid_argument(const char * message)
{
- if(message == 0)
+ if (message == 0)
{
throw invalid_argument();
}
@@ -100,6 +100,4 @@ _UCXXEXPORT void __throw_invalid_argument(const char *)
#endif
-
-
-}
+} // namespace
diff --git a/misc/uClibc++/libxx/uClibc++/stdexcept.cxx b/misc/uClibc++/libxx/uClibc++/stdexcept.cxx
index d372c0b77..73238526f 100644
--- a/misc/uClibc++/libxx/uClibc++/stdexcept.cxx
+++ b/misc/uClibc++/libxx/uClibc++/stdexcept.cxx
@@ -1,63 +1,64 @@
-/* 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
-*/
+/* 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 <exception>
#include <stdexcept>
#ifdef CONFIG_UCLIBCXX_EXCEPTION
-namespace std{
-
- _UCXXEXPORT logic_error::logic_error() throw() : mstring(){
-
- }
-
- _UCXXEXPORT logic_error::logic_error(const string& what_arg) : mstring(what_arg){
-
- }
-
- _UCXXEXPORT const char * logic_error::what() const throw(){
- return mstring.c_str();
- }
-
-
- _UCXXEXPORT out_of_range::out_of_range() : logic_error(){
+namespace std
+{
+ _UCXXEXPORT logic_error::logic_error() throw() : mstring()
+ {
+ }
- }
+ _UCXXEXPORT logic_error::logic_error(const string& what_arg) : mstring(what_arg)
+ {
+ }
- _UCXXEXPORT out_of_range::out_of_range(const string & what_arg) : logic_error(what_arg) {
-
- }
+ _UCXXEXPORT const char * logic_error::what() const throw()
+ {
+ return mstring.c_str();
+ }
- _UCXXEXPORT runtime_error::runtime_error() : mstring(){
+ _UCXXEXPORT out_of_range::out_of_range() : logic_error()
+ {
+ }
- }
+ _UCXXEXPORT out_of_range::out_of_range(const string & what_arg) : logic_error(what_arg)
+ {
+ }
- _UCXXEXPORT runtime_error::runtime_error(const string& what_arg) : mstring(what_arg){
+ _UCXXEXPORT runtime_error::runtime_error() : mstring()
+ {
+ }
- }
+ _UCXXEXPORT runtime_error::runtime_error(const string& what_arg) : mstring(what_arg)
+ {
+ }
- _UCXXEXPORT const char * runtime_error::what() const throw(){
- return mstring.c_str();
- }
+ _UCXXEXPORT const char * runtime_error::what() const throw()
+ {
+ return mstring.c_str();
+ }
-}
+} // namespace
#endif
diff --git a/misc/uClibc++/libxx/uClibc++/string.cxx b/misc/uClibc++/libxx/uClibc++/string.cxx
index 1edf69b5d..dc99fe29e 100644
--- a/misc/uClibc++/libxx/uClibc++/string.cxx
+++ b/misc/uClibc++/libxx/uClibc++/string.cxx
@@ -1,20 +1,20 @@
-/* Copyright (C) 2004 Garrett A. Kajmowicz
+/* Copyright (C) 2004 Garrett A. Kajmowicz
- This file is part of the uClibc++ Library.
+ 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 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.
+ 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
+ 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
*/
#define __UCLIBCXX_COMPILE_STRING__ 1
@@ -26,87 +26,81 @@
#include <string.h>
#include <ostream>
-namespace std{
-
+namespace std
+{
#ifdef __UCLIBCXX_EXPAND_STRING_CHAR__
-
#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
- template _UCXXEXPORT string::basic_string(const allocator<char> &);
- template _UCXXEXPORT string::basic_string(size_type n, char c, const allocator<char> & );
- template _UCXXEXPORT string::basic_string(const char* s, const allocator<char>& al);
- template _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator<char>& al);
- template _UCXXEXPORT string::~basic_string();
+ template _UCXXEXPORT string::basic_string(const allocator<char> &);
+ template _UCXXEXPORT string::basic_string(size_type n, char c, const allocator<char> & );
+ template _UCXXEXPORT string::basic_string(const char* s, const allocator<char>& al);
+ template _UCXXEXPORT string::basic_string(const basic_string& str, size_type pos, size_type n, const allocator<char>& al);
+ template _UCXXEXPORT string::~basic_string();
#endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__
- template _UCXXEXPORT string & string::append(const char * s, size_type n);
+ template _UCXXEXPORT string & string::append(const char * s, size_type n);
- template _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find (char c, size_type pos) const;
- template _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const;
- template _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const;
- template _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find(const string & str, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find(const char* s, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find (char c, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::rfind(const string & str, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::rfind(char c, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::rfind(const char* s, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const;
- template _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const;
- template _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find_first_of(const string &, size_type) const;
+ template _UCXXEXPORT string::size_type string::find_first_of(const char *, size_type pos, size_type n) const;
+ template _UCXXEXPORT string::size_type string::find_first_of(const char*, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find_first_of(char c, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const;
- template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find_last_of (const string & , size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos, size_type n) const;
+ template _UCXXEXPORT string::size_type string::find_last_of (const char* s, size_type pos) const;
+ template _UCXXEXPORT string::size_type string::find_last_of (char c, size_type pos) const;
- template _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const;
- template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const;
- template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const;
- template _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const;
+ template _UCXXEXPORT string::size_type string::find_first_not_of(const string &, size_type) const;
+ template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type, size_type) const;
+ template _UCXXEXPORT string::size_type string::find_first_not_of(const char*, size_type) const;
+ template _UCXXEXPORT string::size_type string::find_first_not_of(char c, size_type) const;
- template _UCXXEXPORT int string::compare(const string & str) const;
-// template _UCXXEXPORT int string::compare(size_type pos1, size_type n1, const string & str) const;
- template _UCXXEXPORT int string::compare(
- size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const;
+ template _UCXXEXPORT int string::compare(const string & str) const;
+//template _UCXXEXPORT int string::compare(size_type pos1, size_type n1, const string & str) const;
+ template _UCXXEXPORT int string::compare(
+ size_type pos1, size_type n1, const string & str, size_type pos2, size_type n2) const;
- template _UCXXEXPORT string string::substr(size_type pos, size_type n) const;
+ template _UCXXEXPORT string string::substr(size_type pos, size_type n) const;
- template _UCXXEXPORT string & string::operator=(const string & str);
- template _UCXXEXPORT string & string::operator=(const char * s);
+ template _UCXXEXPORT string & string::operator=(const string & str);
+ template _UCXXEXPORT string & string::operator=(const char * s);
- template _UCXXEXPORT bool operator==(const string & lhs, const string & rhs);
- template _UCXXEXPORT bool operator==(const char * lhs, const string & rhs);
- template _UCXXEXPORT bool operator==(const string & lhs, const char * rhs);
+ template _UCXXEXPORT bool operator==(const string & lhs, const string & rhs);
+ template _UCXXEXPORT bool operator==(const char * lhs, const string & rhs);
+ template _UCXXEXPORT bool operator==(const string & lhs, const char * rhs);
- template _UCXXEXPORT bool operator!=(const string & lhs, const string & rhs);
- template _UCXXEXPORT bool operator!=(const char * lhs, const string & rhs);
- template _UCXXEXPORT bool operator!=(const string & lhs, const char * rhs);
+ template _UCXXEXPORT bool operator!=(const string & lhs, const string & rhs);
+ template _UCXXEXPORT bool operator!=(const char * lhs, const string & rhs);
+ template _UCXXEXPORT bool operator!=(const string & lhs, const char * rhs);
- template _UCXXEXPORT string operator+(const string & lhs, const char* rhs);
- template _UCXXEXPORT string operator+(const char* lhs, const string & rhs);
- template _UCXXEXPORT string operator+(const string & lhs, const string & rhs);
+ template _UCXXEXPORT string operator+(const string & lhs, const char* rhs);
+ template _UCXXEXPORT string operator+(const char* lhs, const string & rhs);
+ template _UCXXEXPORT string operator+(const string & lhs, const string & rhs);
- template _UCXXEXPORT bool operator> (const string & lhs, const string & rhs);
- template _UCXXEXPORT bool operator< (const string & lhs, const string & rhs);
+ template _UCXXEXPORT bool operator> (const string & lhs, const string & rhs);
+ template _UCXXEXPORT bool operator< (const string & lhs, const string & rhs);
+// Functions dependent upon OSTREAM
-//Functions dependent upon OSTREAM
#ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__
-
template _UCXXEXPORT ostream & operator<<(ostream & os, const string & str);
-
#endif
-//Functions dependent upon ISTREAM
-#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__
+// Functions dependent upon ISTREAM
+#ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__
template _UCXXEXPORT istream & operator>>(istream & is, string & str);
-
-
#endif
-
#endif
-}
+} // namespace