From 23e8d5321a4de9c08a5f9c1e3a919aa740acca78 Mon Sep 17 00:00:00 2001 From: patacongo Date: Fri, 2 Nov 2012 23:22:48 +0000 Subject: [PATCH] Create an STM32F4Discovery configuration for testing uClibc++ git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5300 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/cxxtest/cxxtest_main.cxx | 22 +- misc/uClibc++/include/uClibc++/algorithm | 3764 +++++++++-------- .../include/uClibc++/associative_base | 1160 ++--- misc/uClibc++/include/uClibc++/bitset | 882 ++-- misc/uClibc++/include/uClibc++/char_traits | 323 +- misc/uClibc++/include/uClibc++/complex | 678 +-- misc/uClibc++/include/uClibc++/deque | 36 +- misc/uClibc++/include/uClibc++/fstream | 1297 +++--- misc/uClibc++/include/uClibc++/functional | 860 ++-- misc/uClibc++/include/uClibc++/iomanip | 195 +- misc/uClibc++/include/uClibc++/ios | 903 ++-- misc/uClibc++/include/uClibc++/iosfwd | 153 +- misc/uClibc++/include/uClibc++/iostream | 106 +- misc/uClibc++/include/uClibc++/istream | 1146 ++--- .../uClibc++/include/uClibc++/istream_helpers | 747 ++-- misc/uClibc++/include/uClibc++/iterator | 432 +- misc/uClibc++/include/uClibc++/iterator_base | 566 +-- misc/uClibc++/include/uClibc++/limits | 1287 +++--- misc/uClibc++/include/uClibc++/list | 1847 ++++---- misc/uClibc++/include/uClibc++/map | 379 +- misc/uClibc++/include/uClibc++/memory | 334 +- misc/uClibc++/include/uClibc++/new | 63 +- misc/uClibc++/include/uClibc++/numeric | 297 +- misc/uClibc++/include/uClibc++/ostream | 857 ++-- .../uClibc++/include/uClibc++/ostream_helpers | 1070 +++-- misc/uClibc++/include/uClibc++/queue | 217 +- misc/uClibc++/include/uClibc++/set | 675 +-- misc/uClibc++/include/uClibc++/sstream | 704 +-- misc/uClibc++/include/uClibc++/stack | 130 +- misc/uClibc++/include/uClibc++/streambuf | 587 +-- misc/uClibc++/include/uClibc++/string | 4 + .../uClibc++/include/uClibc++/string_iostream | 184 +- misc/uClibc++/include/uClibc++/type_traits | 139 +- misc/uClibc++/include/uClibc++/utility | 157 +- misc/uClibc++/include/uClibc++/valarray | 2495 ++++++----- misc/uClibc++/include/uClibc++/vector | 1040 ++--- .../libxx/uClibc++/associative_base.cxx | 44 +- misc/uClibc++/libxx/uClibc++/bitset.cxx | 44 +- nuttx/ChangeLog | 8 + nuttx/arch/arm/src/Makefile | 80 +- nuttx/arch/sim/src/Makefile | 8 +- nuttx/configs/sim/README.txt | 8 +- nuttx/configs/sim/cxxtest/Make.defs | 6 +- nuttx/configs/sim/cxxtest/defconfig | 2 +- nuttx/configs/sim/ostest/Make.defs | 96 +- nuttx/configs/stm32f4discovery/README.txt | 29 + .../stm32f4discovery/cxxtest/Make.defs | 184 + .../stm32f4discovery/cxxtest/defconfig | 573 +++ .../stm32f4discovery/cxxtest/setenv.sh | 75 + .../configs/stm32f4discovery/ostest/defconfig | 2 +- 50 files changed, 15444 insertions(+), 11451 deletions(-) create mode 100644 nuttx/configs/stm32f4discovery/cxxtest/Make.defs create mode 100644 nuttx/configs/stm32f4discovery/cxxtest/defconfig create mode 100755 nuttx/configs/stm32f4discovery/cxxtest/setenv.sh diff --git a/apps/examples/cxxtest/cxxtest_main.cxx b/apps/examples/cxxtest/cxxtest_main.cxx index 70d54109f5..9c2974826f 100644 --- a/apps/examples/cxxtest/cxxtest_main.cxx +++ b/apps/examples/cxxtest/cxxtest_main.cxx @@ -203,21 +203,25 @@ static void test_exception(void) // Name: cxxtest_main //***************************************************************************/ -int cxxtest_main(int argc, char *argv[]) +extern "C" { - // If C++ initialization for static constructors is supported, then do - // that first + int cxxtest_main(int argc, char *argv[]) + { + // If C++ initialization for static constructors is supported, then do + // that first #ifdef CONFIG_HAVE_CXXINITIALIZE - up_cxxinitialize(); + up_cxxinitialize(); #endif - test_iostream(); - test_stl(); - test_rtti(); + test_iostream(); + test_stl(); + test_rtti(); #ifdef CONFIG_UCLIBCXX_EXCEPTION - test_exception(); + test_exception(); #endif - return 0; + return 0; + } } + diff --git a/misc/uClibc++/include/uClibc++/algorithm b/misc/uClibc++/include/uClibc++/algorithm index 5e8f139c06..e13713cfc4 100644 --- a/misc/uClibc++/include/uClibc++/algorithm +++ b/misc/uClibc++/include/uClibc++/algorithm @@ -1,19 +1,20 @@ -/* 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 #include @@ -23,1669 +24,2084 @@ #ifndef __STD_HEADER_ALGORITHM #define __STD_HEADER_ALGORITHM 1 -//Elliminate any previously defined macro +//Eliminate any previously defined macro + #undef min #undef max #pragma GCC visibility push(default) -namespace std{ - - // subclause _lib.alg.nonmodifying_, non-modifying sequence operations: - template _UCXXEXPORT - Function for_each(InputIterator first, InputIterator last, Function f) - { - while(first !=last){ - f(*first); - ++first; - } - return f; - } - - - template _UCXXEXPORT - InputIterator find(InputIterator first, InputIterator last, const T& value) - { - while(first !=last && *first != value){ - ++first; - } - return first; - } - - template _UCXXEXPORT - InputIterator find_if(InputIterator first, InputIterator last, Predicate pred) - { - while(first !=last && !pred(*first)){ - ++first; - } - return first; - } - - template _UCXXEXPORT ForwardIterator1 - find_end(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2) - { - ForwardIterator1 retval = last1; - while(first1 !=last1){ - ForwardIterator1 temp1(first1); - ForwardIterator2 temp2(first2); - while(temp2!=last2 && temp1!= last1){ - if(*temp1 != *temp2){ - break; //Exit while loop - } - ++temp1; - ++temp2; - if(temp2 == last2){ //Have successfully checked the whole sequence - retval = first1; - } - } - } - return retval; - } - - template _UCXXEXPORT - ForwardIterator1 - find_end(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2, - BinaryPredicate pred) - { - ForwardIterator1 retval = last1; - while(first1 !=last1){ - ForwardIterator1 temp1(first1); - ForwardIterator2 temp2(first2); - while(temp2!=last2 && temp1!= last1){ - if( ! pred(*temp1, *temp2)){ - break; //Exit while loop - } - ++temp1; - ++temp2; - if(temp2 == last2){ //Have successfully checked the whole sequence - retval = first1; - } - } - } - return retval; - } - - template _UCXXEXPORT - ForwardIterator1 - find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2) - { - while(first1 != last1){ - ForwardIterator2 temp2(first2); - while(temp2 != last2 ){ - if(*temp2 == first1){ - return first1; - } - ++temp2; - } - - } - return last1; - } - - template _UCXXEXPORT - ForwardIterator1 - find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2, - BinaryPredicate pred) - { - while(first1 != last1){ - ForwardIterator2 temp2(first2); - while(temp2 != last2 ){ - if(*temp2 == first1){ - return first1; - } - ++temp2; - } - - } - return last1; - } - - template _UCXXEXPORT ForwardIterator - adjacent_find(ForwardIterator first, ForwardIterator last) - { - ForwardIterator temp; - while(first != last){ - temp = first; - ++temp; - if(*temp == *first){ - return first; - } - ++first; - } - return first; - } - - template _UCXXEXPORT - ForwardIterator - adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) - { - ForwardIterator temp; - while(first != last){ - temp = first; - ++temp; - if( pred(*temp, *first)){ - return first; - } - ++first; - } - return first; - } - - template _UCXXEXPORT - typename iterator_traits::difference_type - count(InputIterator first, InputIterator last, const T& value) - { - typename iterator_traits::difference_type i = 0; - while(first!=last){ - if(*first == value){ - ++i; - } - ++first; - } - return i; - } - - template _UCXXEXPORT - typename iterator_traits::difference_type - count_if(InputIterator first, InputIterator last, Predicate pred) - { - typename iterator_traits::difference_type i = 0; - while(first!=last){ - if( pred(*first) ){ - ++i; - } - ++first; - } - return i; - } - - template _UCXXEXPORT - pair - mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) - { - while(first1 != last1){ - if(*first1 != *first2){ - break; - } - ++first1; - ++first2; - } - - pair retval; - retval.first = first1; - retval.second = first2; - return retval; - } - - template _UCXXEXPORT - pair - mismatch(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, BinaryPredicate pred) - { - while(first1 != last1){ - if( !pred(*first1, *first2) ){ - break; - } - ++first1; - ++first2; - } - - pair retval; - retval.first = first1; - retval.second = first2; - return retval; - } - - template _UCXXEXPORT - bool - equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) - { - while(first1 !=last1){ - if(*first1 != *first2){ - return false; - } - ++first1; - ++first2; - } - return true; - } - - template _UCXXEXPORT - bool - equal(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, BinaryPredicate pred) - { - while(first1 !=last1){ - if( !pred(*first1, *first2) ){ - return false; - } - ++first1; - ++first2; - } - return true; - } - - template _UCXXEXPORT - ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2) - { - equal_to::value_type> c; - return search(first1, last1, first2, last2, c); - } - - - template _UCXXEXPORT - ForwardIterator1 - search(ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2, - BinaryPredicate pred) - { - while(first1 != last1){ - ForwardIterator1 temp1(first1); - ForwardIterator2 temp2(first2); - while(temp2 != last2 && temp1 != last1){ - if( !pred(*temp2, *temp1) ){ - break; - } - ++temp1; - ++temp2; - if(temp2 == last2){ - return first1; - } - } - ++first1; - } - return last1; - } - - - template _UCXXEXPORT - ForwardIterator - search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value) - { - while( first != last ){ - if(*first == value){ - ForwardIterator temp(first); - Size i = 1; - ++first; //Avoid doing the same comparison over again - while(i < count && *temp == value){ - ++first; - ++i; - } - if(i == count){ - return first; - } - } - ++first; - } - return first; - } - - - template _UCXXEXPORT - ForwardIterator - search_n(ForwardIterator first, ForwardIterator last, - Size count, const T& value, BinaryPredicate pred) - { - while( first != last ){ - if( pred(*first, value) ){ - ForwardIterator temp(first); - Size i = 1; - ++first; //Avoid doing the same comparison over again - while(i < count && pred(*temp, value) ){ - ++first; - ++i; - } - if(i == count){ - return first; - } - } - ++first; - } - return first; - - } - - // subclause _lib.alg.modifying.operations_, modifying sequence operations: - - template _UCXXEXPORT - OutputIterator - copy(InputIterator first, InputIterator last, OutputIterator result) - { - while(first != last){ - *result = *first; - ++first; - ++result; - } - return result; - } - - template _UCXXEXPORT - BidirectionalIterator2 - copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, - BidirectionalIterator2 result) - { - while(first !=last ){ - --result; - --last; - *result = *last; - } - return result; - } - - template _UCXXEXPORT void swap(T& a, T& b){ - T temp(a); - a = b; - b = temp; - } - - template _UCXXEXPORT - ForwardIterator2 - swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) - { - while(first1 != last1){ - iter_swap(first1, first2); - ++first1; - ++first2; - } - return first2; - } - - - template _UCXXEXPORT - void - iter_swap(ForwardIterator1 a, ForwardIterator2 b) - { - typename iterator_traits::value_type temp(*a); - *a = *b; - *b = temp; - } - - - template _UCXXEXPORT - OutputIterator - transform(InputIterator first, InputIterator last, - OutputIterator result, UnaryOperation op) - { - while(first != last){ - *result = op(*first); - ++first; - ++result; - } - return result; - } - - - template _UCXXEXPORT - OutputIterator transform(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, OutputIterator result, - BinaryOperation binary_op) - { - while(first1 != last1){ - *result = binary_op(*first1, *first2); - ++first1; - ++first2; - ++result; - } - return result; - } - - - template _UCXXEXPORT - void - replace(ForwardIterator first, ForwardIterator last, - const T& old_value, const T& new_value) - { - while(first != last){ - if(*first == old_value){ - *first = new_value; - } - ++first; - } - } - - template _UCXXEXPORT - void - replace_if(ForwardIterator first, ForwardIterator last, - Predicate pred, const T& new_value) - { - while(first != last){ - if( pred(*first) ){ - *first = new_value; - } - ++first; - } - } - - - template _UCXXEXPORT - OutputIterator - replace_copy(InputIterator first, InputIterator last, - OutputIterator result, const T& old_value, const T& new_value) - { - while(first != last){ - if(*first == old_value){ - *result = new_value; - }else{ - *result = *first; - } - ++first; - ++result; - } - return result; - } - - template _UCXXEXPORT - OutputIterator - replace_copy_if(Iterator first, Iterator last, - OutputIterator result, Predicate pred, const T& new_value) - { - while(first != last){ - if( pred(*first) ){ - *result = new_value; - }else{ - *result = *first; - } - ++first; - ++result; - } - return result; - } - - template _UCXXEXPORT - void - fill(ForwardIterator first, ForwardIterator last, const T& value) - { - while(first != last){ - *first = value; - ++first; - } - } - - template _UCXXEXPORT - void - fill_n(OutputIterator first, Size n, const T& value) - { - while(n != 0){ - *first = value; - --n; - ++first; - } - } - - template _UCXXEXPORT - void - generate(ForwardIterator first, ForwardIterator last, Generator gen) - { - while(first != last){ - *first = gen(); - ++first; - } - } - - template _UCXXEXPORT - void - generate_n(OutputIterator first, Size n, Generator gen) - { - while(n !=0){ - *first = gen(); - --n; - ++first; - } - } - - template _UCXXEXPORT - ForwardIterator - remove(ForwardIterator first, ForwardIterator last, const T& value) - { - ForwardIterator temp(first); - while(temp !=last){ - if(*temp == value){ - - }else{ - *first = *temp; - ++first; - } - ++temp; - } - return first; - } - - template _UCXXEXPORT - ForwardIterator - remove_if(ForwardIterator first, ForwardIterator last, Predicate pred) - { - ForwardIterator temp(first); - while(temp !=last){ - if( pred(*temp) ){ - - }else{ - *first = *temp; - ++first; - } - ++temp; - } - return first; - } - - - template _UCXXEXPORT - OutputIterator - remove_copy(InputIterator first, InputIterator last, - OutputIterator result, const T& value) - { - while(first !=last){ - if(*first != value){ - *result = *first; - ++result; - } - ++first; - } - return result; - } - - template _UCXXEXPORT - OutputIterator - remove_copy_if(InputIterator first, InputIterator last, - OutputIterator result, Predicate pred) - { - while(first !=last){ - if( !pred(*first) ){ - *result = *first; - ++result; - } - ++first; - } - return result; - } - - template _UCXXEXPORT - ForwardIterator - unique(ForwardIterator first, ForwardIterator last) - { - ForwardIterator new_val(first); - ForwardIterator old_val(first); - - while(new_val !=last){ - if(*new_val == *old_val && new_val != old_val){ - - }else{ - *first = *new_val; - old_val = new_val; - ++first; - } - ++new_val; - } - return first; - } - - template _UCXXEXPORT - ForwardIterator - unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) - { - ForwardIterator new_val(first); - ForwardIterator old_val(first); - - while(new_val !=last){ - if( pred(*new_val, *old_val) && new_val != old_val){ - - }else{ - *first = *new_val; - old_val = new_val; - ++first; - } - ++new_val; - } - return first; - } - - template _UCXXEXPORT - OutputIterator - unique_copy(InputIterator first, InputIterator last, OutputIterator result) - { - InputIterator temp(first); - while(first !=last ){ - if(*first == *temp && first != temp){ - - }else{ - *result = *first; - temp = first; - ++result; - } - ++first; - } - return result; - } - - template _UCXXEXPORT - OutputIterator - unique_copy(InputIterator first, InputIterator last, - OutputIterator result, BinaryPredicate pred) - { - InputIterator temp(first); - while(first !=last ){ - if( pred(*first, *temp) && first != temp){ - - }else{ - *result = *first; - temp = first; - ++result; - } - ++first; - } - return result; - } - - template _UCXXEXPORT - void - reverse(BidirectionalIterator first, BidirectionalIterator last) - { - --last; //Don't work with one past the end element - while(first < last){ - iter_swap(first, last); - ++first; - --last; - } - } - - template _UCXXEXPORT - OutputIterator - reverse_copy(BidirectionalIterator first, BidirectionalIterator last, - OutputIterator result) - { - while(last > first){ - --last; - *result = *last; - ++result; - } - return result; - } - - template _UCXXEXPORT - void - rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last) - { - if ((first == middle) || (last == middle)){ - return; - } - - ForwardIterator first2 = middle; - - do { - swap(*first, *first2); - first++; - first2++; - if(first == middle){ - middle = first2; - } - } while(first2 != last); - - first2 = middle; - - while (first2 != last) { - swap(*first, *first2); - first++; - first2++; - if (first == middle){ - middle = first2; - }else if (first2 == last){ - first2 = middle; - } - } - } - - template _UCXXEXPORT - OutputIterator - rotate_copy(ForwardIterator first, ForwardIterator middle, - ForwardIterator last, OutputIterator result) - { - ForwardIterator temp(middle); - while(temp !=last){ - *result = *temp; - ++temp; - ++result; - } - while(first != middle){ - *result = *first; - ++first; - ++result; - } - return result; - } - - - template _UCXXEXPORT - void - random_shuffle(RandomAccessIterator first, RandomAccessIterator last) - { - --last; - while(first != last){ - iter_swap(first, (first + (rand() % (last - first) ) ) ); - ++first; - } - } - - template _UCXXEXPORT - void - random_shuffle(RandomAccessIterator first, RandomAccessIterator last, - RandomNumberGenerator& rand) - { - --last; - while(first != last){ - iter_swap(first, (first + (rand(last - first) ) ) ); - ++first; - } - } - - // _lib.alg.partitions_, partitions: - template _UCXXEXPORT BidirectionalIterator - partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred) - { - return stable_partition(first, last, pred); - } - - template _UCXXEXPORT BidirectionalIterator - stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred) - { - //first now points to the first non-desired element - while( first != last && pred(*first) ){ - ++first; - } - - BidirectionalIterator tempb; - BidirectionalIterator tempe = first; - - while( tempe != last ){ - //Find the next desired element - while( !pred(*tempe) ){ - ++tempe; - - //See if we should exit - if(tempe == last){ - return first; - } - } - - //Rotate the element back to the begining - tempb = tempe; - while(tempb != first){ - iter_swap(tempb, tempb-1 ); - --tempb; - } - //First now has a desired element - ++first; - } - - return first; - } - - template _UCXXEXPORT - void sort(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - sort(first, last, c ); - } - - template _UCXXEXPORT - void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - stable_sort(first, last, comp); - } - - template _UCXXEXPORT - void stable_sort(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - stable_sort(first, last, c); - } - - template _UCXXEXPORT - void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - //FIXME - bubble sort - RandomAccessIterator temp; - --last; - while(last - first > 0){ - temp = last; - while(temp != first){ - if( comp( *temp, *(temp-1) ) ){ - iter_swap( temp-1, temp); - } - --temp; - } - ++first; - } - } - - template _UCXXEXPORT - void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last) - { - less::value_type> c; - partial_sort(first, middle, last, c); - } - template _UCXXEXPORT - void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, - RandomAccessIterator last, Compare comp) - { - //Fixme - partial bubble sort - RandomAccessIterator temp; - --last; - while(first < middle){ - temp = last; - while(temp != first){ - if( comp(*temp, *(temp -1 ) ) ) { - iter_swap( temp-1, temp); - } - --temp; - } - ++first; - } - } - template _UCXXEXPORT - RandomAccessIterator - partial_sort_copy(InputIterator first, InputIterator last, - RandomAccessIterator result_first, RandomAccessIterator result_last) - { - less::value_type> c; - return partial_sort_copy(first, last, result_first, result_last, c); - } - template _UCXXEXPORT - RandomAccessIterator - partial_sort_copy(InputIterator first, InputIterator last, - RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) - { - size_t output_size = last-first; - size_t temp_size = result_last - result_first; - if(temp_size < output_size){ - output_size = temp_size; - } - - RandomAccessIterator middle = result_first + output_size; - RandomAccessIterator temp = result_first; - - while(temp != middle){ - *temp = *first; - ++temp; - ++first; - } - sort(result_first, middle, comp); - - while( first != last){ - if( comp( *first, *(middle-1) ) ){ - *(middle-1) = *first; - sort(result_first, middle, comp); - } - ++first; - } - - return middle; - } - template _UCXXEXPORT - void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last) - { - less::value_type> c; - nth_element(first, nth, last, c); - } - template _UCXXEXPORT - void nth_element(RandomAccessIterator first, RandomAccessIterator nth, - RandomAccessIterator last, Compare comp) - { - partial_sort(first, nth, last, comp); - } - - template _UCXXEXPORT - ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, - const T& value) - { - less::value_type> c; - return lower_bound(first, last, value, c); - } - - template _UCXXEXPORT - ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, - const T& value, Compare comp) - { - if(first == last){ - return last; - } - //If below or equal to the first element - if( comp(*first, value) == false){ - return first; - } - ForwardIterator middle; - - //If greater than the top element - middle = first; - advance(middle, distance(first, last) - 1); - if( comp(*middle, value) ){ - return last; - } - - //Now begin the actual search for the begining - while( distance(first, last) > 1 ){ - //Find middle - middle = first; - advance(middle, (distance(first, last)/2) ); - if( !comp(*middle, value) ){ - last = middle; - }else{ - first = middle; - } - } - - if( !comp(*first, value) ){ - return first; - } - return last; - } - - template _UCXXEXPORT - ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, - const T& value) - { - less::value_type> c; - return upper_bound(first, last, value, c); - } - - - template _UCXXEXPORT - ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, - const T& value, Compare comp) - { - if(first == last){ - return last; - } - //If below the first element - if( comp(value, *first) == true){ - return first; - } - - ForwardIterator middle; - - //If greater than the top element - middle = first; - advance(middle, distance(first, last) - 1); - if( comp(*middle, value) ){ - return last; - } - - //Now begin the actual search for the end - while( distance(first, last) > 1 ){ - //Find middle - middle = first; - advance(middle, (distance(first, last)/2) ); - if( comp(value, *middle) ){ - last = middle; - }else{ - first = middle; - } - } - - if( comp(value, *first) ){ - return first; - } - return last; - } - - - template _UCXXEXPORT - pair - equal_range(ForwardIterator first, ForwardIterator last, const T& value) - { - less::value_type> c; - return equal_range(first, last, value, c); - } - - template _UCXXEXPORT - pair - equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp) - { - pair retval; - retval.first = lower_bound(first, last, value, comp); - //Reuse retval.first in order to (possibly) save a few comparisons - retval.second = upper_bound(retval.first, last, value, comp); - return retval; - - } - - template _UCXXEXPORT - bool binary_search(ForwardIterator first, ForwardIterator last, - const T& value) - { - less::value_type> c; - return binary_search(first, last, value, c); - } - - template _UCXXEXPORT - bool binary_search(ForwardIterator first, ForwardIterator last, - const T& value, Compare comp) - { - if( distance(first, last) == 0){ - return false; - } - - ForwardIterator middle; - - while( distance(first, last) > 1 ){ - //Set middle between first and last - middle = first; - advance(middle, distance(first, last)/2 ); - - if( comp(*middle, value ) == true){ - first = middle; - }else{ - last = middle; - } - } - - if( !comp(*first, value) && !comp(value, *first) ){ - return true; - } - if( !comp(*last, value) && !comp(value, *last) ){ - return true; - } - - return false; - } - - // _lib.alg.merge_, merge: - template _UCXXEXPORT - OutputIterator - merge(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result) - { - less::value_type> c; - return merge(first1, last1, first2, last2, result, c); - } - template _UCXXEXPORT - OutputIterator - merge(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) - { - while( first1 != last1 && first2 != last2){ - //If in this order so first1 elements which are equal come first - if( comp(*first2, *first1) ){ - *result = *first2; - ++first2; - }else{ - *result = *first1; - ++first1; - } - ++result; - } - //Clean up remaining elements - while(first1 != last1){ - *result = *first1; - ++first1; - ++result; - } - while(first2 != last2){ - *result = *first2; - ++first2; - ++result; - } - return result; - } - template _UCXXEXPORT - void inplace_merge(BidirectionalIterator first, - BidirectionalIterator middle, BidirectionalIterator last) - { - less::value_type> c; - inplace_merge(first, middle, last, c); - } - template _UCXXEXPORT - void inplace_merge(BidirectionalIterator first, - BidirectionalIterator middle, BidirectionalIterator last, Compare comp) - { - //FIXME - using a bubble exchange method - while(first != middle && middle !=last){ - if( comp(*middle, *first) ){ - BidirectionalIterator temp(middle); - while( temp != first){ - iter_swap(temp, temp-1); - --temp; - } - ++middle; - } - ++first; - } - } - - // _lib.alg.set.operations_, set operations: - template _UCXXEXPORT - bool includes(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) - { - less::value_type> c; - return includes(first1, last1, first2, last2, c ); - } - - template _UCXXEXPORT - bool includes(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, Compare comp) - { - while(first2 != last2){ - //Advance the large set until no longer smaller than the element we are looking for - while( comp(*first1, *first2) ){ - ++first1; - //If we are at the end of the list, we don't have the desired element - if(first1 == last1){ - return false; - } - } - //If we are past the element we want, it isn't here - if( comp(*first2, *first1) ){ - return false; - } - ++first2; //Move to next element - } - return true; - } - - template _UCXXEXPORT - OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result) - { - less::value_type> c; - return set_union(first1, last1, first2, last2, result, c); - } - - template _UCXXEXPORT - OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) - { - while( first1 != last1 && first2 != last2){ - if( comp(*first2, *first1) ){ - *result = *first2; - - //Elliminate duplicates - InputIterator2 temp = first2; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - }else{ - *result = *first1; - //Elliminate duplicates - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - } - ++result; - } - - //Clean up remaining elements - while(first1 != last1){ - *result = *first1; - ++result; - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - } - - while(first2 != last2){ - *result = *first2; - ++result; - InputIterator2 temp = first2; - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - } - return result; - } - - template _UCXXEXPORT - OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result) - { - less::value_type> c; - return set_intersection(first1, last1, first2, last2, result, c); - } - template _UCXXEXPORT - OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) - { - while( first1 != last1 && first2 != last2){ - if( comp(*first2, *first1) ){ - ++first2; - }else if( comp(*first1, *first2) ) { - ++first1; - }else{ - *result = *first1; - ++result; - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - ++first2; - } - } - return result; - } - template _UCXXEXPORT - OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result) - { - less::value_type> c; - return set_difference(first1, last1, first2, last2, result, c); - } - template _UCXXEXPORT - OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) - { - while( first1 != last1 && first2 != last2){ - if( comp(*first1, *first2) ){ - *result = *first1; - ++result; - - //Elliminate duplicates - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - }else if( comp(*first2, *first1) ){ - - //Elliminate duplicates - InputIterator2 temp = first2; - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - - }else{ //They are identical - skip - //Elliminate duplicates - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - } - } - - //Clean up remaining elements - while(first1 != last1){ - *result = *first1; - ++result; - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - } - - return result; - } - template _UCXXEXPORT - OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result) - { - less::value_type> c; - return set_symmetric_difference(first1, last1, first2, last2, result, c); - } - template _UCXXEXPORT - OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) - { - while( first1 != last1 && first2 != last2){ - if( comp(*first1, *first2) ){ - *result = *first1; - ++result; - - //Elliminate duplicates - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - }else if( comp(*first2, *first1) ){ - *result = *first2; - ++result; - - //Elliminate duplicates - InputIterator2 temp = first2; - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - - }else{ //They are identical - skip - //Elliminate duplicates - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - } - } - - //Clean up remaining elements - while(first1 != last1){ - *result = *first1; - ++result; - InputIterator1 temp = first1; - while( first1 != last1 && !comp( *temp, *first1) ){ - ++first1; - } - } - - while(first2 != last2){ - *result = *first2; - ++result; - InputIterator2 temp = first2; - while( first2 != last2 && !comp( *temp, *first2) ){ - ++first2; - } - } - - return result; - } - - // _lib.alg.heap.operations_, heap operations: - - template _UCXXEXPORT - void push_heap(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - push_heap(first, last, c); - } - - template _UCXXEXPORT - void push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - // *(last - 1) is the last element - RandomAccessIterator begin, middle, end; - begin = first; - end = last - 2; - if(last - first < 2){ //Empty heap - return; - } - if ( comp(*(last-1), *end) ){ //Belongs past the end - already in place - return; - } - while(end - begin > 1){ - middle = begin + ((end - begin)/2); - if( comp(*middle, *(last-1) ) ){ - end = middle; - }else{ - begin = middle; - } - } - - if( comp(*begin, *(last-1)) ){ - middle = begin; - }else{ - middle = end; - } - - //Now all we do is swap the elements up to the begining - --last; - - while(last > middle){ - iter_swap(last, last-1); - --last; - } - } - - template _UCXXEXPORT - void pop_heap(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - pop_heap(first, last, c); - } - template _UCXXEXPORT - void pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare) - { - --last; - while(first < last){ - iter_swap( first, first+1); - ++first; - } - } - - template _UCXXEXPORT - void make_heap(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - make_heap(first, last, c); - } - template _UCXXEXPORT - void make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - sort( reverse_iterator(last), reverse_iterator(first), comp); - } - template _UCXXEXPORT - void sort_heap(RandomAccessIterator first, RandomAccessIterator last) - { - less::value_type> c; - sort_heap(first, last, c); - } - template _UCXXEXPORT - void sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - sort( first, last, comp); - } - - - // _lib.alg.min.max_, minimum and maximum: - template _UCXXEXPORT - const T& min(const T& a, const T& b) - { - if(b < a){ - return b; - } - return a; - } - - template _UCXXEXPORT - const T& min(const T& a, const T& b, Compare comp) - { - if( comp(b, a) == true){ - return b; - } - return a; - } - - template _UCXXEXPORT - const T& max(const T& a, const T& b) - { - if( a < b){ - return b; - } - return a; - } - - template _UCXXEXPORT - const T& max(const T& a, const T& b, Compare comp) - { - if( comp(a, b) ){ - return b; - } - return a; - } - - template _UCXXEXPORT - ForwardIterator min_element(ForwardIterator first, ForwardIterator last) - { - less::value_type> c; - return min_element(first, last, c); - } - - template _UCXXEXPORT - ForwardIterator min_element(ForwardIterator first, ForwardIterator last, Compare comp) - { - ForwardIterator retval = first; - ++first; - while(first != last){ - if( comp( *first, *retval) ){ - retval = first; - } - ++first; - } - return retval; - } - - template _UCXXEXPORT - ForwardIterator max_element(ForwardIterator first, ForwardIterator last) - { - less::value_type> c; - return max_element(first, last, c); - } - - template _UCXXEXPORT - ForwardIterator max_element(ForwardIterator first, ForwardIterator last, Compare comp) - { - ForwardIterator retval = first; - ++first; - while(first != last){ - if( comp( *retval, *first ) ){ - retval = first; - } - ++first; - } - return retval; - } - - template _UCXXEXPORT - bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2) - { - less::value_type> c; - return lexicographical_compare(first1, last1, first2, last2, c); - } - - template _UCXXEXPORT - bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, InputIterator2 last2, Compare comp) - { - while(first1 != last1 && first2 != last2){ - if( comp(*first1, *first2) ){ - return true; - } - if( comp(*first2, *first1) ){ - return false; - } - ++first1; - ++first2; - } - return first1==last1 && first2 != last2; - } - - // _lib.alg.permutation.generators_, permutations - template _UCXXEXPORT - bool next_permutation(BidirectionalIterator first, BidirectionalIterator last) - { - less::value_type> c; - return next_permutation(first, last, c); - } - - template _UCXXEXPORT - bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp) - { - if(first == last){ - return false; // No data - } - BidirectionalIterator i = last; - --i; - if(i == first){ - return false; //Only one element - } - BidirectionalIterator ii = i; - --ii; - //If the last two items are in order, swap them and call it done - if( comp(*ii, *i) ){ - iter_swap(ii, i); - return true; - } - - - //This part of the algorithm copied from G++ header files ver. 3.4.2 - i = last; - --i; - for(;;){ - ii = i; - --i; - if ( comp(*i, *ii) ){ - BidirectionalIterator j = last; - --j; - while ( !comp(*i, *j)){ - --j; - } - iter_swap(i, j); - reverse(ii, last); - return true; - } - if (i == first){ - reverse(first, last); - return false; - } - } - - - } - - template _UCXXEXPORT - bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last) - { - less::value_type> c; - return prev_permutation(first, last, c); - } - - template _UCXXEXPORT - bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp) - { - if(first == last){ - return false; // No data - } - BidirectionalIterator i = last; - --i; - if(i == first){ - return false; //Only one element - } - BidirectionalIterator ii = i; - --ii; - //If the last two items are in reverse order, swap them and call it done - if( comp(*i, *ii) ){ - iter_swap(ii, i); - return true; - } - - //Copied from GNU GCC header files version 3.4.2 - i = last; - --i; - - for(;;){ - ii = i; - --i; - if ( comp(*ii, *i)){ - BidirectionalIterator j = last; - --j; - while ( !comp(*j, *i)){ - --j; - } - iter_swap(i, j); - reverse(ii, last); - return true; - } - if (i == first){ - reverse(first, last); - return false; - } - } - - } - -} +extern "C++" +{ + +namespace std +{ + + // Subclause _lib.alg.nonmodifying_, non-modifying sequence operations: + + template _UCXXEXPORT + Function for_each(InputIterator first, InputIterator last, Function f) + { + while (first !=last) + { + f(*first); + ++first; + } + + return f; + } + + template _UCXXEXPORT + InputIterator find(InputIterator first, InputIterator last, const T& value) + { + while (first !=last && *first != value) + { + ++first; + } + + return first; + } + + template _UCXXEXPORT + InputIterator find_if (InputIterator first, InputIterator last, Predicate pred) + { + while (first !=last && !pred(*first)) + { + ++first; + } + + return first; + } + + template _UCXXEXPORT ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2) + { + ForwardIterator1 retval = last1; + while (first1 != last1) + { + ForwardIterator1 temp1(first1); + ForwardIterator2 temp2(first2); + + while (temp2!=last2 && temp1!= last1) + { + if (*temp1 != *temp2) + { + break; //Exit while loop + } + + ++temp1; + ++temp2; + if (temp2 == last2) + { + //Have successfully checked the whole sequence + + retval = first1; + } + } + } + + return retval; + } + + template _UCXXEXPORT + ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred) + { + ForwardIterator1 retval = last1; + while (first1 !=last1) + { + ForwardIterator1 temp1(first1); + ForwardIterator2 temp2(first2); + while (temp2!=last2 && temp1!= last1) + { + if (!pred(*temp1, *temp2)) + { + break; //Exit while loop + } + + ++temp1; + ++temp2; + if (temp2 == last2) + { + // Have successfully checked the whole sequence + + retval = first1; + } + } + } + + return retval; + } + + template _UCXXEXPORT + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2) + { + while (first1 != last1) + { + ForwardIterator2 temp2(first2); + while (temp2 != last2) + { + if (*temp2 == first1) + { + return first1; + } + + ++temp2; + } + } + + return last1; + } + + template _UCXXEXPORT + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred) + { + while (first1 != last1) + { + ForwardIterator2 temp2(first2); + while (temp2 != last2) + { + if (*temp2 == first1) + { + return first1; + } + + ++temp2; + } + } + + return last1; + } + + template _UCXXEXPORT ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last) + { + ForwardIterator temp; + while (first != last) + { + temp = first; + ++temp; + if (*temp == *first) + { + return first; + } + + ++first; + } + + return first; + } + + template _UCXXEXPORT + ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) + { + ForwardIterator temp; + while (first != last) + { + temp = first; + ++temp; + if (pred(*temp, *first)) + { + return first; + } + + ++first; + } + + return first; + } + + template _UCXXEXPORT + typename iterator_traits::difference_type + count(InputIterator first, InputIterator last, const T& value) + { + typename iterator_traits::difference_type i = 0; + while (first!=last) + { + if (*first == value) + { + ++i; + } + + ++first; + } + + return i; + } + + template _UCXXEXPORT + typename iterator_traits::difference_type + count_if (InputIterator first, InputIterator last, Predicate pred) + { + typename iterator_traits::difference_type i = 0; + while (first!=last) + { + if (pred(*first)) + { + ++i; + } + + ++first; + } + + return i; + } + + template _UCXXEXPORT + pair + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) + { + while (first1 != last1) + { + if (*first1 != *first2) + { + break; + } + + ++first1; + ++first2; + } + + pair retval; + retval.first = first1; + retval.second = first2; + return retval; + } + + template _UCXXEXPORT + pair + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred) + { + while (first1 != last1) + { + if (!pred(*first1, *first2)) + { + break; + } + + ++first1; + ++first2; + } + + pair retval; + retval.first = first1; + retval.second = first2; + return retval; + } + + template _UCXXEXPORT + bool + equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) + { + while (first1 !=last1) + { + if (*first1 != *first2) + { + return false; + } + + ++first1; + ++first2; + } + + return true; + } + + template _UCXXEXPORT + bool + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred) + { + while (first1 !=last1) + { + if (!pred(*first1, *first2)) + { + return false; + } + + ++first1; + ++first2; + } + + return true; + } + + template _UCXXEXPORT + ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2) + { + equal_to::value_type> c; + return search(first1, last1, first2, last2, c); + } + + template _UCXXEXPORT + ForwardIterator1 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred) + { + while (first1 != last1) + { + ForwardIterator1 temp1(first1); + ForwardIterator2 temp2(first2); + while (temp2 != last2 && temp1 != last1) + { + if (!pred(*temp2, *temp1)) + { + break; + } + + ++temp1; + ++temp2; + if (temp2 == last2) + { + return first1; + } + } + + ++first1; + } + + return last1; + } + + + template _UCXXEXPORT + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value) + { + while (first != last) + { + if (*first == value) + { + ForwardIterator temp(first); + Size i = 1; + ++first; // Avoid doing the same comparison over again + while (i < count && *temp == value) + { + ++first; + ++i; + } + + if (i == count) + { + return first; + } + } + + ++first; + } + + return first; + } + + + template _UCXXEXPORT + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, + Size count, const T& value, BinaryPredicate pred) + { + while (first != last) + { + if (pred(*first, value)) + { + ForwardIterator temp(first); + Size i = 1; + ++first; // Avoid doing the same comparison over again + while (i < count && pred(*temp, value)) + { + ++first; + ++i; + } + + if (i == count) + { + return first; + } + } + + ++first; + } + + return first; + } + + // Subclause _lib.alg.modifying.operations_, modifying sequence operations: + + template _UCXXEXPORT + OutputIterator + copy(InputIterator first, InputIterator last, OutputIterator result) + { + while (first != last) + { + *result = *first; + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + BidirectionalIterator2 + copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, + BidirectionalIterator2 result) + { + while (first !=last) + { + --result; + --last; + *result = *last; + } + + return result; + } + + template _UCXXEXPORT void swap(T& a, T& b) + { + T temp(a); + a = b; + b = temp; + } + + template _UCXXEXPORT + ForwardIterator2 + swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) + { + while (first1 != last1) + { + iter_swap(first1, first2); + ++first1; + ++first2; + } + + return first2; + } + + template _UCXXEXPORT + void + iter_swap(ForwardIterator1 a, ForwardIterator2 b) + { + typename iterator_traits::value_type temp(*a); + *a = *b; + *b = temp; + } + + template _UCXXEXPORT + OutputIterator + transform(InputIterator first, InputIterator last, + OutputIterator result, UnaryOperation op) + { + while (first != last) + { + *result = op(*first); + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator transform(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, OutputIterator result, + BinaryOperation binary_op) + { + while (first1 != last1) + { + *result = binary_op(*first1, *first2); + ++first1; + ++first2; + ++result; + } + + return result; + } + + template _UCXXEXPORT + void + replace(ForwardIterator first, ForwardIterator last, + const T& old_value, const T& new_value) + { + while (first != last) + { + if (*first == old_value) + { + *first = new_value; + } + + ++first; + } + } + + template _UCXXEXPORT + void + replace_if (ForwardIterator first, ForwardIterator last, + Predicate pred, const T& new_value) + { + while (first != last) + { + if (pred(*first)) + { + *first = new_value; + } + + ++first; + } + } + + template _UCXXEXPORT + OutputIterator + replace_copy(InputIterator first, InputIterator last, + OutputIterator result, const T& old_value, const T& new_value) + { + while (first != last) + { + if (*first == old_value) + { + *result = new_value; + } + else + { + *result = *first; + } + + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator + replace_copy_if (Iterator first, Iterator last, + OutputIterator result, Predicate pred, const T& new_value) + { + while (first != last) + { + if (pred(*first)) + { + *result = new_value; + } + else + { + *result = *first; + } + + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + void + fill(ForwardIterator first, ForwardIterator last, const T& value) + { + while (first != last) + { + *first = value; + ++first; + } + } + + template _UCXXEXPORT + void + fill_n(OutputIterator first, Size n, const T& value) + { + while (n != 0) + { + *first = value; + --n; + ++first; + } + } + + template _UCXXEXPORT + void + generate(ForwardIterator first, ForwardIterator last, Generator gen) + { + while (first != last) + { + *first = gen(); + ++first; + } + } + + template _UCXXEXPORT + void + generate_n(OutputIterator first, Size n, Generator gen) + { + while (n !=0) + { + *first = gen(); + --n; + ++first; + } + } + + template _UCXXEXPORT + ForwardIterator + remove(ForwardIterator first, ForwardIterator last, const T& value) + { + ForwardIterator temp(first); + while (temp !=last) + { + if (*temp == value) + { + + } + else + { + *first = *temp; + ++first; + } + + ++temp; + } + + return first; + } + + template _UCXXEXPORT + ForwardIterator + remove_if (ForwardIterator first, ForwardIterator last, Predicate pred) + { + ForwardIterator temp(first); + while (temp !=last) + { + if (pred(*temp)) + { + } + else + { + *first = *temp; + ++first; + } + + ++temp; + } + + return first; + } + + template _UCXXEXPORT + OutputIterator + remove_copy(InputIterator first, InputIterator last, + OutputIterator result, const T& value) + { + while (first !=last) + { + if (*first != value) + { + *result = *first; + ++result; + } + + ++first; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator + remove_copy_if (InputIterator first, InputIterator last, + OutputIterator result, Predicate pred) + { + while (first !=last) + { + if (!pred(*first)) + { + *result = *first; + ++result; + } + + ++first; + } + + return result; + } + + template _UCXXEXPORT + ForwardIterator + unique(ForwardIterator first, ForwardIterator last) + { + ForwardIterator new_val(first); + ForwardIterator old_val(first); + + while (new_val !=last) + { + if (*new_val == *old_val && new_val != old_val) + { + } + else + { + *first = *new_val; + old_val = new_val; + ++first; + } + + ++new_val; + } + + return first; + } + + template _UCXXEXPORT + ForwardIterator + unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred) + { + ForwardIterator new_val(first); + ForwardIterator old_val(first); + + while (new_val !=last) + { + if (pred(*new_val, *old_val) && new_val != old_val) + { + } + else + { + *first = *new_val; + old_val = new_val; + ++first; + } + + ++new_val; + } + + return first; + } + + template _UCXXEXPORT + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result) + { + InputIterator temp(first); + while (first !=last) + { + if (*first == *temp && first != temp) + { + } + else + { + *result = *first; + temp = first; + ++result; + } + + ++first; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator + unique_copy(InputIterator first, InputIterator last, + OutputIterator result, BinaryPredicate pred) + { + InputIterator temp(first); + while (first !=last) + { + if (pred(*first, *temp) && first != temp) + { + } + else + { + *result = *first; + temp = first; + ++result; + } + + ++first; + } + + return result; + } + + template _UCXXEXPORT + void + reverse(BidirectionalIterator first, BidirectionalIterator last) + { + --last; //Don't work with one past the end element + while (first < last) + { + iter_swap(first, last); + ++first; + --last; + } + } + + template _UCXXEXPORT + OutputIterator + reverse_copy(BidirectionalIterator first, BidirectionalIterator last, + OutputIterator result) + { + while (last > first) + { + --last; + *result = *last; + ++result; + } + + return result; + } + + template _UCXXEXPORT + void + rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last) + { + if ((first == middle) || (last == middle)) + { + return; + } + + ForwardIterator first2 = middle; + + do + { + swap(*first, *first2); + first++; + first2++; + if (first == middle) + { + middle = first2; + } + } + while (first2 != last); + + first2 = middle; + + while (first2 != last) + { + swap(*first, *first2); + first++; + first2++; + if (first == middle) + { + middle = first2; + } + else if (first2 == last) + { + first2 = middle; + } + } + } + + template _UCXXEXPORT + OutputIterator + rotate_copy(ForwardIterator first, ForwardIterator middle, + ForwardIterator last, OutputIterator result) + { + ForwardIterator temp(middle); + while (temp !=last) + { + *result = *temp; + ++temp; + ++result; + } + + while (first != middle) + { + *result = *first; + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last) + { + --last; + while (first != last) + { + iter_swap(first, (first + (rand() % (last - first)))); + ++first; + } + } + + template _UCXXEXPORT + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last, + RandomNumberGenerator& rand) + { + --last; + while (first != last) + { + iter_swap(first, (first + (rand(last - first)))); + ++first; + } + } + + // _lib.alg.partitions_, partitions: + + template _UCXXEXPORT BidirectionalIterator + partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred) + { + return stable_partition(first, last, pred); + } + + template _UCXXEXPORT BidirectionalIterator + stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred) + { + // First now points to the first non-desired element + + while (first != last && pred(*first)){ + ++first; + } + + BidirectionalIterator tempb; + BidirectionalIterator tempe = first; + + while (tempe != last) + { + //Find the next desired element + + while (!pred(*tempe)) + { + ++tempe; + + //See if we should exit + + if (tempe == last) + { + return first; + } + } + + // Rotate the element back to the begining + + tempb = tempe; + while (tempb != first) + { + iter_swap(tempb, tempb-1); + --tempb; + } + + // First now has a desired element + + ++first; + } + + return first; + } + + template _UCXXEXPORT + void sort(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + sort(first, last, c); + } + + template _UCXXEXPORT + void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + stable_sort(first, last, comp); + } + + template _UCXXEXPORT + void stable_sort(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + stable_sort(first, last, c); + } + + template _UCXXEXPORT + void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + //FIXME - bubble sort + + RandomAccessIterator temp; + --last; + while (last - first > 0) + { + temp = last; + while (temp != first) + { + if (comp(*temp, *(temp-1))) + { + iter_swap(temp-1, temp); + } + + --temp; + } + + ++first; + } + } + + template _UCXXEXPORT + void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last) + { + less::value_type> c; + partial_sort(first, middle, last, c); + } + + template _UCXXEXPORT + void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, + RandomAccessIterator last, Compare comp) + { + //Fixme - partial bubble sort + + RandomAccessIterator temp; + --last; + while (first < middle) + { + temp = last; + while (temp != first) + { + if (comp(*temp, *(temp -1))) + { + iter_swap(temp-1, temp); + } + + --temp; + } + + ++first; + } + } + + template _UCXXEXPORT + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last) + { + less::value_type> c; + return partial_sort_copy(first, last, result_first, result_last, c); + } + + template _UCXXEXPORT + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp) + { + size_t output_size = last-first; + size_t temp_size = result_last - result_first; + if (temp_size < output_size) + { + output_size = temp_size; + } + + RandomAccessIterator middle = result_first + output_size; + RandomAccessIterator temp = result_first; + + while (temp != middle) + { + *temp = *first; + ++temp; + ++first; + } + + sort(result_first, middle, comp); + + while (first != last) + { + if (comp(*first, *(middle-1))) + { + *(middle-1) = *first; + sort(result_first, middle, comp); + } + + ++first; + } + + return middle; + } + + template _UCXXEXPORT + void nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last) + { + less::value_type> c; + nth_element(first, nth, last, c); + } + + template _UCXXEXPORT + void nth_element(RandomAccessIterator first, RandomAccessIterator nth, + RandomAccessIterator last, Compare comp) + { + partial_sort(first, nth, last, comp); + } + + template _UCXXEXPORT + ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, + const T& value) + { + less::value_type> c; + return lower_bound(first, last, value, c); + } + + template _UCXXEXPORT + ForwardIterator lower_bound(ForwardIterator first, ForwardIterator last, + const T& value, Compare comp) + { + if (first == last) + { + return last; + } + + // If below or equal to the first element + + if (comp(*first, value) == false) + { + return first; + } + + ForwardIterator middle; + + // If greater than the top element + + middle = first; + advance(middle, distance(first, last) - 1); + if (comp(*middle, value)) + { + return last; + } + + // Now begin the actual search for the begining + + while (distance(first, last) > 1) + { + // Find middle + + middle = first; + advance(middle, (distance(first, last)/2)); + if (!comp(*middle, value)) + { + last = middle; + } + else + { + first = middle; + } + } + + if (!comp(*first, value)) + { + return first; + } + + return last; + } + + template _UCXXEXPORT + ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, + const T& value) + { + less::value_type> c; + return upper_bound(first, last, value, c); + } + + template _UCXXEXPORT + ForwardIterator upper_bound(ForwardIterator first, ForwardIterator last, + const T& value, Compare comp) + { + if (first == last) + { + return last; + } + + // If below the first element + + if (comp(value, *first) == true) + { + return first; + } + + ForwardIterator middle; + + // If greater than the top element + + middle = first; + advance(middle, distance(first, last) - 1); + if (comp(*middle, value)) + { + return last; + } + + // Now begin the actual search for the end + + while (distance(first, last) > 1) + { + // Find middle + + middle = first; + advance(middle, (distance(first, last)/2)); + if (comp(value, *middle)) + { + last = middle; + } + else + { + first = middle; + } + } + + if (comp(value, *first)) + { + return first; + } + + return last; + } + + template _UCXXEXPORT + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value) + { + less::value_type> c; + return equal_range(first, last, value, c); + } + + template _UCXXEXPORT + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp) + { + pair retval; + retval.first = lower_bound(first, last, value, comp); + + //Reuse retval.first in order to (possibly) save a few comparisons + + retval.second = upper_bound(retval.first, last, value, comp); + return retval; + + } + + template _UCXXEXPORT + bool binary_search(ForwardIterator first, ForwardIterator last, + const T& value) + { + less::value_type> c; + return binary_search(first, last, value, c); + } + + template _UCXXEXPORT + bool binary_search(ForwardIterator first, ForwardIterator last, + const T& value, Compare comp) + { + if (distance(first, last) == 0) + { + return false; + } + + ForwardIterator middle; + + while (distance(first, last) > 1) + { + //Set middle between first and last + + middle = first; + advance(middle, distance(first, last)/2); + + if (comp(*middle, value) == true) + { + first = middle; + } + else + { + last = middle; + } + } + + if (!comp(*first, value) && !comp(value, *first)) + { + return true; + } + + if (!comp(*last, value) && !comp(value, *last)) + { + return true; + } + + return false; + } + + // _lib.alg.merge_, merge: + + template _UCXXEXPORT + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result) + { + less::value_type> c; + return merge(first1, last1, first2, last2, result, c); + } + + template _UCXXEXPORT + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + //If in this order so first1 elements which are equal come first + + if (comp(*first2, *first1)) + { + *result = *first2; + ++first2; + } + else + { + *result = *first1; + ++first1; + } + + ++result; + } + + //Clean up remaining elements + + while (first1 != last1) + { + *result = *first1; + ++first1; + ++result; + } + + while (first2 != last2) + { + *result = *first2; + ++first2; + ++result; + } + + return result; + } + + template _UCXXEXPORT + void inplace_merge(BidirectionalIterator first, + BidirectionalIterator middle, BidirectionalIterator last) + { + less::value_type> c; + inplace_merge(first, middle, last, c); + } + + template _UCXXEXPORT + void inplace_merge(BidirectionalIterator first, + BidirectionalIterator middle, BidirectionalIterator last, Compare comp) + { + //FIXME - using a bubble exchange method + + while (first != middle && middle !=last) + { + if (comp(*middle, *first)) + { + BidirectionalIterator temp(middle); + while (temp != first) + { + iter_swap(temp, temp-1); + --temp; + } + + ++middle; + } + + ++first; + } + } + + // _lib.alg.set.operations_, set operations: + + template _UCXXEXPORT + bool includes(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2) + { + less::value_type> c; + return includes(first1, last1, first2, last2, c); + } + + template _UCXXEXPORT + bool includes(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp) + { + while (first2 != last2) + { + //Advance the large set until no longer smaller than the element we are looking for + + while (comp(*first1, *first2)) + { + ++first1; + + // If we are at the end of the list, we don't have the desired element + + if (first1 == last1) + { + return false; + } + } + + // If we are past the element we want, it isn't here + + if (comp(*first2, *first1)) + { + return false; + } + + ++first2; //Move to next element + } + + return true; + } + + template _UCXXEXPORT + OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result) + { + less::value_type> c; + return set_union(first1, last1, first2, last2, result, c); + } + + template _UCXXEXPORT + OutputIterator set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + if (comp(*first2, *first1)) + { + *result = *first2; + + // Eliminate duplicates + + InputIterator2 temp = first2; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + else + { + *result = *first1; + + // Eliminate duplicates + + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + ++result; + } + + // Clean up remaining elements + + while (first1 != last1) + { + *result = *first1; + ++result; + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + } + + while (first2 != last2) + { + *result = *first2; + ++result; + InputIterator2 temp = first2; + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + + return result; + } + + template _UCXXEXPORT + OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result) + { + less::value_type> c; + return set_intersection(first1, last1, first2, last2, result, c); + } + + template _UCXXEXPORT + OutputIterator set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + if (comp(*first2, *first1)) + { + ++first2; + } + else if (comp(*first1, *first2)) + { + ++first1; + } + else + { + *result = *first1; + ++result; + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + + ++first2; + } + } + + return result; + } + + template _UCXXEXPORT + OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result) + { + less::value_type> c; + return set_difference(first1, last1, first2, last2, result, c); + } + + template _UCXXEXPORT + OutputIterator set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + if (comp(*first1, *first2)) + { + *result = *first1; + ++result; + + // Eliminate duplicates + + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + } + else if (comp(*first2, *first1)) + { + // Eliminate duplicates + + InputIterator2 temp = first2; + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + + } + else + { + //They are identical - skip + // Eliminate duplicates + + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + } + + // Clean up remaining elements + + while (first1 != last1) + { + *result = *first1; + ++result; + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + } + + return result; + } + + template _UCXXEXPORT + OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result) + { + less::value_type> c; + return set_symmetric_difference(first1, last1, first2, last2, result, c); + } + + template _UCXXEXPORT + OutputIterator set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + if (comp(*first1, *first2)) + { + *result = *first1; + ++result; + + // Eliminate duplicates + + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + } + else if (comp(*first2, *first1)) + { + *result = *first2; + ++result; + + // Eliminate duplicates + + InputIterator2 temp = first2; + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + + } + else + { + //They are identical - skip + // Eliminate duplicates + + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + } + + // Clean up remaining elements + + while (first1 != last1) + { + *result = *first1; + ++result; + InputIterator1 temp = first1; + while (first1 != last1 && !comp(*temp, *first1)) + { + ++first1; + } + } + + while (first2 != last2) + { + *result = *first2; + ++result; + InputIterator2 temp = first2; + while (first2 != last2 && !comp(*temp, *first2)) + { + ++first2; + } + } + + return result; + } + + // _lib.alg.heap.operations_, heap operations: + + template _UCXXEXPORT + void push_heap(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + push_heap(first, last, c); + } + + template _UCXXEXPORT + void push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + // *(last - 1) is the last element + + RandomAccessIterator begin, middle, end; + begin = first; + end = last - 2; + + if (last - first < 2) + { + //Empty heap + + return; + } + + if (comp(*(last-1), *end)) + { + //Belongs past the end - already in place + + return; + } + + while (end - begin > 1) + { + middle = begin + ((end - begin)/2); + if (comp(*middle, *(last-1))) + { + end = middle; + } + else + { + begin = middle; + } + } + + if (comp(*begin, *(last-1))) + { + middle = begin; + } + else + { + middle = end; + } + + // Now all we do is swap the elements up to the begining + + --last; + + while (last > middle) + { + iter_swap(last, last-1); + --last; + } + } + + template _UCXXEXPORT + void pop_heap(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + pop_heap(first, last, c); + } + + template _UCXXEXPORT + void pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare) + { + --last; + while (first < last) + { + iter_swap(first, first+1); + ++first; + } + } + + template _UCXXEXPORT + void make_heap(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + make_heap(first, last, c); + } + + template _UCXXEXPORT + void make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + sort(reverse_iterator(last), reverse_iterator(first), comp); + } + + template _UCXXEXPORT + void sort_heap(RandomAccessIterator first, RandomAccessIterator last) + { + less::value_type> c; + sort_heap(first, last, c); + } + + template _UCXXEXPORT + void sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + sort(first, last, comp); + } + + // _lib.alg.min.max_, minimum and maximum: + + template _UCXXEXPORT + const T& min(const T& a, const T& b) + { + if (b < a) + { + return b; + } + + return a; + } + + template _UCXXEXPORT + const T& min(const T& a, const T& b, Compare comp) + { + if (comp(b, a) == true) + { + return b; + } + + return a; + } + + template _UCXXEXPORT + const T& max(const T& a, const T& b) + { + if (a < b) + { + return b; + } + + return a; + } + + template _UCXXEXPORT + const T& max(const T& a, const T& b, Compare comp) + { + if (comp(a, b)) + { + return b; + } + + return a; + } + + template _UCXXEXPORT + ForwardIterator min_element(ForwardIterator first, ForwardIterator last) + { + less::value_type> c; + return min_element(first, last, c); + } + + template _UCXXEXPORT + ForwardIterator min_element(ForwardIterator first, ForwardIterator last, Compare comp) + { + ForwardIterator retval = first; + ++first; + while (first != last) + { + if (comp(*first, *retval)) + { + retval = first; + } + + ++first; + } + + return retval; + } + + template _UCXXEXPORT + ForwardIterator max_element(ForwardIterator first, ForwardIterator last) + { + less::value_type> c; + return max_element(first, last, c); + } + + template _UCXXEXPORT + ForwardIterator max_element(ForwardIterator first, ForwardIterator last, Compare comp) + { + ForwardIterator retval = first; + ++first; + while (first != last) + { + if (comp(*retval, *first)) + { + retval = first; + } + + ++first; + } + + return retval; + } + + template _UCXXEXPORT + bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2) + { + less::value_type> c; + return lexicographical_compare(first1, last1, first2, last2, c); + } + + template _UCXXEXPORT + bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp) + { + while (first1 != last1 && first2 != last2) + { + if (comp(*first1, *first2)) + { + return true; + } + + if (comp(*first2, *first1)) + { + return false; + } + + ++first1; + ++first2; + } + + return first1 == last1 && first2 != last2; + } + + // _lib.alg.permutation.generators_, permutations + + template _UCXXEXPORT + bool next_permutation(BidirectionalIterator first, BidirectionalIterator last) + { + less::value_type> c; + return next_permutation(first, last, c); + } + + template _UCXXEXPORT + bool next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp) + { + if (first == last) + { + return false; // No data + } + + BidirectionalIterator i = last; + --i; + if (i == first) + { + return false; //Only one element + } + + BidirectionalIterator ii = i; + --ii; + + // If the last two items are in order, swap them and call it done + + if (comp(*ii, *i)) + { + iter_swap(ii, i); + return true; + } + + // This part of the algorithm copied from G++ header files ver. 3.4.2 + + i = last; + --i; + for (;;) + { + ii = i; + --i; + if (comp(*i, *ii)) + { + BidirectionalIterator j = last; + --j; + while (!comp(*i, *j)) + { + --j; + } + + iter_swap(i, j); + reverse(ii, last); + return true; + } + + if (i == first) + { + reverse(first, last); + return false; + } + } + } + + template _UCXXEXPORT + bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last) + { + less::value_type> c; + return prev_permutation(first, last, c); + } + + template _UCXXEXPORT + bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp) + { + if (first == last) + { + return false; // No data + } + + BidirectionalIterator i = last; + --i; + if (i == first) + { + return false; //Only one element + } + + BidirectionalIterator ii = i; + --ii; + + // If the last two items are in reverse order, swap them and call it done + + if (comp(*i, *ii)) + { + iter_swap(ii, i); + return true; + } + + // Copied from GNU GCC header files version 3.4.2 + + i = last; + --i; + + for (;;) + { + ii = i; + --i; + if (comp(*ii, *i)) + { + BidirectionalIterator j = last; + --j; + while (!comp(*j, *i)) + { + --j; + } + + iter_swap(i, j); + reverse(ii, last); + return true; + } + + if (i == first) + { + reverse(first, last); + return false; + } + } + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/associative_base b/misc/uClibc++/include/uClibc++/associative_base index 27ae0ef9f8..67122691b3 100644 --- a/misc/uClibc++/include/uClibc++/associative_base +++ b/misc/uClibc++/include/uClibc++/associative_base @@ -1,47 +1,46 @@ -/* Copyright (C) 2007 Garrett A. Kajmowicz - This file is part of the uClibc++ Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - - - -#include -#include -#include -#include -#include +/* Copyright (C) 2007 Garrett A. Kajmowicz + * This file is part of the uClibc++ Library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include +#include +#include +#include +#include #ifndef __STD_HEADER_ASSOCIATIVE_BASE #define __STD_HEADER_ASSOCIATIVE_BASE #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ -/* - * The basic premise here is that most of the code used by map, multimap, set and - * multiset is really common. There are a number of interface additions, and - * considerations about how to address multiple entries with the same key. - * The goal is that the tree/storage code should be here, and managing - * single or multiple counts will be left to subclasses. - * Yes, inheritence for the purpose of code sharing is usually a bad idea. - * However, since our goal is to reduce the total amount of code written - * and the overall binary size, this seems to be the best approach possible. +/* The basic premise here is that most of the code used by map, multimap, set and + * multiset is really common. There are a number of interface additions, and + * considerations about how to address multiple entries with the same key. + * The goal is that the tree/storage code should be here, and managing + * single or multiple counts will be left to subclasses. + * Yes, inheritence for the purpose of code sharing is usually a bad idea. + * However, since our goal is to reduce the total amount of code written + * and the overall binary size, this seems to be the best approach possible. */ template, class Allocator = allocator > class __base_associative; @@ -56,585 +55,712 @@ template class _UCXX protected: public: - typedef Key key_type; - typedef ValueType value_type; - typedef Compare key_compare; - typedef Allocator allocator_type; - typedef typename Allocator::reference reference; - typedef typename Allocator::const_reference const_reference; - typedef typename Allocator::size_type size_type; - typedef typename Allocator::difference_type difference_type; - typedef typename Allocator::pointer pointer; - typedef typename Allocator::const_pointer const_pointer; - typedef __base_associative associative_type; + typedef Key key_type; + typedef ValueType value_type; + typedef Compare key_compare; + typedef Allocator allocator_type; + typedef typename Allocator::reference reference; + typedef typename Allocator::const_reference const_reference; + typedef typename Allocator::size_type size_type; + typedef typename Allocator::difference_type difference_type; + typedef typename Allocator::pointer pointer; + typedef typename Allocator::const_pointer const_pointer; + typedef __base_associative associative_type; - typedef _associative_iter iterator; - typedef _associative_citer const_iterator; - typedef typename std::reverse_iterator reverse_iterator; - typedef typename std::reverse_iterator const_reverse_iterator; + typedef _associative_iter iterator; + typedef _associative_citer const_iterator; + typedef typename std::reverse_iterator reverse_iterator; + typedef typename std::reverse_iterator const_reverse_iterator; + explicit __base_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) + : c(comp), value_to_key(v_to_k) { } - explicit __base_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) - : c(comp), value_to_key(v_to_k) { } protected: - __base_associative(const associative_type& x) - : c(x.c), backing(x.backing), value_to_key(x.value_to_key) { } + __base_associative(const associative_type& x) + : c(x.c), backing(x.backing), value_to_key(x.value_to_key) { } public: - ~__base_associative(){ - } + ~__base_associative() + { + } - bool empty() const{ - return backing.empty(); - } - size_type size() const{ - return backing.size(); - } - size_type max_size() const{ - return backing.max_size(); - } + bool empty() const + { + return backing.empty(); + } - iterator begin(){ - return iterator(backing.begin()); - } + size_type size() const + { + return backing.size(); + } - const_iterator begin() const{ - return const_iterator(backing.begin()); - } + size_type max_size() const + { + return backing.max_size(); + } - iterator end() { - return iterator(backing.end()); - } + iterator begin() + { + return iterator(backing.begin()); + } - const_iterator end() const{ - return const_iterator(backing.end()); - } + const_iterator begin() const + { + return const_iterator(backing.begin()); + } - reverse_iterator rbegin(){ - return reverse_iterator(end()); - } + iterator end() + { + return iterator(backing.end()); + } - const_reverse_iterator rbegin() const{ - return const_reverse_iterator(end()); - } + const_iterator end() const + { + return const_iterator(backing.end()); + } - reverse_iterator rend(){ - return reverse_iterator(begin()); - } + reverse_iterator rbegin() + { + return reverse_iterator(end()); + } - const_reverse_iterator rend() const{ - return const_reverse_iterator(begin()); - } + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end()); + } + reverse_iterator rend() + { + return reverse_iterator(begin()); + } - iterator lower_bound(const key_type &x); - const_iterator lower_bound(const key_type &x) const; - iterator upper_bound(const key_type &x); - const_iterator upper_bound(const key_type &x) const; + const_reverse_iterator rend() const + { + return const_reverse_iterator(begin()); + } - pair equal_range(const key_type& x){ - pair retval; - retval.first = lower_bound(x); - retval.second = retval.first; - while(retval.second != end() && !c(x, value_to_key(*retval.second))){ - ++retval.second; - } - return retval; - } - pair equal_range(const key_type& x) const{ - pair retval; - retval.first = lower_bound(x); - retval.second = retval.first; - while(retval.second != end() && !c(x, value_to_key(*retval.second))){ - ++retval.second; - } - return retval; - } + iterator lower_bound(const key_type &x); + const_iterator lower_bound(const key_type &x) const; + iterator upper_bound(const key_type &x); + const_iterator upper_bound(const key_type &x) const; - iterator find(const key_type& x){ - iterator retval = lower_bound(x); - if(retval == end()){ - return retval; - } - if(c(x, value_to_key(*retval))){ - return end(); - } - return retval; - } - const_iterator find(const key_type& x) const{ - const_iterator retval = lower_bound(x); - if(retval == end()){ - return retval; - } - if(c(x, value_to_key(*retval))){ - return end(); - } - return retval; - } - size_type count(const key_type& x) const{ - size_type retval(0); - const_iterator first = lower_bound(x); - while(first != end() && !c(x, value_to_key(*first))){ - ++retval; - ++first; - } - return retval; - } + pair equal_range(const key_type& x) + { + pair retval; + retval.first = lower_bound(x); + retval.second = retval.first; + while (retval.second != end() && !c(x, value_to_key(*retval.second))) + { + ++retval.second; + } - void clear(){ - backing.clear(); - } + return retval; + } - void erase(iterator pos){ - backing.erase(pos.base_iterator()); - } - size_type erase(const key_type& x){ - size_type count(0); - iterator start = lower_bound(x); - iterator end = upper_bound(x); - while(start != end){ - start = backing.erase(start.base_iterator()); - ++count; - } - return count; - } - void erase(iterator first, iterator last){ - while(first != last){ - backing.erase(first.base_iterator()); - ++first; - } - } + pair equal_range(const key_type& x) const + { + pair retval; + retval.first = lower_bound(x); + retval.second = retval.first; + while (retval.second != end() && !c(x, value_to_key(*retval.second))) + { + ++retval.second; + } - key_compare key_comp() const{ - return c; - } + return retval; + } - __base_associative &operator=(const __base_associative & x){ - c = x.c; - backing = x.backing; - value_to_key = x.value_to_key; - return *this; - } - bool operator==(const __base_associative & x){ - return x.backing == backing; - } - bool operator!=(const __base_associative & x){ - return !(x.backing == backing); - } + iterator find(const key_type& x) + { + iterator retval = lower_bound(x); + if (retval == end()) + { + return retval; + } + + if (c(x, value_to_key(*retval))) + { + return end(); + } + + return retval; + } + + const_iterator find(const key_type& x) const + { + const_iterator retval = lower_bound(x); + if (retval == end()) + { + return retval; + } + + if (c(x, value_to_key(*retval))) + { + return end(); + } + + return retval; + } + + size_type count(const key_type& x) const + { + size_type retval(0); + const_iterator first = lower_bound(x); + while (first != end() && !c(x, value_to_key(*first))) + { + ++retval; + ++first; + } + + return retval; + } + + void clear() + { + backing.clear(); + } + + void erase(iterator pos) + { + backing.erase(pos.base_iterator()); + } + + size_type erase(const key_type& x) + { + size_type count(0); + iterator start = lower_bound(x); + iterator end = upper_bound(x); + while (start != end) + { + start = backing.erase(start.base_iterator()); + ++count; + } + + return count; + } + + void erase(iterator first, iterator last) + { + while (first != last) + { + backing.erase(first.base_iterator()); + ++first; + } + } + + key_compare key_comp() const + { + return c; + } + + __base_associative &operator=(const __base_associative & x) + { + c = x.c; + backing = x.backing; + value_to_key = x.value_to_key; + return *this; + } + + bool operator==(const __base_associative & x) + { + return x.backing == backing; + } + + bool operator!=(const __base_associative & x) + { + return !(x.backing == backing); + } protected: - void swap(__base_associative & x); + void swap(__base_associative & x); - Compare c; - std::list backing; - - const key_type (*value_to_key)(const value_type); + Compare c; + std::list backing; + const key_type (*value_to_key)(const value_type); }; - -/* - * Tree iterators for the base associative class - */ +/* Tree iterators for the base associative class */ template class _associative_citer - : public std::iterator< - bidirectional_iterator_tag, - ValueType, - typename Allocator::difference_type, - ValueType*, - ValueType& - > + : public std::iterator< + bidirectional_iterator_tag, + ValueType, + typename Allocator::difference_type, + ValueType*, + ValueType& + > { protected: - typedef std::list listtype; + typedef std::list listtype; + + typename listtype::const_iterator base_iter; + friend class _associative_iter; - typename listtype::const_iterator base_iter; - friend class _associative_iter; public: - _associative_citer() { } - _associative_citer(const _associative_citer & m) - : base_iter(m.base_iter) { } - _associative_citer(const typename listtype::const_iterator & m) - : base_iter(m) { } - ~_associative_citer() { } - ValueType operator*() const{ - return *base_iter; - } - const ValueType * operator->() const{ - return &(*base_iter); - } - _associative_citer & operator=(const _associative_citer & m){ - base_iter = m.base_iter; - return *this; - } - bool operator==(const _associative_citer & m) const{ - return m.base_iter == base_iter; - } - bool operator!=(const _associative_citer & m) const{ - return m.base_iter != base_iter; - } - _associative_citer & operator++(){ - ++base_iter; - return *this; - } - _associative_citer operator++(int){ - //The following approach ensures that we only need to - //provide code for ++ in one place (above) - _associative_citer temp(base_iter); - ++base_iter; - return temp; - } - _associative_citer & operator--(){ - --base_iter; - return *this; - } - _associative_citer operator--(int){ - //The following approach ensures that we only need to - //provide code for -- in one place (above) - _associative_citer temp(base_iter); - --base_iter; - return temp; - } + _associative_citer() { } + _associative_citer(const _associative_citer & m) + : base_iter(m.base_iter) { } + _associative_citer(const typename listtype::const_iterator & m) + : base_iter(m) { } + ~_associative_citer() { } - //This is an implementation-defined function designed to make internals work correctly - typename listtype::const_iterator base_iterator(){ - return base_iter; - } + ValueType operator*() const + { + return *base_iter; + } + + const ValueType * operator->() const + { + return &(*base_iter); + } + + _associative_citer & operator=(const _associative_citer & m) + { + base_iter = m.base_iter; + return *this; + } + + bool operator==(const _associative_citer & m) const + { + return m.base_iter == base_iter; + } + + bool operator!=(const _associative_citer & m) const{ + return m.base_iter != base_iter; + } + + _associative_citer & operator++() + { + ++base_iter; + return *this; + } + + _associative_citer operator++(int) + { + // The following approach ensures that we only need to + // provide code for ++ in one place (above) + + _associative_citer temp(base_iter); + ++base_iter; + return temp; + } + + _associative_citer & operator--() + { + --base_iter; + return *this; + } + + _associative_citer operator--(int) + { + // The following approach ensures that we only need to + // provide code for -- in one place (above) + + _associative_citer temp(base_iter); + --base_iter; + return temp; + } + + // This is an implementation-defined function designed to make internals work correctly + + typename listtype::const_iterator base_iterator() + { + return base_iter; + } }; - template class _associative_iter - : public std::iterator< - bidirectional_iterator_tag, - ValueType, - typename Allocator::difference_type, - ValueType*, - ValueType& - > + : public std::iterator< + bidirectional_iterator_tag, + ValueType, + typename Allocator::difference_type, + ValueType*, + ValueType& + > { protected: - typedef std::list listtype; + typedef std::list listtype; - typename listtype::iterator base_iter; - typedef _associative_citer __associative_citer; + typename listtype::iterator base_iter; + typedef _associative_citer __associative_citer; public: - _associative_iter() { } - _associative_iter(const _associative_iter & m) - : base_iter(m.base_iter) { } - _associative_iter(const typename listtype::iterator & m) - : base_iter(m) { } - ~_associative_iter() { } - const ValueType & operator*() const{ - return *base_iter; - } - ValueType & operator*(){ - return *base_iter; - } - ValueType * operator->(){ - return &(*base_iter); - } - const ValueType * operator->() const{ - return &(*base_iter); - } - _associative_iter & operator=(const _associative_iter & m){ - base_iter = m.base_iter; - return *this; - } - bool operator==(const _associative_iter & m) const{ - return m.base_iter == base_iter; - } - bool operator==(const __associative_citer & m) const{ - return m.base_iter == base_iter; - } - bool operator!=(const _associative_iter & m) const{ - return m.base_iter != base_iter; - } - bool operator!=(const __associative_citer & m) const{ - return m.base_iter != base_iter; - } - _associative_iter & operator++(){ - ++base_iter; - return *this; - } - _associative_iter operator++(int){ - //The following approach ensures that we only need to - //provide code for ++ in one place (above) - _associative_iter temp(base_iter); - ++base_iter; - return temp; - } - _associative_iter & operator--(){ - --base_iter; - return *this; - } - _associative_iter operator--(int){ - //The following approach ensures that we only need to - //provide code for -- in one place (above) - _associative_iter temp(base_iter); - --base_iter; - return temp; - } - operator __associative_citer() const{ - return __associative_citer(base_iter); - } - typename listtype::iterator base_iterator(){ - return base_iter; - } - const typename listtype::iterator base_iterator() const{ - return base_iter; - } + _associative_iter() { } + _associative_iter(const _associative_iter & m) + : base_iter(m.base_iter) { } + _associative_iter(const typename listtype::iterator & m) + : base_iter(m) { } + ~_associative_iter() { } + const ValueType & operator*() const + { + return *base_iter; + } + + ValueType & operator*() + { + return *base_iter; + } + + ValueType * operator->() + { + return &(*base_iter); + } + + const ValueType * operator->() const + { + return &(*base_iter); + } + + _associative_iter & operator=(const _associative_iter & m) + { + base_iter = m.base_iter; + return *this; + } + + bool operator==(const _associative_iter & m) const + { + return m.base_iter == base_iter; + } + + bool operator==(const __associative_citer & m) const + { + return m.base_iter == base_iter; + } + + bool operator!=(const _associative_iter & m) const + { + return m.base_iter != base_iter; + } + + bool operator!=(const __associative_citer & m) const + { + return m.base_iter != base_iter; + } + + _associative_iter & operator++() + { + ++base_iter; + return *this; + } + + _associative_iter operator++(int) + { + // The following approach ensures that we only need to + // provide code for ++ in one place (above) + + _associative_iter temp(base_iter); + ++base_iter; + return temp; + } + + _associative_iter & operator--() + { + --base_iter; + return *this; + } + + _associative_iter operator--(int) + { + // The following approach ensures that we only need to + // provide code for -- in one place (above) + + _associative_iter temp(base_iter); + --base_iter; + return temp; + } + + operator __associative_citer() const + { + return __associative_citer(base_iter); + } + + typename listtype::iterator base_iterator() + { + return base_iter; + } + + const typename listtype::iterator base_iterator() const + { + return base_iter; + } }; - - // The lower_bound code is really crappy linear search. However, it is a dead - // simple implementation (easy to audit). It can also be easily replaced. + // The lower_bound code is really crappy linear search. However, it is a dead + // simple implementation (easy to audit). It can also be easily replaced. - template - typename __base_associative::iterator - __base_associative::lower_bound(const key_type &x) - { - iterator retval = begin(); - while(retval != end() && c(value_to_key(*retval), x)){ - ++retval; - } - return retval; - } + template + typename __base_associative::iterator + __base_associative::lower_bound(const key_type &x) + { + iterator retval = begin(); + while (retval != end() && c(value_to_key(*retval), x)) + { + ++retval; + } - template - typename __base_associative::const_iterator - __base_associative::lower_bound(const key_type &x) const - { - const_iterator retval = begin(); - while(retval != end() && c(value_to_key(*retval), x)){ - ++retval; - } - return retval; - } + return retval; + } - // Upper bound search is linear from the point of lower_bound. This is likely the best solution - // in all but the most pathological of cases. + template + typename __base_associative::const_iterator + __base_associative::lower_bound(const key_type &x) const + { + const_iterator retval = begin(); + while (retval != end() && c(value_to_key(*retval), x)) + { + ++retval; + } - template - typename __base_associative::iterator - __base_associative::upper_bound(const key_type &x) - { - iterator retval = lower_bound(x); - while(retval != end() && !c(x, value_to_key(*retval))){ - ++retval; - } - return retval; - } + return retval; + } - template - typename __base_associative::const_iterator - __base_associative::upper_bound(const key_type &x) const - { - const_iterator retval = begin(); - while(retval != end() && !c(x, value_to_key(*retval))){ - ++retval; - } - return retval; - } + // Upper bound search is linear from the point of lower_bound. This is likely the best solution + // in all but the most pathological of cases. + template + typename __base_associative::iterator + __base_associative::upper_bound(const key_type &x) + { + iterator retval = lower_bound(x); + while (retval != end() && !c(x, value_to_key(*retval))) + { + ++retval; + } - template - void __base_associative::swap(__base_associative& m) - { - Compare n = c; - c = m.c; - m.c = n; + return retval; + } - m.backing.swap(backing); - } + template + typename __base_associative::const_iterator + __base_associative::upper_bound(const key_type &x) const + { + const_iterator retval = begin(); + while (retval != end() && !c(x, value_to_key(*retval))) + { + ++retval; + } + return retval; + } + + template + void __base_associative::swap(__base_associative& m) + { + Compare n = c; + c = m.c; + m.c = n; + + m.backing.swap(backing); + } template class _UCXXEXPORT __single_associative : - public __base_associative + public __base_associative { protected: - typedef __base_associative base; - using base::backing; + typedef __base_associative base; + using base::backing; - using base::c; + using base::c; public: - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - using base::begin; - using base::end; - using base::rbegin; - using base::rend; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::empty; - using base::size; - using base::max_size; + using base::empty; + using base::size; + using base::max_size; - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; - using base::operator=; - using base::operator==; - using base::operator!=; + using base::operator=; + using base::operator==; + using base::operator!=; - explicit __single_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) - : base(comp, A, v_to_k) { } + explicit __single_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) + : base(comp, A, v_to_k) { } - template __single_associative( - InputIterator first, - InputIterator last, - const Compare& comp, - const Allocator& A, - const key_type (*v_to_k)(const value_type) - ) : base(comp, A, v_to_k) { - insert(first, last); - } + template __single_associative( + InputIterator first, + InputIterator last, + const Compare& comp, + const Allocator& A, + const key_type (*v_to_k)(const value_type) + ) : base(comp, A, v_to_k) + { + insert(first, last); + } - pair insert(const value_type& x){ - pair retval; - iterator location = lower_bound(this->value_to_key(x)); - retval.second = true; - //Empty list or need to insert at end - if(end() == location){ - backing.push_back(x); - retval.first = --(end()); - return retval; - } - //Something in the list - if(c(this->value_to_key(x), this->value_to_key(*location))){ - location = backing.insert(location.base_iterator(), x); - retval.first = location; - }else{ - retval.second = false; - retval.first = location; - } - return retval; - } + pair insert(const value_type& x) + { + pair retval; + iterator location = lower_bound(this->value_to_key(x)); + retval.second = true; - iterator insert(iterator position, const value_type& x){ - // FIXME - this is cheating and probably should be more efficient since we are - // now log(n) to find for inserts - return insert(x).first; - } + // Empty list or need to insert at end - template void insert(InputIterator first, InputIterator last){ - while(first != last){ - insert(*first); - ++first; - } - } + if (end() == location) + { + backing.push_back(x); + retval.first = --(end()); + return retval; + } + // Something in the list + + if (c(this->value_to_key(x), this->value_to_key(*location))) + { + location = backing.insert(location.base_iterator(), x); + retval.first = location; + } + else + { + retval.second = false; + retval.first = location; + } + + return retval; + } + + iterator insert(iterator position, const value_type& x) + { + // FIXME - this is cheating and probably should be more efficient since we are + // now log(n) to find for inserts + + return insert(x).first; + } + + template void insert(InputIterator first, InputIterator last) + { + while (first != last) + { + insert(*first); + ++first; + } + } }; template class _UCXXEXPORT __multi_associative : - public __base_associative + public __base_associative { protected: - typedef __base_associative base; - using base::backing; + typedef __base_associative base; + using base::backing; - using base::c; + using base::c; public: - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - using base::begin; - using base::end; - using base::rbegin; - using base::rend; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::empty; - using base::size; - using base::max_size; + using base::empty; + using base::size; + using base::max_size; - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; - using base::operator=; - using base::operator==; + using base::operator=; + using base::operator==; - explicit __multi_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) - : base(comp, A, v_to_k) { } + explicit __multi_associative(const Compare& comp, const Allocator& A, const key_type (*v_to_k)(const value_type)) + : base(comp, A, v_to_k) { } - template __multi_associative( - InputIterator first, - InputIterator last, - const Compare& comp, - const Allocator& A, - const key_type (*v_to_k)(const value_type) - ) : base(comp, A, v_to_k) { - insert(first, last); - } + template __multi_associative( + InputIterator first, + InputIterator last, + const Compare& comp, + const Allocator& A, + const key_type (*v_to_k)(const value_type) + ) : base(comp, A, v_to_k) + { + insert(first, last); + } - iterator insert(const value_type& x){ - iterator location = lower_bound(this->value_to_key(x)); + iterator insert(const value_type& x) + { + iterator location = lower_bound(this->value_to_key(x)); - if(location == begin()){ - backing.push_front(x); - location = begin(); - }else{ - location = backing.insert(location.base_iterator(), x); - } - return location; - } + if (location == begin()) + { + backing.push_front(x); + location = begin(); + } + else + { + location = backing.insert(location.base_iterator(), x); + } - iterator insert(iterator position, const value_type& x){ - // FIXME - this is cheating and probably should be more efficient since we are - // now log(n) to find for inserts - return insert(x); - } + return location; + } - template void insert(InputIterator first, InputIterator last){ - while(first != last){ - insert(*first); - ++first; - } - } + iterator insert(iterator position, const value_type& x) + { + // FIXME - this is cheating and probably should be more efficient since we are + // now log(n) to find for inserts + + return insert(x); + } + + template void insert(InputIterator first, InputIterator last) + { + while (first != last) + { + insert(*first); + ++first; + } + } }; - - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop -#endif //__STD_HEADER_ASSOCIATIVE_BASE +#endif //__STD_HEADER_ASSOCIATIVE_BASE diff --git a/misc/uClibc++/include/uClibc++/bitset b/misc/uClibc++/include/uClibc++/bitset index 50d540469a..92243b208f 100644 --- a/misc/uClibc++/include/uClibc++/bitset +++ b/misc/uClibc++/include/uClibc++/bitset @@ -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 #include @@ -29,395 +29,551 @@ #pragma GCC visibility push(default) -namespace std{ - template class bitset; +extern "C++" +{ +namespace std +{ + template class bitset; + template bitset operator&(const bitset&, const bitset&); + template bitset operator|(const bitset&, const bitset&); + template bitset operator^(const bitset&, const bitset&); + template basic_istream& + operator>>(basic_istream& is, bitset& x); - template bitset operator&(const bitset&, const bitset&); - template bitset operator|(const bitset&, const bitset&); - template bitset operator^(const bitset&, const bitset&); - template basic_istream& - operator>>(basic_istream& is, bitset& x); + template basic_ostream& + operator<<(basic_ostream& os, const bitset& x); + + // Actual Code - template basic_ostream& - operator<<(basic_ostream& os, const bitset& x); - - //Actual Code + template class _UCXXEXPORT bitset { + private: + //Number of characters allocated to hold the bits + static const size_t WORD_SIZE = CHAR_BIT; //Use int maybe? + static const size_t num_bytes = (N + WORD_SIZE - 1) / WORD_SIZE; - template class _UCXXEXPORT bitset { - private: - //Number of characters allocated to hold the bits - static const size_t WORD_SIZE = CHAR_BIT; //Use int maybe? - static const size_t num_bytes = (N + WORD_SIZE - 1) / WORD_SIZE; + //From the bit number, figure out which byte we are working with - //From the bit number, figure out which byte we are working with - size_t byte_num(size_t bit_num) const{ - if(WORD_SIZE == 8){ - return (bit_num >> 3); - } - if(WORD_SIZE == 16){ - return (bit_num >> 4); - } - if(WORD_SIZE == 32){ - return (bit_num >> 5); - } - if(WORD_SIZE == 64){ - return (bit_num >> 6); - } - return bit_num / WORD_SIZE; - } - //From the bit number, figure out which bit inside the byte we need - size_t bit_num(const size_t bit_num) const{ - return bit_num % WORD_SIZE; - } + size_t byte_num(size_t bit_num) const + { + if (WORD_SIZE == 8) + { + return (bit_num >> 3); + } + if (WORD_SIZE == 16) + { + return (bit_num >> 4); + } - //Point to the actual data - char data[num_bytes]; - public: + if (WORD_SIZE == 32) + { + return (bit_num >> 5); + } - class _UCXXEXPORT reference { - friend class bitset; - reference() : bit_num(0), parent(0) { } - size_t bit_num; - bitset * parent; - public: - ~reference() { } - reference& operator=(bool x){ // for b[i] = x; - parent->set(bit_num, x); - return *this; - } - reference& operator=(const reference& x){ // for b[i] = b[j]; - parent->set(bit_num, x); - return *this; - } - bool operator~() const{ // flips the bit - return !parent->test(bit_num); - } - operator bool() const{ // for x = b[i]; - return parent->test(bit_num); - } - reference& flip(){ // for b[i].flip(); - parent->flip(bit_num); - return *this; - } - }; + if (WORD_SIZE == 64) + { + return (bit_num >> 6); + } - bitset(){ - reset(); - } - bitset(unsigned long val){ - reset(); - size_t count = sizeof(val) * CHAR_BIT; - if(count > N){ - count = N; - } - for(size_t i = 0; i < count; ++i){ - set(i, ((val >> i) & 1)); - } - } + return bit_num / WORD_SIZE; + } - bitset(const bitset & val){ - for(size_t i = 0; i < num_bytes; ++i){ - data[i] = val.data[i]; - } - } + // From the bit number, figure out which bit inside the byte we need - template _UCXXEXPORT - explicit bitset( - const basic_string& str, - typename basic_string::size_type pos = 0, - typename basic_string::size_type n = - basic_string::npos - - ){ - reset(); - if(n > str.length()){ - n = str.length(); - } - size_t width = n; - if (width + pos > str.length()){ - width = str.length() - pos; - } + size_t bit_num(const size_t bit_num) const + { + return bit_num % WORD_SIZE; + } - for(size_t i = 0; i < width; ++i){ - switch(str[pos + width - i - 1]){ - case '0': - break; - case '1': - set(i); - break; - default: - __throw_invalid_argument(); - } - } - } + //Point to the actual data - bitset& operator&=(const bitset& rhs){ - for(size_t i =0; i < num_bytes; ++i){ - data[i] &= rhs.data[i]; - } - return *this; - } + char data[num_bytes]; - bitset& operator|=(const bitset& rhs){ - for(size_t i =0; i < num_bytes; ++i){ - data[i] |= rhs.data[i]; - } - return *this; - } - bitset& operator^=(const bitset& rhs){ - for(size_t i=0; i < num_bytes; ++i){ - data[i] ^= rhs.data[i]; - } - return *this; - } + public: - bitset& operator<<=(size_t pos){ - for(size_t i = N-1; i >=pos; --i){ - set(i, test(i - pos)); - } - for(size_t i = 0; i < pos; ++i){ - reset(i); - } - return *this; - } + class _UCXXEXPORT reference + { + friend class bitset; + reference() : bit_num(0), parent(0) { } + size_t bit_num; + bitset * parent; + public: + ~reference() { } - bitset& operator>>=(size_t pos){ - for(size_t i = 0; i < (N - pos); ++i){ - set(i, test(i + pos)); - } - for(size_t i = pos; i > 0; --i){ - reset(N - i); - } - return *this; - } + reference& operator=(bool x) + { + // for b[i] = x; - bitset& set(){ - size_t i; - for(i = 0; i < N ; ++i){ - data[byte_num(i)] |= (1<& set(size_t pos, int val = true){ - if(val == true){ - data[byte_num(pos)] |= (1<& reset(){ - for(size_t i = 0; i < num_bytes; ++i){ - data[i] = 0; - } - return *this; - } - bitset& reset(size_t pos){ - data[byte_num(pos)] &= ~(1< operator~() const{ - bitset retval(*this); - retval.flip(); - return retval; - } + parent->set(bit_num, x); + return *this; + } - bitset& flip(){ - for(size_t i = 0; i < num_bytes; ++i){ - data[i] = ~data[i]; - } - return *this; - } - bitset& flip(size_t pos){ - char temp = data[byte_num(pos)] & (1 << bit_num(pos)); - if(temp == 0){ //Bit was 0 - data[byte_num(pos)] |= (1 << bit_num(pos)); - }else{ //Bit was 1 - data[byte_num(pos)] &= ~(1<set(bit_num, x); + return *this; + } - unsigned long to_ulong() const{ - if(N > sizeof(unsigned long) * CHAR_BIT){ - __throw_overflow_error(); - } - unsigned long retval = 0; - size_t count = N; - for(size_t i = count; i > 0; --i){ - if(test(i)){ - retval +=1; - } - retval<<=1; - } - if(test(0)){ - retval +=1; - } - return retval; - } + bool operator~() const + { + // flips the bit - template - basic_string to_string() const - { - basic_string retval; - retval.reserve(N); - for(size_t i = N ; i > 0; --i){ - if(test(i-1) == true){ - retval.append("1"); - }else{ - retval.append("0"); - } - } - return retval; - } + return !parent->test(bit_num); + } + operator bool() const + { + // for x = b[i]; - size_t count() const{ - size_t retval = 0; - for(size_t i =0; i < N; ++i){ - if(test(i)){ - ++retval; - } - } - return retval; - } - size_t size() const{ - return N; - } + return parent->test(bit_num); + } - bitset& operator=(const bitset & rhs){ - if(&rhs == this){ - return *this; - } - for(size_t i = 0; i <= byte_num(N); ++i){ - data[i] = rhs.data[i]; - } - return *this; - } + reference& flip() + { + // for b[i].flip(); + parent->flip(bit_num); + return *this; + } + }; - bool operator==(const bitset& rhs) const{ - for(size_t i =0; i< N; ++i){ - if(test(i) != rhs.test(i)){ - return false; - } - } - return true; - } + bitset() + { + reset(); + } - bool operator!=(const bitset& rhs) const{ - for(size_t i =0; i< N; ++i){ - if(test(i) != rhs.test(i)){ - return true; - } - } - return false; - } + bitset(unsigned long val) + { + reset(); + size_t count = sizeof(val) * CHAR_BIT; + if (count > N) + { + count = N; + } - bool test(size_t pos) const{ - return (data[byte_num(pos)] & (1<> i) & 1)); + } + } - bool any() const{ - for(size_t i = 0; i< N; ++i){ - if(test(i)==true){ - return true; - } - } - return false; - } + bitset(const bitset & val) + { + for (size_t i = 0; i < num_bytes; ++i) + { + data[i] = val.data[i]; + } + } - bool none() const{ - if(any() == true){ - return false; - } - return true; - } + template _UCXXEXPORT + explicit bitset + ( + const basic_string& str, + typename basic_string::size_type pos = 0, + typename basic_string::size_type n = + basic_string::npos + + ) + { + reset(); + if (n > str.length()) + { + n = str.length(); + } - bitset operator<<(size_t pos) const{ - bitset retval(*this); - retval<<=pos; - return retval; - } - bitset operator>>(size_t pos) const{ - bitset retval(*this); - retval>>=pos; - return retval; - } - }; + size_t width = n; + if (width + pos > str.length()) + { + width = str.length() - pos; + } - //Non-member functions + for (size_t i = 0; i < width; ++i) + { + switch (str[pos + width - i - 1]) + { + case '0': + break; + case '1': + set(i); + break; + default: + __throw_invalid_argument(); + } + } + } + bitset& operator&=(const bitset& rhs) + { + for (size_t i =0; i < num_bytes; ++i) + { + data[i] &= rhs.data[i]; + } - template _UCXXEXPORT bitset operator&(const bitset& lhs, const bitset& rhs){ - bitset retval(lhs); - retval &= rhs; - return retval; - } + return *this; + } - template _UCXXEXPORT bitset operator|(const bitset& lhs, const bitset& rhs){ - bitset retval(lhs); - retval |= rhs; - return retval; - } + bitset& operator|=(const bitset& rhs) + { + for (size_t i =0; i < num_bytes; ++i) + { + data[i] |= rhs.data[i]; + } - template _UCXXEXPORT bitset operator^(const bitset& lhs, const bitset& rhs){ - bitset retval(lhs); - retval ^= rhs; - return retval; - } + return *this; + } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, bitset& x) - { - string s; - charT c; - for(size_t i = 0; i < N; ++i){ - is.get(c); - if(!is.good()){ - break; - } - if(c != '1' && c !='0'){ - is.putback(c); - break; - } - s+=c; - } - bitset temp(s); - x = temp; - - return is; - } + bitset& operator^=(const bitset& rhs) + { + for (size_t i=0; i < num_bytes; ++i) + { + data[i] ^= rhs.data[i]; + } - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const bitset& x) - { - for(size_t i = N ; i > 0; --i){ - if(x.test(i-1) == true){ - os << "1"; - }else{ - os << "0"; - } - } - return os; - } + return *this; + } + bitset& operator<<=(size_t pos) + { + for (size_t i = N-1; i >=pos; --i) + { + set(i, test(i - pos)); + } + for (size_t i = 0; i < pos; ++i) + { + reset(i); + } + return *this; + } -} + bitset& operator>>=(size_t pos) + { + for (size_t i = 0; i < (N - pos); ++i) + { + set(i, test(i + pos)); + } + + for (size_t i = pos; i > 0; --i) + { + reset(N - i); + } + + return *this; + } + + bitset& set() + { + size_t i; + for (i = 0; i < N ; ++i) + { + data[byte_num(i)] |= (1<& set(size_t pos, int val = true) + { + if (val == true) + { + data[byte_num(pos)] |= (1<& reset() + { + for (size_t i = 0; i < num_bytes; ++i) + { + data[i] = 0; + } + + return *this; + } + + bitset& reset(size_t pos) + { + data[byte_num(pos)] &= ~(1< operator~() const + { + bitset retval(*this); + retval.flip(); + return retval; + } + + bitset& flip() + { + for (size_t i = 0; i < num_bytes; ++i) + { + data[i] = ~data[i]; + } + + return *this; + } + + bitset& flip(size_t pos) + { + char temp = data[byte_num(pos)] & (1 << bit_num(pos)); + if (temp == 0) + { + // Bit was 0 + + data[byte_num(pos)] |= (1 << bit_num(pos)); + } + else + { + // Bit was 1 + + data[byte_num(pos)] &= ~(1< sizeof(unsigned long) * CHAR_BIT) + { + __throw_overflow_error(); + } + + unsigned long retval = 0; + size_t count = N; + for (size_t i = count; i > 0; --i) + { + if (test(i)) + { + retval +=1; + } + + retval <<= 1; + } + + if (test(0)) + { + retval +=1; + } + + return retval; + } + + template + basic_string to_string() const + { + basic_string retval; + retval.reserve(N); + for (size_t i = N ; i > 0; --i) + { + if (test(i-1) == true) + { + retval.append("1"); + } + else + { + retval.append("0"); + } + } + + return retval; + } + + size_t count() const + { + size_t retval = 0; + for (size_t i =0; i < N; ++i) + { + if (test(i)) + { + ++retval; + } + } + + return retval; + } + + size_t size() const + { + return N; + } + + bitset& operator=(const bitset & rhs) + { + if (&rhs == this) + { + return *this; + } + + for (size_t i = 0; i <= byte_num(N); ++i) + { + data[i] = rhs.data[i]; + } + + return *this; + } + + bool operator==(const bitset& rhs) const + { + for (size_t i =0; i< N; ++i) + { + if (test(i) != rhs.test(i)) + { + return false; + } + } + + return true; + } + + bool operator!=(const bitset& rhs) const + { + for (size_t i =0; i< N; ++i) + { + if (test(i) != rhs.test(i)) + { + return true; + } + } + + return false; + } + + bool test(size_t pos) const + { + return (data[byte_num(pos)] & (1< operator<<(size_t pos) const + { + bitset retval(*this); + retval<<=pos; + return retval; + } + + bitset operator>>(size_t pos) const + { + bitset retval(*this); + retval>>=pos; + return retval; + } + }; + + // Non-member functions + + template _UCXXEXPORT bitset operator&(const bitset& lhs, const bitset& rhs) + { + bitset retval(lhs); + retval &= rhs; + return retval; + } + + template _UCXXEXPORT bitset operator|(const bitset& lhs, const bitset& rhs) + { + bitset retval(lhs); + retval |= rhs; + return retval; + } + + template _UCXXEXPORT bitset operator^(const bitset& lhs, const bitset& rhs) + { + bitset retval(lhs); + retval ^= rhs; + return retval; + } + + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, bitset& x) + { + string s; + charT c; + for (size_t i = 0; i < N; ++i) + { + is.get(c); + if (!is.good()) + { + break; + } + + if (c != '1' && c !='0') + { + is.putback(c); + break; + } + + s += c; + } + + bitset temp(s); + x = temp; + return is; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& os, const bitset& x) + { + for (size_t i = N ; i > 0; --i) + { + if (x.test(i-1) == true) + { + os << "1"; + } + else + { + os << "0"; + } + } + + return os; + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop #endif - diff --git a/misc/uClibc++/include/uClibc++/char_traits b/misc/uClibc++/include/uClibc++/char_traits index d09de41b6d..ec2900ba77 100644 --- a/misc/uClibc++/include/uClibc++/char_traits +++ b/misc/uClibc++/include/uClibc++/char_traits @@ -32,8 +32,7 @@ // POSSIBILITY OF SUCH DAMAGE. // //*************************************************************************** -//#ifndef __INCLUDE_CXX_CHAR1_TRAITS -//#define __INCLUDE_CXX_CHAR1_TRAITS + #include #include #include @@ -47,169 +46,223 @@ #ifndef __HEADER_CHAR_TRAITS #define __HEADER_CHAR_TRAITS 1 -namespace std{ - /* Inlining all wrapped function calls to shrink the amount of code generated*/ - //Typedefs to use for stuff - typedef signed int char_traits_off_type; +extern "C++" +{ - //Generic char_traits - template struct _UCXXEXPORT char_traits { }; +namespace std +{ + /* Inlining all wrapped function calls to shrink the amount of code generated */ + // Typedefs to use for stuff - //Specialize for char - template<> struct _UCXXEXPORT char_traits { - typedef char char_type; - typedef short int int_type; - typedef char_traits_off_type off_type; - typedef char_traits_off_type pos_type; - typedef char state_type; - - inline static void assign(char_type & c, const char_type & d) { c = d; } + typedef signed int char_traits_off_type; - static bool eq(const char_type& c1, const char_type& c2); + // Generic char_traits - static char_type to_char_type(const int_type & i); + template struct _UCXXEXPORT char_traits { }; - inline static int_type to_int_type(const char_type & c){ - return (short int)(unsigned char)c; - } + // Specialize for char - inline static bool eq_int_type(const int_type & a, const int_type & b){ - if(a==b){ - return true; - } - return false; - } + template<> struct _UCXXEXPORT char_traits + { + typedef char char_type; + typedef short int int_type; + typedef char_traits_off_type off_type; + typedef char_traits_off_type pos_type; + typedef char state_type; + + inline static void assign(char_type & c, const char_type & d) { c = d; } + static bool eq(const char_type& c1, const char_type& c2); - inline static bool lt(const char_type& c1, const char_type& c2){ - if(strncmp(&c1, &c2, 1) < 0){ - return true; - } - return false; - } + static char_type to_char_type(const int_type & i); - inline static char_type* move(char_type* s1, const char_type* s2, size_t n){ - return (char*) memmove(s1, s2, n); - } + inline static int_type to_int_type(const char_type & c) + { + return (short int)(unsigned char)c; + } - inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){ - for(unsigned long int i=0; i< n; ++i){ - assign(s1[i], s2[i]); - } - return s1 + n; - } + inline static bool eq_int_type(const int_type & a, const int_type & b) + { + if (a==b) + { + return true; + } - inline static char_type* assign(char_type* s, size_t n, char_type a){ - return (char *)memset(s, a, n); - } + return false; + } - inline static int compare(const char_type* s1, const char_type* s2, size_t n){ - return strncmp(s1, s2, n); - } + inline static bool lt(const char_type& c1, const char_type& c2) + { + if (strncmp(&c1, &c2, 1) < 0) + { + return true; + } - inline static size_t length(const char_type* s){ - return strlen(s); - } + return false; + } - static const char_type* find(const char_type* s, int n, const char_type& a); + inline static char_type* move(char_type* s1, const char_type* s2, size_t n) + { + return (char*) memmove(s1, s2, n); + } - inline static char_type eos() { return 0; } - inline static int_type eof() { return -1; } - inline static int_type not_eof(const int_type & i) { - if(i == -1){ - return 0; - } else { - return i; - } - } - static state_type get_state(pos_type p){ - p = p; - state_type a; - return a; - } - }; + inline static char_type* copy(char_type* s1, const char_type* s2, size_t n) + { + for (unsigned long int i=0; i< n; ++i) + { + assign(s1[i], s2[i]); + } + return s1 + n; + } + + inline static char_type* assign(char_type* s, size_t n, char_type a) + { + return (char *)memset(s, a, n); + } + + inline static int compare(const char_type* s1, const char_type* s2, size_t n) + { + return strncmp(s1, s2, n); + } + + inline static size_t length(const char_type* s) + { + return strlen(s); + } + + static const char_type* find(const char_type* s, int n, const char_type& a); + + inline static char_type eos() { return 0; } + inline static int_type eof() { return -1; } + + inline static int_type not_eof(const int_type & i) + { + if (i == -1) + { + return 0; + } + else + { + return i; + } + } + + static state_type get_state(pos_type p) + { + p = p; + state_type a; + return a; + } + }; #ifdef __UCLIBCXX_HAS_WCHAR__ - template<> struct _UCXXEXPORT char_traits { - typedef wchar_t char_type; - typedef wint_t int_type; - typedef char_traits_off_type off_type; - typedef char_traits_off_type pos_type; - typedef mbstate_t state_type; + template<> struct _UCXXEXPORT char_traits + { + typedef wchar_t char_type; + typedef wint_t int_type; + typedef char_traits_off_type off_type; + typedef char_traits_off_type pos_type; + typedef mbstate_t state_type; - static void assign(char_type & c, const char_type & d){ c=d; } + static void assign(char_type & c, const char_type & d){ c=d; } - static char_type to_char_type(const int_type & i){ - return i; - } + static char_type to_char_type(const int_type & i) + { + return i; + } - static int_type to_int_type(const char_type & c){ - return c; - } + static int_type to_int_type(const char_type & c) + { + return c; + } - inline static bool eq_int_type(const int_type & a, const int_type & b){ - if(a==b){ - return true; - } - return false; - } + inline static bool eq_int_type(const int_type & a, const int_type & b) + { + if (a == b) + { + return true; + } - inline static bool eq(const char_type& c1, const char_type& c2){ - if(wcsncmp(&c1, &c2, 1) == 0){ - return true; - } - return false; - } + return false; + } - inline static bool lt(const char_type& c1, const char_type& c2){ - if(wcsncmp(&c1, &c2, 1) < 0){ - return true; - } - return false; - } + inline static bool eq(const char_type& c1, const char_type& c2) + { + if (wcsncmp(&c1, &c2, 1) == 0) + { + return true; + } - inline static char_type* move(char_type* s1, const char_type* s2, size_t n){ - return (char_type*) memmove(s1, s2, n * sizeof(char_type)); - } + return false; + } - inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){ - for(unsigned long int i=0; i< n; ++i){ - assign(s1[i], s2[i]); - } - return s1 + n; - } + inline static bool lt(const char_type& c1, const char_type& c2) + { + if(wcsncmp(&c1, &c2, 1) < 0) + { + return true; + } - inline static char_type* assign(char_type* s, size_t n, char_type a){ - return (char_type *)memset(s, a, n); /*FIXME*/ - } + return false; + } - inline static int compare(const char_type* s1, const char_type* s2, size_t n){ - return wcsncmp(s1, s2, n); - } + inline static char_type* move(char_type* s1, const char_type* s2, size_t n) + { + return (char_type*) memmove(s1, s2, n * sizeof(char_type)); + } - inline static size_t length(const char_type* s){ - return wcslen(s); - } + inline static char_type* copy(char_type* s1, const char_type* s2, size_t n) + { + for (unsigned long int i = 0; i< n; ++i) + { + assign(s1[i], s2[i]); + } - static const char_type* find(const char_type* s, int n, const char_type& a); + return s1 + n; + } - inline static char_type eos() { return 0; } - inline static int_type eof() { return WEOF; } - inline static int_type not_eof(const int_type & i) { - if(i == WEOF){ - return (int_type)0; - } else { - return i; - } - } - static state_type get_state(pos_type){ - state_type a; - return a; - } - }; -#endif + inline static char_type* assign(char_type* s, size_t n, char_type a) + { + return (char_type *)memset(s, a, n); /*FIXME*/ + } -} + inline static int compare(const char_type* s1, const char_type* s2, size_t n) + { + return wcsncmp(s1, s2, n); + } -#endif + inline static size_t length(const char_type* s) + { + return wcslen(s); + } + + static const char_type* find(const char_type* s, int n, const char_type& a); + + inline static char_type eos() { return 0; } + inline static int_type eof() { return WEOF; } + + inline static int_type not_eof(const int_type & i) + { + if (i == WEOF) + { + return (int_type)0; + } + else + { + return i; + } + } + + static state_type get_state(pos_type) + { + state_type a; + return a; + } + }; +#endif // __UCLIBCXX_HAS_WCHAR__ + +} // namespace +} // extern "C++" + +#endif // __HEADER_CHAR_TRAITS diff --git a/misc/uClibc++/include/uClibc++/complex b/misc/uClibc++/include/uClibc++/complex index 2c3c82b961..9081ec83c7 100644 --- a/misc/uClibc++/include/uClibc++/complex +++ b/misc/uClibc++/include/uClibc++/complex @@ -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 #include @@ -23,305 +23,411 @@ #ifndef __STD_HEADER_COMPLEX #define __STD_HEADER_COMPLEX 1 +extern "C++" +{ +namespace std +{ +// class complex; +// class complex; +// class complex; -namespace std { -// class complex; -// class complex; -// class complex; + template class _UCXXEXPORT complex{ + public: + typedef T value_type; - template class _UCXXEXPORT complex{ - public: - typedef T value_type; + complex(const T& re = T(), const T& im = T()) : r(re), i(im) { } + complex(const complex& c): r(c.r), i(c.i){ } + template complex(const complex& c): r(c.r), i(c.i){ } - complex(const T& re = T(), const T& im = T()) : r(re), i(im) { } - complex(const complex& c): r(c.r), i(c.i){ } - template complex(const complex& c): r(c.r), i(c.i){ } + inline T real() const + { + return r; + } - inline T real() const{ - return r; - } - inline T imag() const{ - return i; - } + inline T imag() const + { + return i; + } - complex& operator= (const T& v){ - r = v; - i = 0; - return *this; - } - complex& operator+=(const T& v){ - r +=v; - return *this; - } - complex& operator-=(const T& v){ - r -=v; - return *this; - } - complex& operator*=(const T& v){ - r*=v; - i*=v; - return *this; - } - complex& operator/=(const T& v){ - r/=v; - i/=v; - return *this; - } - complex& operator=(const complex& v){ - if(&v != this){ - r = v.r; - i = v.i; - } - return *this; - } - template complex& operator= (const complex& v){ - r = v.r; - i = v.i; - return *this; - } - template complex& operator+=(const complex& v){ - r+=v.r; - i+=v.i; - return *this; - } - template complex& operator-=(const complex& v){ - r-=v.r; - i-=v.i; - return *this; - } - template complex& operator*=(const complex& v){ - T tempr = r*v.r - i*v.i; - T tempi = r*v.i + i*v.r; - r = tempr; - i = tempi; - return *this; - } - template complex& operator/=(const complex& v){ - T tempr = (r*v.r + i*v.i) / (v.r*v.r + v.i*v.i); - T tempi = (i*v.r - r*v.i) / (v.r*v.r + v.i*v.i); - r = tempr; - i = tempi; - return *this; - } - private: - T r; - T i; - }; + complex& operator= (const T& v) + { + r = v; + i = 0; + return *this; + } - template _UCXXEXPORT complex operator+(const complex& ls, const complex& rs){ - complex retval(ls); - retval += rs; - return retval; - } - template _UCXXEXPORT complex operator+(const complex& ls, const T& rs){ - complex retval(ls); - ls += rs; - return retval; - } - template _UCXXEXPORT inline complex operator+(const T& ls, const complex& rs){ - return rs + ls; - } - template _UCXXEXPORT complex operator-(const complex& ls, const complex& rs){ - complex retval(ls); - retval -= rs; - return retval; - } - template _UCXXEXPORT complex operator-(const complex& ls, const T& rs){ - complex retval(ls); - retval -= rs; - return retval; - } - template _UCXXEXPORT complex operator-(const T& ls, const complex& rs){ - complex retval(ls); - retval -= rs; - return retval; - } - template _UCXXEXPORT complex operator*(const complex& ls, const complex& rs){ - complex retval(ls); - retval *= rs; - return retval; - } - template _UCXXEXPORT complex operator*(const complex& ls, const T& rs){ - complex retval(ls); - retval *= rs; - return retval; - } - template _UCXXEXPORT complex operator*(const T& ls, const complex& rs){ - complex retval(ls); - retval *=rs; - return retval; - } - template _UCXXEXPORT complex operator/(const complex& ls, const complex& rs){ - complex retval(ls); - retval/=rs; - return retval; - } - template _UCXXEXPORT complex operator/(const complex& ls, const T& rs){ - complex retval(ls); - retval/=rs; - return retval; - } - template _UCXXEXPORT complex operator/(const T& ls, const complex& rs){ - complex retval(ls); - retval/=rs; - return retval; - } - template _UCXXEXPORT complex operator+(const complex& v){ - return v; - } - template _UCXXEXPORT complex operator-(const complex& v){ - return complex (-v.real(), -v.imag()); - } - template _UCXXEXPORT bool operator==(const complex& ls, const complex& rs){ - if( ls.real() == rs.real() && ls.imag() == rs.image()){ - return true; - } - return false; - } - template _UCXXEXPORT bool operator==(const complex& ls, const T& rs){ - if(ls.real() == rs && ls.imag() == T()){ - return true; - } - return false; - } - template _UCXXEXPORT bool operator==(const T& ls, const complex& rs){ - if(ls == rs.real() && rs.imag() == T()){ - return true; - } - return false; - } - template _UCXXEXPORT bool operator!=(const complex& ls, const complex& rs){ - if(ls == rs){ - return false; - } - return true; - } - template _UCXXEXPORT bool operator!=(const complex& ls, const T& rs){ - if(ls == rs){ - return false; - } - return true; - } - template _UCXXEXPORT bool operator!=(const T& ls, const complex& rs){ - if(ls == rs){ - return false; - } - return true; - } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, complex& v) - { - T tempr; - T tempi; - is >> tempr; - is.get(); - is >> tempi; - v = complex(tempr, tempi); - return is; - } + complex& operator+=(const T& v) + { + r +=v; + return *this; + } - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const complex&v) - { - os << v.real() << ", " << v.imag(); - return os; - } + complex& operator-=(const T& v) + { + r -=v; + return *this; + } - template _UCXXEXPORT T real(const complex& v){ - return v.real(); - } + complex& operator*=(const T& v) + { + r*=v; + i*=v; + return *this; + } - template _UCXXEXPORT T imag(const complex& v){ - return v.imag(); - } + complex& operator/=(const T& v) + { + r/=v; + i/=v; + return *this; + } - template _UCXXEXPORT T norm(const complex& v){ - return (v.real() * v.real() + v.imag() * v.imag()); - } + complex& operator=(const complex& v) + { + if (&v != this){ + r = v.r; + i = v.i; + } + return *this; + } - template _UCXXEXPORT complex conj(const complex& v){ - return complex(v.real(), -v.imag()); - } + template complex& operator= (const complex& v) + { + r = v.r; + i = v.i; + return *this; + } -#ifdef __UCLIBCXX_SUPPORT_MATH__ //Can we link with libm? + template complex& operator+=(const complex& v) + { + r+=v.r; + i+=v.i; + return *this; + } - template _UCXXEXPORT T abs(const complex& v){ - return sqrt(v.real() * v.real() + v.imag() * v.imag()); - } + template complex& operator-=(const complex& v) + { + r-=v.r; + i-=v.i; + return *this; + } - template _UCXXEXPORT T arg(const complex& v){ - return atan2(v.imag(), v.real()); - } + template complex& operator*=(const complex& v) + { + T tempr = r*v.r - i*v.i; + T tempi = r*v.i + i*v.r; + r = tempr; + i = tempi; + return *this; + } - template _UCXXEXPORT complex polar(const T& rho, const T& theta){ - return complex(rho * cos(theta), rho * sin(theta)); - } + template complex& operator/=(const complex& v) + { + T tempr = (r*v.r + i*v.i) / (v.r*v.r + v.i*v.i); + T tempi = (i*v.r - r*v.i) / (v.r*v.r + v.i*v.i); + r = tempr; + i = tempi; + return *this; + } - template _UCXXEXPORT complex cos (const complex& v){ - return complex(cos(v.real()) * cosh(v.imag()), -sin(v.real()) * sinh(v.imag())); - } + private: + T r; + T i; + }; - template _UCXXEXPORT complex cosh (const complex& v){ - return complex(cosh(v.real()) * cos(v.imag()), sinh(v.real()) * sin(v.imag())); - } + template _UCXXEXPORT complex operator+(const complex& ls, const complex& rs) + { + complex retval(ls); + retval += rs; + return retval; + } - template _UCXXEXPORT complex exp (const complex& v){ - return polar(exp(v.real()), v.imag()); - } + template _UCXXEXPORT complex operator+(const complex& ls, const T& rs) + { + complex retval(ls); + ls += rs; + return retval; + } - template _UCXXEXPORT complex log (const complex& v){ - return complex(log(abs(v)), arg(v)); - } + template _UCXXEXPORT inline complex operator+(const T& ls, const complex& rs) + { + return rs + ls; + } - template _UCXXEXPORT complex log10(const complex& v){ - return (log(v) / log(T(10.0))); - } + template _UCXXEXPORT complex operator-(const complex& ls, const complex& rs) + { + complex retval(ls); + retval -= rs; + return retval; + } - template _UCXXEXPORT complex pow(const complex& v, int p){ - T rho = pow(abs(v), p); - T theta = arg(v); - return complex(rho * cos(p * theta), rho * sin(p * theta) ); - } + template _UCXXEXPORT complex operator-(const complex& ls, const T& rs) + { + complex retval(ls); + retval -= rs; + return retval; + } - template _UCXXEXPORT complex pow(const complex& v, const T& p){ - return polar( pow(abs(v),p), arg(v)*p ); - } + template _UCXXEXPORT complex operator-(const T& ls, const complex& rs) + { + complex retval(ls); + retval -= rs; + return retval; + } - template _UCXXEXPORT complex pow(const complex& v, const complex& p){ - if(v == T()){ - //We are using "0" as the value - return T(); - } - return exp(p * log(v)); - } + template _UCXXEXPORT complex operator*(const complex& ls, const complex& rs) + { + complex retval(ls); + retval *= rs; + return retval; + } - template _UCXXEXPORT complex pow(const T& v, const complex& p){ - if(v == T()){ - return T(); - } - return polar(pow(v,p.real()), y.imag() * log(x) ); - } + template _UCXXEXPORT complex operator*(const complex& ls, const T& rs) + { + complex retval(ls); + retval *= rs; + return retval; + } - template _UCXXEXPORT complex sin (const complex& v){ - return complex(sin(v.real()) * cosh(v.imag()), cosh(v.real()) * sin(v.imag())); - } + template _UCXXEXPORT complex operator*(const T& ls, const complex& rs) + { + complex retval(ls); + retval *=rs; + return retval; + } - template _UCXXEXPORT complex sinh (const complex& v){ - return complext(sinh(v.real()) * cos(v.imag()), cosh(v.real()) * sin(v.imag()) ); - } + template _UCXXEXPORT complex operator/(const complex& ls, const complex& rs) + { + complex retval(ls); + retval/=rs; + return retval; + } - template _UCXXEXPORT complex sqrt (const complex&); - template _UCXXEXPORT complex tan (const complex& v){ - return sin(v) / cos(v); - } + template _UCXXEXPORT complex operator/(const complex& ls, const T& rs) + { + complex retval(ls); + retval/=rs; + return retval; + } - template _UCXXEXPORT complex tanh (const complex& v){ - return sinh(v) / cosh(v); - } + template _UCXXEXPORT complex operator/(const T& ls, const complex& rs) + { + complex retval(ls); + retval/=rs; + return retval; + } + + template _UCXXEXPORT complex operator+(const complex& v) + { + return v; + } + + template _UCXXEXPORT complex operator-(const complex& v) + { + return complex (-v.real(), -v.imag()); + } + + template _UCXXEXPORT bool operator==(const complex& ls, const complex& rs) + { + if (ls.real() == rs.real() && ls.imag() == rs.image()) + { + return true; + } + + return false; + } + + template _UCXXEXPORT bool operator==(const complex& ls, const T& rs) + { + if (ls.real() == rs && ls.imag() == T()) + { + return true; + } + + return false; + } + + template _UCXXEXPORT bool operator==(const T& ls, const complex& rs) + { + if (ls == rs.real() && rs.imag() == T()) + { + return true; + } + + return false; + } + + template _UCXXEXPORT bool operator!=(const complex& ls, const complex& rs) + { + if (ls == rs) + { + return false; + } + + return true; + } + + template _UCXXEXPORT bool operator!=(const complex& ls, const T& rs) + { + if (ls == rs) + { + return false; + } + + return true; + } + + template _UCXXEXPORT bool operator!=(const T& ls, const complex& rs) + { + if (ls == rs) + { + return false; + } + + return true; + } + + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, complex& v) + { + T tempr; + T tempi; + is >> tempr; + is.get(); + is >> tempi; + v = complex(tempr, tempi); + return is; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& os, const complex&v) + { + os << v.real() << ", " << v.imag(); + return os; + } + + template _UCXXEXPORT T real(const complex& v) + { + return v.real(); + } + + template _UCXXEXPORT T imag(const complex& v) + { + return v.imag(); + } + + template _UCXXEXPORT T norm(const complex& v) + { + return (v.real() * v.real() + v.imag() * v.imag()); + } + + template _UCXXEXPORT complex conj(const complex& v) + { + return complex(v.real(), -v.imag()); + } + +#ifdef __UCLIBCXX_SUPPORT_MATH__ //Can we link with libm? + + template _UCXXEXPORT T abs(const complex& v) + { + return sqrt(v.real() * v.real() + v.imag() * v.imag()); + } + + template _UCXXEXPORT T arg(const complex& v) + { + return atan2(v.imag(), v.real()); + } + + template _UCXXEXPORT complex polar(const T& rho, const T& theta) + { + return complex(rho * cos(theta), rho * sin(theta)); + } + + template _UCXXEXPORT complex cos (const complex& v) + { + return complex(cos(v.real()) * cosh(v.imag()), -sin(v.real()) * sinh(v.imag())); + } + + template _UCXXEXPORT complex cosh (const complex& v) + { + return complex(cosh(v.real()) * cos(v.imag()), sinh(v.real()) * sin(v.imag())); + } + + template _UCXXEXPORT complex exp (const complex& v) + { + return polar(exp(v.real()), v.imag()); + } + + template _UCXXEXPORT complex log (const complex& v) + { + return complex(log(abs(v)), arg(v)); + } + + template _UCXXEXPORT complex log10(const complex& v) + { + return (log(v) / log(T(10.0))); + } + + template _UCXXEXPORT complex pow(const complex& v, int p) + { + T rho = pow(abs(v), p); + T theta = arg(v); + return complex(rho * cos(p * theta), rho * sin(p * theta)); + } + + template _UCXXEXPORT complex pow(const complex& v, const T& p) + { + return polar(pow(abs(v),p), arg(v)*p); + } + + template _UCXXEXPORT complex pow(const complex& v, const complex& p) + { + if (v == T()) + { + // We are using "0" as the value + + return T(); + } + + return exp(p * log(v)); + } + + template _UCXXEXPORT complex pow(const T& v, const complex& p) + { + if (v == T()) + { + return T(); + } + + return polar(pow(v,p.real()), y.imag() * log(x)); + } + + template _UCXXEXPORT complex sin (const complex& v) + { + return complex(sin(v.real()) * cosh(v.imag()), cosh(v.real()) * sin(v.imag())); + } + + template _UCXXEXPORT complex sinh (const complex& v) + { + return complext(sinh(v.real()) * cos(v.imag()), cosh(v.real()) * sin(v.imag())); + } + + template _UCXXEXPORT complex sqrt (const complex&); + + template _UCXXEXPORT complex tan (const complex& v) + { + return sin(v) / cos(v); + } + + template _UCXXEXPORT complex tanh (const complex& v) + { + return sinh(v) / cosh(v); + } #endif -} +} // namespace +} // extern "C++" #endif diff --git a/misc/uClibc++/include/uClibc++/deque b/misc/uClibc++/include/uClibc++/deque index 19be5c8bb4..48b5db3b33 100644 --- a/misc/uClibc++/include/uClibc++/deque +++ b/misc/uClibc++/include/uClibc++/deque @@ -1,20 +1,20 @@ /* 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 - -*/ + * + * This file is part of the uClibc++ Library. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include @@ -25,6 +25,8 @@ #ifndef __STD_HEADER_DEQUE #define __STD_HEADER_DEQUE +extern "C++" +{ namespace std { template > class deque; @@ -1057,7 +1059,9 @@ namespace std template _UCXXEXPORT void swap(deque& x, deque& y){ x.swap(y); } + } // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/fstream b/misc/uClibc++/include/uClibc++/fstream index d5c1d083b0..0f0388e5dd 100644 --- a/misc/uClibc++/include/uClibc++/fstream +++ b/misc/uClibc++/include/uClibc++/fstream @@ -1,25 +1,24 @@ -/* 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 + */ #ifndef __STD_HEADER_FSTREAM #define __STD_HEADER_FSTREAM 1 - #include #include @@ -40,637 +39,821 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + template class basic_filebuf; - template class basic_filebuf; - - typedef basic_filebuf filebuf; + typedef basic_filebuf filebuf; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_filebuf wfilebuf; + typedef basic_filebuf wfilebuf; #endif - - template class _UCXXEXPORT basic_filebuf - : public basic_streambuf - { + template class _UCXXEXPORT basic_filebuf + : public basic_streambuf + { #ifdef __UCLIBCXX_SUPPORT_CDIR__ - friend ios_base::Init::Init(); //Needed for cout/cin stuff + friend ios_base::Init::Init(); // Needed for cout/cin stuff #endif - public: - // Types (inherited from basic_streambuf: - typedef typename basic_streambuf::char_type char_type; - typedef typename basic_streambuf::int_type int_type; - typedef typename basic_streambuf::pos_type pos_type; - typedef typename basic_streambuf::off_type off_type; - typedef traits traits_type; + public: + // Types (inherited from basic_streambuf: - //Constructors/destructor: + typedef typename basic_streambuf::char_type char_type; + typedef typename basic_streambuf::int_type int_type; + typedef typename basic_streambuf::pos_type pos_type; + typedef typename basic_streambuf::off_type off_type; + typedef traits traits_type; - _UCXXEXPORT basic_filebuf() : basic_streambuf(), fp(0), pbuffer(0), gbuffer(0) - { - append=false; - pbuffer = new char_type[CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE]; - gbuffer = new char_type[CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE]; + // Constructors/destructor: - this->setp(pbuffer, pbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE); - //Position get buffer so that there is no data available - this->setg(gbuffer, gbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE, - gbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE); - } + _UCXXEXPORT basic_filebuf() : basic_streambuf(), fp(0), pbuffer(0), gbuffer(0) + { + append=false; + pbuffer = new char_type[CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE]; + gbuffer = new char_type[CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE]; + this->setp(pbuffer, pbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE); - _UCXXEXPORT virtual ~basic_filebuf(){ - sync(); - close(); - delete [] pbuffer; - delete [] gbuffer; - pbuffer = 0; - gbuffer = 0; - } + //Position get buffer so that there is no data available + this->setg(gbuffer, gbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE, + gbuffer + CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE); + } - //Members: + _UCXXEXPORT virtual ~basic_filebuf(){ + sync(); + close(); + delete [] pbuffer; + delete [] gbuffer; + pbuffer = 0; + gbuffer = 0; + } - _UCXXEXPORT bool is_open() const{ - if(fp == 0){ - return false; - } - return true; - } + // Members: - _UCXXEXPORT basic_filebuf* open(const char* s, ios_base::openmode mode){ - bool move_end = (mode & ios_base::ate) != 0; - if(is_open() !=false){ //Must call close() first - return 0; - } - basic_streambuf::openedFor = mode; - mode = mode & ~ios_base::ate; + _UCXXEXPORT bool is_open() const + { + if (fp == 0) + { + return false; + } + return true; + } - if(mode == ios_base::out || mode == (ios_base::out | ios_base::trunc)){ - fp = fopen(s, "w" ); - }else if((mode & ios_base::app) && ! (mode & ios_base::trunc)){ - if(mode & ios_base::binary){ - if(mode & ios_base::in){ - fp = fopen(s, "a+b"); - }else{ - fp = fopen(s, "ab"); - } - }else{ - if(mode & ios_base::in){ - fp = fopen(s, "a+"); - }else{ - fp = fopen(s, "a"); - } - } - }else if(mode == ios_base::in){ - fp = fopen(s, "r"); - }else if(mode == (ios_base::in | ios_base::out)){ - fp = fopen(s, "r+"); - }else if(mode == (ios_base::in | ios_base::out | ios_base::trunc)){ - fp = fopen(s, "w+"); - }else if(mode == (ios_base::binary | ios_base::out)){ - fp = fopen(s, "wb"); - }else if(mode == (ios_base::in | ios_base::binary)){ - fp = fopen(s, "rb"); - }else if(mode == (ios_base::in | ios_base::binary | ios_base::out)){ - fp = fopen(s, "r+b"); - }else if(mode==(ios_base::binary | ios_base::out | ios_base::trunc)){ - fp = fopen(s, "w+b"); - }else if(mode == (ios_base::in | ios_base::binary | ios_base::out | ios_base::trunc)){ - fp = fopen(s, "w+b"); - } + _UCXXEXPORT basic_filebuf* open(const char* s, ios_base::openmode mode) + { + bool move_end = (mode & ios_base::ate) != 0; + if (is_open() !=false) + { + // Must call close() first - if(fp == 0){ - return 0; - } - if(ferror(fp)){ - fclose(fp); - fp=0; - return 0; - } - int retval = 0; + return 0; + } - //Check to make sure the stream is good - if(move_end == true){ - retval = fseek(fp, 0, SEEK_END); - }else{ - retval = fseek(fp, 0, SEEK_SET); - } - if(retval!=0){ //Seek error - fclose(fp); - fp=0; - return 0; - } + basic_streambuf::openedFor = mode; + mode = mode & ~ios_base::ate; - basic_streambuf::mgnext = basic_streambuf::mgend; + if (mode == ios_base::out || mode == (ios_base::out | ios_base::trunc)) + { + fp = fopen(s, "w"); + } + else if ((mode & ios_base::app) && ! (mode & ios_base::trunc)) + { + if (mode & ios_base::binary) + { + if (mode & ios_base::in) + { + fp = fopen(s, "a+b"); + } + else + { + fp = fopen(s, "ab"); + } + } + else + { + if (mode & ios_base::in) + { + fp = fopen(s, "a+"); + } + else + { + fp = fopen(s, "a"); + } + } + } + else if (mode == ios_base::in) + { + fp = fopen(s, "r"); + } + else if (mode == (ios_base::in | ios_base::out)) + { + fp = fopen(s, "r+"); + } + else if (mode == (ios_base::in | ios_base::out | ios_base::trunc)) + { + fp = fopen(s, "w+"); + } + else if (mode == (ios_base::binary | ios_base::out)) + { + fp = fopen(s, "wb"); + } + else if (mode == (ios_base::in | ios_base::binary)) + { + fp = fopen(s, "rb"); + } + else if (mode == (ios_base::in | ios_base::binary | ios_base::out)) + { + fp = fopen(s, "r+b"); + } + else if (mode==(ios_base::binary | ios_base::out | ios_base::trunc)) + { + fp = fopen(s, "w+b"); + } + else if (mode == (ios_base::in | ios_base::binary | ios_base::out | ios_base::trunc)) + { + fp = fopen(s, "w+b"); + } - return this; - } - _UCXXEXPORT basic_filebuf* close(){ - if(fp != 0 && fp != stdin && fp != stdout && fp !=stderr ){ - overflow(); - sync(); - int retval = fclose(fp); - if(retval !=0){ //Error of some sort - return 0; - } - fp=0; - } - return this; - } - protected: - _UCXXEXPORT basic_filebuf(const basic_filebuf &){ } - _UCXXEXPORT basic_filebuf & operator=(const basic_filebuf &){ return *this; } + if (fp == 0) + { + return 0; + } - //Overridden virtual functions: + if (ferror(fp)) + { + fclose(fp); + fp = 0; + return 0; + } - virtual _UCXXEXPORT int showmanyc(){ - return basic_streambuf::egptr() - basic_streambuf::gptr(); - } - virtual _UCXXEXPORT int_type underflow(){ - /* Some variables used internally: - Buffer pointers: - charT * mgbeg; - charT * mgnext; - charT * mgend; + int retval = 0; - eback() returns mgbeg - gptr() returns mgnext - egptr() returns mgend + // Check to make sure the stream is good - gbump(int n) mgnext+=n + if (move_end == true) + { + retval = fseek(fp, 0, SEEK_END); + } + else + { + retval = fseek(fp, 0, SEEK_SET); + } - */ + if (retval != 0) + { + //Seek error - if(!is_open()){ - return traits::eof(); - } + fclose(fp); + fp=0; + return 0; + } - if(basic_streambuf::eback() == 0){ - //No buffer, so... - charT c; - int retval; - retval = fread(&c, sizeof(charT), 1, fp); + basic_streambuf::mgnext = basic_streambuf::mgend; - if(retval == 0 || feof(fp) || ferror(fp) ){ - return traits::eof(); - } - return traits::to_int_type(c); - } + return this; + } - if(basic_streambuf::eback() == basic_streambuf::gptr()){ //Buffer is full - return traits::to_int_type(*basic_streambuf::gptr()); - } - //Shift entire buffer back to the begining - size_t offset = basic_streambuf::gptr() - basic_streambuf::eback(); - size_t amountData = basic_streambuf::egptr() - basic_streambuf::gptr(); + _UCXXEXPORT basic_filebuf* close() + { + if (fp != 0 && fp != stdin && fp != stdout && fp !=stderr) + { + overflow(); + sync(); + int retval = fclose(fp); + if (retval !=0) + { + //Error of some sort - for(charT * i = basic_streambuf::gptr(); i < basic_streambuf::egptr(); ++i){ - *(i-offset) = *i; - } + return 0; + } - size_t retval = 0; - //Save operating flags from file descriptor - int fcntl_flags = fcntl(fileno(fp), F_GETFL); - retval = 0; + fp=0; + } - //Set to non_blocking mode - fcntl(fileno(fp), F_SETFL, fcntl_flags | O_NONBLOCK); + return this; + } - //Fill rest of buffer - retval = fread(basic_streambuf::egptr() - - basic_streambuf::gptr() + basic_streambuf::eback(), - sizeof(charT), - offset, - fp - ); + protected: + _UCXXEXPORT basic_filebuf(const basic_filebuf &){ } + _UCXXEXPORT basic_filebuf & operator=(const basic_filebuf &){ return *this; } - //Clear problems where we didn't read in enough characters - if(EAGAIN == errno){ - clearerr(fp); - } + //Overridden virtual functions: - //Restore file descriptor clase - fcntl(fileno(fp), F_SETFL, fcntl_flags); + virtual _UCXXEXPORT int showmanyc() + { + return basic_streambuf::egptr() - basic_streambuf::gptr(); + } - //Now we are going to make sure that we read in at least one character. The hard way. - if(retval == 0){ - fcntl_flags = fcntl(fileno(fp), F_GETFL); - //Set to blocking mode - fcntl(fileno(fp), F_SETFL, fcntl_flags & ~O_NONBLOCK); + virtual _UCXXEXPORT int_type underflow() + { + /* Some variables used internally: + Buffer pointers: + charT * mgbeg; + charT * mgnext; + charT * mgend; - retval = fread(basic_streambuf::egptr() - - basic_streambuf::gptr() + basic_streambuf::eback(), - sizeof(charT), - 1, - fp - ); + eback() returns mgbeg + gptr() returns mgnext + egptr() returns mgend - //Restore file descriptor clase - fcntl(fileno(fp), F_SETFL, fcntl_flags); + gbump(int n) mgnext+=n + */ - } + if (!is_open()) + { + return traits::eof(); + } - if(retval !=offset){ //Slide buffer forward again - for(size_t i = 0; i < amountData + retval; ++i){ - *(basic_streambuf::egptr() - i - 1) = - *(basic_streambuf::eback() + amountData + retval - i - 1); - } - } + if (basic_streambuf::eback() == 0) + { + // No buffer, so... - basic_streambuf::mgnext -= retval; + charT c; + int retval; + retval = fread(&c, sizeof(charT), 1, fp); - if( (retval <= 0 && feof(fp)) || ferror(fp) ){ - return traits::eof(); - } + if (retval == 0 || feof(fp) || ferror(fp)) + { + return traits::eof(); + } - return traits::to_int_type(*basic_streambuf::gptr()); - } - virtual _UCXXEXPORT int_type uflow(){ - bool dobump = (basic_streambuf::gptr() != 0); - int_type retval = underflow(); - if(dobump){ - basic_streambuf::gbump(1); - } - return retval; - } - virtual _UCXXEXPORT int_type pbackfail(int_type c = traits::eof()){ - if(is_open() == false || - basic_streambuf::gptr() == basic_streambuf::eback()) - { - return traits::eof(); - } - if(traits::eq_int_type(c,traits::eof()) == false){ - if(traits::eq(traits::to_char_type(c), basic_streambuf::gptr()[-1]) == true){ - basic_streambuf::gbump(-1); - }else{ - basic_streambuf::gbump(-1); - basic_streambuf::gptr()[0] = c; - } - return c; - }else{ - basic_streambuf::gbump(-1); - return traits::not_eof(c); - } - } + return traits::to_int_type(c); + } - virtual _UCXXEXPORT int_type overflow(int_type c = traits::eof()){ - if(is_open() == false){ - //Can't do much - return traits::eof(); - } - if(basic_streambuf::pbase() == 0){ //Unbuffered - elliminate dupe code below - if(fputc(c, fp) == EOF){ - return traits::eof(); - } - return c; - } - if(basic_streambuf::pbase() == 0 && traits::eq_int_type(c,traits::eof()) ){ - //Nothing to flush - return traits::not_eof(c); - } - size_t r = basic_streambuf::pptr() - basic_streambuf::pbase(); + if (basic_streambuf::eback() == basic_streambuf::gptr()) + { + // Buffer is full - if( r == 0 && traits::eq_int_type(c,traits::eof()) ){ - return traits::not_eof(c); - }else if (r == 0 ){ - if(fputc(c, fp) == EOF){ - return traits::eof(); - } - return c; - } + return traits::to_int_type(*basic_streambuf::gptr()); + } - size_t totalChars = r; + // Shift entire buffer back to the begining - char_type *buffer = 0; - if(traits::eq_int_type(c,traits::eof())){ - buffer = new char_type[r]; - }else{ - buffer = new char_type[r+1]; - buffer[r] = c; - totalChars++; - } + size_t offset = basic_streambuf::gptr() - basic_streambuf::eback(); + size_t amountData = basic_streambuf::egptr() - basic_streambuf::gptr(); - traits::copy(buffer, basic_streambuf::pbase(), r); -// memcpy(buffer, basic_streambuf::pbase(), r); + for (charT * i = basic_streambuf::gptr(); i < basic_streambuf::egptr(); ++i) + { + *(i-offset) = *i; + } - size_t retval = fwrite(buffer, sizeof(charT), totalChars, fp); - if(retval !=totalChars){ - if(retval == 0){ - delete [] buffer; - return traits::eof(); - } - basic_streambuf::pbump(-retval); - fprintf(stderr, "***** Did not write the full buffer out. Should be: %d, actually: %d\n", - totalChars, retval); - }else{ - basic_streambuf::pbump(-r); - } + size_t retval = 0; - delete [] buffer; - return traits::not_eof(c); - } + // Save operating flags from file descriptor - virtual _UCXXEXPORT basic_streambuf* setbuf(char_type* s, streamsize n){ - if(s == 0 && n == 0){ //Unbuffered - if(pbuffer !=0){ - delete [] pbuffer; - } - if(gbuffer !=0){ - delete [] gbuffer; - } - pbuffer = 0; - gbuffer = 0; - }else if(basic_streambuf::gptr() !=0 && - basic_streambuf::gptr()==basic_streambuf::egptr()) - { - delete [] pbuffer; - pbuffer = s; - } - return this; - } - virtual _UCXXEXPORT pos_type seekoff(off_type off, ios_base::seekdir way, - ios_base::openmode = ios_base::in | ios_base::out) - { - if(is_open() == false){ - return -1; - } - int whence = SEEK_SET; // if(way == basic_ios::beg) - off_type position = off; + int fcntl_flags = fcntl(fileno(fp), F_GETFL); + retval = 0; - if(way == basic_ios::cur){ - whence = SEEK_CUR; - position -= (basic_streambuf::egptr() - basic_streambuf::gptr()); - }else if(way == basic_ios::end){ - whence = SEEK_END; - } + // Set to non_blocking mode - sync(); + fcntl(fileno(fp), F_SETFL, fcntl_flags | O_NONBLOCK); - int retval = fseek( - fp, - sizeof(charT)*(position), - whence - ); + // Fill rest of buffer - //Invalidate read buffer - basic_streambuf::gbump( - basic_streambuf::egptr() - basic_streambuf::gptr() - ); + retval = fread(basic_streambuf::egptr() - + basic_streambuf::gptr() + basic_streambuf::eback(), + sizeof(charT), + offset, + fp); - if(-1 != retval){ - retval = ftell(fp); - } + // Clear problems where we didn't read in enough characters - return retval; - } - virtual _UCXXEXPORT pos_type seekpos(pos_type sp, ios_base::openmode = ios_base::in | ios_base::out){ - if(is_open() == false){ - return -1; - } - sync(); + if (EAGAIN == errno) + { + clearerr(fp); + } - int retval = fseek(fp,sizeof(charT)* sp, SEEK_SET); + // Restore file descriptor clase - //Invalidate read buffer - basic_streambuf::gbump(basic_streambuf::egptr() - basic_streambuf::gptr()); - if(retval > -1){ - return sp; - } - return -1; - } - virtual _UCXXEXPORT int sync(){ - if(pbuffer !=0){ - if(overflow() == traits::eof()){ - return -1; - } - } - if(0 != fp && 0 != fflush(fp)){ - return -1; - } - return 0; - } - virtual _UCXXEXPORT void imbue(const locale&){ - return; - } + fcntl(fileno(fp), F_SETFL, fcntl_flags); + // Now we are going to make sure that we read in at least one character. The hard way. - virtual _UCXXEXPORT streamsize xsputn(const char_type* s, streamsize n){ - if(is_open() == false){ - return 0; - } - //Check to see if buffered + if (retval == 0) + { + fcntl_flags = fcntl(fileno(fp), F_GETFL); - //Check to see if we can buffer the data - streamsize buffer_avail = basic_streambuf::epptr() - basic_streambuf::pptr(); + // Set to blocking mode - if(n > buffer_avail){ //Flush buffer and write directly - overflow(); //Flush the buffer - return fwrite(s, sizeof(charT), n, fp); - } + fcntl(fileno(fp), F_SETFL, fcntl_flags & ~O_NONBLOCK); - //Add to buffer to be written later + retval = fread(basic_streambuf::egptr() - + basic_streambuf::gptr() + basic_streambuf::eback(), + sizeof(charT), + 1, + fp); - traits::copy(basic_streambuf::pptr(), s, n); - basic_streambuf::pbump(n); + // Restore file descriptor clase - return n; - } + fcntl(fileno(fp), F_SETFL, fcntl_flags); + } - FILE * fp; - char_type * pbuffer; - char_type * gbuffer; - bool append; - }; + if (retval !=offset) + { + // Slide buffer forward again + for (size_t i = 0; i < amountData + retval; ++i) + { + *(basic_streambuf::egptr() - i - 1) = + *(basic_streambuf::eback() + amountData + retval - i - 1); + } + } + + basic_streambuf::mgnext -= retval; + + if ((retval <= 0 && feof(fp)) || ferror(fp)) + { + return traits::eof(); + } + + return traits::to_int_type(*basic_streambuf::gptr()); + } + + virtual _UCXXEXPORT int_type uflow() + { + bool dobump = (basic_streambuf::gptr() != 0); + int_type retval = underflow(); + if (dobump) + { + basic_streambuf::gbump(1); + } + + return retval; + } + + virtual _UCXXEXPORT int_type pbackfail(int_type c = traits::eof()) + { + if (is_open() == false || + basic_streambuf::gptr() == basic_streambuf::eback()) + { + return traits::eof(); + } + + if (traits::eq_int_type(c,traits::eof()) == false) + { + if (traits::eq(traits::to_char_type(c), basic_streambuf::gptr()[-1]) == true) + { + basic_streambuf::gbump(-1); + } + else + { + basic_streambuf::gbump(-1); + basic_streambuf::gptr()[0] = c; + } + + return c; + } + else + { + basic_streambuf::gbump(-1); + return traits::not_eof(c); + } + } + + virtual _UCXXEXPORT int_type overflow(int_type c = traits::eof()) + { + if (is_open() == false) + { + // Can't do much + + return traits::eof(); + } + + if (basic_streambuf::pbase() == 0) + { + // Unbuffered - elliminate dupe code below + + if (fputc(c, fp) == EOF) + { + return traits::eof(); + } + + return c; + } + + if (basic_streambuf::pbase() == 0 && traits::eq_int_type(c,traits::eof())) + { + // Nothing to flush + + return traits::not_eof(c); + } + + size_t r = basic_streambuf::pptr() - basic_streambuf::pbase(); + + if (r == 0 && traits::eq_int_type(c,traits::eof())) + { + return traits::not_eof(c); + } + else if (r == 0) + { + if (fputc(c, fp) == EOF) + { + return traits::eof(); + } + + return c; + } + + size_t totalChars = r; + + char_type *buffer = 0; + if (traits::eq_int_type(c,traits::eof())) + { + buffer = new char_type[r]; + } + else + { + buffer = new char_type[r+1]; + buffer[r] = c; + totalChars++; + } + + traits::copy(buffer, basic_streambuf::pbase(), r); +// memcpy(buffer, basic_streambuf::pbase(), r); + + size_t retval = fwrite(buffer, sizeof(charT), totalChars, fp); + if (retval !=totalChars) + { + if (retval == 0) + { + delete [] buffer; + return traits::eof(); + } + + basic_streambuf::pbump(-retval); + fprintf(stderr, "***** Did not write the full buffer out. Should be: %d, actually: %d\n", + totalChars, retval); + } + else + { + basic_streambuf::pbump(-r); + } + + delete [] buffer; + return traits::not_eof(c); + } + + virtual _UCXXEXPORT basic_streambuf* setbuf(char_type* s, streamsize n) + { + if (s == 0 && n == 0) + { + // Unbuffered + + if (pbuffer !=0) + { + delete [] pbuffer; + } + + if (gbuffer !=0) + { + delete [] gbuffer; + } + + pbuffer = 0; + gbuffer = 0; + } + else if (basic_streambuf::gptr() !=0 && + basic_streambuf::gptr()==basic_streambuf::egptr()) + { + delete [] pbuffer; + pbuffer = s; + } + + return this; + } + + virtual _UCXXEXPORT pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode = ios_base::in | ios_base::out) + { + if (is_open() == false) + { + return -1; + } + + int whence = SEEK_SET; // if (way == basic_ios::beg) + off_type position = off; + + if (way == basic_ios::cur) + { + whence = SEEK_CUR; + position -= (basic_streambuf::egptr() - basic_streambuf::gptr()); + } + else if (way == basic_ios::end) + { + whence = SEEK_END; + } + + sync(); + + int retval = fseek( + fp, + sizeof(charT)*(position), + whence); + + // Invalidate read buffer + + basic_streambuf::gbump( + basic_streambuf::egptr() - basic_streambuf::gptr()); + + if (-1 != retval) + { + retval = ftell(fp); + } + + return retval; + } + + virtual _UCXXEXPORT pos_type seekpos(pos_type sp, ios_base::openmode = ios_base::in | ios_base::out) + { + if (is_open() == false) + { + return -1; + } + + sync(); + + int retval = fseek(fp,sizeof(charT)* sp, SEEK_SET); + + // Invalidate read buffer + + basic_streambuf::gbump(basic_streambuf::egptr() - basic_streambuf::gptr()); + if (retval > -1) + { + return sp; + } + + return -1; + } + + virtual _UCXXEXPORT int sync() + { + if (pbuffer !=0) + { + if (overflow() == traits::eof()) + { + return -1; + } + } + + if (0 != fp && 0 != fflush(fp)) + { + return -1; + } + + return 0; + } + + virtual _UCXXEXPORT void imbue(const locale&) + { + return; + } + + virtual _UCXXEXPORT streamsize xsputn(const char_type* s, streamsize n) + { + if (is_open() == false) + { + return 0; + } + + // Check to see if buffered + + // Check to see if we can buffer the data + + streamsize buffer_avail = basic_streambuf::epptr() - basic_streambuf::pptr(); + + if (n > buffer_avail) + { + // Flush buffer and write directly + + overflow(); // Flush the buffer + return fwrite(s, sizeof(charT), n, fp); + } + + // Add to buffer to be written later + + traits::copy(basic_streambuf::pptr(), s, n); + basic_streambuf::pbump(n); + + return n; + } + + FILE * fp; + char_type * pbuffer; + char_type * gbuffer; + bool append; + }; #ifdef __UCLIBCXX_HAS_WCHAR__ template <> _UCXXEXPORT basic_filebuf >::int_type - basic_filebuf >::overflow(int_type c); + basic_filebuf >::overflow(int_type c); template <> _UCXXEXPORT basic_filebuf >::int_type - basic_filebuf >::underflow(); + basic_filebuf >::underflow(); #endif //__UCLIBCXX_HAS_WCHAR__ +#ifdef __UCLIBCXX_EXPAND_FSTREAM_CHAR__ +#ifndef __UCLIBCXX_COMPILE_FSTREAM__ +#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ + + template <> _UCXXEXPORT filebuf::basic_filebuf(); + template <> _UCXXEXPORT filebuf::~basic_filebuf(); + +#endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ + + template <> _UCXXEXPORT filebuf::int_type filebuf::pbackfail(filebuf::int_type c); + template <> _UCXXEXPORT filebuf * filebuf::open(const char* s, ios_base::openmode mode); + template <> _UCXXEXPORT filebuf * filebuf::close(); + template <> _UCXXEXPORT filebuf::int_type filebuf::overflow(filebuf::int_type c); + template <> _UCXXEXPORT filebuf::int_type filebuf::underflow (); + + template <> _UCXXEXPORT basic_streambuf > * filebuf::setbuf(char * s, streamsize n); + template <> _UCXXEXPORT streamsize filebuf::xsputn(const char* s, streamsize n); + +#endif +#endif + + template class _UCXXEXPORT basic_ifstream + : public basic_istream + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + + _UCXXEXPORT basic_ifstream(): basic_ios(&sb), basic_istream(&sb){ + //Passing the address of sb + } + + explicit _UCXXEXPORT basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in) + : basic_ios(&sb), basic_istream(&sb) + { + if (sb.open(s, mode) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + virtual _UCXXEXPORT ~basic_ifstream() + { + } + + _UCXXEXPORT basic_filebuf* rdbuf() const + { + return (basic_filebuf*)&sb; + } + + _UCXXEXPORT bool is_open() const + { + return sb.is_open(); + } + + _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::in) + { + if (sb.open(s, mode) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + _UCXXEXPORT void close() + { + sb.close(); + } + + private: + basic_filebuf sb; + }; + + template class _UCXXEXPORT basic_ofstream + : public basic_ostream + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + + _UCXXEXPORT basic_ofstream() : basic_ios(&sb), basic_ostream(&sb) + { + } + + virtual _UCXXEXPORT ~basic_ofstream(); + + explicit _UCXXEXPORT basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out | ios_base::trunc) : + basic_ios(&sb), basic_ostream(&sb) + { + if (sb.open(s, mode | ios_base::out) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + _UCXXEXPORT basic_filebuf* rdbuf() const + { + return (basic_filebuf*)&sb; + } + + _UCXXEXPORT bool is_open() const + { + return sb.is_open(); + } + + _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::out | ios_base::trunc) + { + if (sb.open(s, mode) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + _UCXXEXPORT void close() + { + sb.close(); + } + + private: + basic_filebuf sb; + }; + + template _UCXXEXPORT basic_ofstream::~basic_ofstream() + { + basic_ostream::flush(); + } + + template class _UCXXEXPORT basic_fstream + : public basic_iostream + { + public: + typedef charT char_type; + typedef typename traits::int_type ins_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + + _UCXXEXPORT basic_fstream(): basic_ios(&sb), basic_iostream(&sb){ } + + explicit _UCXXEXPORT basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out): + basic_ios(&sb), basic_iostream(&sb) + { + if (sb.open(s, mode) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + _UCXXEXPORT basic_filebuf* rdbuf() const + { + return (basic_filebuf*)&sb; + } + + _UCXXEXPORT bool is_open() const + { + return sb.is_open(); + } + + _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out) + { + if (sb.open(s, mode) == 0) + { + basic_ios::setstate(ios_base::failbit); + } + } + + _UCXXEXPORT void close() + { + sb.close(); + } + + private: + basic_filebuf sb; + }; #ifdef __UCLIBCXX_EXPAND_FSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_FSTREAM__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT filebuf::basic_filebuf(); - template <> _UCXXEXPORT filebuf::~basic_filebuf(); + template <> _UCXXEXPORT basic_ofstream >::basic_ofstream(); + template <> _UCXXEXPORT basic_ofstream >::basic_ofstream(const char* s, ios_base::openmode mode); + template <> _UCXXEXPORT basic_ofstream >::~basic_ofstream(); -#endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - - template <> _UCXXEXPORT filebuf::int_type filebuf::pbackfail(filebuf::int_type c); - template <> _UCXXEXPORT filebuf * filebuf::open(const char* s, ios_base::openmode mode); - template <> _UCXXEXPORT filebuf * filebuf::close(); - template <> _UCXXEXPORT filebuf::int_type filebuf::overflow(filebuf::int_type c); - template <> _UCXXEXPORT filebuf::int_type filebuf::underflow (); - - template <> _UCXXEXPORT basic_streambuf > * filebuf::setbuf(char * s, streamsize n); - template <> _UCXXEXPORT streamsize filebuf::xsputn(const char* s, streamsize n); - -#endif -#endif - - - template class _UCXXEXPORT basic_ifstream - : public basic_istream - { - public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - - _UCXXEXPORT basic_ifstream(): basic_ios(&sb), basic_istream(&sb){ - //Passing the address of sb - } - explicit _UCXXEXPORT basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in) - : basic_ios(&sb), basic_istream(&sb) - { - if(sb.open(s, mode) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - - virtual _UCXXEXPORT ~basic_ifstream(){ - - } - - _UCXXEXPORT basic_filebuf* rdbuf() const{ - return (basic_filebuf*)&sb; - } - _UCXXEXPORT bool is_open() const{ - return sb.is_open(); - } - _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::in){ - if(sb.open(s, mode) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - _UCXXEXPORT void close(){ - sb.close(); - } - private: - basic_filebuf sb; - }; - - - template class _UCXXEXPORT basic_ofstream - : public basic_ostream - { - public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - - _UCXXEXPORT basic_ofstream() : basic_ios(&sb), basic_ostream(&sb){ - - } - - virtual _UCXXEXPORT ~basic_ofstream(); - - explicit _UCXXEXPORT basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out | ios_base::trunc) : - basic_ios(&sb), basic_ostream(&sb) - { - if(sb.open(s, mode | ios_base::out ) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - - _UCXXEXPORT basic_filebuf* rdbuf() const{ - return (basic_filebuf*)&sb; - } - - _UCXXEXPORT bool is_open() const{ - return sb.is_open(); - } - _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::out | ios_base::trunc){ - if(sb.open(s, mode) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - _UCXXEXPORT void close(){ - sb.close(); - } - private: - basic_filebuf sb; - }; - - template _UCXXEXPORT basic_ofstream::~basic_ofstream(){ - basic_ostream::flush(); - } - - - template class _UCXXEXPORT basic_fstream - : public basic_iostream - { - public: - typedef charT char_type; - typedef typename traits::int_type ins_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - - _UCXXEXPORT basic_fstream(): basic_ios(&sb), basic_iostream(&sb){ } - - explicit _UCXXEXPORT basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out): - basic_ios(&sb), basic_iostream(&sb) - { - if(sb.open(s, mode) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - - _UCXXEXPORT basic_filebuf* rdbuf() const{ - return (basic_filebuf*)&sb; - } - _UCXXEXPORT bool is_open() const{ - return sb.is_open(); - } - _UCXXEXPORT void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out){ - if(sb.open(s, mode) == 0){ - basic_ios::setstate(ios_base::failbit); - } - } - _UCXXEXPORT void close(){ - sb.close(); - } - private: - basic_filebuf sb; - }; - - - -#ifdef __UCLIBCXX_EXPAND_FSTREAM_CHAR__ -#ifndef __UCLIBCXX_COMPILE_FSTREAM__ - -#ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - - template <> _UCXXEXPORT basic_ofstream >::basic_ofstream(); - template <> _UCXXEXPORT basic_ofstream >::basic_ofstream(const char* s, ios_base::openmode mode); - template <> _UCXXEXPORT basic_ofstream >::~basic_ofstream(); - - template <> _UCXXEXPORT basic_ifstream >::basic_ifstream(); - template <> _UCXXEXPORT basic_ifstream >::basic_ifstream(const char* s, ios_base::openmode mode); - template <> _UCXXEXPORT basic_ifstream >::~basic_ifstream(); + template <> _UCXXEXPORT basic_ifstream >::basic_ifstream(); + template <> _UCXXEXPORT basic_ifstream >::basic_ifstream(const char* s, ios_base::openmode mode); + template <> _UCXXEXPORT basic_ifstream >::~basic_ifstream(); #endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ #endif #endif - - -} +} // namespace +} // exteren "C++" #pragma GCC visibility pop #endif - diff --git a/misc/uClibc++/include/uClibc++/functional b/misc/uClibc++/include/uClibc++/functional index b7932e2cf9..e11e9f3166 100644 --- a/misc/uClibc++/include/uClibc++/functional +++ b/misc/uClibc++/include/uClibc++/functional @@ -1,20 +1,20 @@ -/* 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 + */ #ifndef __STD_HEADER_FUNCTIONAL #define __STD_HEADER_FUNCTIONAL 1 @@ -23,414 +23,466 @@ #pragma GCC visibility push(default) -namespace std{ - - template struct unary_function; - template struct binary_function; - - template struct plus; - template struct minus; - template struct multiplies; - template struct divides; - template struct modulus; - template struct negate; - - template struct equal_to; - template struct not_equal_to; - template struct greater; - template struct less; - template struct greater_equal; - template struct less_equal; - - template struct logical_and; - template struct logical_or; - template struct logical_not; - - template struct unary_negate; - template unary_negate not1(const Predicate&); - template struct binary_negate; - template binary_negate not2(const Predicate&); - - - template class binder1st; - template binder1st bind1st(const Operation&, const T&); - template class binder2nd; - template binder2nd bind2nd(const Operation&, const T&); - - template class pointer_to_unary_function; - template pointer_to_unary_function ptr_fun(Result (*)(Arg)); - template class pointer_to_binary_function; - template - pointer_to_binary_function ptr_fun(Result (*)(Arg1,Arg2)); - - template class mem_fun_t; - template class mem_fun1_t; - template class const_mem_fun_t; - template class const_mem_fun1_t; - template mem_fun_t mem_fun(S (T::*f)()); - template mem_fun1_t mem_fun(S (T::*f)(A)); - template class mem_fun_ref_t; - template class mem_fun1_ref_t; - template mem_fun_ref_t mem_fun_ref(S (T::*f)()); - template mem_fun1_ref_t mem_fun1_ref(S (T::*f)(A)); - - //Implementation - - template struct _UCXXEXPORT unary_function{ - typedef Arg argument_type; - typedef Result result_type; - }; - - - template struct _UCXXEXPORT binary_function{ - typedef Arg1 first_argument_type; - typedef Arg2 second_argument_type; - typedef Result result_type; - }; - - template struct _UCXXEXPORT plus : binary_function{ - T operator()(const T& x, const T& y) const{ - return x + y; - } - }; - - template struct _UCXXEXPORT minus : binary_function{ - T operator()(const T& x, const T& y) const{ - return x - y; - } - }; - - template struct _UCXXEXPORT multiplies : binary_function{ - T operator()(const T& x, const T& y) const{ - return x * y; - } - }; - - template struct _UCXXEXPORT divides : binary_function{ - T operator()(const T& x, const T& y) const{ - return x / y; - } - }; - - template struct _UCXXEXPORT modulus : binary_function{ - T operator()(const T& x, const T& y) const{ - return x % y; - } - }; - - template struct _UCXXEXPORT negate : unary_function{ - T operator()(const T& x) const{ - return -x; - } - }; - - template struct _UCXXEXPORT equal_to : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x == y); - } - }; - - template struct _UCXXEXPORT not_equal_to : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x != y); - } - }; - - template struct _UCXXEXPORT greater : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x > y); - } - }; - - template struct _UCXXEXPORT less : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x < y); - } - }; - - template struct _UCXXEXPORT greater_equal : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x >= y); - } - }; - - template struct _UCXXEXPORT less_equal : binary_function{ - bool operator()(const T& x, const T& y) const{ - return (x <= y); - } - }; - - template struct _UCXXEXPORT logical_and : binary_function { - bool operator()(const T& x, const T& y) const{ - return (x && y); - } - }; - - template struct _UCXXEXPORT logical_or : binary_function { - bool operator()(const T& x, const T& y) const{ - return (x || y); - } - }; - - template struct _UCXXEXPORT logical_not : unary_function { - bool operator()(const T& x) const{ - return !x; - } - }; - - template class _UCXXEXPORT unary_negate - : public unary_function - { - public: - explicit unary_negate(const Predicate& pred) : p(pred) { } - bool operator()(const typename Predicate::argument_type& x) const{ - return !p(x); - } - private: - Predicate p; - }; - - - template _UCXXEXPORT unary_negate not1(const Predicate& pred){ - return unary_negate(pred); - } - - - template class _UCXXEXPORT binary_negate : public - binary_function - { - public: - explicit binary_negate(const Predicate& pred) : p(pred) { } - bool operator()(const typename Predicate::first_argument_type& x, - const typename Predicate::second_argument_type& y) const - { - return !p(x, y); - } - private: - Predicate p; - }; - - - template _UCXXEXPORT binary_negate not2(const Predicate& pred){ - return binary_negate(pred); - } - - - template class _UCXXEXPORT binder1st - : public unary_function - { - protected: - Operation op; - typename Operation::first_argument_type value; - public: - binder1st(const Operation& x, const typename Operation::first_argument_type& y) : op(x), value(y){ } - typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const{ - return op(value,x); - } - }; - - - template _UCXXEXPORT binder1st bind1st(const Operation& op, const T& x){ - return binder1st(op, typename Operation::first_argument_type(x)); - } - - - template class _UCXXEXPORT binder2nd - : public unary_function - { - protected: - Operation op; - typename Operation::second_argument_type value; - public: - binder2nd(const Operation& x, const typename Operation::second_argument_type& y) : op(x), value(y) { } - typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const{ - return op(x,value); - } - }; - - - template _UCXXEXPORT - binder2nd bind2nd(const Operation& op, const T& x) - { - return binder2nd(op, typename Operation::second_argument_type(x)); - } - - - template class _UCXXEXPORT - pointer_to_unary_function : public unary_function - { - protected: - Result (*func)(Arg); - public: - explicit pointer_to_unary_function(Result (*f)(Arg)) : func(f) { } - Result operator()(Arg x) const{ - return func(x); - } - }; - - - template _UCXXEXPORT pointer_to_unary_function ptr_fun(Result (*f)(Arg)){ - return pointer_to_unary_function(f); - } - - - template class _UCXXEXPORT - pointer_to_binary_function : public binary_function - { - protected: - Result (*func)(Arg1, Arg2); - public: - explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)) : func(f) { } - Result operator()(Arg1 x, Arg2 y) const{ - return func(x, y); - } - }; - - template _UCXXEXPORT - pointer_to_binary_function ptr_fun(Result (*f)(Arg1, Arg2)) - { - return pointer_to_binary_function(f); - } - - - template class _UCXXEXPORT mem_fun_t - : public unary_function - { - public: - explicit mem_fun_t(S (T::*p)()) : m(p) { } - S operator()(T* p) const { return (p->*m)(); } - private: - S (T::*m)(); - }; - - - template class _UCXXEXPORT mem_fun1_t - : public binary_function - { - public: - explicit mem_fun1_t(S (T::*p)(A)) : m(p) { } - S operator()(T* p, A x) const { return (p->*m)(x); } - private: - S (T::*m)(A); - }; - - - template class _UCXXEXPORT const_mem_fun_t - : public unary_function - { - public: - explicit const_mem_fun_t(S (T::*p)() const) : m(p) { } - S operator()(const T* p) const { return (p->*m)(); } - private: - S (T::*m)() const; - }; - - - template class _UCXXEXPORT const_mem_fun1_t - : public binary_function - { - public: - explicit const_mem_fun1_t(S (T::*p)(A) const) : m(p) { } - S operator()(const T* p, A x) const { return (p->*m)(x); } - private: - S (T::*m)(A) const; - }; - - - template _UCXXEXPORT mem_fun_t mem_fun(S (T::*f)()){ - return mem_fun_t(f); - } - - template _UCXXEXPORT const_mem_fun_t mem_fun(S (T::*f)() const){ - return const_mem_fun_t(f); - } - - template _UCXXEXPORT mem_fun1_t mem_fun(S (T::*f)(A)){ - return mem_fun1_t(f); - } - - template _UCXXEXPORT const_mem_fun1_t mem_fun(S (T::*f)(A) const){ - return const_mem_fun1_t(f); - } - - template class _UCXXEXPORT mem_fun_ref_t - : public unary_function - { - public: - explicit mem_fun_ref_t(S (T::*p)()) : mf(p) { } - S operator()(T& p) { return (p.*mf)(); } - private: - S (T::*mf)(); - }; - - template class _UCXXEXPORT mem_fun1_ref_t - : public binary_function - { - public: - explicit mem_fun1_ref_t(S (T::*p)(A)) : mf(p) { } - S operator()(T& p, A x) { return (p.*mf)(x); } - private: - S (T::*mf)(A); - }; - - template _UCXXEXPORT mem_fun_ref_t mem_fun_ref(S (T::*f)()){ - return mem_fun_ref_t(f); - } - - template _UCXXEXPORT mem_fun1_ref_t mem_fun1_ref(S (T::*f)(A)){ - return mem_fun1_ref_t(f); - } - - -} - - -//These are SGI extensions which are checked for by some conformance checks. They +extern "C++" +{ + +namespace std +{ + + template struct unary_function; + template struct binary_function; + + template struct plus; + template struct minus; + template struct multiplies; + template struct divides; + template struct modulus; + template struct negate; + + template struct equal_to; + template struct not_equal_to; + template struct greater; + template struct less; + template struct greater_equal; + template struct less_equal; + + template struct logical_and; + template struct logical_or; + template struct logical_not; + + template struct unary_negate; + template unary_negate not1(const Predicate&); + template struct binary_negate; + template binary_negate not2(const Predicate&); + + template class binder1st; + template binder1st bind1st(const Operation&, const T&); + template class binder2nd; + template binder2nd bind2nd(const Operation&, const T&); + + template class pointer_to_unary_function; + template pointer_to_unary_function ptr_fun(Result (*)(Arg)); + template class pointer_to_binary_function; + template + pointer_to_binary_function ptr_fun(Result (*)(Arg1,Arg2)); + + template class mem_fun_t; + template class mem_fun1_t; + template class const_mem_fun_t; + template class const_mem_fun1_t; + template mem_fun_t mem_fun(S (T::*f)()); + template mem_fun1_t mem_fun(S (T::*f)(A)); + template class mem_fun_ref_t; + template class mem_fun1_ref_t; + template mem_fun_ref_t mem_fun_ref(S (T::*f)()); + template mem_fun1_ref_t mem_fun1_ref(S (T::*f)(A)); + + // Implementation + + template struct _UCXXEXPORT unary_function + { + typedef Arg argument_type; + typedef Result result_type; + }; + + template struct _UCXXEXPORT binary_function + { + typedef Arg1 first_argument_type; + typedef Arg2 second_argument_type; + typedef Result result_type; + }; + + template struct _UCXXEXPORT plus : binary_function + { + T operator()(const T& x, const T& y) const{ + return x + y; + } + }; + + template struct _UCXXEXPORT minus : binary_function + { + T operator()(const T& x, const T& y) const + { + return x - y; + } + }; + + template struct _UCXXEXPORT multiplies : binary_function + { + T operator()(const T& x, const T& y) const{ + return x * y; + } + }; + + template struct _UCXXEXPORT divides : binary_function + { + T operator()(const T& x, const T& y) const{ + return x / y; + } + }; + + template struct _UCXXEXPORT modulus : binary_function + { + T operator()(const T& x, const T& y) const + { + return x % y; + } + }; + + template struct _UCXXEXPORT negate : unary_function + { + T operator()(const T& x) const{ + return -x; + } + }; + + template struct _UCXXEXPORT equal_to : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x == y); + } + }; + + template struct _UCXXEXPORT not_equal_to : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x != y); + } + }; + + template struct _UCXXEXPORT greater : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x > y); + } + }; + + template struct _UCXXEXPORT less : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x < y); + } + }; + + template struct _UCXXEXPORT greater_equal : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x >= y); + } + }; + + template struct _UCXXEXPORT less_equal : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x <= y); + } + }; + + template struct _UCXXEXPORT logical_and : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x && y); + } + }; + + template struct _UCXXEXPORT logical_or : binary_function + { + bool operator()(const T& x, const T& y) const + { + return (x || y); + } + }; + + template struct _UCXXEXPORT logical_not : unary_function + { + bool operator()(const T& x) const + { + return !x; + } + }; + + template class _UCXXEXPORT unary_negate + : public unary_function + { + public: + explicit unary_negate(const Predicate& pred) : p(pred) { } + + bool operator()(const typename Predicate::argument_type& x) const + { + return !p(x); + } + + private: + Predicate p; + }; + + template _UCXXEXPORT unary_negate not1(const Predicate& pred) + { + return unary_negate(pred); + } + + template class _UCXXEXPORT binary_negate : public + binary_function + { + public: + explicit binary_negate(const Predicate& pred) : p(pred) { } + + bool operator()(const typename Predicate::first_argument_type& x, + const typename Predicate::second_argument_type& y) const + { + return !p(x, y); + } + + private: + Predicate p; + }; + + template _UCXXEXPORT binary_negate not2(const Predicate& pred){ + return binary_negate(pred); + } + + template class _UCXXEXPORT binder1st + : public unary_function + { + protected: + Operation op; + typename Operation::first_argument_type value; + public: + binder1st(const Operation& x, const typename Operation::first_argument_type& y) : op(x), value(y){ } + + typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const + { + return op(value,x); + } + }; + + template _UCXXEXPORT binder1st bind1st(const Operation& op, const T& x) + { + return binder1st(op, typename Operation::first_argument_type(x)); + } + + template class _UCXXEXPORT binder2nd + : public unary_function + { + protected: + Operation op; + typename Operation::second_argument_type value; + public: + binder2nd(const Operation& x, const typename Operation::second_argument_type& y) : op(x), value(y) { } + + typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const + { + return op(x,value); + } + }; + + template _UCXXEXPORT + binder2nd bind2nd(const Operation& op, const T& x) + { + return binder2nd(op, typename Operation::second_argument_type(x)); + } + + template class _UCXXEXPORT + pointer_to_unary_function : public unary_function + { + protected: + Result (*func)(Arg); + public: + explicit pointer_to_unary_function(Result (*f)(Arg)) : func(f) { } + + Result operator()(Arg x) const + { + return func(x); + } + }; + + template _UCXXEXPORT pointer_to_unary_function ptr_fun(Result (*f)(Arg)) + { + return pointer_to_unary_function(f); + } + + template class _UCXXEXPORT + pointer_to_binary_function : public binary_function + { + protected: + Result (*func)(Arg1, Arg2); + + public: + explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)) : func(f) { } + + Result operator()(Arg1 x, Arg2 y) const + { + return func(x, y); + } + }; + + template _UCXXEXPORT + pointer_to_binary_function ptr_fun(Result (*f)(Arg1, Arg2)) + { + return pointer_to_binary_function(f); + } + + template class _UCXXEXPORT mem_fun_t + : public unary_function + { + public: + explicit mem_fun_t(S (T::*p)()) : m(p) { } + S operator()(T* p) const { return (p->*m)(); } + + private: + S (T::*m)(); + }; + + template class _UCXXEXPORT mem_fun1_t + : public binary_function + { + public: + explicit mem_fun1_t(S (T::*p)(A)) : m(p) { } + S operator()(T* p, A x) const { return (p->*m)(x); } + private: + S (T::*m)(A); + }; + + template class _UCXXEXPORT const_mem_fun_t + : public unary_function + { + public: + explicit const_mem_fun_t(S (T::*p)() const) : m(p) { } + S operator()(const T* p) const { return (p->*m)(); } + + private: + S (T::*m)() const; + }; + + template class _UCXXEXPORT const_mem_fun1_t + : public binary_function + { + public: + explicit const_mem_fun1_t(S (T::*p)(A) const) : m(p) { } + S operator()(const T* p, A x) const { return (p->*m)(x); } + + private: + S (T::*m)(A) const; + }; + + template _UCXXEXPORT mem_fun_t mem_fun(S (T::*f)()) + { + return mem_fun_t(f); + } + + template _UCXXEXPORT const_mem_fun_t mem_fun(S (T::*f)() const) + { + return const_mem_fun_t(f); + } + + template _UCXXEXPORT mem_fun1_t mem_fun(S (T::*f)(A)) + { + return mem_fun1_t(f); + } + + template _UCXXEXPORT const_mem_fun1_t mem_fun(S (T::*f)(A) const) + { + return const_mem_fun1_t(f); + } + + template class _UCXXEXPORT mem_fun_ref_t + : public unary_function + { + public: + explicit mem_fun_ref_t(S (T::*p)()) : mf(p) { } + S operator()(T& p) { return (p.*mf)(); } + + private: + S (T::*mf)(); + }; + + template class _UCXXEXPORT mem_fun1_ref_t + : public binary_function + { + public: + explicit mem_fun1_ref_t(S (T::*p)(A)) : mf(p) { } + S operator()(T& p, A x) { return (p.*mf)(x); } + + private: + S (T::*mf)(A); + }; + + template _UCXXEXPORT mem_fun_ref_t mem_fun_ref(S (T::*f)()) + { + return mem_fun_ref_t(f); + } + + template _UCXXEXPORT mem_fun1_ref_t mem_fun1_ref(S (T::*f)(A)) + { + return mem_fun1_ref_t(f); + } + +} // namespace + +// These are SGI extensions which are checked for by some conformance checks. They // are *NOT* part of the C++ standard, however template class _UCXXEXPORT unary_compose : - public std::unary_function + public std::unary_function { protected: - Op1 mf1; - Op2 mf2; + Op1 mf1; + Op2 mf2; + public: - unary_compose(const Op1& x, const Op2& y) : mf1(x), mf2(y) { } - typename Op1::result_type operator()(const typename Op2::argument_type& x) const { - return mf1(mf2(x)); - } + unary_compose(const Op1& x, const Op2& y) : mf1(x), mf2(y) { } + + typename Op1::result_type operator()(const typename Op2::argument_type& x) const + { + return mf1(mf2(x)); + } }; template _UCXXEXPORT inline unary_compose -compose1(const Op1& fn1, const Op2& fn2){ - return unary_compose(fn1, fn2); +compose1(const Op1& fn1, const Op2& fn2) +{ + return unary_compose(fn1, fn2); } template class _UCXXEXPORT binary_compose : - public std::unary_function + public std::unary_function { protected: - Op1 mf1; - Op2 mf2; - Op3 mf3; + Op1 mf1; + Op2 mf2; + Op3 mf3; + public: - binary_compose(const Op1 & x, const Op2 & y, const Op3 & z) - : mf1(x), mf2(y), mf3(z){ } - typename Op1::result_type operator()(const typename Op2::argument_type & x) const { - return mf1(mf2(x), mf3(x)); - } + binary_compose(const Op1 & x, const Op2 & y, const Op3 & z) + : mf1(x), mf2(y), mf3(z){ } + + typename Op1::result_type operator()(const typename Op2::argument_type & x) const + { + return mf1(mf2(x), mf3(x)); + } }; template inline _UCXXEXPORT binary_compose -compose2(const Op1 & fn1, const Op2 & fn2, const Op3 & fn3){ - return binary_compose(fn1, fn2, fn3); + +compose2(const Op1 & fn1, const Op2 & fn2, const Op3 & fn3) +{ + return binary_compose(fn1, fn2, fn3); } +} // extern "C++" + #pragma GCC visibility pop #endif diff --git a/misc/uClibc++/include/uClibc++/iomanip b/misc/uClibc++/include/uClibc++/iomanip index 14a82607c1..82125268a6 100644 --- a/misc/uClibc++/include/uClibc++/iomanip +++ b/misc/uClibc++/include/uClibc++/iomanip @@ -1,21 +1,21 @@ -/* Copyright (C) 2005 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) 2005 Garrett A. Kajmowicz + * + * This file is part of the uClibc++ Library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include @@ -25,144 +25,157 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ // These are the helper classes which we are going to be using to // hold the required data -class _UCXXEXPORT __resetiosflags{ +class _UCXXEXPORT __resetiosflags +{ public: - ios_base::fmtflags m; - _UCXXEXPORT __resetiosflags(ios_base::fmtflags mask) : m(mask){ } + ios_base::fmtflags m; + _UCXXEXPORT __resetiosflags(ios_base::fmtflags mask) : m(mask){ } }; -class _UCXXEXPORT __setiosflags{ +class _UCXXEXPORT __setiosflags +{ public: - ios_base::fmtflags m; - _UCXXEXPORT __setiosflags(ios_base::fmtflags mask) : m(mask){ } + ios_base::fmtflags m; + _UCXXEXPORT __setiosflags(ios_base::fmtflags mask) : m(mask){ } }; -class _UCXXEXPORT __setbase{ +class _UCXXEXPORT __setbase +{ public: - int base; - _UCXXEXPORT __setbase(int b) : base(b){ } + int base; + _UCXXEXPORT __setbase(int b) : base(b){ } }; -class _UCXXEXPORT __setfill{ +class _UCXXEXPORT __setfill +{ public: - int character; - _UCXXEXPORT __setfill(int c): character(c){ } + int character; + _UCXXEXPORT __setfill(int c): character(c){ } }; -class _UCXXEXPORT __setprecision{ +class _UCXXEXPORT __setprecision +{ public: - int digits; - _UCXXEXPORT __setprecision(int n): digits(n) { } + int digits; + _UCXXEXPORT __setprecision(int n): digits(n) { } }; -class _UCXXEXPORT __setw{ +class _UCXXEXPORT __setw +{ public: - int width; - _UCXXEXPORT __setw(int n): width(n) { } + int width; + _UCXXEXPORT __setw(int n): width(n) { } }; +// Actual manipulator functions -//Actual manipulator functions - -inline __resetiosflags resetiosflags(ios_base::fmtflags mask){ - return __resetiosflags(mask); +inline __resetiosflags resetiosflags(ios_base::fmtflags mask) +{ + return __resetiosflags(mask); } -inline __setiosflags setiosflags(ios_base::fmtflags mask){ - return __setiosflags(mask); +inline __setiosflags setiosflags(ios_base::fmtflags mask) +{ + return __setiosflags(mask); } -inline __setbase setbase(int b){ - return __setbase(b); +inline __setbase setbase(int b) +{ + return __setbase(b); } -inline __setfill setfill(int c){ - return __setfill(c); +inline __setfill setfill(int c) +{ + return __setfill(c); } -inline __setprecision setprecision(int n){ - return __setprecision(n); +inline __setprecision setprecision(int n) +{ + return __setprecision(n); } -inline __setw setw(int n){ - return __setw(n); +inline __setw setw(int n) +{ + return __setw(n); } - -//How to handle interaction with [i|o]stream classes +// How to handle interaction with [i|o]stream classes template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __resetiosflags s) + operator<<(basic_ostream& os, const __resetiosflags s) { - os.setf(ios_base::fmtflags(0),s.m); - return os; + os.setf(ios_base::fmtflags(0),s.m); + return os; } template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, const __resetiosflags s) + operator>>(basic_istream& is, const __resetiosflags s) { - is.setf(ios_base::fmtflags(0),s.m); - return is; + is.setf(ios_base::fmtflags(0),s.m); + return is; } template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __setiosflags s) + operator<<(basic_ostream& os, const __setiosflags s) { - os.setf(s.m); - return os; + os.setf(s.m); + return os; } template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __setbase s) + operator<<(basic_ostream& os, const __setbase s) { - ios_base::fmtflags f(0); - switch(s.base){ - case 8: - f = ios_base::oct; - break; - case 10: - f = ios_base::dec; - break; - case 16: - f = ios_base::hex; - break; - default: - break; + ios_base::fmtflags f(0); + switch(s.base) + { + case 8: + f = ios_base::oct; + break; + case 10: + f = ios_base::dec; + break; + case 16: + f = ios_base::hex; + break; + default: + break; + } - } - os.setf(f, ios_base::basefield); - return os; + os.setf(f, ios_base::basefield); + return os; } template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __setfill s) + operator<<(basic_ostream& os, const __setfill s) { - os.fill(s.character); - return os; + os.fill(s.character); + return os; } template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __setprecision s) + operator<<(basic_ostream& os, const __setprecision s) { - os.precision(s.digits); - return os; + os.precision(s.digits); + return os; } template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const __setw s) + operator<<(basic_ostream& os, const __setw s) { - os.width(s.width); - return os; + os.width(s.width); + return os; } - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/ios b/misc/uClibc++/include/uClibc++/ios index 2af1a14cb2..6b49921ed8 100644 --- a/misc/uClibc++/include/uClibc++/ios +++ b/misc/uClibc++/include/uClibc++/ios @@ -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 #include @@ -27,472 +27,583 @@ #pragma GCC visibility push(default) -namespace std{ - typedef signed long int streamoff; +extern "C++" +{ +namespace std +{ + typedef signed long int streamoff; - template class fpos; + template class fpos; - class _UCXXEXPORT ios_base { - public: - class failure; + class _UCXXEXPORT ios_base + { + public: + class failure; #ifdef CONFIG_UCLIBCXX_EXCEPTION - class failure : public exception { - public: - explicit failure(const std::string&) { } - explicit failure() { } - virtual const char* what() const throw() { - return "std::ios_base failure exception"; - } - }; + class failure : public exception + { + public: + explicit failure(const std::string&) { } + explicit failure() { } + virtual const char* what() const throw() { + return "std::ios_base failure exception"; + } + }; #endif #ifdef __UCLIBCXX_SUPPORT_CDIR__ - class _UCXXLOCAL Init{ - public: - _UCXXEXPORT Init(); - _UCXXEXPORT ~Init(); - private: - static int init_cnt; - }; + class _UCXXLOCAL Init + { + public: + _UCXXEXPORT Init(); + _UCXXEXPORT ~Init(); + private: + static int init_cnt; + }; #endif - public: + public: - typedef unsigned short int fmtflags; + typedef unsigned short int fmtflags; - static const fmtflags skipws = 0x0001; + static const fmtflags skipws = 0x0001; - static const fmtflags left = 0x0002; - static const fmtflags right = 0x0004; - static const fmtflags internal = 0x0008; + static const fmtflags left = 0x0002; + static const fmtflags right = 0x0004; + static const fmtflags internal = 0x0008; - static const fmtflags boolalpha = 0x0010; + static const fmtflags boolalpha = 0x0010; - static const fmtflags dec = 0x0020; - static const fmtflags oct = 0x0040; - static const fmtflags hex = 0x0080; + static const fmtflags dec = 0x0020; + static const fmtflags oct = 0x0040; + static const fmtflags hex = 0x0080; - static const fmtflags scientific = 0x0100; - static const fmtflags fixed = 0x0200; + static const fmtflags scientific = 0x0100; + static const fmtflags fixed = 0x0200; - static const fmtflags showbase = 0x0400; - static const fmtflags showpoint = 0x0800; - static const fmtflags showpos = 0x1000; - static const fmtflags uppercase = 0x2000; + static const fmtflags showbase = 0x0400; + static const fmtflags showpoint = 0x0800; + static const fmtflags showpos = 0x1000; + static const fmtflags uppercase = 0x2000; - static const fmtflags adjustfield = left | right | internal; - static const fmtflags basefield = dec | oct | hex; - static const fmtflags floatfield = fixed | scientific; + static const fmtflags adjustfield = left | right | internal; + static const fmtflags basefield = dec | oct | hex; + static const fmtflags floatfield = fixed | scientific; - static const fmtflags unitbuf = 0x4000; + static const fmtflags unitbuf = 0x4000; - typedef unsigned char iostate; - static const iostate goodbit = 0x00; - static const iostate badbit = 0x01; - static const iostate eofbit = 0x02; - static const iostate failbit = 0x04; + typedef unsigned char iostate; + static const iostate goodbit = 0x00; + static const iostate badbit = 0x01; + static const iostate eofbit = 0x02; + static const iostate failbit = 0x04; - typedef unsigned char openmode; - static const openmode app = 0x01; - static const openmode ate = 0x02; - static const openmode binary = 0x04; - static const openmode in = 0x08; - static const openmode out = 0x10; - static const openmode trunc = 0x20; + typedef unsigned char openmode; + static const openmode app = 0x01; + static const openmode ate = 0x02; + static const openmode binary = 0x04; + static const openmode in = 0x08; + static const openmode out = 0x10; + static const openmode trunc = 0x20; - typedef unsigned char seekdir; - static const seekdir beg = 0x01; - static const seekdir cur = 0x02; - static const seekdir end = 0x04; + typedef unsigned char seekdir; + static const seekdir beg = 0x01; + static const seekdir cur = 0x02; + static const seekdir end = 0x04; - _UCXXEXPORT fmtflags flags() const{ - return mformat; - } - _UCXXEXPORT fmtflags flags(fmtflags fmtfl); + _UCXXEXPORT fmtflags flags() const + { + return mformat; + } - fmtflags setf(fmtflags fmtfl); - fmtflags setf(fmtflags fmtfl, fmtflags mask ); + _UCXXEXPORT fmtflags flags(fmtflags fmtfl); - _UCXXEXPORT void unsetf(fmtflags mask){ - mformat&= ~mask; - } + fmtflags setf(fmtflags fmtfl); + fmtflags setf(fmtflags fmtfl, fmtflags mask); - _UCXXEXPORT streamsize precision() const{ - return mprecision; - } + _UCXXEXPORT void unsetf(fmtflags mask) + { + mformat&= ~mask; + } - _UCXXEXPORT streamsize precision(streamsize prec); + _UCXXEXPORT streamsize precision() const + { + return mprecision; + } - _UCXXEXPORT streamsize width() const{ - return mwidth; - } + _UCXXEXPORT streamsize precision(streamsize prec); - _UCXXEXPORT streamsize width(streamsize wide); + _UCXXEXPORT streamsize width() const + { + return mwidth; + } - _UCXXEXPORT locale imbue(const locale& loc); + _UCXXEXPORT streamsize width(streamsize wide); - _UCXXEXPORT locale getloc() const{ - return mLocale; - } + _UCXXEXPORT locale imbue(const locale& loc); -// FIXME - These need to be implemented -// static int xalloc(); -// long& iword(int index); -// void*& pword(int index); + _UCXXEXPORT locale getloc() const + { + return mLocale; + } - _UCXXEXPORT ~ios_base() { } +// FIXME - These need to be implemented +// static int xalloc(); +// long& iword(int index); +// void*& pword(int index); - enum event { erase_event, imbue_event, copyfmt_event }; + _UCXXEXPORT ~ios_base() { } - typedef void (*event_callback)(event, ios_base&, int index); -// void register_callback(event_call_back fn, int index); + enum event { erase_event, imbue_event, copyfmt_event }; - //We are going to wrap stdio so we don't need implementation of the following: - inline static bool sync_with_stdio(bool = true) { return true; } + typedef void (*event_callback)(event, ios_base&, int index); +// void register_callback(event_call_back fn, int index); - protected: - _UCXXEXPORT ios_base() : mLocale(), mformat(dec | skipws ), mstate(goodbit), - mmode(), mdir(), mprecision(6), mwidth(0) + //We are going to wrap stdio so we don't need implementation of the following: + inline static bool sync_with_stdio(bool = true) { return true; } + + protected: + _UCXXEXPORT ios_base() : mLocale(), mformat(dec | skipws), mstate(goodbit), + mmode(), mdir(), mprecision(6), mwidth(0) #ifdef __UCLIBCXX_SUPPORT_CDIR__ - ,mInit() + ,mInit() #endif - { + { - } - locale mLocale; - fmtflags mformat; - iostate mstate; - openmode mmode; - seekdir mdir; - streamsize mprecision; - streamsize mwidth; + } + locale mLocale; + fmtflags mformat; + iostate mstate; + openmode mmode; + seekdir mdir; + streamsize mprecision; + streamsize mwidth; #ifdef __UCLIBCXX_SUPPORT_CDIR__ - Init mInit; + Init mInit; #endif - }; + }; + // ios_base manipulators - //ios_base manipulators + inline ios_base& boolalpha(ios_base& str) + { + str.setf(ios_base::boolalpha); + return str; + } + inline ios_base& noboolalpha(ios_base& str) + { + str.unsetf(ios_base::boolalpha); + return str; + } - inline ios_base& boolalpha (ios_base& str){ - str.setf(ios_base::boolalpha); - return str; - } - inline ios_base& noboolalpha(ios_base& str){ - str.unsetf(ios_base::boolalpha); - return str; - } - inline ios_base& showbase (ios_base& str){ - str.setf(ios_base::showbase); - return str; - } - inline ios_base& noshowbase (ios_base& str){ - str.unsetf(ios_base::showbase); - return str; - } - inline ios_base& showpoint (ios_base& str){ - str.setf(ios_base::showpoint); - return str; - } - inline ios_base& noshowpoint(ios_base& str){ - str.unsetf(ios_base::showpoint); - return str; - } - inline ios_base& showpos (ios_base& str){ - str.setf(ios_base::showpos); - return str; - } - inline ios_base& noshowpos (ios_base& str){ - str.unsetf(ios_base::showpos); - return str; - } - inline ios_base& skipws (ios_base& str){ - str.setf(ios_base::skipws); - return str; - } - inline ios_base& noskipws (ios_base& str){ - str.unsetf(ios_base::skipws); - return str; - } - inline ios_base& uppercase (ios_base& str){ - str.setf(ios_base::uppercase); - return str; - } - inline ios_base& nouppercase(ios_base& str){ - str.unsetf(ios_base::uppercase); - return str; - } + inline ios_base& showbase(ios_base& str){ + str.setf(ios_base::showbase); + return str; + } - inline ios_base& unitbuf (ios_base& str){ - str.setf(ios_base::unitbuf); - return str; - } - inline ios_base& nounitbuf (ios_base& str){ - str.unsetf(ios_base::unitbuf); - return str; - } - inline ios_base& internal (ios_base& str){ - str.setf(ios_base::internal, ios_base::adjustfield); - return str; - } - inline ios_base& left (ios_base& str){ - str.setf(ios_base::left, ios_base::adjustfield); - return str; - } - inline ios_base& right (ios_base& str){ - str.setf(ios_base::right, ios_base::adjustfield); - return str; - } + inline ios_base& noshowbase(ios_base& str) + { + str.unsetf(ios_base::showbase); + return str; + } - inline ios_base& dec (ios_base& str){ - str.setf(ios_base::dec, ios_base::basefield); - return str; - } - inline ios_base& hex (ios_base& str){ - str.setf(ios_base::hex, ios_base::basefield); - return str; - } - inline ios_base& oct (ios_base& str){ - str.setf(ios_base::oct, ios_base::basefield); - return str; - } + inline ios_base& showpoint(ios_base& str) + { + str.setf(ios_base::showpoint); + return str; + } - inline ios_base& fixed (ios_base& str){ - str.setf(ios_base::fixed, ios_base::floatfield); - return str; - } - inline ios_base& scientific (ios_base& str){ - str.setf(ios_base::scientific, ios_base::floatfield); - return str; - } + inline ios_base& noshowpoint(ios_base& str) + { + str.unsetf(ios_base::showpoint); + return str; + } + inline ios_base& showpos(ios_base& str) + { + str.setf(ios_base::showpos); + return str; + } - //basic_ios class definition + inline ios_base& noshowpos(ios_base& str) + { + str.unsetf(ios_base::showpos); + return str; + } + inline ios_base& skipws(ios_base& str) + { + str.setf(ios_base::skipws); + return str; + } - template class _UCXXEXPORT basic_ios - : public ios_base - { - public: - // Types: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - typedef traits traits_type; + inline ios_base& noskipws(ios_base& str) + { + str.unsetf(ios_base::skipws); + return str; + } - _UCXXEXPORT operator void*() const{ - if(fail() ){ - return 0; - } - return (void *)(1); //Must return a non-NULL pointer (though it can be *any* pointer) - } + inline ios_base& uppercase(ios_base& str) + { + str.setf(ios_base::uppercase); + return str; + } - _UCXXEXPORT bool operator!() const{ - return fail(); - } - _UCXXEXPORT iostate rdstate() const{ - return mstate; - } - _UCXXEXPORT void clear(iostate state = goodbit){ - if(rdbuf()!=0){ - mstate = state; - }else{ - mstate = state|ios_base::badbit; - } - } - _UCXXEXPORT void setstate(iostate state) { - clear(rdstate() | state); + inline ios_base& nouppercase(ios_base& str) + { + str.unsetf(ios_base::uppercase); + return str; + } + + inline ios_base& unitbuf(ios_base& str) + { + str.setf(ios_base::unitbuf); + return str; + } + + inline ios_base& nounitbuf(ios_base& str) + { + str.unsetf(ios_base::unitbuf); + return str; + } + + inline ios_base& internal(ios_base& str) + { + str.setf(ios_base::internal, ios_base::adjustfield); + return str; + } + + inline ios_base& left(ios_base& str) + { + str.setf(ios_base::left, ios_base::adjustfield); + return str; + } + + inline ios_base& right(ios_base& str) + { + str.setf(ios_base::right, ios_base::adjustfield); + return str; + } + + inline ios_base& dec(ios_base& str) + { + str.setf(ios_base::dec, ios_base::basefield); + return str; + } + + inline ios_base& hex(ios_base& str) + { + str.setf(ios_base::hex, ios_base::basefield); + return str; + } + + inline ios_base& oct(ios_base& str) + { + str.setf(ios_base::oct, ios_base::basefield); + return str; + } + + inline ios_base& fixed(ios_base& str) + { + str.setf(ios_base::fixed, ios_base::floatfield); + return str; + } + + inline ios_base& scientific(ios_base& str) + { + str.setf(ios_base::scientific, ios_base::floatfield); + return str; + } + + // basic_ios class definition + + template class _UCXXEXPORT basic_ios + : public ios_base + { + public: + // Types: + + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef traits traits_type; + + _UCXXEXPORT operator void*() const + { + if (fail()) + { + return 0; + } + + return (void *)(1); // Must return a non-NULL pointer (though it can be *any* pointer) + } + + _UCXXEXPORT bool operator!() const + { + return fail(); + } + + _UCXXEXPORT iostate rdstate() const + { + return mstate; + } + + _UCXXEXPORT void clear(iostate state = goodbit) + { + if (rdbuf()!=0) + { + mstate = state; + } + else + { + mstate = state|ios_base::badbit; + } + } + + _UCXXEXPORT void setstate(iostate state) + { + clear(rdstate() | state); #ifdef CONFIG_UCLIBCXX_EXCEPTION - if(rdstate() & throw_mask){ - throw failure(); - } + if (rdstate() & throw_mask) + { + throw failure(); + } #endif - } + } - _UCXXEXPORT bool good() const{ - return (rdstate() == 0); - } - _UCXXEXPORT bool eof() const{ - if(rdstate() & eofbit){ - return true; - } - return false; - } - _UCXXEXPORT bool fail() const{ - if( mstate & (failbit | badbit) ){ - return true; - } - return false; - } + _UCXXEXPORT bool good() const + { + return (rdstate() == 0); + } - _UCXXEXPORT bool bad() const{ - if(mstate & badbit){ - return true; - } - return false; - } + _UCXXEXPORT bool eof() const + { + if (rdstate() & eofbit) + { + return true; + } - _UCXXEXPORT iostate exceptions() const{ - return throw_mask; - } - _UCXXEXPORT void exceptions(iostate except){ - throw_mask = except; - } + return false; + } - explicit _UCXXEXPORT basic_ios(basic_streambuf* sb) : fill_char(' '), mtied(0), mstreambuf(0){ - init(sb); - } + _UCXXEXPORT bool fail() const + { + if (mstate & (failbit | badbit)) + { + return true; + } - basic_ios() : mtied(0), mstreambuf(0){ } + return false; + } - virtual _UCXXEXPORT ~basic_ios(){ - } + _UCXXEXPORT bool bad() const + { + if (mstate & badbit) + { + return true; + } - _UCXXEXPORT basic_ostream* tie() const{ - return mtied; - } - _UCXXEXPORT basic_ostream* tie(basic_ostream* tiestr){ - basic_ostream* retval= mtied; - mtied = tiestr; - return retval; - } - _UCXXEXPORT basic_streambuf* rdbuf() const{ - return mstreambuf; - } - _UCXXEXPORT basic_streambuf* rdbuf(basic_streambuf* sb){ - basic_streambuf* retval = mstreambuf; - mstreambuf = sb; - return retval; - } - _UCXXEXPORT basic_ios& copyfmt(const basic_ios& rhs); - _UCXXEXPORT char_type fill() const{ - return fill_char; - } - _UCXXEXPORT char_type fill(char_type ch){ - char_type temp = fill_char; - fill_char = ch; - return temp; - } + return false; + } - _UCXXEXPORT locale imbue(const locale& loc){ - return ios_base::imbue(loc); - } - _UCXXEXPORT char narrow(char_type c, char dfault) const; - _UCXXEXPORT char_type widen(char c) const; + _UCXXEXPORT iostate exceptions() const + { + return throw_mask; + } - protected: - char_type fill_char; - basic_ostream* mtied; - basic_streambuf* mstreambuf; - iostate throw_mask; - _UCXXEXPORT basic_ios(const basic_ios &){ } - _UCXXEXPORT basic_ios & operator=(const basic_ios &){ return *this; } - _UCXXEXPORT void init(basic_streambuf* sb){ - ios_base::mformat = skipws|dec; - mstreambuf = sb; - mstate = goodbit; - throw_mask = goodbit; - } - }; + _UCXXEXPORT void exceptions(iostate except) + { + throw_mask = except; + } + + explicit _UCXXEXPORT basic_ios(basic_streambuf* sb) : fill_char(' '), mtied(0), mstreambuf(0) + { + init(sb); + } + + basic_ios() : mtied(0), mstreambuf(0){ } + + virtual _UCXXEXPORT ~basic_ios() + { + } + + _UCXXEXPORT basic_ostream* tie() const + { + return mtied; + } + + _UCXXEXPORT basic_ostream* tie(basic_ostream* tiestr) + { + basic_ostream* retval= mtied; + mtied = tiestr; + return retval; + } + + _UCXXEXPORT basic_streambuf* rdbuf() const + { + return mstreambuf; + } + + _UCXXEXPORT basic_streambuf* rdbuf(basic_streambuf* sb) + { + basic_streambuf* retval = mstreambuf; + mstreambuf = sb; + return retval; + } + + _UCXXEXPORT basic_ios& copyfmt(const basic_ios& rhs); + + _UCXXEXPORT char_type fill() const + { + return fill_char; + } + + _UCXXEXPORT char_type fill(char_type ch) + { + char_type temp = fill_char; + fill_char = ch; + return temp; + } + + _UCXXEXPORT locale imbue(const locale& loc) + { + return ios_base::imbue(loc); + } + + _UCXXEXPORT char narrow(char_type c, char dfault) const; + _UCXXEXPORT char_type widen(char c) const; + + protected: + char_type fill_char; + basic_ostream* mtied; + basic_streambuf* mstreambuf; + iostate throw_mask; + _UCXXEXPORT basic_ios(const basic_ios &){ } + _UCXXEXPORT basic_ios & operator=(const basic_ios &){ return *this; } + + _UCXXEXPORT void init(basic_streambuf* sb) + { + ios_base::mformat = skipws|dec; + mstreambuf = sb; + mstate = goodbit; + throw_mask = goodbit; + } + }; #ifdef __UCLIBCXX_EXPAND_IOS_CHAR__ #ifndef __UCLIBCXX_COMPILE_IOS__ - template <> _UCXXEXPORT void basic_ios >::clear(iostate state); - template <> _UCXXEXPORT void basic_ios >::setstate(iostate state); + template <> _UCXXEXPORT void basic_ios >::clear(iostate state); + template <> _UCXXEXPORT void basic_ios >::setstate(iostate state); #endif #endif + template + inline char basic_ios::narrow(char_type c, char dfault) const + { + return dfault; + } - template - inline char basic_ios::narrow(char_type c, char dfault) const - { - return dfault; - } - - template <> - inline char basic_ios >::narrow(char_type c, char) const - { - return c; - } + template <> + inline char basic_ios >::narrow(char_type c, char) const + { + return c; + } #ifdef __UCLIBCXX_HAS_WCHAR__ - template <> - inline char basic_ios >::narrow(char_type c, char dfault) const - { - char retval = wctob (c); - if(retval == EOF){ - retval = dfault; - } - return retval; - } + template <> + inline char basic_ios >::narrow(char_type c, char dfault) const + { + char retval = wctob(c); + if (retval == EOF) + { + retval = dfault; + } -#endif //__UCLIBCXX_HAS_WCHAR__ + return retval; + } - template - inline typename basic_ios::char_type - basic_ios::widen(char c) const - { - return c; - } +#endif //__UCLIBCXX_HAS_WCHAR__ - template <> - inline basic_ios >::char_type - basic_ios >::widen(char c) const - { - return c; - } + template + inline typename basic_ios::char_type + basic_ios::widen(char c) const + { + return c; + } + + template <> + inline basic_ios >::char_type + basic_ios >::widen(char c) const + { + return c; + } #ifdef __UCLIBCXX_HAS_WCHAR__ - template <> - inline basic_ios >::char_type - basic_ios >::widen(char c) const - { - return btowc(c); - } + template <> + inline basic_ios >::char_type + basic_ios >::widen(char c) const + { + return btowc(c); + } #endif //__UCLIBCXX_HAS_WCHAR__ - template class _UCXXEXPORT fpos{ - public: - _UCXXEXPORT fpos(stateT s){ - st = s; - } - _UCXXEXPORT stateT state() const{ - return st; - } - _UCXXEXPORT void state(stateT s){ - st = s; - } - _UCXXEXPORT bool operator==(const fpos &rhs){ - return st == rhs.st; - } - _UCXXEXPORT bool operator!=(const fpos &rhs){ - return st != rhs.st; - } - _UCXXEXPORT fpos & operator+(const streamoff & o){ - st += o; - return *this; - } - _UCXXEXPORT fpos & operator-(const streamoff & o){ - st -= o; - return *this; - } - _UCXXEXPORT streamoff operator-(const fpos & rhs){ - return st - rhs.st; - } + template class _UCXXEXPORT fpos{ + public: + _UCXXEXPORT fpos(stateT s) + { + st = s; + } - private: - stateT st; - }; + _UCXXEXPORT stateT state() const + { + return st; + } + _UCXXEXPORT void state(stateT s) + { + st = s; + } -} + _UCXXEXPORT bool operator==(const fpos &rhs) + { + return st == rhs.st; + } + + _UCXXEXPORT bool operator!=(const fpos &rhs) + { + return st != rhs.st; + } + + _UCXXEXPORT fpos & operator+(const streamoff & o) + { + st += o; + return *this; + } + + _UCXXEXPORT fpos & operator-(const streamoff & o) + { + st -= o; + return *this; + } + + _UCXXEXPORT streamoff operator-(const fpos & rhs) + { + return st - rhs.st; + } + + private: + stateT st; + }; + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/iosfwd b/misc/uClibc++/include/uClibc++/iosfwd index 2c14725e32..c322b64d33 100644 --- a/misc/uClibc++/include/uClibc++/iosfwd +++ b/misc/uClibc++/include/uClibc++/iosfwd @@ -1,114 +1,119 @@ -/* 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 #include #include - #ifndef __HEADER_STD_IOSFWD #define __HEADER_STD_IOSFWD 1 #pragma GCC visibility push(default) -namespace std { - class ios_base; - template<> class char_traits; +extern "C++" +{ + +namespace std +{ + class ios_base; + template<> class char_traits; #ifdef __UCLIBCXX_HAS_WCHAR__ - template<> class char_traits; + template<> class char_traits; #endif - template > class basic_ios; + template > class basic_ios; - template > class basic_streambuf; - template > class basic_istream; - template > class basic_ostream; - template > class basic_iostream; + template > class basic_streambuf; + template > class basic_istream; + template > class basic_ostream; + template > class basic_iostream; - template , - class Allocator = allocator > class basic_stringbuf; + template , + class Allocator = allocator > class basic_stringbuf; - template , - class Allocator = allocator > class basic_istringstream; + template , + class Allocator = allocator > class basic_istringstream; - template , - class Allocator = allocator > class basic_ostringstream; + template , + class Allocator = allocator > class basic_ostringstream; - template , - class Allocator = allocator > class basic_stringstream; + template , + class Allocator = allocator > class basic_stringstream; - template > class basic_filebuf; + template > class basic_filebuf; - template > class basic_ifstream; + template > class basic_ifstream; - template > class basic_ofstream; + template > class basic_ofstream; - template > class basic_fstream; + template > class basic_fstream; - template > class basic_istreambuf_iterator; + template > class basic_istreambuf_iterator; - template > class basic_ostreambuf_iterator; + template > class basic_ostreambuf_iterator; - typedef basic_ios ios; + typedef basic_ios ios; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_ios wios; + typedef basic_ios wios; #endif - typedef basic_streambuf streambuf; - typedef basic_istream istream; - typedef basic_ostream ostream; - typedef basic_iostream iostream; + typedef basic_streambuf streambuf; + typedef basic_istream istream; + typedef basic_ostream ostream; + typedef basic_iostream iostream; - typedef basic_stringbuf stringbuf; - typedef basic_istringstream istringstream; - typedef basic_ostringstream ostringstream; - typedef basic_stringstream stringstream; + typedef basic_stringbuf stringbuf; + typedef basic_istringstream istringstream; + typedef basic_ostringstream ostringstream; + typedef basic_stringstream stringstream; - typedef basic_filebuf filebuf; - typedef basic_ifstream ifstream; - typedef basic_ofstream ofstream; - typedef basic_fstream fstream; + typedef basic_filebuf filebuf; + typedef basic_ifstream ifstream; + typedef basic_ofstream ofstream; + typedef basic_fstream fstream; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_streambuf wstreambuf; - typedef basic_istream wistream; - typedef basic_ostream wostream; - typedef basic_iostream wiostream; + typedef basic_streambuf wstreambuf; + typedef basic_istream wistream; + typedef basic_ostream wostream; + typedef basic_iostream wiostream; - typedef basic_stringbuf wstringbuf; - typedef basic_istringstream wistringstream; - typedef basic_ostringstream wostringstream; - typedef basic_stringstream wstringstream; + typedef basic_stringbuf wstringbuf; + typedef basic_istringstream wistringstream; + typedef basic_ostringstream wostringstream; + typedef basic_stringstream wstringstream; - typedef basic_filebuf wfilebuf; - typedef basic_ifstream wifstream; - typedef basic_ofstream wofstream; - typedef basic_fstream wfstream; + typedef basic_filebuf wfilebuf; + typedef basic_ifstream wifstream; + typedef basic_ofstream wofstream; + typedef basic_fstream wfstream; #endif - - template class fpos; - typedef fpos::state_type> streampos; + + template class fpos; + typedef fpos::state_type> streampos; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef fpos::state_type> wstreampos; + typedef fpos::state_type> wstreampos; #endif -} + +} // namespace +} // extern "C++" #pragma GCC visibility pop -#endif +#endif // __HEADER_STD_IOSFWD diff --git a/misc/uClibc++/include/uClibc++/iostream b/misc/uClibc++/include/uClibc++/iostream index f93987f3bb..3a2f5c09ee 100644 --- a/misc/uClibc++/include/uClibc++/iostream +++ b/misc/uClibc++/include/uClibc++/iostream @@ -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 @@ -31,70 +31,70 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + #ifdef __UCLIBCXX_SUPPORT_CIN__ - extern istream cin; + extern istream cin; #endif #ifdef __UCLIBCXX_SUPPORT_COUT__ - extern ostream cout; + extern ostream cout; #endif #ifdef __UCLIBCXX_SUPPORT_CERR__ - extern ostream cerr; + extern ostream cerr; #endif #ifdef __UCLIBCXX_SUPPORT_CLOG__ - extern ostream clog; + extern ostream clog; #endif #ifdef __UCLIBCXX_SUPPORT_WCIN__ - extern wistream wcin; + extern wistream wcin; #endif #ifdef __UCLIBCXX_SUPPORT_WCOUT__ - extern wostream wcout; + extern wostream wcout; #endif #ifdef __UCLIBCXX_SUPPORT_WCERR__ - extern wostream wcerr; + extern wostream wcerr; #endif #ifdef __UCLIBCXX_SUPPORT_WCLOG__ - extern wostream wclog; + extern wostream wclog; #endif + template class _UCXXEXPORT basic_iostream : + public basic_istream, public basic_ostream + { + public: + // constructor/destructor + explicit _UCXXEXPORT basic_iostream(basic_streambuf* sb); + virtual _UCXXEXPORT ~basic_iostream(); //Below + }; - template class _UCXXEXPORT basic_iostream : - public basic_istream, public basic_ostream - { - public: - // constructor/destructor - explicit _UCXXEXPORT basic_iostream(basic_streambuf* sb); - virtual _UCXXEXPORT ~basic_iostream(); //Below - }; - - template _UCXXEXPORT - basic_iostream:: basic_iostream(basic_streambuf* sb) - : basic_ios(sb), basic_istream(sb), basic_ostream(sb) - { - return; - } - - - template _UCXXEXPORT basic_iostream::~basic_iostream(){ - return; - } + template _UCXXEXPORT + basic_iostream:: basic_iostream(basic_streambuf* sb) + : basic_ios(sb), basic_istream(sb), basic_ostream(sb) + { + return; + } + template _UCXXEXPORT basic_iostream::~basic_iostream(){ + return; + } #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ #ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_IOSTREAM__ - template <> _UCXXEXPORT basic_iostream >:: - basic_iostream(basic_streambuf >* sb); - template <> _UCXXEXPORT basic_iostream >::~basic_iostream(); + template <> _UCXXEXPORT basic_iostream >:: + basic_iostream(basic_streambuf >* sb); + template <> _UCXXEXPORT basic_iostream >::~basic_iostream(); #endif #endif #endif - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/istream b/misc/uClibc++/include/uClibc++/istream index 37ffa127b6..faedcc1c8f 100644 --- a/misc/uClibc++/include/uClibc++/istream +++ b/misc/uClibc++/include/uClibc++/istream @@ -1,21 +1,21 @@ -/* Copyright (C) 2004 Garrett A. Kajmowicz - - This file is part of the uClibc C++ Library. This library is free - software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the - Free Software Foundation; either version 2, 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this library; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. -*/ +/* Copyright (C) 2004 Garrett A. Kajmowicz + * + * This file is part of the uClibc C++ Library. This library is free + * software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this library; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, + * USA. + */ #include #include @@ -28,572 +28,704 @@ #pragma GCC visibility push(default) -namespace std{ - - typedef basic_istream istream; +extern "C++" +{ +namespace std +{ + typedef basic_istream istream; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_istream wistream; + typedef basic_istream wistream; #endif - template basic_istream& ws(basic_istream& is); + template basic_istream& ws(basic_istream& is); - template class _UCXXEXPORT basic_istream : - virtual public basic_ios - { - public: + template class _UCXXEXPORT basic_istream : + virtual public basic_ios + { + public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - typedef basic_streambuf streambuf_type; - typedef traits traits_type; + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef basic_streambuf streambuf_type; + typedef traits traits_type; - explicit basic_istream(basic_streambuf* sb) - : basic_ios(sb), count_last_ufmt_input(0) - { - basic_ios::init(sb); - } - virtual ~basic_istream() { } + explicit basic_istream(basic_streambuf* sb) + : basic_ios(sb), count_last_ufmt_input(0) + { + basic_ios::init(sb); + } - class sentry; + virtual ~basic_istream() { } - basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); - basic_istream& operator>>(basic_ios& (*pf)(basic_ios&)); - basic_istream& operator>>(ios_base& (*pf)(ios_base&)); - basic_istream& operator>>(bool& n); - basic_istream& operator>>(short& n); - basic_istream& operator>>(unsigned short& n); - basic_istream& operator>>(int& n); - basic_istream& operator>>(unsigned int& n); - basic_istream& operator>>(long& n); - basic_istream& operator>>(unsigned long& n); - basic_istream& operator>>(void*& p); - basic_istream& operator>>(basic_streambuf* sb); + class sentry; + + basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); + basic_istream& operator>>(basic_ios& (*pf)(basic_ios&)); + basic_istream& operator>>(ios_base& (*pf)(ios_base&)); + basic_istream& operator>>(bool& n); + basic_istream& operator>>(short& n); + basic_istream& operator>>(unsigned short& n); + basic_istream& operator>>(int& n); + basic_istream& operator>>(unsigned int& n); + basic_istream& operator>>(long& n); + basic_istream& operator>>(unsigned long& n); + basic_istream& operator>>(void*& p); + basic_istream& operator>>(basic_streambuf* sb); #ifdef CONFIG_HAVE_FLOAT - basic_istream& operator>>(float& f); - basic_istream& operator>>(double& f); - basic_istream& operator>>(long double& f); + basic_istream& operator>>(float& f); + basic_istream& operator>>(double& f); + basic_istream& operator>>(long double& f); #endif - _UCXXEXPORT streamsize gcount() const{ - return count_last_ufmt_input; - } + _UCXXEXPORT streamsize gcount() const + { + return count_last_ufmt_input; + } - _UCXXEXPORT int_type get(); //below - _UCXXEXPORT basic_istream& get(char_type& c); //Below + _UCXXEXPORT int_type get(); //below + _UCXXEXPORT basic_istream& get(char_type& c); //Below - _UCXXEXPORT basic_istream& get(char_type* s, streamsize n){ - return get(s, n, basic_ios::widen('\n')); - } + _UCXXEXPORT basic_istream& get(char_type* s, streamsize n) + { + return get(s, n, basic_ios::widen('\n')); + } - _UCXXEXPORT basic_istream& get(char_type* s, streamsize n, char_type delim){ - sentry(*this, true); - streamsize i = 0; - int_type c; - for(i=0;i::mstreambuf->sgetc(); - basic_ios::mstreambuf->sbumpc(); - if(c == traits::eof() ){ - if(i==0){ - basic_ios::setstate(ios_base::failbit); - }else{ - basic_ios::setstate(ios_base::eofbit); - } - break; - } - if(c == delim){ - if(i==0){ - basic_ios::setstate(ios_base::failbit); - } - basic_ios::mstreambuf->sputbackc(c); - break; - } - s[i] = c; - } - s[i] = traits::eos(); - count_last_ufmt_input = i; - return *this; - } + _UCXXEXPORT basic_istream& get(char_type* s, streamsize n, char_type delim) + { + sentry(*this, true); + streamsize i = 0; + int_type c; + for (i = 0; i < n-1; ++i) + { + c = basic_ios::mstreambuf->sgetc(); + basic_ios::mstreambuf->sbumpc(); + if (c == traits::eof()) + { + if (i==0) + { + basic_ios::setstate(ios_base::failbit); + } + else + { + basic_ios::setstate(ios_base::eofbit); + } - _UCXXEXPORT basic_istream& get(basic_streambuf& sb){ - return get(sb, basic_ios::widen('\n')); - } + break; + } - _UCXXEXPORT basic_istream& get(basic_streambuf& sb, char_type delim){ - sentry(*this, true); - streamsize i = 0; - int_type c; - while(1){ //We will exit internally based upon error conditions - c = basic_ios::mstreambuf->sgetc(); - if(c == traits::eof()){ - if(i==0){ - basic_ios::setstate(ios_base::failbit); - }else{ - basic_ios::setstate(ios_base::eofbit); - } - count_last_ufmt_input = i; - return *this; - } - if(c == delim){ - if(i==0){ - basic_ios::setstate(ios_base::failbit); - } - count_last_ufmt_input = i; - return *this; - } - if(sb.sputc(c) != c){ //Error doing output - count_last_ufmt_input = i; - return *this; - } - ++i; - basic_ios::mstreambuf->sbumpc(); - } - } + if (c == delim) + { + if (i==0) + { + basic_ios::setstate(ios_base::failbit); + } - _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n){ - return getline(s, n, basic_ios::widen('\n')); - } + basic_ios::mstreambuf->sputbackc(c); + break; + } - _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n, char_type delim){ - sentry(*this, true); - streamsize i = 0; - int_type c; - for(i=0;i::mstreambuf->sgetc(); - if(c == traits::eof() ){ - if( basic_ios::eof() ){ - basic_ios::setstate(ios_base::failbit); - }else{ - basic_ios::setstate(ios_base::eofbit); - } - count_last_ufmt_input = i; - s[i] = traits::eos(); - return *this; - } - if(basic_ios::mstreambuf->sbumpc()==traits::eof() ){ - basic_ios::setstate(ios_base::eofbit); - } - if(c == delim){ - count_last_ufmt_input = i+1; - s[i] = traits::eos(); - return *this; - } - s[i] = c; - } - s[n-1] = traits::eos(); - return *this; - } + s[i] = c; + } - _UCXXEXPORT basic_istream& ignore (streamsize n = 1, int_type delim = traits::eof()){ - sentry(*this, true); - streamsize i; - int_type c; - for(i=0;i::mstreambuf->sgetc(); - if(c == traits::eof()){ - basic_ios::setstate(ios_base::eofbit); - return *this; - } - basic_ios::mstreambuf->sbumpc(); - if(c == delim){ - return *this; - } - } - return *this; - } + s[i] = traits::eos(); + count_last_ufmt_input = i; + return *this; + } - _UCXXEXPORT int_type peek(){ - if(basic_ios::good() == false){ - return traits::eof(); - }else{ - int_type c = basic_ios::mstreambuf->sgetc(); - if(c == traits::eof()){ - basic_ios::setstate(ios_base::eofbit); - } - return basic_ios::mstreambuf->sgetc(); - } - } + _UCXXEXPORT basic_istream& get(basic_streambuf& sb) + { + return get(sb, basic_ios::widen('\n')); + } - _UCXXEXPORT basic_istream& read (char_type* s, streamsize n){ - sentry(*this, true); - streamsize i; - int_type c; - for(i=0;i::mstreambuf->sgetc(); + _UCXXEXPORT basic_istream& get(basic_streambuf& sb, char_type delim) + { + sentry(*this, true); + streamsize i = 0; + int_type c; + while (1) + { + // We will exit internally based upon error conditions - if(c == traits::eof()){ - basic_ios::setstate(ios_base::failbit); - basic_ios::setstate(ios_base::eofbit); - count_last_ufmt_input = i; - return *this; - } - basic_ios::mstreambuf->sbumpc(); - s[i] = c; - } - count_last_ufmt_input = n; - return *this; - } + c = basic_ios::mstreambuf->sgetc(); + if (c == traits::eof()) + { + if (i==0) + { + basic_ios::setstate(ios_base::failbit); + } + else + { + basic_ios::setstate(ios_base::eofbit); + } - _UCXXEXPORT streamsize readsome(char_type* s, streamsize n){ - sentry(*this, true); - if(!basic_ios::good()){ - count_last_ufmt_input = 0; - basic_ios::setstate(ios_base::failbit); - return 0; - } + count_last_ufmt_input = i; + return *this; + } - if( basic_ios::mstreambuf->in_avail() == -1){ - count_last_ufmt_input=0; - basic_ios::setstate(ios_base::eofbit); - return 0; - } + if (c == delim) + { + if (i == 0) + { + basic_ios::setstate(ios_base::failbit); + } - if(n > basic_ios::mstreambuf->in_avail() ){ - n = basic_ios::mstreambuf->in_avail(); - } + count_last_ufmt_input = i; + return *this; + } - streamsize i; - int_type c; + if (sb.sputc(c) != c) + { + // Error doing output - for(i=0;i::mstreambuf->sgetc(); - basic_ios::mstreambuf->sbumpc(); - s[i] = c; - } - count_last_ufmt_input = n; - return n; - } + count_last_ufmt_input = i; + return *this; + } - _UCXXEXPORT basic_istream& putback(char_type c){ - sentry(*this, true); - if(!basic_ios::good()){ - basic_ios::setstate(ios_base::failbit); - return *this; - } - if(basic_ios::mstreambuf == 0){ - basic_ios::setstate(ios_base::badbit); - return *this; - } - if(basic_ios::mstreambuf->sputbackc(c) == traits::eof()){ - basic_ios::setstate(ios_base::badbit); - return *this; - } - return *this; - } + ++i; + basic_ios::mstreambuf->sbumpc(); + } + } - _UCXXEXPORT basic_istream& unget(){ - sentry(*this, true); - if(!basic_ios::good()){ - basic_ios::setstate(ios_base::failbit); - return *this; - } - if(basic_ios::mstreambuf == 0){ - basic_ios::setstate(ios_base::failbit); - return *this; - } - if(basic_ios::mstreambuf->sungetc() == traits::eof()){ - basic_ios::setstate(ios_base::failbit); - } - return *this; - } + _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n) + { + return getline(s, n, basic_ios::widen('\n')); + } - _UCXXEXPORT int sync(){ - sentry(*this, true); - if(basic_ios::mstreambuf == 0){ - return -1; - } - if(basic_ios::mstreambuf->pubsync() == -1){ - basic_ios::setstate(ios_base::badbit); - return traits::eof(); - } - return 0; - } + _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n, char_type delim) + { + sentry(*this, true); + streamsize i = 0; + int_type c; + for (i = 0; i < n-1; ++i) + { + c = basic_ios::mstreambuf->sgetc(); + if (c == traits::eof()) + { + if (basic_ios::eof()) + { + basic_ios::setstate(ios_base::failbit); + } + else + { + basic_ios::setstate(ios_base::eofbit); + } - _UCXXEXPORT pos_type tellg(){ - if(basic_ios::fail() !=false){ - return pos_type(-1); - } - return basic_ios::mstreambuf->pubseekoff(0, ios_base::cur, ios_base::in); - } + count_last_ufmt_input = i; + s[i] = traits::eos(); + return *this; + } - _UCXXEXPORT basic_istream& seekg(pos_type pos){ - if(basic_ios::fail() !=true){ - basic_ios::mstreambuf->pubseekpos(pos); - } - return *this; - } + if (basic_ios::mstreambuf->sbumpc()==traits::eof()) + { + basic_ios::setstate(ios_base::eofbit); + } - _UCXXEXPORT basic_istream& seekg(off_type off, ios_base::seekdir dir){ - if(basic_ios::fail() !=true){ - basic_ios::mstreambuf->pubseekoff(off, dir); - } - return *this; - } + if (c == delim) + { + count_last_ufmt_input = i+1; + s[i] = traits::eos(); + return *this; + } - protected: - _UCXXEXPORT basic_istream(const basic_istream &): basic_ios() { } - _UCXXEXPORT basic_istream & operator=(const basic_istream &){ return *this; } - streamsize count_last_ufmt_input; + s[i] = c; + } - }; + s[n-1] = traits::eos(); + return *this; + } - template > class _UCXXEXPORT basic_istream::sentry { - bool ok; - public: - explicit _UCXXEXPORT sentry(basic_istream& os, bool noskipws = false){ - if(os.good() !=0){ //Prepare for output - } + _UCXXEXPORT basic_istream& ignore (streamsize n = 1, int_type delim = traits::eof()) + { + sentry(*this, true); + streamsize i; + int_type c; + for (i = 0; i < n; ++i) + { + c = basic_ios::mstreambuf->sgetc(); + if (c == traits::eof()) + { + basic_ios::setstate(ios_base::eofbit); + return *this; + } - //Flush any tied buffer - if(os.tie() != 0){ - os.tie()->flush(); - } - if(!noskipws){ - __skipws(os); - } + basic_ios::mstreambuf->sbumpc(); + if (c == delim) + { + return *this; + } + } - ok = true; - } - _UCXXEXPORT ~sentry() { } - _UCXXEXPORT operator bool() { - return ok; - } - }; + return *this; + } - //Template implementations of basic_istream functions which may be partially specialized - //For code reduction + _UCXXEXPORT int_type peek() + { + if (basic_ios::good() == false) + { + return traits::eof(); + } + else + { + int_type c = basic_ios::mstreambuf->sgetc(); + if (c == traits::eof()) + { + basic_ios::setstate(ios_base::eofbit); + } - template - _UCXXEXPORT typename basic_istream::int_type basic_istream::get(){ - sentry(*this, true); - int_type retval = basic_ios::mstreambuf->sgetc(); - if(retval == traits::eof()){ - count_last_ufmt_input = 0; - basic_ios::setstate(ios_base::eofbit); - }else{ - count_last_ufmt_input = 1; - basic_ios::mstreambuf->sbumpc(); - } - return retval; - } + return basic_ios::mstreambuf->sgetc(); + } + } - template - _UCXXEXPORT basic_istream& basic_istream::get(char_type& c){ - sentry(*this, true); - int_type retval = basic_ios::mstreambuf->sgetc(); - if(retval == traits::eof()){ - count_last_ufmt_input = 0; - basic_ios::setstate(ios_base::eofbit); - basic_ios::setstate(ios_base::failbit); - }else{ - count_last_ufmt_input = 1; - c = traits::to_char_type(retval); - basic_ios::mstreambuf->sbumpc(); - } - return *this; - } + _UCXXEXPORT basic_istream& read (char_type* s, streamsize n) + { + sentry(*this, true); + streamsize i; + int_type c; + for (i = 0; i < n; ++i) + { + c = basic_ios::mstreambuf->sgetc(); + if (c == traits::eof()) + { + basic_ios::setstate(ios_base::failbit); + basic_ios::setstate(ios_base::eofbit); + count_last_ufmt_input = i; + return *this; + } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(bool& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + basic_ios::mstreambuf->sbumpc(); + s[i] = c; + } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(short& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + count_last_ufmt_input = n; + return *this; + } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(unsigned short& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + _UCXXEXPORT streamsize readsome(char_type* s, streamsize n) + { + sentry(*this, true); + if (!basic_ios::good()) + { + count_last_ufmt_input = 0; + basic_ios::setstate(ios_base::failbit); + return 0; + } - template _UCXXEXPORT basic_istream& basic_istream::operator>>(int& n){ - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + if (basic_ios::mstreambuf->in_avail() == -1) + { + count_last_ufmt_input=0; + basic_ios::setstate(ios_base::eofbit); + return 0; + } - template _UCXXEXPORT basic_istream& basic_istream::operator>>(unsigned int& n){ - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + if (n > basic_ios::mstreambuf->in_avail()) + { + n = basic_ios::mstreambuf->in_avail(); + } - template _UCXXEXPORT basic_istream& basic_istream::operator>>(long int& n){ - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + streamsize i; + int_type c; - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(unsigned long int& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + for (i = 0; i < n; ++i) + { + c = basic_ios::mstreambuf->sgetc(); + basic_ios::mstreambuf->sbumpc(); + s[i] = c; + } + + count_last_ufmt_input = n; + return n; + } + + _UCXXEXPORT basic_istream& putback(char_type c) + { + sentry(*this, true); + if (!basic_ios::good()) + { + basic_ios::setstate(ios_base::failbit); + return *this; + } + + if (basic_ios::mstreambuf == 0){ + + basic_ios::setstate(ios_base::badbit); + return *this; + } + + if (basic_ios::mstreambuf->sputbackc(c) == traits::eof()) + { + basic_ios::setstate(ios_base::badbit); + return *this; + } + + return *this; + } + + _UCXXEXPORT basic_istream& unget() + { + sentry(*this, true); + if (!basic_ios::good()) + { + basic_ios::setstate(ios_base::failbit); + return *this; + } + + if (basic_ios::mstreambuf == 0) + { + basic_ios::setstate(ios_base::failbit); + return *this; + } + + if (basic_ios::mstreambuf->sungetc() == traits::eof()) + { + basic_ios::setstate(ios_base::failbit); + } + + return *this; + } + + _UCXXEXPORT int sync() + { + sentry(*this, true); + if (basic_ios::mstreambuf == 0) + { + return -1; + } + + if (basic_ios::mstreambuf->pubsync() == -1) + { + basic_ios::setstate(ios_base::badbit); + return traits::eof(); + } + + return 0; + } + + _UCXXEXPORT pos_type tellg() + { + if (basic_ios::fail() !=false) + { + return pos_type(-1); + } + + return basic_ios::mstreambuf->pubseekoff(0, ios_base::cur, ios_base::in); + } + + _UCXXEXPORT basic_istream& seekg(pos_type pos) + { + if (basic_ios::fail() !=true) + { + basic_ios::mstreambuf->pubseekpos(pos); + } + + return *this; + } + + _UCXXEXPORT basic_istream& seekg(off_type off, ios_base::seekdir dir) + { + if (basic_ios::fail() !=true) + { + basic_ios::mstreambuf->pubseekoff(off, dir); + } + + return *this; + } + + protected: + _UCXXEXPORT basic_istream(const basic_istream &): basic_ios() { } + _UCXXEXPORT basic_istream & operator=(const basic_istream &){ return *this; } + streamsize count_last_ufmt_input; + }; + + template > class _UCXXEXPORT basic_istream::sentry + { + bool ok; + public: + explicit _UCXXEXPORT sentry(basic_istream& os, bool noskipws = false){ + if (os.good() !=0) + { + // Prepare for output + } + + // Flush any tied buffer + + if (os.tie() != 0) + { + os.tie()->flush(); + } + + if (!noskipws) + { + __skipws(os); + } + + ok = true; + } + + _UCXXEXPORT ~sentry() { } + + _UCXXEXPORT operator bool() + { + return ok; + } + }; + + // Template implementations of basic_istream functions which may be partially specialized + // For code reduction + + template + _UCXXEXPORT typename basic_istream::int_type basic_istream::get() + { + sentry(*this, true); + int_type retval = basic_ios::mstreambuf->sgetc(); + if (retval == traits::eof()) + { + count_last_ufmt_input = 0; + basic_ios::setstate(ios_base::eofbit); + } + else + { + count_last_ufmt_input = 1; + basic_ios::mstreambuf->sbumpc(); + } + + return retval; + } + + template + _UCXXEXPORT basic_istream& basic_istream::get(char_type& c) + { + sentry(*this, true); + int_type retval = basic_ios::mstreambuf->sgetc(); + if (retval == traits::eof()) + { + count_last_ufmt_input = 0; + basic_ios::setstate(ios_base::eofbit); + basic_ios::setstate(ios_base::failbit); + } + else + { + count_last_ufmt_input = 1; + c = traits::to_char_type(retval); + basic_ios::mstreambuf->sbumpc(); + } + + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(bool& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(short& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(unsigned short& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& basic_istream::operator>>(int& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& basic_istream::operator>>(unsigned int& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& basic_istream::operator>>(long int& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(unsigned long int& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } #ifdef CONFIG_HAVE_FLOAT - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(float& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(double& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(long double& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(float& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(double& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(long double& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } #endif - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(void *& n) - { - sentry(*this); - __istream_readin::readin(*this, n); - return *this; - } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, charT& c) - { - typename basic_istream::sentry s(is); - is.get(c); - return is; - } + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(void *& n) + { + sentry(*this); + __istream_readin::readin(*this, n); + return *this; + } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, unsigned char& c) - { - typename basic_istream::sentry s(is); - char b; - is.get(b); - c = b; - return is; - } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, signed char& c) - { - typename basic_istream::sentry s(is); - is.get(c); - return is; - } + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, charT& c) + { + typename basic_istream::sentry s(is); + is.get(c); + return is; + } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, charT* c) - { - typename basic_istream::sentry s(is); - int n = is.width(); - if(n == 0){ - n = __STRING_MAX_UNITS; - } - is.get(c, n); - return is; + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, unsigned char& c) + { + typename basic_istream::sentry s(is); + char b; + is.get(b); + c = b; + return is; + } - } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, unsigned char* c) - { - typename basic_istream::sentry s(is); - int n = is.width(); - if(n == 0){ - n = __STRING_MAX_UNITS; - } - is.get(c, n); - return is; - } - template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, signed char* c) - { - typename basic_istream::sentry s(is); - int n = is.width(); - if(n == 0){ - n = __STRING_MAX_UNITS; - } - is.get(c, n); - return is; - } + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, signed char& c) + { + typename basic_istream::sentry s(is); + is.get(c); + return is; + } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(basic_istream& (*pf)(basic_istream&)) - { - sentry(*this); - pf(*this); - return *this; - } + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, charT* c) + { + typename basic_istream::sentry s(is); + int n = is.width(); + if (n == 0) + { + n = __STRING_MAX_UNITS; + } - template _UCXXEXPORT basic_istream& - basic_istream::operator>>(basic_ios& (*pf)(basic_ios&)) - { - sentry(*this); - pf(*this); - return *this; - } + is.get(c, n); + return is; - template _UCXXEXPORT basic_istream& - ws(basic_istream& is) - { - __skipws(is); - return is; - } + } + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, unsigned char* c) + { + typename basic_istream::sentry s(is); + int n = is.width(); + if (n == 0) + { + n = __STRING_MAX_UNITS; + } + + is.get(c, n); + return is; + } + + template _UCXXEXPORT basic_istream& + operator>>(basic_istream& is, signed char* c) + { + typename basic_istream::sentry s(is); + int n = is.width(); + if (n == 0) + { + n = __STRING_MAX_UNITS; + } + is.get(c, n); + return is; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(basic_istream& (*pf)(basic_istream&)) + { + sentry(*this); + pf(*this); + return *this; + } + + template _UCXXEXPORT basic_istream& + basic_istream::operator>>(basic_ios& (*pf)(basic_ios&)) + { + sentry(*this); + pf(*this); + return *this; + } + + template _UCXXEXPORT basic_istream& + ws(basic_istream& is) + { + __skipws(is); + return is; + } #ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_ISTREAM__ + template <> _UCXXEXPORT istream & basic_istream >::get(char & c); + template <> _UCXXEXPORT istream::int_type basic_istream >::get(); - template <> _UCXXEXPORT istream & basic_istream >::get(char & c); - template <> _UCXXEXPORT istream::int_type basic_istream >::get(); - - template <> _UCXXEXPORT istream & istream::operator>>(bool &n); - template <> _UCXXEXPORT istream & istream::operator>>(short &n); - template <> _UCXXEXPORT istream & istream::operator>>(unsigned short &n); - template <> _UCXXEXPORT istream & istream::operator>>(int &n); - template <> _UCXXEXPORT istream & istream::operator>>(unsigned int &n); - template <> _UCXXEXPORT istream & istream::operator>>(long unsigned &n); - template <> _UCXXEXPORT istream & istream::operator>>(long int &n); - template <> _UCXXEXPORT istream & istream::operator>>(void *& p); + template <> _UCXXEXPORT istream & istream::operator>>(bool &n); + template <> _UCXXEXPORT istream & istream::operator>>(short &n); + template <> _UCXXEXPORT istream & istream::operator>>(unsigned short &n); + template <> _UCXXEXPORT istream & istream::operator>>(int &n); + template <> _UCXXEXPORT istream & istream::operator>>(unsigned int &n); + template <> _UCXXEXPORT istream & istream::operator>>(long unsigned &n); + template <> _UCXXEXPORT istream & istream::operator>>(long int &n); + template <> _UCXXEXPORT istream & istream::operator>>(void *& p); #ifdef CONFIG_HAVE_FLOAT - template <> _UCXXEXPORT istream & istream::operator>>(float &f); - template <> _UCXXEXPORT istream & istream::operator>>(double &f); - template <> _UCXXEXPORT istream & istream::operator>>(long double &f); + template <> _UCXXEXPORT istream & istream::operator>>(float &f); + template <> _UCXXEXPORT istream & istream::operator>>(double &f); + template <> _UCXXEXPORT istream & istream::operator>>(long double &f); #endif - template <> _UCXXEXPORT istream & operator>>(istream & is, char & c); + template <> _UCXXEXPORT istream & operator>>(istream & is, char & c); - template <> _UCXXEXPORT void __skipws(basic_istream >& is); + template <> _UCXXEXPORT void __skipws(basic_istream >& is); #endif #endif -} +} // namespace +} // extern "C++" #pragma GCC visibility pop #endif - diff --git a/misc/uClibc++/include/uClibc++/istream_helpers b/misc/uClibc++/include/uClibc++/istream_helpers index 36765dd70b..b514f1a1e3 100644 --- a/misc/uClibc++/include/uClibc++/istream_helpers +++ b/misc/uClibc++/include/uClibc++/istream_helpers @@ -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 #include @@ -28,343 +28,452 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + /* We are making the following template class for serveral reasons. Firstly, + * we want to keep the main istream code neat and tidy. Secondly, we want it + * to be easy to do partial specialization of the istream code so that it can + * be expanded and put into the library. This will allow us to make application + * code smaller at the expense of increased library size. This is a fair + * trade-off when there are multiple applications being compiled. Also, this + * feature will be used optionally via configuration options. It will also + * allow us to keep the code bases in sync, dramatically simplifying the + * maintenance required. We specialized for char because wchar and others + * require different scanf functions + */ + template _UCXXEXPORT + basic_string _readToken(basic_istream& stream) + { + basic_string temp; + typename traits::int_type c; + while (true) + { + c = stream.rdbuf()->sgetc(); + if (c != traits::eof() && isspace(c) == false) + { + stream.rdbuf()->sbumpc(); + temp.append(1, traits::to_char_type(c)); + } + else + { + break; + } + } - /* We are making the following template class for serveral reasons. Firstly, - * we want to keep the main istream code neat and tidy. Secondly, we want it - * to be easy to do partial specialization of the istream code so that it can - * be expanded and put into the library. This will allow us to make application - * code smaller at the expense of increased library size. This is a fair - * trade-off when there are multiple applications being compiled. Also, this - * feature will be used optionally via configuration options. It will also - * allow us to keep the code bases in sync, dramatically simplifying the - * maintenance required. We specialized for char because wchar and others - * require different scanf functions - */ + if (temp.size() == 0) + { + stream.setstate(ios_base::eofbit|ios_base::failbit); + } - template _UCXXEXPORT - basic_string _readToken(basic_istream& stream) - { - basic_string temp; - typename traits::int_type c; - while(true){ - c = stream.rdbuf()->sgetc(); - if(c != traits::eof() && isspace(c) == false){ - stream.rdbuf()->sbumpc(); - temp.append(1, traits::to_char_type(c)); - }else{ - break; - } - } - if (temp.size() == 0) - stream.setstate(ios_base::eofbit|ios_base::failbit); + return temp; + } - return temp; - } + template _UCXXEXPORT + basic_string _readTokenDecimal(basic_istream& stream) + { + basic_string temp; + typename traits::int_type c; + while (true) + { + c = stream.rdbuf()->sgetc(); + if (c != traits::eof() && isspace(c) == false && ( + isdigit(c) || + c == '.' || + c == ',' || + ((c == '-' || c == '+') && temp.size() == 0))) + { + stream.rdbuf()->sbumpc(); + temp.append(1, traits::to_char_type(c)); + } + else + { + break; + } + } - template _UCXXEXPORT - basic_string _readTokenDecimal(basic_istream& stream) - { - basic_string temp; - typename traits::int_type c; - while(true){ - c = stream.rdbuf()->sgetc(); - if(c != traits::eof() && isspace(c) == false && ( - isdigit(c) || - c == '.' || - c == ',' || - ((c == '-' || c == '+') && temp.size() == 0) ) - ){ - stream.rdbuf()->sbumpc(); - temp.append(1, traits::to_char_type(c)); - }else{ - break; - } - } - if (temp.size() == 0) - stream.setstate(ios_base::eofbit|ios_base::failbit); + if (temp.size() == 0) + { + stream.setstate(ios_base::eofbit|ios_base::failbit); + } - return temp; - } + return temp; + } #ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ - - template <> _UCXXEXPORT string _readToken >(istream & stream); - + template <> _UCXXEXPORT string _readToken >(istream & stream); #endif + template class _UCXXEXPORT __istream_readin + { + public: + static void readin(basic_istream& stream, dataType & var); + }; - template class _UCXXEXPORT __istream_readin{ - public: - static void readin(basic_istream& stream, dataType & var); - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, bool & var) + { + /* 22.4.2.1.2.4 */ - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, bool & var) - { - /* 22.4.2.1.2.4 */ - basic_string temp; - temp = _readToken( stream); - if (stream.flags() & ios_base::boolalpha) { - if (temp == "true") // truename() - var = true; - else { - var = false; - if (temp != "false") // falsename() - stream.setstate(ios_base::failbit); - } - } else { - long int i = 0; - int ret; - if (stream.flags() & ios_base::dec) { - ret = sscanf(temp.c_str(), "%ld", &i ); - } else { - if (stream.flags() & ios_base::oct) { - ret = sscanf(temp.c_str(), "%lo", (unsigned long int *)(&i)); - } else if (stream.flags() & ios_base::hex) { - if (stream.flags() & ios_base::uppercase) { - ret = sscanf(temp.c_str(), "%lX", (unsigned long int *)(&i)); - } else { - ret = sscanf(temp.c_str(), "%lx", (unsigned long int *)(&i)); - } - } else { - ret = sscanf(temp.c_str(), "%li", &i); - } - } - if (ret != 1 || i >> 1) - stream.setstate(ios_base::failbit); - var = ret == 1 && bool(i); - } - } - }; + basic_string temp; + temp = _readToken(stream); + if (stream.flags() & ios_base::boolalpha) + { + if (temp == "true") // truename() + { + var = true; + } + else + { + var = false; + if (temp != "false") // falsename() + { + stream.setstate(ios_base::failbit); + } + } + } + else + { + long int i = 0; + int ret; + if (stream.flags() & ios_base::dec) + { + ret = sscanf(temp.c_str(), "%ld", &i); + } + else + { + if (stream.flags() & ios_base::oct) + { + ret = sscanf(temp.c_str(), "%lo", (unsigned long int *)(&i)); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + ret = sscanf(temp.c_str(), "%lX", (unsigned long int *)(&i)); + } + else + { + ret = sscanf(temp.c_str(), "%lx", (unsigned long int *)(&i)); + } + } + else + { + ret = sscanf(temp.c_str(), "%li", &i); + } + } + if (ret != 1 || i >> 1) + { + stream.setstate(ios_base::failbit); + } - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, short & var) - { - basic_string temp; + var = ret == 1 && bool(i); + } + } + }; - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%hd", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%ho", (unsigned short int *)(&var) ); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%hX", (unsigned short int *)(&var) ); - }else{ - sscanf(temp.c_str(), "%hx", (unsigned short int *)(&var) ); - } - }else{ - sscanf(temp.c_str(), "%hi", &var); - } - } - } - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, short & var) + { + basic_string temp; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, unsigned short & var) - { - basic_string temp; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%hd", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%ho", (unsigned short int *)(&var)); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%hX", (unsigned short int *)(&var)); + } + else + { + sscanf(temp.c_str(), "%hx", (unsigned short int *)(&var)); + } + } + else + { + sscanf(temp.c_str(), "%hi", &var); + } + } + } + }; - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%hu", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%ho", &var); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%hX", &var ); - }else{ - sscanf(temp.c_str(), "%hx", &var); - } - }else{ - sscanf(temp.c_str(), "%hi", (signed short int*)(&var) ); - } - } - } - }; + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, unsigned short & var) + { + basic_string temp; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, int & var) - { - basic_string temp; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%hu", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%ho", &var); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%hX", &var); + } + else + { + sscanf(temp.c_str(), "%hx", &var); + } + } + else + { + sscanf(temp.c_str(), "%hi", (signed short int*)(&var)); + } + } + } + }; - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%d", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%o", (unsigned int *)(&var) ); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%X", (unsigned int *)(&var) ); - }else{ - sscanf(temp.c_str(), "%x", (unsigned int *)(&var) ); - } - }else{ - sscanf(temp.c_str(), "%i", &var); - } - } - } - }; + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, int & var) + { + basic_string temp; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, unsigned int & var) - { - basic_string temp; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%d", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%o", (unsigned int *)(&var)); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%X", (unsigned int *)(&var)); + } + else + { + sscanf(temp.c_str(), "%x", (unsigned int *)(&var)); + } + } + else + { + sscanf(temp.c_str(), "%i", &var); + } + } + } + }; - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%u", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%o", (unsigned int *)(&var) ); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%X", (unsigned int *)(&var) ); - }else{ - sscanf(temp.c_str(), "%x", (unsigned int *)(&var) ); - } - }else{ - sscanf(temp.c_str(), "%i", (int *)(&var) ); - } - } + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, unsigned int & var) + { + basic_string temp; - } - }; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%u", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%o", (unsigned int *)(&var)); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%X", (unsigned int *)(&var)); + } + else + { + sscanf(temp.c_str(), "%x", (unsigned int *)(&var)); + } + } + else + { + sscanf(temp.c_str(), "%i", (int *)(&var)); + } + } + } + }; + template class _UCXXEXPORT __istream_readin{ + public: + inline static void readin(basic_istream& stream, long int & var) + { + basic_string temp; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, long int & var) - { - basic_string temp; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%ld", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%lo", (unsigned long int *)(&var)); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%lX", (unsigned long int *)(&var)); + } + else + { + sscanf(temp.c_str(), "%lx", (unsigned long int *)(&var)); + } + } + else + { + sscanf(temp.c_str(), "%li", (long int *)(&var)); + } + } + } + }; - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%ld", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%lo", (unsigned long int *)(&var) ); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%lX", (unsigned long int *)(&var) ); - }else{ - sscanf(temp.c_str(), "%lx", (unsigned long int *)(&var) ); - } - }else{ - sscanf(temp.c_str(), "%li", (long int *)(&var) ); - } - } - - } - }; - - - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, unsigned long int & var) - { - basic_string temp; - - if(stream.flags() & ios_base::dec){ - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%lu", &var ); - }else{ - temp = _readToken( stream); - if( stream.flags() & ios_base::oct){ - sscanf(temp.c_str(), "%lo", &var ); - }else if(stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::uppercase){ - sscanf(temp.c_str(), "%lX", &var ); - }else{ - sscanf(temp.c_str(), "%lx", &var); - } - }else{ - sscanf(temp.c_str(), "%li", (long int *)(&var) ); - } - } - } - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, unsigned long int & var) + { + basic_string temp; + if (stream.flags() & ios_base::dec) + { + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%lu", &var); + } + else + { + temp = _readToken(stream); + if (stream.flags() & ios_base::oct) + { + sscanf(temp.c_str(), "%lo", &var); + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::uppercase) + { + sscanf(temp.c_str(), "%lX", &var); + } + else + { + sscanf(temp.c_str(), "%lx", &var); + } + } + else + { + sscanf(temp.c_str(), "%li", (long int *)(&var)); + } + } + } + }; #ifdef CONFIG_HAVE_FLOAT - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, float & var) - { - basic_string temp; - temp = _readTokenDecimal( stream); + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, float & var) + { + basic_string temp; + temp = _readTokenDecimal(stream); - sscanf(temp.c_str(), "%g", &var); - } - }; + sscanf(temp.c_str(), "%g", &var); + } + }; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, double & var) - { - basic_string temp; - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%lg", &var); - } - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, double & var) + { + basic_string temp; + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%lg", &var); + } + }; - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, long double & var) - { - basic_string temp; - temp = _readTokenDecimal( stream); - sscanf(temp.c_str(), "%Lg", &var); - } - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, long double & var) + { + basic_string temp; + temp = _readTokenDecimal(stream); + sscanf(temp.c_str(), "%Lg", &var); + } + }; -#endif // ifdef CONFIG_HAVE_FLOAT +#endif // ifdef CONFIG_HAVE_FLOAT - template class _UCXXEXPORT __istream_readin{ - public: - inline static void readin(basic_istream& stream, void* & var) - { - basic_string temp; - temp = _readToken( stream); - sscanf(temp.c_str(), "%p", &var); - } - }; + template class _UCXXEXPORT __istream_readin + { + public: + inline static void readin(basic_istream& stream, void* & var) + { + basic_string temp; + temp = _readToken(stream); + sscanf(temp.c_str(), "%p", &var); + } + }; + template void __skipws(basic_istream& is) + { + const typename basic_istream::int_type eof = traits::eof(); + typename basic_istream::int_type c; - template void __skipws(basic_istream& is){ - const typename basic_istream::int_type eof = traits::eof(); - typename basic_istream::int_type c; - //While the next character normally read doesn't equal eof - //and that character is a space, advance to the next read position - //Thus itterating through all whitespace until we get to the meaty stuff - while ( - !traits::eq_int_type((c = is.rdbuf()->sgetc()), eof) - && isspace(c) - ) { - is.rdbuf()->sbumpc(); - } - if(traits::eq_int_type(c, eof)){ - is.setstate(ios_base::eofbit); - } - } -} + // While the next character normally read doesn't equal eof + // and that character is a space, advance to the next read position + // Thus itterating through all whitespace until we get to the meaty stuff + + while ( + !traits::eq_int_type((c = is.rdbuf()->sgetc()), eof) + && isspace(c)) + { + is.rdbuf()->sbumpc(); + } + + if (traits::eq_int_type(c, eof)) + { + is.setstate(ios_base::eofbit); + } + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/iterator b/misc/uClibc++/include/uClibc++/iterator index b3d81b2074..9a690d83da 100644 --- a/misc/uClibc++/include/uClibc++/iterator +++ b/misc/uClibc++/include/uClibc++/iterator @@ -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 #include @@ -23,204 +23,250 @@ #include #include - - #ifndef __STD_HEADER_ITERATOR #define __STD_HEADER_ITERATOR 1 #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ - // subclause _lib.stream.iterators_, stream iterators: - template , class Distance = ptrdiff_t> class istream_iterator; - template bool - operator==(const istream_iterator& x, const istream_iterator& y); - template bool - operator!=(const istream_iterator& x, const istream_iterator& y); - template > class ostream_iterator; - template > class istreambuf_iterator; - template bool - operator==(const istreambuf_iterator& a, const istreambuf_iterator& b); - template bool - operator!=(const istreambuf_iterator& a, const istreambuf_iterator& b); - template > class ostreambuf_iterator; +namespace std +{ + // Subclause _lib.stream.iterators_, stream iterators: - template < class T, class charT, class traits, class Distance > class _UCXXEXPORT istream_iterator - : public iterator - { - public: - typedef charT char_type; - typedef traits traits_type; - typedef basic_istream istream_type; - istream_iterator() : in_stream(0), value(0) {} - istream_iterator(istream_type& s) : in_stream(&s), value() { - *in_stream >> value; - } - istream_iterator(const istream_iterator& x) - : in_stream(x.in_stream), value(x.value) - { } - ~istream_iterator() { } - const T& operator*() const{ - return value; - } - const T* operator->() const{ - return &value; - } - istream_iterator& operator++() { - *in_stream >> value; - return *this; - } - istream_iterator operator++(int){ - istream_iterator tmp = *this; - *in_stream >> value; - return (tmp); - } - bool m_equal(const istream_iterator& x) const{ - return (in_stream == x.in_stream); - } - private: - basic_istream* in_stream; - T value; - }; + template , class Distance = ptrdiff_t> class istream_iterator; + template bool + operator==(const istream_iterator& x, const istream_iterator& y); + template bool + operator!=(const istream_iterator& x, const istream_iterator& y); + template > class ostream_iterator; + template > class istreambuf_iterator; + template bool + operator==(const istreambuf_iterator& a, const istreambuf_iterator& b); + template bool + operator!=(const istreambuf_iterator& a, const istreambuf_iterator& b); + template > class ostreambuf_iterator; - template _UCXXEXPORT - bool operator==(const istream_iterator& x, - const istream_iterator& y) - { - return x.m_equal(y); - } + template < class T, class charT, class traits, class Distance > class _UCXXEXPORT istream_iterator + : public iterator + { + public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_istream istream_type; + istream_iterator() : in_stream(0), value(0) {} - template _UCXXEXPORT - bool operator!=(const istream_iterator& x, - const istream_iterator& y) - { - return !(x == y); - } + istream_iterator(istream_type& s) : in_stream(&s), value() + { + *in_stream >> value; + } - template class _UCXXEXPORT ostream_iterator - : public iterator - { - public: - typedef charT char_type; - typedef traits traits_type; - typedef basic_ostream ostream_type; + istream_iterator(const istream_iterator& x) + : in_stream(x.in_stream), value(x.value) + { } - ostream_iterator(ostream_type& s) : out_stream(&s), delim(0) { } - ostream_iterator(ostream_type& s, const charT* delimiter) : out_stream(&s), delim(delimiter) { } - ostream_iterator(const ostream_iterator& x) : out_stream(x.out_stream), delim(x.delim) { } - ~ostream_iterator() { } - ostream_iterator& operator=(const T& value){ - *out_stream << value; - if(delim != 0){ - *out_stream << delim; - } - return (*this); - } - ostream_iterator& operator*(){ return *this; } - ostream_iterator& operator++() { return *this; } - ostream_iterator operator++(int) { return *this; } - private: - basic_ostream* out_stream; - const char* delim; - }; + ~istream_iterator() { } - template class _UCXXEXPORT istreambuf_iterator : - public iterator - { - public: - typedef charT char_type; - typedef traits traits_type; - typedef typename traits::int_type int_type; - typedef basic_streambuf streambuf_type; - typedef basic_istream istream_type; + const T& operator*() const + { + return value; + } - class _UCXXEXPORT proxy{ - charT val; - basic_streambuf * buf; + const T* operator->() const + { + return &value; + } - proxy(charT v, basic_streambuf * b) : val(v), buf(b) { } - public: - charT operator*() { return val; } - }; + istream_iterator& operator++() + { + *in_stream >> value; + return *this; + } - istreambuf_iterator() throw() : sbuf(0) { } - istreambuf_iterator(istream_type& s) throw() : sbuf(s.rdbuf()) { } - istreambuf_iterator(streambuf_type* s) throw() : sbuf(s) { } - istreambuf_iterator(const proxy& p) throw() : sbuf(&p.buf) { } + istream_iterator operator++(int) + { + istream_iterator tmp = *this; + *in_stream >> value; + return (tmp); + } - charT operator*() const{ - return sbuf->sgetc(); - } - istreambuf_iterator& operator++(){ - sbuf->sbumpc(); - return *this; - } - proxy operator++(int){ - istreambuf_iterator tmp = *this; - sbuf->sbumpc(); - return(tmp); - } + bool m_equal(const istream_iterator& x) const + { + return (in_stream == x.in_stream); + } - bool equal(const istreambuf_iterator& b) const{ - return sbuf == b.sbuf || is_eof() && b.is_eof(); - } - private: - streambuf_type* sbuf; - inline bool is_eof() const{ - return sbuf == 0 || sbuf->sgetc() == traits_type::eof(); - } - }; + private: + basic_istream* in_stream; + T value; + }; - template _UCXXEXPORT bool - operator==(const istreambuf_iterator& a, - const istreambuf_iterator& b) - { - return a.equal(b); - } + template _UCXXEXPORT + bool operator==(const istream_iterator& x, + const istream_iterator& y) + { + return x.m_equal(y); + } - template bool _UCXXEXPORT - operator!=(const istreambuf_iterator& a, - const istreambuf_iterator& b) - { - return !a.equal(b); - } + template _UCXXEXPORT + bool operator!=(const istream_iterator& x, + const istream_iterator& y) + { + return !(x == y); + } - template class _UCXXEXPORT ostreambuf_iterator - : iterator - { - public: - typedef charT char_type; - typedef traits traits_type; - typedef basic_streambuf streambuf_type; - typedef basic_ostream ostream_type; - public: - ostreambuf_iterator(ostream_type& s) throw() : sbuf(s.rdbuf()), f(false) { } - ostreambuf_iterator(streambuf_type* s) throw() : sbuf(s), f(false) { } - ostreambuf_iterator& operator=(charT c){ - if(failed() == false){ - if(sbuf->sputc(c) == traits::eof()){ - f = true; - } - } - return *this; - } - ostreambuf_iterator& operator*(){ - return *this; - } - ostreambuf_iterator& operator++() { return *this; } - ostreambuf_iterator operator++(int) { return *this; } - bool failed() const throw(){ - return f; - } + template class _UCXXEXPORT ostream_iterator + : public iterator + { + public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_ostream ostream_type; - private: - streambuf_type* sbuf; - bool f; - }; + ostream_iterator(ostream_type& s) : out_stream(&s), delim(0) { } + ostream_iterator(ostream_type& s, const charT* delimiter) : out_stream(&s), delim(delimiter) { } + ostream_iterator(const ostream_iterator& x) : out_stream(x.out_stream), delim(x.delim) { } -} + ~ostream_iterator() { } + + ostream_iterator& operator=(const T& value) + { + *out_stream << value; + if (delim != 0) + { + *out_stream << delim; + } + + return (*this); + } + + ostream_iterator& operator*(){ return *this; } + ostream_iterator& operator++() { return *this; } + ostream_iterator operator++(int) { return *this; } + + private: + basic_ostream* out_stream; + const char* delim; + }; + + template class _UCXXEXPORT istreambuf_iterator : + public iterator + { + public: + typedef charT char_type; + typedef traits traits_type; + typedef typename traits::int_type int_type; + typedef basic_streambuf streambuf_type; + typedef basic_istream istream_type; + + class _UCXXEXPORT proxy + { + charT val; + basic_streambuf * buf; + + proxy(charT v, basic_streambuf * b) : val(v), buf(b) { } + + public: + charT operator*() { return val; } + }; + + istreambuf_iterator() throw() : sbuf(0) { } + istreambuf_iterator(istream_type& s) throw() : sbuf(s.rdbuf()) { } + istreambuf_iterator(streambuf_type* s) throw() : sbuf(s) { } + istreambuf_iterator(const proxy& p) throw() : sbuf(&p.buf) { } + + charT operator*() const + { + return sbuf->sgetc(); + } + + istreambuf_iterator& operator++() + { + sbuf->sbumpc(); + return *this; + } + + proxy operator++(int) + { + istreambuf_iterator tmp = *this; + sbuf->sbumpc(); + return(tmp); + } + + bool equal(const istreambuf_iterator& b) const + { + return sbuf == b.sbuf || is_eof() && b.is_eof(); + } + + private: + streambuf_type* sbuf; + + inline bool is_eof() const + { + return sbuf == 0 || sbuf->sgetc() == traits_type::eof(); + } + }; + + template _UCXXEXPORT bool + operator==(const istreambuf_iterator& a, + const istreambuf_iterator& b) + { + return a.equal(b); + } + + template bool _UCXXEXPORT + operator!=(const istreambuf_iterator& a, + const istreambuf_iterator& b) + { + return !a.equal(b); + } + + template class _UCXXEXPORT ostreambuf_iterator + : iterator + { + public: + typedef charT char_type; + typedef traits traits_type; + typedef basic_streambuf streambuf_type; + typedef basic_ostream ostream_type; + public: + ostreambuf_iterator(ostream_type& s) throw() : sbuf(s.rdbuf()), f(false) { } + ostreambuf_iterator(streambuf_type* s) throw() : sbuf(s), f(false) { } + + ostreambuf_iterator& operator=(charT c) + { + if (failed() == false) + { + if (sbuf->sputc(c) == traits::eof()) + { + f = true; + } + } + + return *this; + } + + ostreambuf_iterator& operator*() + { + return *this; + } + + ostreambuf_iterator& operator++() { return *this; } + ostreambuf_iterator operator++(int) { return *this; } + + bool failed() const throw() + { + return f; + } + + private: + streambuf_type* sbuf; + bool f; + }; + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/iterator_base b/misc/uClibc++/include/uClibc++/iterator_base index 1cae589661..307174440e 100644 --- a/misc/uClibc++/include/uClibc++/iterator_base +++ b/misc/uClibc++/include/uClibc++/iterator_base @@ -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 @@ -24,282 +24,320 @@ #pragma GCC visibility push(default) -namespace std{ - template struct iterator_traits; - template struct iterator_traits; +extern "C++" +{ - template struct iterator; +namespace std +{ + template struct iterator_traits; + template struct iterator_traits; - struct _UCXXEXPORT input_iterator_tag {}; - struct _UCXXEXPORT output_iterator_tag {}; - struct _UCXXEXPORT forward_iterator_tag: public input_iterator_tag {}; - struct _UCXXEXPORT bidirectional_iterator_tag: public forward_iterator_tag {}; - struct _UCXXEXPORT random_access_iterator_tag: public bidirectional_iterator_tag {}; + template struct iterator; - template _UCXXEXPORT void advance(InputIterator& i, Distance n){ - while(n > 0){ - --n; - ++i; - } - } + struct _UCXXEXPORT input_iterator_tag {}; + struct _UCXXEXPORT output_iterator_tag {}; + struct _UCXXEXPORT forward_iterator_tag: public input_iterator_tag {}; + struct _UCXXEXPORT bidirectional_iterator_tag: public forward_iterator_tag {}; + struct _UCXXEXPORT random_access_iterator_tag: public bidirectional_iterator_tag {}; - template _UCXXEXPORT typename iterator_traits::difference_type - distance(InputIterator first, InputIterator last) - { - typename iterator_traits::difference_type d = 0; - while(first++ !=last){ - d++; - } - return d; - } + template _UCXXEXPORT void advance(InputIterator& i, Distance n) + { + while (n > 0) + { + --n; + ++i; + } + } + + template _UCXXEXPORT typename iterator_traits::difference_type + distance(InputIterator first, InputIterator last) + { + typename iterator_traits::difference_type d = 0; + while (first++ !=last) + { + d++; + } + return d; + } // subclause _lib.predef.iterators_, predefined iterators: - template class reverse_iterator; - template bool operator==(const reverse_iterator& x, const reverse_iterator& y); - template bool operator<(const reverse_iterator& x, const reverse_iterator& y); - template bool operator!=(const reverse_iterator& x, const reverse_iterator& y); - template bool operator>(const reverse_iterator& x, const reverse_iterator& y); - template bool operator>=(const reverse_iterator& x, const reverse_iterator& y); - template bool operator<=(const reverse_iterator& x, const reverse_iterator& y); - template typename reverse_iterator::difference_type - operator-( const reverse_iterator& x, const reverse_iterator& y); - template reverse_iterator - operator+( typename reverse_iterator::difference_type n, const reverse_iterator& x); - template class back_insert_iterator; - template back_insert_iterator back_inserter(Container& x); - template class front_insert_iterator; - template front_insert_iterator front_inserter(Container& x); - template class insert_iterator; - template - insert_iterator inserter(Container& x, Iterator i); - //Actual Template definitions + template class reverse_iterator; + template bool operator==(const reverse_iterator& x, const reverse_iterator& y); + template bool operator<(const reverse_iterator& x, const reverse_iterator& y); + template bool operator!=(const reverse_iterator& x, const reverse_iterator& y); + template bool operator>(const reverse_iterator& x, const reverse_iterator& y); + template bool operator>=(const reverse_iterator& x, const reverse_iterator& y); + template bool operator<=(const reverse_iterator& x, const reverse_iterator& y); + template typename reverse_iterator::difference_type + operator-( const reverse_iterator& x, const reverse_iterator& y); + template reverse_iterator + operator+( typename reverse_iterator::difference_type n, const reverse_iterator& x); + template class back_insert_iterator; + template back_insert_iterator back_inserter(Container& x); + template class front_insert_iterator; + template front_insert_iterator front_inserter(Container& x); + template class insert_iterator; + template + insert_iterator inserter(Container& x, Iterator i); - template struct _UCXXEXPORT iterator_traits { - typedef typename Iterator::difference_type difference_type; - typedef typename Iterator::value_type value_type; - typedef typename Iterator::pointer pointer; - typedef typename Iterator::reference reference; - typedef typename Iterator::iterator_category iterator_category; - }; + // Actual Template definitions - //Pointer specialization - required by standard - template struct _UCXXEXPORT iterator_traits { - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef T* pointer; - typedef T& reference; - typedef random_access_iterator_tag iterator_category; - }; + template struct _UCXXEXPORT iterator_traits + { + typedef typename Iterator::difference_type difference_type; + typedef typename Iterator::value_type value_type; + typedef typename Iterator::pointer pointer; + typedef typename Iterator::reference reference; + typedef typename Iterator::iterator_category iterator_category; + }; - //Specialization recomended by standard -/* template struct _UCXXEXPORT iterator_traits { - typedef long difference_type; - typedef T value_type; - typedef T __far* pointer; - typedef T __far& reference; - typedef random_access_iterator_tag iterator_category; - };*/ + //Pointer specialization - required by standard -/* template _UCXXEXPORT void - reverse(BidirectionalIterator first, BidirectionalIterator last) - { - typename iterator_traits::difference_type n = distance(first, last); - --n; - while(n > 0){ - typename iterator_traits::value_type tmp = *first; - *first++ = * --last; - *last = tmp; - n -= 2; - } - };*/ + template struct _UCXXEXPORT iterator_traits + { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category; + }; + + //Specialization recomended by standard + +/* template struct _UCXXEXPORT iterator_traits + { + typedef long difference_type; + typedef T value_type; + typedef T __far* pointer; + typedef T __far& reference; + typedef random_access_iterator_tag iterator_category; + };*/ + +/* template _UCXXEXPORT void + reverse(BidirectionalIterator first, BidirectionalIterator last) + { + typename iterator_traits::difference_type n = distance(first, last); + --n; + while(n > 0) + { + typename iterator_traits::value_type tmp = *first; + *first++ = * --last; + *last = tmp; + n -= 2; + } + };*/ + + template + struct _UCXXEXPORT iterator + { + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; + }; - template - struct _UCXXEXPORT iterator - { - typedef T value_type; - typedef Distance difference_type; - typedef Pointer pointer; - typedef Reference reference; - typedef Category iterator_category; - }; + template class _UCXXEXPORT reverse_iterator + : public iterator::iterator_category, + typename iterator_traits::value_type, typename iterator_traits::difference_type, + typename iterator_traits::pointer, typename iterator_traits::reference> + { + protected: + Iterator current; + friend bool operator== (const reverse_iterator& x, const reverse_iterator& y); + friend bool operator< (const reverse_iterator& x, const reverse_iterator& y); + public: + typedef Iterator iterator_type; - template class _UCXXEXPORT reverse_iterator - : public iterator::iterator_category, - typename iterator_traits::value_type, typename iterator_traits::difference_type, - typename iterator_traits::pointer, typename iterator_traits::reference> - { - protected: - Iterator current; - friend bool operator== (const reverse_iterator& x, const reverse_iterator& y); - friend bool operator< (const reverse_iterator& x, const reverse_iterator& y); + reverse_iterator() : current(){}; + explicit reverse_iterator(Iterator x) : current(x) { } + template reverse_iterator(const reverse_iterator &x) : current(x.base()){} - public: - typedef Iterator iterator_type; + Iterator base() const { return current; } // explicit - reverse_iterator() : current(){}; - explicit reverse_iterator(Iterator x) : current(x) { } - template reverse_iterator(const reverse_iterator &x) : current(x.base()){} + typename iterator_traits::reference operator*() const { Iterator tmp = current; return *--tmp; } + typename iterator_traits::pointer operator->() const { return &(operator*()); } + typename iterator_traits::reference operator[](typename iterator_traits::difference_type n) const + { + return current[-n-1]; + } - Iterator base() const { return current; } // explicit + reverse_iterator& operator++(){ --current; return *this; } + reverse_iterator operator++(int) {reverse_iterator tmp = *this; --current; return tmp; } + reverse_iterator& operator--() { ++ current; return *this; } + reverse_iterator operator--(int) {reverse_iterator tmp = *this; ++current; return tmp; } - typename iterator_traits::reference operator*() const { Iterator tmp = current; return *--tmp; } - typename iterator_traits::pointer operator->() const { return &(operator*()); } - typename iterator_traits::reference operator[](typename iterator_traits::difference_type n) const{ - return current[-n-1]; - } + reverse_iterator operator+ (typename iterator_traits::difference_type n) const + { + reverse_iterator retval( *this ); + retval+=n; + return retval; + } - reverse_iterator& operator++(){ --current; return *this; } - reverse_iterator operator++(int) {reverse_iterator tmp = *this; --current; return tmp; } - reverse_iterator& operator--() { ++ current; return *this; } - reverse_iterator operator--(int) {reverse_iterator tmp = *this; ++current; return tmp; } + reverse_iterator& operator+=(typename iterator_traits::difference_type n) + { + current -= n; + return *this; + } - reverse_iterator operator+ (typename iterator_traits::difference_type n) const{ - reverse_iterator retval( *this ); - retval+=n; - return retval; - } - reverse_iterator& operator+=(typename iterator_traits::difference_type n){ - current -= n; - return *this; - } - reverse_iterator operator- (typename iterator_traits::difference_type n) const{ - reverse_iterator retval( *this ); - retval-=n; - return retval; - } - reverse_iterator& operator-=(typename iterator_traits::difference_type n){ - current += n; - return *this; - } - }; + reverse_iterator operator- (typename iterator_traits::difference_type n) const + { + reverse_iterator retval( *this ); + retval-=n; + return retval; + } + reverse_iterator& operator-=(typename iterator_traits::difference_type n) + { + current += n; + return *this; + } + }; - template _UCXXEXPORT bool - operator==(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() == y.base(); - } - template _UCXXEXPORT bool - operator<(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() < y.base(); - } - template _UCXXEXPORT bool - operator!=(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() != y.base(); - } - template _UCXXEXPORT bool - operator>(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() > y.base(); - } - template _UCXXEXPORT bool - operator>=(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() >= y.base(); - } - template _UCXXEXPORT bool - operator<=(const reverse_iterator& x, const reverse_iterator& y) - { - return x.base() <= y.base(); - } - template _UCXXEXPORT typename reverse_iterator::difference_type - operator-( const reverse_iterator& x, const reverse_iterator& y) - { - return y.base() - x.base(); - } - template _UCXXEXPORT reverse_iterator - operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) - { - return reverse_iterator (x.base() - n); - } + template _UCXXEXPORT bool + operator==(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() == y.base(); + } - template class _UCXXEXPORT back_insert_iterator : - public iterator - { - protected: - Container& container; - public: - typedef Container container_type; - explicit back_insert_iterator(Container& x):container(x) {}; - back_insert_iterator& operator=(const typename Container::value_type& value){ - container.push_back(value); - return *this; - } - back_insert_iterator& operator*(){ - return *this; - } - back_insert_iterator& operator++(){ - return *this; - } - back_insert_iterator operator++(int){ - return *this; - } - }; + template _UCXXEXPORT bool + operator<(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() < y.base(); + } - template _UCXXEXPORT back_insert_iterator - back_inserter(Container& x) - { - return back_insert_iterator(x); - } + template _UCXXEXPORT bool + operator!=(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() != y.base(); + } - template class _UCXXEXPORT front_insert_iterator - : public iterator - { - protected: - Container& container; - public: - typedef Container container_type; - explicit front_insert_iterator(Container& x): container(x) {} - front_insert_iterator& operator=(const typename Container::value_type& value){ - container.push_front(value); - return *this; - } + template _UCXXEXPORT bool + operator>(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() > y.base(); + } - front_insert_iterator& operator*() { return *this; } - front_insert_iterator& operator++() { return *this; } - front_insert_iterator operator++(int) { return *this; } - }; + template _UCXXEXPORT bool + operator>=(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() >= y.base(); + } - template _UCXXEXPORT front_insert_iterator - front_inserter(Container& x) - { - return front_insert_iterator(x); - } + template _UCXXEXPORT bool + operator<=(const reverse_iterator& x, const reverse_iterator& y) + { + return x.base() <= y.base(); + } - template class _UCXXEXPORT insert_iterator - : public iterator - { - protected: - Container& container; - typename Container::iterator iter; - public: - typedef Container container_type; - insert_iterator(Container& x, typename Container::iterator i) : container(x), iter(i) {} - insert_iterator& operator=(const typename Container::value_type& value){ - iter = container.insert(iter, value); - ++iter; - return *this; - } - insert_iterator& operator*() { return *this; } - insert_iterator& operator++() { return *this; } - insert_iterator operator++(int) { return *this; } - }; + template _UCXXEXPORT typename reverse_iterator::difference_type + operator-( const reverse_iterator& x, const reverse_iterator& y) + { + return y.base() - x.base(); + } - template _UCXXEXPORT insert_iterator - inserter(Container& x, Iterator i) - { - return insert_iterator(x,typename Container::iterator(i)); - } + template _UCXXEXPORT reverse_iterator + operator+(typename reverse_iterator::difference_type n, const reverse_iterator& x) + { + return reverse_iterator (x.base() - n); + } -} + template class _UCXXEXPORT back_insert_iterator : + public iterator + { + protected: + Container& container; + public: + typedef Container container_type; + explicit back_insert_iterator(Container& x):container(x) {}; + + back_insert_iterator& operator=(const typename Container::value_type& value) + { + container.push_back(value); + return *this; + } + + back_insert_iterator& operator*() + { + return *this; + } + + back_insert_iterator& operator++() + { + return *this; + } + + back_insert_iterator operator++(int) + { + return *this; + } + }; + + template _UCXXEXPORT back_insert_iterator + back_inserter(Container& x) + { + return back_insert_iterator(x); + } + + template class _UCXXEXPORT front_insert_iterator + : public iterator + { + protected: + Container& container; + public: + typedef Container container_type; + explicit front_insert_iterator(Container& x): container(x) {} + + front_insert_iterator& operator=(const typename Container::value_type& value) + { + container.push_front(value); + return *this; + } + + front_insert_iterator& operator*() { return *this; } + front_insert_iterator& operator++() { return *this; } + front_insert_iterator operator++(int) { return *this; } + }; + + template _UCXXEXPORT front_insert_iterator + front_inserter(Container& x) + { + return front_insert_iterator(x); + } + + template class _UCXXEXPORT insert_iterator + : public iterator + { + protected: + Container& container; + typename Container::iterator iter; + public: + typedef Container container_type; + insert_iterator(Container& x, typename Container::iterator i) : container(x), iter(i) {} + + insert_iterator& operator=(const typename Container::value_type& value) + { + iter = container.insert(iter, value); + ++iter; + return *this; + } + + insert_iterator& operator*() { return *this; } + insert_iterator& operator++() { return *this; } + insert_iterator operator++(int) { return *this; } + }; + + template _UCXXEXPORT insert_iterator + inserter(Container& x, Iterator i) + { + return insert_iterator(x,typename Container::iterator(i)); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop - -#endif - - +#endif // __STD_HEADER_ITERATOR_BASE diff --git a/misc/uClibc++/include/uClibc++/limits b/misc/uClibc++/include/uClibc++/limits index e275eb5ec0..0b5b159e99 100644 --- a/misc/uClibc++/include/uClibc++/limits +++ b/misc/uClibc++/include/uClibc++/limits @@ -1,20 +1,20 @@ -/* Copyright (C) 2006 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) 2006 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 @@ -25,638 +25,795 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ -enum float_round_style{ - round_indeterminate =-1, - round_toward_zero = 0, - round_to_nearest = 1, - round_toward_infinity = 2, - round_toward_neg_infinity = 3 +enum float_round_style +{ + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3 }; -template struct __bits_to_base_10{ - static const int size = -1; -}; -template <> struct __bits_to_base_10<7>{ - static const int size = 2; -}; -template <> struct __bits_to_base_10<8>{ - static const int size = 2; -}; -template <> struct __bits_to_base_10<9>{ - static const int size = 2; -}; -template <> struct __bits_to_base_10<10>{ - static const int size = 3; -}; -template <> struct __bits_to_base_10<15>{ - static const int size = 4; -}; -template <> struct __bits_to_base_10<16>{ - static const int size = 4; -}; -template <> struct __bits_to_base_10<17>{ - static const int size = 5; -}; -template <> struct __bits_to_base_10<18>{ - static const int size = 5; -}; -template <> struct __bits_to_base_10<31>{ - static const int size = 9; -}; -template <> struct __bits_to_base_10<32>{ - static const int size = 9; -}; -template <> struct __bits_to_base_10<35>{ - static const int size = 10; -}; -template <> struct __bits_to_base_10<36>{ - static const int size = 10; -}; -template <> struct __bits_to_base_10<63>{ - static const int size = 18; -}; -template <> struct __bits_to_base_10<64>{ - static const int size = 19; -}; -template <> struct __bits_to_base_10<71>{ - static const int size = 21; -}; -template <> struct __bits_to_base_10<72>{ - static const int size = 21; -}; -template <> struct __bits_to_base_10<79>{ - static const int size = 23; -}; -template <> struct __bits_to_base_10<80>{ - static const int size = 24; -}; -template <> struct __bits_to_base_10<127>{ - static const int size = 38; -}; -template <> struct __bits_to_base_10<128>{ - static const int size = 38; +template struct __bits_to_base_10 +{ + static const int size = -1; }; +template <> struct __bits_to_base_10<7> +{ + static const int size = 2; +}; +template <> struct __bits_to_base_10<8> +{ + static const int size = 2; +}; +template <> struct __bits_to_base_10<9> +{ + static const int size = 2; +}; +template <> struct __bits_to_base_10<10> +{ + static const int size = 3; +}; +template <> struct __bits_to_base_10<15> +{ + static const int size = 4; +}; -template class numeric_limits { +template <> struct __bits_to_base_10<16> +{ + static const int size = 4; +}; + +template <> struct __bits_to_base_10<17> +{ + static const int size = 5; +}; + +template <> struct __bits_to_base_10<18> +{ + static const int size = 5; +}; + +template <> struct __bits_to_base_10<31> +{ + static const int size = 9; +}; + +template <> struct __bits_to_base_10<32> +{ + static const int size = 9; +}; + +template <> struct __bits_to_base_10<35> +{ + static const int size = 10; +}; + +template <> struct __bits_to_base_10<36> +{ + static const int size = 10; +}; + +template <> struct __bits_to_base_10<63> +{ + static const int size = 18; +}; + +template <> struct __bits_to_base_10<64> +{ + static const int size = 19; +}; + +template <> struct __bits_to_base_10<71> +{ + static const int size = 21; +}; + +template <> struct __bits_to_base_10<72> +{ + static const int size = 21; +}; + +template <> struct __bits_to_base_10<79> +{ + static const int size = 23; +}; + +template <> struct __bits_to_base_10<80> +{ + static const int size = 24; +}; + +template <> struct __bits_to_base_10<127> +{ + static const int size = 38; +}; + +template <> struct __bits_to_base_10<128> +{ + static const int size = 38; +}; + +template class numeric_limits +{ public: - // General -- meaningful for all specializations. + // General -- meaningful for all specializations. - static const bool is_specialized = false; - static T min(); - static T max(); - static const int radix; - static const int digits; - static const int digits10; - static const bool is_signed; - static const bool is_integer; - static const bool is_exact; - static const bool traps; - static const bool is_modulo; - static const bool is_bounded; + static const bool is_specialized = false; + static T min(); + static T max(); + static const int radix; + static const int digits; + static const int digits10; + static const bool is_signed; + static const bool is_integer; + static const bool is_exact; + static const bool traps; + static const bool is_modulo; + static const bool is_bounded; - // Floating point specific. + // Floating point specific. - static T epsilon(); - static T round_error(); - static const int min_exponent10; - static const int max_exponent10; - static const int min_exponent; + static T epsilon(); + static T round_error(); + static const int min_exponent10; + static const int max_exponent10; + static const int min_exponent; - static const int max_exponent; - static const bool has_infinity; - static const bool has_quiet_NaN; - static const bool has_signaling_NaN; - static const bool is_iec559; - static const bool has_denorm; - static const bool tinyness_before; - static const float_round_style round_style; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static const int max_exponent; + static const bool has_infinity; + static const bool has_quiet_NaN; + static const bool has_signaling_NaN; + static const bool is_iec559; + static const bool has_denorm; + static const bool tinyness_before; + static const float_round_style round_style; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef bool T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return false; - } - static T max(){ - return true; - } - static const int radix = 2; - static const int digits = 1; - static const int digits10 = 0; - static const bool is_signed = false; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = false; - static const bool is_bounded = true; + typedef bool T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return false; + } + + static T max() + { + return true; + } + + static const int radix = 2; + static const int digits = 1; + static const int digits10 = 0; + static const bool is_signed = false; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = false; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef unsigned char T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return 0; - } - static T max(){ - return UCHAR_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT; - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = false; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef unsigned char T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return 0; + } + + static T max() + { + return UCHAR_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT; + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = false; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef signed char T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return SCHAR_MIN; - } - static T max(){ - return SCHAR_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT - 1; - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = true; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef signed char T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return SCHAR_MIN; + } + + static T max() + { + return SCHAR_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT - 1; + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef char T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return CHAR_MIN; - } - static T max(){ - return CHAR_MAX; - } - static const int radix = 2; - static const int digits = (CHAR_MIN != 0) ? CHAR_BIT - 1 : CHAR_BIT; - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = (CHAR_MIN != 0); - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef char T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return CHAR_MIN; + } + + static T max() + { + return CHAR_MAX; + } + + static const int radix = 2; + static const int digits = (CHAR_MIN != 0) ? CHAR_BIT - 1 : CHAR_BIT; + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = (CHAR_MIN != 0); + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon(){ + return 0; + } + + static T round_error(){ + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef unsigned short T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return 0; - } - static T max(){ - return USHRT_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = false; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef unsigned short T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return 0; + } + + static T max() + { + return USHRT_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = false; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef signed short T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return SHRT_MIN; - } - static T max(){ - return SHRT_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = true; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef signed short T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return SHRT_MIN; + } + + static T max() + { + return SHRT_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef unsigned int T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return 0; - } - static T max(){ - return UINT_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = false; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef unsigned int T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return 0; + } + + static T max() + { + return UINT_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = false; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef signed int T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return INT_MIN; - } - static T max(){ - return INT_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = true; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef signed int T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return INT_MIN; + } + + static T max() + { + return INT_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef unsigned long int T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return 0; - } - static T max(){ - return ULONG_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = false; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef unsigned long int T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min( + ){ + return 0; + } + + static T max() + { + return ULONG_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = false; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef signed long int T; - // General -- meaningful for all specializations. - static const bool is_specialized = true; - static T min(){ - return LONG_MIN; - } - static T max(){ - return LONG_MAX; - } - static const int radix = 2; - static const int digits = CHAR_BIT * sizeof(T); - static const int digits10 = __bits_to_base_10::size; - static const bool is_signed = true; - static const bool is_integer = true; - static const bool is_exact = true; - static const bool traps = false; - static const bool is_modulo = true; - static const bool is_bounded = true; + typedef signed long int T; - // Floating point specific. + // General -- meaningful for all specializations. - static T epsilon(){ - return 0; - } - static T round_error(){ - return 0; - } - static const int min_exponent10 = 0; - static const int max_exponent10 = 0; - static const int min_exponent = 0; + static const bool is_specialized = true; - static const int max_exponent = 0; - static const bool has_infinity = false; - static const bool has_quiet_NaN = false; - static const bool has_signaling_NaN = false; - static const bool is_iec559 = false; - static const bool has_denorm = false; - static const bool tinyness_before = false; - static const float_round_style round_style = round_indeterminate; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T min() + { + return LONG_MIN; + } + + static T max() + { + return LONG_MAX; + } + + static const int radix = 2; + static const int digits = CHAR_BIT * sizeof(T); + static const int digits10 = __bits_to_base_10::size; + static const bool is_signed = true; + static const bool is_integer = true; + static const bool is_exact = true; + static const bool traps = false; + static const bool is_modulo = true; + static const bool is_bounded = true; + + // Floating point specific. + + static T epsilon() + { + return 0; + } + + static T round_error() + { + return 0; + } + + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_indeterminate; + static T denorm_min(); + static T infinity(); + static T quiet_NaN(); + static T signaling_NaN(); }; -template <> class numeric_limits { +template <> class numeric_limits +{ public: - typedef double numeric_type; + typedef double numeric_type; - static const bool is_specialized = true; - static numeric_type min () { return __DBL_MIN__; } - static numeric_type max () { return __DBL_MAX__; } - static const int radix = __FLT_RADIX__; - static const int digits = __DBL_MANT_DIG__; - static const int digits10 = __DBL_DIG__; - static const bool is_signed = true; - static const bool is_integer = false; - static const bool is_exact = false; - static const bool traps = false; // this is a guess - static const bool is_modulo = false; - static const bool is_bounded = true; + static const bool is_specialized = true; + static numeric_type min () { return __DBL_MIN__; } + static numeric_type max () { return __DBL_MAX__; } + static const int radix = __FLT_RADIX__; + static const int digits = __DBL_MANT_DIG__; + static const int digits10 = __DBL_DIG__; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const bool traps = false; // this is a guess + static const bool is_modulo = false; + static const bool is_bounded = true; - // Floating point specific. + // Floating point specific. - static numeric_type epsilon () { return __DBL_EPSILON__; } - static numeric_type round_error () { return 0.5; } - static const int min_exponent10 = -1; //How do I properly get this? - static const int max_exponent10 = -1; //How do I properly get this? - static const int min_exponent = -1; //How do I properly get this? - static const int max_exponent = -1; //How do I properly get this? - static const bool has_infinity = false; //I don't know, so until I can find out, I'm saying no - static const bool has_quiet_NaN = false; //I don't know, so until I can find out, I'm saying no - static const bool has_signaling_NaN = false; //I don't know, so until I can find out, I'm saying no - static const bool has_denorm = false; //I don't know, so until I can find out, I'm saying no + static numeric_type epsilon () { return __DBL_EPSILON__; } + static numeric_type round_error () { return 0.5; } + static const int min_exponent10 = -1; //How do I properly get this? + static const int max_exponent10 = -1; //How do I properly get this? + static const int min_exponent = -1; //How do I properly get this? + static const int max_exponent = -1; //How do I properly get this? + static const bool has_infinity = false; //I don't know, so until I can find out, I'm saying no + static const bool has_quiet_NaN = false; //I don't know, so until I can find out, I'm saying no + static const bool has_signaling_NaN = false; //I don't know, so until I can find out, I'm saying no + static const bool has_denorm = false; //I don't know, so until I can find out, I'm saying no - static const bool is_iec559 = false; //I don't know, so until I can find out, I'm saying no - static const bool tinyness_before = false; // more questions - static const float_round_style round_style = round_to_nearest; // more questions - static numeric_type denorm_min () { return -1; } //How do I properly get this? - static numeric_type infinity () { return -1; } //How do I properly get this? - static numeric_type quiet_NaN () { return -1; } //How do I properly get this? - static numeric_type signaling_NaN () { return -1; } //How do I properly get this? + static const bool is_iec559 = false; //I don't know, so until I can find out, I'm saying no + static const bool tinyness_before = false; // more questions + static const float_round_style round_style = round_to_nearest; // more questions + static numeric_type denorm_min () { return -1; } //How do I properly get this? + static numeric_type infinity () { return -1; } //How do I properly get this? + static numeric_type quiet_NaN () { return -1; } //How do I properly get this? + static numeric_type signaling_NaN () { return -1; } //How do I properly get this? }; - - - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/list b/misc/uClibc++/include/uClibc++/list index 2fe182c66e..8daf8144d7 100644 --- a/misc/uClibc++/include/uClibc++/list +++ b/misc/uClibc++/include/uClibc++/list @@ -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 #include @@ -26,897 +26,1072 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ - template > class _UCXXEXPORT list { - public: - typedef typename Allocator::reference reference; - typedef typename Allocator::const_reference const_reference; - 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; +namespace std +{ - protected: - class node; - class iter_list; + template > class _UCXXEXPORT list { + public: + typedef typename Allocator::reference reference; + typedef typename Allocator::const_reference const_reference; + 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; - node * list_start; - node * list_end; - size_type elements; - Allocator a; + protected: + class node; + class iter_list; - public: + node * list_start; + node * list_end; + size_type elements; + Allocator a; - typedef iter_list iterator; - typedef iter_list const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; + public: + typedef iter_list iterator; + typedef iter_list const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; - explicit list(const Allocator& = Allocator()); - explicit list(size_type n, const T& value = T(), const Allocator& = Allocator()); - template list(InputIterator first, InputIterator last, - const Allocator& al= Allocator()); - list(const list& x); - ~list(); + explicit list(const Allocator& = Allocator()); + explicit list(size_type n, const T& value = T(), const Allocator& = Allocator()); + template list(InputIterator first, InputIterator last, + const Allocator& al= Allocator()); + list(const list& x); + ~list(); - list& operator=(const list& x){ - if(&x == this){ - return *this; - } - clear(); - iterator i = x.begin(); - while(i != x.end()){ - push_back(*i); - ++i; - } - return *this; - } + list& operator=(const list& x) + { + if (&x == this) + { + return *this; + } - template void assign(InputIterator first, InputIterator last); - template void assign(Size n, const U& u = U()); - allocator_type get_allocator() const; + clear(); + iterator i = x.begin(); + while (i != x.end()) + { + push_back(*i); + ++i; + } - 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; + return *this; + } - bool empty() const; - size_type size() const; - size_type max_size() const; - void resize(size_type sz, T c = T()); + template void assign(InputIterator first, InputIterator last); + template void assign(Size n, const U& u = U()); + allocator_type get_allocator() const; - reference front(); - const_reference front() const; - reference back(); - const_reference back() 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; - void push_front(const T& x); - void pop_front(); - void push_back(const T& x); - void pop_back(); - iterator insert(iterator position, const T& x = T()); - void insert(iterator position, size_type n, const T& x); - template void insert(iterator position, InputIterator first, InputIterator last); - iterator erase(iterator position); - iterator erase(iterator position, iterator last); - void swap(list&); - void clear(); + bool empty() const; + size_type size() const; + size_type max_size() const; + void resize(size_type sz, T c = T()); - void splice(iterator position, list& x); - void splice(iterator position, list& x, iterator i); - void splice(iterator position, list& x, iterator first, iterator last); - void remove(const T& value); - template void remove_if(Predicate pred); - void unique(); - template void unique(BinaryPredicate binary_pred); - void merge(list& x); - template void merge(list& x, Compare comp); - void sort(); - template void sort(Compare comp); - void reverse(); - protected: - void swap_nodes(node * x, node * y); - }; + reference front(); + const_reference front() const; + reference back(); + const_reference back() const; + void push_front(const T& x); + void pop_front(); + void push_back(const T& x); + void pop_back(); + iterator insert(iterator position, const T& x = T()); + void insert(iterator position, size_type n, const T& x); + template void insert(iterator position, InputIterator first, InputIterator last); + iterator erase(iterator position); + iterator erase(iterator position, iterator last); + void swap(list&); + void clear(); - //Implementations of List + void splice(iterator position, list& x); + void splice(iterator position, list& x, iterator i); + void splice(iterator position, list& x, iterator first, iterator last); + void remove(const T& value); + template void remove_if (Predicate pred); + void unique(); + template void unique(BinaryPredicate binary_pred); + void merge(list& x); + template void merge(list& x, Compare comp); + void sort(); + template void sort(Compare comp); + void reverse(); - //List node - template class _UCXXEXPORT list::node{ - public: - node * previous; - node * next; - T * val; + protected: + void swap_nodes(node * x, node * y); + }; - node(): previous(0), next(0), val(0){ } - node(const T & t ): previous(0), next(0), val(0) { - val = new T(t); - //FIXME use allocator somehow but only call constructor once - } - node(const T & t, node * p, node * n): previous(p), next(n), val(0) { - val = new T(t); - } - ~node(){ } - }; + // Implementations of List - //List iterator - template class _UCXXEXPORT list::iter_list - : public std::iterator< - bidirectional_iterator_tag, - T, - typename Allocator::difference_type, - typename Allocator::pointer, - typename Allocator::reference - > - { - private: - node * current; - public: - iter_list():current(0) { } - iter_list( typename list::node * n): current(n) { } - iter_list(const list::iter_list & l): current(l.current) { } - ~iter_list(){ } + // List node - iter_list & operator=(const list::iter_list & right ){ - current = right.current; - return *this; - } + template class _UCXXEXPORT list::node + { + public: + node * previous; + node * next; + T * val; - T & operator*(){ - return *(current->val); - } - T * operator->(){ - return current->val; - } - const T & operator*() const{ - return *current->val; - } - const T * operator->() const{ - return current->val; - } + node(): previous(0), next(0), val(0){ } - bool operator==(const list::iter_list & right) const { - return (current == right.current); - } + node(const T & t): previous(0), next(0), val(0) + { + val = new T(t); + //FIXME use allocator somehow but only call constructor once + } - bool operator!=(const list::iter_list & right) const { - return (current != right.current); - } + node(const T & t, node * p, node * n): previous(p), next(n), val(0) + { + val = new T(t); + } - iter_list & operator++(){ - current = current->next; - return *this; - } + ~node(){ } + }; - iter_list operator++(int){ - iter_list temp(current); - current = current->next; - return temp; - } - iter_list & operator--(){ - current = current->previous; - return *this; - } + // List iterator - iter_list operator--(int){ - iter_list temp(current); - current = current->previous; - return temp; - } - node * link_struct(){ - return current; - } - iter_list & operator+=(unsigned int n){ - for(unsigned int i = 0; i < n; ++i){ - current = current->next; - } - return *this; - } - iter_list & operator-=(unsigned int n){ - for(unsigned int i = 0; i < n; ++i){ - current = current->previous; - } - return *this; - } - }; + template class _UCXXEXPORT list::iter_list + : public std::iterator< + bidirectional_iterator_tag, + T, + typename Allocator::difference_type, + typename Allocator::pointer, + typename Allocator::reference + > + { + private: + node * current; + public: + iter_list():current(0) { } + iter_list(typename list::node * n): current(n) { } + iter_list(const list::iter_list & l): current(l.current) { } + ~iter_list(){ } + iter_list & operator=(const list::iter_list & right) + { + current = right.current; + return *this; + } - template list::list(const Allocator& al) - :list_start(0), list_end(0), elements(0), a(al) - { - //End node - list_start = new node(); - list_end = list_start; - return; - } + T & operator*() + { + return *(current->val); + } - template list::list - (typename Allocator::size_type n, const T& value, const Allocator& al) - :list_start(0), list_end(0), elements(0), a(al) - { - //End node - list_start = new node(); - list_end = list_start; + T * operator->() + { + return current->val; + } - for(typename Allocator::size_type i = 0; i < n ; ++i){ - push_back(value); - } - } + const T & operator*() const + { + return *current->val; + } - template template - list::list - (InputIterator first, InputIterator last, const Allocator& al) - : list_start(0), list_end(0), elements(0), a(al) - { - list_start = new node(); - list_end = list_start; - while(first != last){ - push_back(*first); - ++first; - } - } + const T * operator->() const + { + return current->val; + } - template list::list(const list& x) - : list_start(0), list_end(0), elements(0), a(x.a) - { - list_start = new node(); - list_end = list_start; + bool operator==(const list::iter_list & right) const + { + return (current == right.current); + } - iterator i = x.begin(); - while(i != x.end()){ - push_back( *i); - ++i; - } - } + bool operator!=(const list::iter_list & right) const + { + return (current != right.current); + } - template list::~list(){ - while(elements > 0){ - pop_front(); - } - delete list_start->val; + iter_list & operator++() + { + current = current->next; + return *this; + } + + iter_list operator++(int) + { + iter_list temp(current); + current = current->next; + return temp; + } + + iter_list & operator--() + { + current = current->previous; + return *this; + } + + iter_list operator--(int) + { + iter_list temp(current); + current = current->previous; + return temp; + } + + node *link_struct() + { + return current; + } + + iter_list & operator+=(unsigned int n) + { + for (unsigned int i = 0; i < n; ++i) + { + current = current->next; + } + + return *this; + } + + iter_list & operator-=(unsigned int n) + { + for (unsigned int i = 0; i < n; ++i) + { + current = current->previous; + } + + return *this; + } + }; + + template list::list(const Allocator& al) + :list_start(0), list_end(0), elements(0), a(al) + { + // End node + + list_start = new node(); + list_end = list_start; + return; + } + + template list::list + (typename Allocator::size_type n, const T& value, const Allocator& al) + :list_start(0), list_end(0), elements(0), a(al) + { + // End node + + list_start = new node(); + list_end = list_start; + + for (typename Allocator::size_type i = 0; i < n ; ++i) + { + push_back(value); + } + } + + template template + list::list + (InputIterator first, InputIterator last, const Allocator& al) + : list_start(0), list_end(0), elements(0), a(al) + { + list_start = new node(); + list_end = list_start; + while (first != last) + { + push_back(*first); + ++first; + } + } + + template list::list(const list& x) + : list_start(0), list_end(0), elements(0), a(x.a) + { + list_start = new node(); + list_end = list_start; + + iterator i = x.begin(); + while (i != x.end()) + { + push_back(*i); + ++i; + } + } + + template list::~list(){ + while (elements > 0) + { + pop_front(); + } + + delete list_start->val; #ifdef CONFIG_DEBUG_LIB - list_start->val = 0; + list_start->val = 0; #endif - delete list_start; + delete list_start; #ifdef CONFIG_DEBUG_LIB - list_start = 0; - list_end = 0; + list_start = 0; + list_end = 0; #endif - } + } - template void list::swap_nodes(node * x, node * y){ - T * v = x->val; - x->val = y->val; - y->val = v; - } + template void list::swap_nodes(node * x, node * y) + { + T * v = x->val; + x->val = y->val; + y->val = v; + } - template typename list::iterator - list::begin() - { - return iterator(list_start); - } + template typename list::iterator + list::begin() + { + return iterator(list_start); + } + template typename list::const_iterator + list::begin() const + { + return const_iterator(list_start); + } - template typename list::const_iterator - list::begin() const - { - return const_iterator(list_start); - } + template typename list::iterator + list::end() + { + return iterator(list_end); + } + template typename list::const_iterator + list::end() const + { + return const_iterator(list_end); + } - template typename list::iterator - list::end() - { - return iterator(list_end); - } + template typename list::reverse_iterator + list::rbegin() + { + return reverse_iterator(end()); + } - template typename list::const_iterator - list::end() const - { - return const_iterator(list_end); - } + template typename list::const_reverse_iterator + list::rbegin() const + { + return const_reverse_iterator(end()); + } - template typename list::reverse_iterator - list::rbegin() - { - return reverse_iterator(end()); - } + template typename list::reverse_iterator + list::rend() + { + return reverse_iterator(begin()); + } - template typename list::const_reverse_iterator - list::rbegin() const - { - return const_reverse_iterator(end()); - } + template typename list::const_reverse_iterator + list::rend() const + { + return const_reverse_iterator(begin()); + } - template typename list::reverse_iterator - list::rend() - { - return reverse_iterator(begin()); - } + template bool list::empty() const{ + return (elements == 0); + } - template typename list::const_reverse_iterator - list::rend() const - { - return const_reverse_iterator(begin()); - } + template typename list::size_type list::size() const{ + return elements; + } - template bool list::empty() const{ - return (elements == 0); - } - template typename list::size_type list::size() const{ - return elements; - } - template typename list::size_type list::max_size() const{ - return ((size_type)(-1)) / (sizeof(T) + sizeof(node)); - } - template void list::resize(typename Allocator::size_type sz, T c){ -// if(sz > elements){ - for(typename Allocator::size_type i = elements; i < sz; ++i){ - push_back(c); - } -// } -// if(sz < elements){ - for(typename Allocator::size_type i = elements; i > sz; --i){ - pop_back(); - } -// } - } + template typename list::size_type list::max_size() const + { + return ((size_type)(-1)) / (sizeof(T) + sizeof(node)); + } - template typename list::reference list::front(){ - return *(list_start->val); - } - template typename list::const_reference list::front() const{ - return *(list_start->val); - } - template typename list::reference list::back(){ - return *(list_end->previous->val); - } - template typename list::const_reference list::back() const{ - return *(list_end->previous->val); - } + template void list::resize(typename Allocator::size_type sz, T c) + { +// if (sz > elements) +// { + for (typename Allocator::size_type i = elements; i < sz; ++i) + { + push_back(c); + } +// } +// if (sz < elements) +// { + for (typename Allocator::size_type i = elements; i > sz; --i) + { + pop_back(); + } +// } + } + template typename list::reference list::front(){ + return *(list_start->val); + } - template void list::push_front(const T& x){ - node * temp = new node(x); - list_start->previous = temp; - temp->previous = 0; - temp->next = list_start; - list_start = temp; - ++elements; - } + template typename list::const_reference list::front() const + { + return *(list_start->val); + } - template void list::pop_front(){ - if(elements > 0){ - list_start = list_start->next; - delete list_start->previous->val; + template typename list::reference list::back() + { + return *(list_end->previous->val); + } + + template typename list::const_reference list::back() const + { + return *(list_end->previous->val); + } + + template void list::push_front(const T& x) + { + node * temp = new node(x); + list_start->previous = temp; + temp->previous = 0; + temp->next = list_start; + list_start = temp; + ++elements; + } + + template void list::pop_front() + { + if (elements > 0) + { + list_start = list_start->next; + delete list_start->previous->val; #ifdef CONFIG_DEBUG_LIB - list_start->previous->val = 0; - list_start->previous->next = 0; - list_start->previous->previous = 0; + list_start->previous->val = 0; + list_start->previous->next = 0; + list_start->previous->previous = 0; #endif - delete list_start->previous; - list_start->previous = 0; - --elements; - } - } + delete list_start->previous; + list_start->previous = 0; + --elements; + } + } - template void list::push_back(const T& x){ - if(elements == 0){ - //The list is completely empty - list_start = new node(x); - list_end->previous = list_start; - list_start->previous = 0; - list_start->next = list_end; - elements = 1; - }else{ - node * temp = new node(x); - temp->previous = list_end->previous; - temp->next = list_end; - list_end->previous->next = temp; - list_end->previous = temp; - ++elements; - } - } + template void list::push_back(const T& x) + { + if (elements == 0) + { + // The list is completely empty - template void list::pop_back(){ - if(elements > 0){ - node * temp = list_end->previous; - if(temp == list_start){ - list_end->previous = 0; - list_start = list_end; - }else{ - temp->previous->next = temp->next; - list_end->previous = temp->previous; - } - delete temp->val; + list_start = new node(x); + list_end->previous = list_start; + list_start->previous = 0; + list_start->next = list_end; + elements = 1; + } + else + { + node * temp = new node(x); + temp->previous = list_end->previous; + temp->next = list_end; + list_end->previous->next = temp; + list_end->previous = temp; + ++elements; + } + } + + template void list::pop_back() + { + if (elements > 0) + { + node * temp = list_end->previous; + if (temp == list_start) + { + list_end->previous = 0; + list_start = list_end; + } + else + { + temp->previous->next = temp->next; + list_end->previous = temp->previous; + } + + delete temp->val; #ifdef CONFIG_DEBUG_LIB - temp->val = 0; - temp->next = 0; - temp->previous = 0; + temp->val = 0; + temp->next = 0; + temp->previous = 0; #endif - delete temp; + delete temp; #ifdef CONFIG_DEBUG_LIB - temp = 0; + temp = 0; #endif - --elements; - } - } + --elements; + } + } - template typename list::iterator - list::insert(iterator position, const T& x) - { - node * temp = new node(x); + template typename list::iterator + list::insert(iterator position, const T& x) + { + node * temp = new node(x); - temp->previous = position.link_struct()->previous; - temp->next = position.link_struct(); + temp->previous = position.link_struct()->previous; + temp->next = position.link_struct(); - if(temp->previous == 0){ - list_start = temp; - }else{ - position.link_struct()->previous->next = temp; - } + if (temp->previous == 0) + { + list_start = temp; + } + else + { + position.link_struct()->previous->next = temp; + } - position.link_struct()->previous = temp; + position.link_struct()->previous = temp; - ++elements; - --position; - return position; - } + ++elements; + --position; + return position; + } - template void list::insert(iterator position, size_type n, const T& x){ - for(typename list::size_type i = 0; i < n; ++i){ - position = insert(position, x); - } - } + template void list::insert(iterator position, size_type n, const T& x) + { + for (typename list::size_type i = 0; i < n; ++i) + { + position = insert(position, x); + } + } - template template void - list::insert(iterator position, InputIterator first, InputIterator last) - { - while(first !=last){ - insert(position, *first); - ++first; - } - } - template typename list::iterator - list::erase(iterator position) - { - if(position != end() ){ - node * temp = position.link_struct(); - if(temp == list_start){ - ++position; - temp->next->previous = 0; - list_start = temp->next; - }else{ - --position; - temp->next->previous = temp->previous; - temp->previous->next = temp->next; - ++position; - } - delete temp->val; + template template void + list::insert(iterator position, InputIterator first, InputIterator last) + { + while (first !=last) + { + insert(position, *first); + ++first; + } + } + + template typename list::iterator + list::erase(iterator position) + { + if (position != end()) + { + node * temp = position.link_struct(); + if (temp == list_start) + { + ++position; + temp->next->previous = 0; + list_start = temp->next; + } + else + { + --position; + temp->next->previous = temp->previous; + temp->previous->next = temp->next; + ++position; + } + + delete temp->val; #ifdef CONFIG_DEBUG_LIB - temp->next = 0; - temp->previous = 0; - temp->val = 0; + temp->next = 0; + temp->previous = 0; + temp->val = 0; #endif - delete temp; + delete temp; #ifdef CONFIG_DEBUG_LIB - temp = 0; + temp = 0; #endif - --elements; - } - return position; - } - template typename list::iterator - list::erase(iterator position, iterator last) - { - iterator temp = position; - while(position !=last){ - position = erase(position); - } - return position; - } - template void list::swap(list& l){ - node * temp; - size_type tempel; - - temp = list_start; - list_start = l.list_start; - l.list_start = temp; - - temp = list_end; - list_end = l.list_end; - l.list_end = temp; - - tempel = elements; - elements = l.elements; - l.elements = tempel; - } - template void list::clear(){ - while(elements > 0){ - pop_front(); - } - } - - template - void list::splice(iterator position, list& x) - { - - //Can't add non-existant elements - if(x.elements == 0){ - return; - } - - elements += x.elements; - x.elements = 0; - - - //Chaining to the begining - if(position == begin()){ - x.list_end->previous->next = list_start; - list_start->previous = x.list_end->previous; - - list_start = x.list_start; - - x.list_start = x.list_end; - x.list_end->previous = 0; - - return; - } - - //Link everything we need - x.list_start->previous = position.link_struct()->previous; - position.link_struct()->previous->next = x.list_start; - - position.link_struct()->previous = x.list_end->previous; - x.list_end->previous->next = position.link_struct(); - - //Clean up the other list - - x.list_start = x.list_end; - x.list_end->previous=0; - - } - - template - void list::splice(iterator position, list& x, iterator i) - { - //Invalid conditions - if( x.elements == 0 || i == position || position.link_struct() == i.link_struct()->next ){ - return; - } - - //Do we need to adjust the begining pointer? - if(i == x.begin()){ - x.list_start = x.list_start->next; - x.list_start->previous = 0; - } - - - //Insert at begining special case - if(position == begin()){ - - i.link_struct()->previous->next = i.link_struct()->next; - i.link_struct()->next->previous = i.link_struct()->previous; - - i.link_struct()->previous = 0; - i.link_struct()->next = position.link_struct(); - position.link_struct()->previous = i.link_struct(); - - list_start = i.link_struct(); - - --x.elements; - ++elements; - return; - } - - if( i.link_struct()->previous != 0){ - i.link_struct()->previous->next = i.link_struct()->next; - i.link_struct()->next->previous = i.link_struct()->previous; - }else{ - i.link_struct()->next->previous = 0; - x.list_start = i.link_struct()->next; - } - - i.link_struct()->previous = position.link_struct()->previous; - position.link_struct()->previous->next = i.link_struct(); - - i.link_struct()->next = position.link_struct(); - position.link_struct()->previous = i.link_struct(); - - --x.elements; - ++elements; - } - - template - void list::splice(iterator position, list& x, - iterator first, iterator last) - { - if(x.elements == 0){ - return; - } - - iterator temp; - while(first != last){ - temp = first; - ++first; - splice(position, x, temp); - } - } - - - template void list::remove(const T& value){ - iterator temp = begin(); - while( temp != end() ){ - if(*temp == value){ - temp = erase(temp); - }else{ - ++temp; - } - } - } - - - template template void list::remove_if(Predicate pred){ - iterator temp = begin(); - while( temp != end() ){ - if( pred(*temp) ){ - temp = erase(temp); - }else{ - ++temp; - } - } - } - - - template void list::unique(){ - equal_to::value_type> p; - unique(p); - } - - template template - void list::unique(BinaryPredicate binary_pred) - { - iterator temp1 = begin(); - iterator temp2; - ++temp1; - while( temp1 != end() ){ - temp2 = temp1; - --temp2; - if( binary_pred(*temp1, *temp2) ){ - erase(temp1); - temp1 = temp2; - } - ++temp1; - } - } - - template void list::merge(list& x){ - less::iterator>::value_type> c; - merge(x, c); - } - - template template - void list::merge(list& x, Compare comp) - { - iterator source = x.begin(); - iterator temp; - iterator dest = begin(); - - while(source != x.end()){ - while( dest != end() && comp (*dest, *source) ){ - ++dest; - } - ++elements; - --x.elements; - - temp = source; - ++temp; - - if(dest == begin()){ - dest.link_struct()->previous = source.link_struct(); - source.link_struct()->next = dest.link_struct(); - source.link_struct()->previous = 0; - list_start = source.link_struct(); - }else{ - source.link_struct()->previous = dest.link_struct()->previous; - dest.link_struct()->previous->next = source.link_struct(); - source.link_struct()->next = dest.link_struct(); - dest.link_struct()->previous = source.link_struct(); - } - source = temp; - } - - //Fix up x; - x.list_start = x.list_end; - x.list_start->previous = 0; - } - - template void list::sort(){ - less::iterator>::value_type> c; - sort(c); - } - - template template - void list::sort(Compare comp) - { - typename list::iterator i, j, k; - - //FIXME - bubble sort - - if(elements == 0){ - return; - } - - i = end(); - --i; - while(i != begin()){ - j = begin(); - k = j; - ++k; - while(j != i){ - if( comp(*k, *j) ){ - swap_nodes(k.link_struct(), j.link_struct()); - } - ++j; - ++k; - } - --i; - } - } - - - template void list::reverse(){ - if(elements == 0){ - return; - } - - node * current; - node * following; - node * temp; - - //Need to move the list_end element to the begining - - temp = list_end; - list_end = temp->previous; - list_end->next = 0; - - list_start->previous = temp; - temp->previous = 0; - temp->next = list_start; - list_start = temp; - - current = list_start; - - while( current != list_end ){ - following = current->next; - - //Swap the values pointed to/at with the current node - temp = current->next; - current->next = current->previous; - current->previous = temp; - - current = following; - } - - //Swap pointers on the end node - temp = list_end->next; - list_end->next = list_end->previous; - list_end->previous = temp; - - - //Swap the fixed pointers - temp = list_start; - list_start = list_end; - list_end = temp; - - } - - template - bool operator==(const list& x, const list& y){ - if(x.size() != y.size()){ - return false; - } - typename list::const_iterator i = x.begin(); - typename list::const_iterator j = y.begin(); - - while(i != x.end()){ - if( *i != *j){ - return false; - } - ++i; - ++j; - } - return true; - } - - template - bool operator< (const list& x, const list& y){ - typename list::const_iterator i = x.begin(); - typename list::const_iterator j = y.begin(); - while(i != x.end() && j != y.end()){ - if( *i < *j){ - return true; - } - if(*j < *i){ - return false; - } - ++i; - ++j; - } - return (i == x.end() && j != y.end()); - } - - template - bool operator!=(const list& x, const list& y){ - return !(x == y); - } - - template - bool operator> (const list& x, const list& y){ - typename list::const_iterator i = x.begin(); - typename list::const_iterator j = y.begin(); - while(i != x.end() && j != y.end()){ - if( *i > *j){ - return true; - } - if( *j > *i){ - return false; - } - ++i; - ++j; - } - return (i != x.end() && j == y.end()); - } - - template - bool operator>=(const list& x, const list& y){ - typename list::const_iterator i = x.begin(); - typename list::const_iterator j = y.begin(); - while(i != x.end() && j != y.end()){ - if( *i >= *j){ - return true; - } - if(*j >= *i){ - return false; - } - ++i; - ++j; - } - return (i != x.end() && j == y.end()); - } - - template - bool operator<=(const list& x, const list& y){ - typename list::const_iterator i = x.begin(); - typename list::const_iterator j = y.begin(); - while(i != x.end() && j != y.end()){ - if( *i <= *j){ - return true; - } - if(*j <= *i){ - return false; - } - ++i; - ++j; - } - return (i == x.end()); - } - - template - void swap(list& x, list& y){ - x.swap(y); - } - -} + --elements; + } + + return position; + } + + template typename list::iterator + list::erase(iterator position, iterator last) + { + iterator temp = position; + while (position !=last) + { + position = erase(position); + } + + return position; + } + + template void list::swap(list& l) + { + node * temp; + size_type tempel; + + temp = list_start; + list_start = l.list_start; + l.list_start = temp; + + temp = list_end; + list_end = l.list_end; + l.list_end = temp; + + tempel = elements; + elements = l.elements; + l.elements = tempel; + } + + template void list::clear() + { + while (elements > 0) + { + pop_front(); + } + } + + template + void list::splice(iterator position, list& x) + { + // Can't add non-existant elements + + if (x.elements == 0) + { + return; + } + + elements += x.elements; + x.elements = 0; + + // Chaining to the begining + + if (position == begin()) + { + x.list_end->previous->next = list_start; + list_start->previous = x.list_end->previous; + + list_start = x.list_start; + + x.list_start = x.list_end; + x.list_end->previous = 0; + + return; + } + + // Link everything we need + + x.list_start->previous = position.link_struct()->previous; + position.link_struct()->previous->next = x.list_start; + + position.link_struct()->previous = x.list_end->previous; + x.list_end->previous->next = position.link_struct(); + + // Clean up the other list + + x.list_start = x.list_end; + x.list_end->previous=0; + } + + template + void list::splice(iterator position, list& x, iterator i) + { + // Invalid conditions + + if (x.elements == 0 || i == position || position.link_struct() == i.link_struct()->next) + { + return; + } + + // Do we need to adjust the begining pointer? + + if (i == x.begin()) + { + x.list_start = x.list_start->next; + x.list_start->previous = 0; + } + + // Insert at begining special case + + if (position == begin()) + { + i.link_struct()->previous->next = i.link_struct()->next; + i.link_struct()->next->previous = i.link_struct()->previous; + + i.link_struct()->previous = 0; + i.link_struct()->next = position.link_struct(); + position.link_struct()->previous = i.link_struct(); + + list_start = i.link_struct(); + + --x.elements; + ++elements; + return; + } + + if (i.link_struct()->previous != 0) + { + i.link_struct()->previous->next = i.link_struct()->next; + i.link_struct()->next->previous = i.link_struct()->previous; + } + else + { + i.link_struct()->next->previous = 0; + x.list_start = i.link_struct()->next; + } + + i.link_struct()->previous = position.link_struct()->previous; + position.link_struct()->previous->next = i.link_struct(); + + i.link_struct()->next = position.link_struct(); + position.link_struct()->previous = i.link_struct(); + + --x.elements; + ++elements; + } + + template + void list::splice(iterator position, list& x, + iterator first, iterator last) + { + if (x.elements == 0) + { + return; + } + + iterator temp; + while (first != last) + { + temp = first; + ++first; + splice(position, x, temp); + } + } + + template void list::remove(const T& value) + { + iterator temp = begin(); + while (temp != end()) + { + if (*temp == value) + { + temp = erase(temp); + } + else + { + ++temp; + } + } + } + + template template void list::remove_if (Predicate pred) + { + iterator temp = begin(); + while (temp != end()) + { + if (pred(*temp)) + { + temp = erase(temp); + } + else + { + ++temp; + } + } + } + + template void list::unique() + { + equal_to::value_type> p; + unique(p); + } + + template template + void list::unique(BinaryPredicate binary_pred) + { + iterator temp1 = begin(); + iterator temp2; + ++temp1; + while (temp1 != end()) + { + temp2 = temp1; + --temp2; + if (binary_pred(*temp1, *temp2)) + { + erase(temp1); + temp1 = temp2; + } + + ++temp1; + } + } + + template void list::merge(list& x) + { + less::iterator>::value_type> c; + merge(x, c); + } + + template template + void list::merge(list& x, Compare comp) + { + iterator source = x.begin(); + iterator temp; + iterator dest = begin(); + + while (source != x.end()) + { + while (dest != end() && comp (*dest, *source)) + { + ++dest; + } + + ++elements; + --x.elements; + + temp = source; + ++temp; + + if (dest == begin()) + { + dest.link_struct()->previous = source.link_struct(); + source.link_struct()->next = dest.link_struct(); + source.link_struct()->previous = 0; + list_start = source.link_struct(); + } + else + { + source.link_struct()->previous = dest.link_struct()->previous; + dest.link_struct()->previous->next = source.link_struct(); + source.link_struct()->next = dest.link_struct(); + dest.link_struct()->previous = source.link_struct(); + } + + source = temp; + } + + // Fix up x; + + x.list_start = x.list_end; + x.list_start->previous = 0; + } + + template void list::sort() + { + less::iterator>::value_type> c; + sort(c); + } + + template template + void list::sort(Compare comp) + { + typename list::iterator i, j, k; + + // FIXME - bubble sort + + if (elements == 0) + { + return; + } + + i = end(); + --i; + while (i != begin()) + { + j = begin(); + k = j; + ++k; + while (j != i) + { + if (comp(*k, *j)) + { + swap_nodes(k.link_struct(), j.link_struct()); + } + + ++j; + ++k; + } + + --i; + } + } + + + template void list::reverse() + { + if (elements == 0) + { + return; + } + + node * current; + node * following; + node * temp; + + // Need to move the list_end element to the begining + + temp = list_end; + list_end = temp->previous; + list_end->next = 0; + + list_start->previous = temp; + temp->previous = 0; + temp->next = list_start; + list_start = temp; + + current = list_start; + + while (current != list_end) + { + following = current->next; + + // Swap the values pointed to/at with the current node + + temp = current->next; + current->next = current->previous; + current->previous = temp; + + current = following; + } + + // Swap pointers on the end node + + temp = list_end->next; + list_end->next = list_end->previous; + list_end->previous = temp; + + //Swap the fixed pointers + + temp = list_start; + list_start = list_end; + list_end = temp; + } + + template + bool operator==(const list& x, const list& y) + { + if (x.size() != y.size()) + { + return false; + } + + typename list::const_iterator i = x.begin(); + typename list::const_iterator j = y.begin(); + + while (i != x.end()) + { + if (*i != *j) + { + return false; + } + + ++i; + ++j; + } + + return true; + } + + template + bool operator< (const list& x, const list& y) + { + typename list::const_iterator i = x.begin(); + typename list::const_iterator j = y.begin(); + while (i != x.end() && j != y.end()) + { + if (*i < *j) + { + return true; + } + + if (*j < *i) + { + return false; + } + + ++i; + ++j; + } + + return (i == x.end() && j != y.end()); + } + + template + bool operator!=(const list& x, const list& y) + { + return !(x == y); + } + + template + bool operator> (const list& x, const list& y) + { + typename list::const_iterator i = x.begin(); + typename list::const_iterator j = y.begin(); + while (i != x.end() && j != y.end()) + { + if (*i > *j) + { + return true; + } + + if (*j > *i) + { + return false; + } + + ++i; + ++j; + } + + return (i != x.end() && j == y.end()); + } + + template + bool operator>=(const list& x, const list& y) + { + typename list::const_iterator i = x.begin(); + typename list::const_iterator j = y.begin(); + while (i != x.end() && j != y.end()) + { + if (*i >= *j) + { + return true; + } + + if (*j >= *i) + { + return false; + } + + ++i; + ++j; + } + + return (i != x.end() && j == y.end()); + } + + template + bool operator<=(const list& x, const list& y) + { + typename list::const_iterator i = x.begin(); + typename list::const_iterator j = y.begin(); + while (i != x.end() && j != y.end()) + { + if (*i <= *j) + { + return true; + } + + if (*j <= *i) + { + return false; + } + + ++i; + ++j; + } + + return (i == x.end()); + } + + template + void swap(list& x, list& y) + { + x.swap(y); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/map b/misc/uClibc++/include/uClibc++/map index 038191af7c..6816116bbb 100644 --- a/misc/uClibc++/include/uClibc++/map +++ b/misc/uClibc++/include/uClibc++/map @@ -1,63 +1,60 @@ -/* Copyright (C) 2004-2007 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-2007 Garrett A. Kajmowicz + * This file is part of the uClibc++ Library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include #include #include - - #ifndef __STD_HEADER_MAP #define __STD_HEADER_MAP #pragma GCC visibility push(default) -namespace std{ - +extern "C++" +{ +namespace std +{ template, class Allocator = allocator > class map; template, class Allocator = allocator > class multimap; + //Compare the keys of the two items - //Compare the keys of the two items -/* template class _UCXXEXPORT - __base_map::value_compare : public binary_function< - typename map::value_type, - typename map::value_type, - bool> - { - friend class __base_map; - protected: - Compare comp; - value_compare(Compare c) : comp(c) { } - ~value_compare() { } - public: - bool operator()(const value_type& x, const value_type& y) const { - return comp(x.first, y.first); - } - }; + /* template class _UCXXEXPORT + __base_map::value_compare : public binary_function< + typename map::value_type, + typename map::value_type, + bool> +{ + friend class __base_map; + protected: + Compare comp; + value_compare(Compare c) : comp(c) { } + ~value_compare() { } + public: + bool operator()(const value_type& x, const value_type& y) const + { + return comp(x.first, y.first); + } + }; */ -// value_compare value_comp() const; - - +// value_compare value_comp() const; /* This is the implementation for the map container. As noted above, it deviates * from ISO spec by deriving from a base class in order to reduce code redundancy. @@ -66,199 +63,207 @@ template, class Allocator = alloca * the specifications too much to be worth the risk. */ - - //Implementation of map - template class _UCXXEXPORT map - : public __single_associative, Compare, Allocator> + : public __single_associative, Compare, Allocator> { - //Default value of allocator does not meet C++ standard specs, but it works for this library - //Deal with it + // Default value of allocator does not meet C++ standard specs, but it works for this library + // Deal with it public: - typedef __single_associative, Compare, Allocator> base; - typedef T mapped_type; - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; + typedef __single_associative, Compare, Allocator> base; + typedef T mapped_type; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - static const key_type v_t_k(const value_type v){ - return v.first; - } + static const key_type v_t_k(const value_type v) + { + return v.first; + } -// using base::value_compare; +// using base::value_compare; - explicit map(const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(comp, al, v_t_k) { } + explicit map(const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(comp, al, v_t_k) { } - template map(InputIterator first, InputIterator last, - const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(first, last, comp, al, v_t_k) { } + template map(InputIterator first, InputIterator last, + const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(first, last, comp, al, v_t_k) { } - map(const map& x) : base(x) { } - ~map() { } + map(const map& x) : base(x) { } + ~map() { } - using base::operator=; - using base::operator==; - using base::operator!=; + using base::operator=; + using base::operator==; + using base::operator!=; - using base::insert; - using base::erase; + using base::insert; + using base::erase; - using base::begin; - using base::end; - using base::rbegin; - using base::rend; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::empty; - using base::size; - using base::max_size; + using base::empty; + using base::size; + using base::max_size; - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; - using base::swap; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; + using base::swap; - reference operator[](const key_type& k){ - iterator i = lower_bound(k); - if (i == end() || base::c(k, i->first)) { - i = insert(make_pair(k, T())).first; - } - return i->second; - } + reference operator[](const key_type& k) + { + iterator i = lower_bound(k); + if (i == end() || base::c(k, i->first)) + { + i = insert(make_pair(k, T())).first; + } + + return i->second; + } protected: - using base::backing; + using base::backing; }; - -//Implementation of multimap - +// Implementation of multimap template class _UCXXEXPORT multimap - : public __multi_associative, Compare, Allocator> - + : public __multi_associative, Compare, Allocator> { - //Default value of allocator does not meet C++ standard specs, but it works for this library - //Deal with it + // Default value of allocator does not meet C++ standard specs, but it works for this library + // Deal with it + public: - typedef __multi_associative, Compare, Allocator> base; - typedef T mapped_type; - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; + typedef __multi_associative, Compare, Allocator> base; + typedef T mapped_type; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - static const key_type v_t_k(const value_type v){ - return v.first; - } + static const key_type v_t_k(const value_type v) + { + return v.first; + } - explicit multimap(const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(comp, al, v_t_k) { } + explicit multimap(const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(comp, al, v_t_k) { } - template multimap(InputIterator first, InputIterator last, - const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(first, last, comp, al, v_t_k) { } + template multimap(InputIterator first, InputIterator last, + const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(first, last, comp, al, v_t_k) { } + multimap(const multimap& x) : base(x) { } + ~multimap() { } - multimap(const multimap& x) : base(x) { } - ~multimap() { } + using base::operator=; + using base::operator==; + using base::operator!=; - using base::operator=; - using base::operator==; - using base::operator!=; + using base::insert; + using base::erase; - using base::insert; - using base::erase; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::begin; - using base::end; - using base::rbegin; - using base::rend; + using base::empty; + using base::size; + using base::max_size; - using base::empty; - using base::size; - using base::max_size; - - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; - using base::swap; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; + using base::swap; protected: - using base::c; - + using base::c; }; - /* Non-member functions. These are at the end because they are not associated with any - particular class. These will be implemented as I figure out exactly what all of - them are supposed to do, and I have time. + * particular class. These will be implemented as I figure out exactly what all of + * them are supposed to do, and I have time. */ - template _UCXXEXPORT bool operator< - (const map& x, const map& y); - template _UCXXEXPORT bool operator!= - (const map& x, const map& y); - template _UCXXEXPORT bool operator> - (const map& x, const map& y); - template _UCXXEXPORT bool operator>= - (const map& x, const map& y); - template _UCXXEXPORT bool operator<= - (const map& x, const map& y); - template _UCXXEXPORT void swap - (map& x, map& y); + template _UCXXEXPORT bool operator< + (const map& x, const map& y); + template _UCXXEXPORT bool operator!= + (const map& x, const map& y); - template _UCXXEXPORT bool operator== - (const multimap& x, const multimap& y); - template _UCXXEXPORT bool operator< - (const multimap& x, const multimap& y); - template _UCXXEXPORT bool operator!= - (const multimap& x, const multimap& y); - template _UCXXEXPORT bool operator> - (const multimap& x, const multimap& y); - template _UCXXEXPORT bool operator>= - (const multimap& x, const multimap& y); - template _UCXXEXPORT bool operator<= - (const multimap& x, const multimap& y); - template _UCXXEXPORT void swap - (multimap& x, multimap& y); + template _UCXXEXPORT bool operator> + (const map& x, const map& y); -} + template _UCXXEXPORT bool operator>= + (const map& x, const map& y); + + template _UCXXEXPORT bool operator<= + (const map& x, const map& y); + + template _UCXXEXPORT void swap + (map& x, map& y); + + template _UCXXEXPORT bool operator== + (const multimap& x, const multimap& y); + + template _UCXXEXPORT bool operator< + (const multimap& x, const multimap& y); + + template _UCXXEXPORT bool operator!= + (const multimap& x, const multimap& y); + + template _UCXXEXPORT bool operator> + (const multimap& x, const multimap& y); + + template _UCXXEXPORT bool operator>= + (const multimap& x, const multimap& y); + + template _UCXXEXPORT bool operator<= + (const multimap& x, const multimap& y); + + template _UCXXEXPORT void swap + (multimap& x, multimap& y); + +} // namespace +} // extern "C++" #pragma GCC visibility pop #endif - + diff --git a/misc/uClibc++/include/uClibc++/memory b/misc/uClibc++/include/uClibc++/memory index 2a7ce8c152..cd3956f185 100644 --- a/misc/uClibc++/include/uClibc++/memory +++ b/misc/uClibc++/include/uClibc++/memory @@ -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 #include @@ -29,166 +29,214 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ + +namespace std +{ template class allocator; - // Specialize for void: + // Specialize for void: -template <> class _UCXXEXPORT allocator { +template <> class _UCXXEXPORT allocator +{ public: - typedef void* pointer; - typedef const void* const_pointer; - typedef void value_type; - template struct rebind { typedef allocator other; }; + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + template struct rebind { typedef allocator other; }; }; -template class _UCXXEXPORT allocator{ +template class _UCXXEXPORT allocator +{ public: - typedef T value_type; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - typedef T* pointer; - typedef const T* const_pointer; + typedef T value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + + typedef T* pointer; + typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; + typedef T& reference; + typedef const T& const_reference; - pointer address(reference r) const { return &r; } - const_pointer address(const_reference r) const { return &r; } - - allocator() throw(){} - template allocator(const allocator& ) throw(); - ~allocator() throw(){} + pointer address(reference r) const { return &r; } + const_pointer address(const_reference r) const { return &r; } + + allocator() throw(){} + template allocator(const allocator& ) throw(); + ~allocator() throw(){} - //Space for n Ts - pointer allocate(size_type n, typename allocator::const_pointer = 0){ - return (T*)(::operator new( n * sizeof(T) )); - } - void deallocate(pointer p, size_type){ - ::operator delete(p); - } + // Space for n Ts - //Use placement new to engage the constructor - void construct(pointer p, const T& val) { new((void*)p) T(val); } - void destroy(pointer p){ ((T*)p)->~T(); } //Call destructor + pointer allocate(size_type n, typename allocator::const_pointer = 0) + { + return (T*)(::operator new( n * sizeof(T) )); + } - size_type max_size() const throw(); - template struct rebind { typedef allocator other; }; + void deallocate(pointer p, size_type) + { + ::operator delete(p); + } + // Use placement new to engage the constructor + + void construct(pointer p, const T& val) { new((void*)p) T(val); } + void destroy(pointer p){ ((T*)p)->~T(); } //Call destructor + + size_type max_size() const throw(); + template struct rebind { typedef allocator other; }; }; template class _UCXXEXPORT raw_storage_iterator - : public iterator + : public iterator { - Out p; + Out p; public: - explicit raw_storage_iterator(Out pp) : p (pp) { } - raw_storage_iterator & operator*() { return *this; } - raw_storage_iterator & operator=(const T& val) { - T* pp = &*p; - new(pp) T(val); - return *this; - } + explicit raw_storage_iterator(Out pp) : p (pp) { } + raw_storage_iterator & operator*() { return *this; } - raw_storage_iterator & operator++() { ++p; return *this; } - raw_storage_iterator operator++(int) { - raw_storage_iterator t = *this; - ++p; - return t; - } + raw_storage_iterator & operator=(const T& val) + { + T* pp = &*p; + new(pp) T(val); + return *this; + } + + raw_storage_iterator & operator++() { ++p; return *this; } + + raw_storage_iterator operator++(int) + { + raw_storage_iterator t = *this; + ++p; + return t; + } }; -template _UCXXEXPORT pair get_temporary_buffer(ptrdiff_t n){ - pair retval; - retval.first = static_cast(malloc(n * sizeof(T))); - if(retval.first == 0){ - retval.second = 0; - }else{ - retval.second = n; - } - return retval; +template _UCXXEXPORT pair get_temporary_buffer(ptrdiff_t n) +{ + pair retval; + retval.first = static_cast(malloc(n * sizeof(T))); + if (retval.first == 0) + { + retval.second = 0; + } + else + { + retval.second = n; + } + + return retval; } -template _UCXXEXPORT void return_temporary_buffer(T* p){ - free(p); +template _UCXXEXPORT void return_temporary_buffer(T* p) +{ + free(p); } -template class _UCXXEXPORT auto_ptr{ - +template class _UCXXEXPORT auto_ptr +{ private: - T * object; - template struct auto_ptr_ref{ - Y * p; - }; + T * object; + template struct auto_ptr_ref + { + Y * p; + }; public: - typedef T element_type; + typedef T element_type; - explicit auto_ptr(T* p =0) throw() : object(p){ } - auto_ptr(auto_ptr& p) throw() : object(p.release()){ } - auto_ptr(auto_ptr_ref r) throw() : object(r.p){ - r.p = 0; - } - template auto_ptr(auto_ptr& p) throw() : object(p.release()){ } - auto_ptr& operator=(auto_ptr& p) throw(){ - if(&p == this){ - return *this; - } - delete object; - object = p.release(); - return *this; - } - template auto_ptr& operator=(auto_ptr& p) throw(){ - if(&p == this){ - return *this; - } - delete object; - object = p.release(); - return *this; - } - ~auto_ptr(){ - delete object; - } + explicit auto_ptr(T* p =0) throw() : object(p){ } + auto_ptr(auto_ptr& p) throw() : object(p.release()){ } - T& operator*() const throw(){ - return *object; - } - T* operator->() const throw(){ - return object; - } - T* get() const throw(){ - return object; - } - T* release() throw(){ - T * temp(object); - object = 0; - return temp; - } - void reset(T * p=0) throw(){ - if(p != object){ - delete object; - object = p; - } - } - template operator auto_ptr_ref() throw(){ - auto_ptr_ref retval; - retval.p = object; - object = 0; - return retval; - } - template operator auto_ptr() throw(){ - auto_ptr retval(object); - object = 0; - return retval; - } - + auto_ptr(auto_ptr_ref r) throw() : object(r.p) + { + r.p = 0; + } + + template auto_ptr(auto_ptr& p) throw() : object(p.release()){ } + + auto_ptr& operator=(auto_ptr& p) throw() + { + if (&p == this) + { + return *this; + } + + delete object; + object = p.release(); + return *this; + } + + template auto_ptr& operator=(auto_ptr& p) throw() + { + if (&p == this) + { + return *this; + } + + delete object; + object = p.release(); + return *this; + } + + ~auto_ptr() + { + delete object; + } + + T& operator*() const throw() + { + return *object; + } + + T* operator->() const throw() + { + return object; + } + + T* get() const throw() + { + return object; + } + + T* release() throw() + { + T * temp(object); + object = 0; + return temp; + } + + void reset(T * p=0) throw() + { + if(p != object) + { + delete object; + object = p; + } + } + + template operator auto_ptr_ref() throw() + { + auto_ptr_ref retval; + retval.p = object; + object = 0; + return retval; + } + + template operator auto_ptr() throw() + { + auto_ptr retval(object); + object = 0; + return retval; + } }; -} //namespace std +} // namespace std +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/new b/misc/uClibc++/include/uClibc++/new index 665e783952..29baba6afd 100644 --- a/misc/uClibc++/include/uClibc++/new +++ b/misc/uClibc++/include/uClibc++/new @@ -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 #include @@ -26,16 +26,19 @@ #pragma GCC visibility push(default) -namespace std{ - class _UCXXEXPORT bad_alloc : public exception {}; +extern "C++" +{ - struct _UCXXEXPORT nothrow_t {}; - extern const nothrow_t nothrow; +namespace std +{ + class _UCXXEXPORT bad_alloc : public exception {}; - typedef void (*new_handler)(); - _UCXXEXPORT new_handler set_new_handler(new_handler new_p) throw(); -} + struct _UCXXEXPORT nothrow_t {}; + extern const nothrow_t nothrow; + typedef void (*new_handler)(); + _UCXXEXPORT new_handler set_new_handler(new_handler new_p) throw(); +} // namespace _UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc); _UCXXEXPORT void operator delete(void* ptr) throw(); @@ -51,14 +54,16 @@ _UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) t _UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) throw(); #endif - /* Placement operators */ +/* Placement operators */ + inline void* operator new(std::size_t, void* ptr) throw() {return ptr; } inline void operator delete(void* , void *) throw() { } - + inline void* operator new[](std::size_t, void *p) throw() { return p; } inline void operator delete[](void* , void *) throw() {} +} // extern "C++" + #pragma GCC visibility pop -#endif - +#endif // __STD_NEW_OPERATOR diff --git a/misc/uClibc++/include/uClibc++/numeric b/misc/uClibc++/include/uClibc++/numeric index 25d1b27468..880eb79f7a 100644 --- a/misc/uClibc++/include/uClibc++/numeric +++ b/misc/uClibc++/include/uClibc++/numeric @@ -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 #include @@ -25,135 +25,150 @@ #pragma GCC visibility push(default) -namespace std{ - template _UCXXEXPORT - T accumulate(InputIterator first, InputIterator last, T init) - { - while(first != last){ - init = init + *first; - ++first; - } - return init; - } +extern "C++" +{ +namespace std +{ + template _UCXXEXPORT + T accumulate(InputIterator first, InputIterator last, T init) + { + while (first != last) + { + init = init + *first; + ++first; + } - template _UCXXEXPORT - T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) - { - while(first != last){ - init = binary_op(init, *first); - ++first; - } - return init; - } + return init; + } + + template _UCXXEXPORT + T accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) + { + while (first != last) + { + init = binary_op(init, *first); + ++first; + } + + return init; + } + + template _UCXXEXPORT + T inner_product(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init) + { + while (first1 != last1) + { + init = init + *first1 * *first2; + ++first1; + ++first2; + } + + return init; + } + + template _UCXXEXPORT + T inner_product(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T init, + BinaryOperation1 binary_op1, + BinaryOperation2 binary_op2) + { + while (first1 != last1) + { + init = binary_op1(init, binary_op2(*first1, *first2)); + ++first1; + ++first2; + } + + return init; + } + + template _UCXXEXPORT + OutputIterator partial_sum(InputIterator first, InputIterator last, + OutputIterator result) + { + OutputIterator temp(result); + *result = *first; + ++first; + ++result; + + while (first != last) + { + *result = *first + *temp; + temp = result; + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator partial_sum(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op) + { + OutputIterator temp(result); + *result = *first; + ++first; + ++result; + + while(first != last) + { + *result = binary_op(*first, *temp); + temp = result; + ++first; + ++result; + } + + return result; + } + + template _UCXXEXPORT + OutputIterator + adjacent_difference(InputIterator first, InputIterator last, + OutputIterator result) + { + OutputIterator temp(first); + *result = *first; + ++first; + ++result; + + while(first != last) + { + *result = *first - *temp; + temp = first; + ++first; + ++result; + } + + return result; + } - template _UCXXEXPORT - T inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, T init) - { - while(first1 != last1){ - init = init + *first1 * *first2; - ++first1; - ++first2; - } - return init; - } + template _UCXXEXPORT + OutputIterator + adjacent_difference(InputIterator first, InputIterator last, + OutputIterator result, BinaryOperation binary_op) + { + OutputIterator temp(first); + *result = *first; + ++first; + ++result; - template _UCXXEXPORT - T inner_product(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, T init, - BinaryOperation1 binary_op1, - BinaryOperation2 binary_op2) - { - while(first1 != last1){ - init = binary_op1(init, binary_op2(*first1, *first2)); - ++first1; - ++first2; - } - return init; - } + while(first != last) + { + *result = binary_op(*first, *temp); + temp = first; + ++first; + ++result; + } - template _UCXXEXPORT - OutputIterator partial_sum(InputIterator first, InputIterator last, - OutputIterator result) - { - OutputIterator temp(result); - *result = *first; - ++first; - ++result; + return result; + } - while(first != last){ - *result = *first + *temp; - temp = result; - ++first; - ++result; - } - return result; - } - - - template _UCXXEXPORT - OutputIterator partial_sum(InputIterator first, InputIterator last, - OutputIterator result, BinaryOperation binary_op) - { - OutputIterator temp(result); - *result = *first; - ++first; - ++result; - - while(first != last){ - *result = binary_op(*first, *temp); - temp = result; - ++first; - ++result; - } - return result; - } - - - template _UCXXEXPORT - OutputIterator - adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result) - { - OutputIterator temp(first); - *result = *first; - ++first; - ++result; - - while(first != last){ - *result = *first - *temp; - temp = first; - ++first; - ++result; - } - - return result; - } - - - template _UCXXEXPORT - OutputIterator - adjacent_difference(InputIterator first, InputIterator last, - OutputIterator result, BinaryOperation binary_op) - { - OutputIterator temp(first); - *result = *first; - ++first; - ++result; - - while(first != last){ - *result = binary_op(*first, *temp); - temp = first; - ++first; - ++result; - } - - return result; - } - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/ostream b/misc/uClibc++/include/uClibc++/ostream index 55bace3a0e..c62b4c92d9 100644 --- a/misc/uClibc++/include/uClibc++/ostream +++ b/misc/uClibc++/include/uClibc++/ostream @@ -1,20 +1,20 @@ -/* Copyright (C) 2004-2008 Garrett A. Kajmowicz +/* Copyright (C) 2004-2008 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 */ #include @@ -30,479 +30,542 @@ #pragma GCC visibility push(default) -namespace std { - template class basic_ostream; - typedef basic_ostream ostream; +extern "C++" +{ +namespace std +{ + template class basic_ostream; + typedef basic_ostream ostream; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_ostream wostream; + typedef basic_ostream wostream; #endif - template basic_ostream& endl(basic_ostream& os); - template basic_ostream& ends(basic_ostream& os); - template basic_ostream& flush(basic_ostream& os); + template basic_ostream& endl(basic_ostream& os); + template basic_ostream& ends(basic_ostream& os); + template basic_ostream& flush(basic_ostream& os); - template class _UCXXEXPORT basic_ostream - : virtual public basic_ios - { - public: + template class _UCXXEXPORT basic_ostream + : virtual public basic_ios + { + public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - typedef traits traits_type; + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef traits traits_type; + _UCXXEXPORT basic_ostream(basic_streambuf* sb) + : basic_ios(sb) + { + basic_ios::init(sb); + } - _UCXXEXPORT basic_ostream(basic_streambuf* sb) - : basic_ios(sb) - { - basic_ios::init(sb); - } - virtual _UCXXEXPORT ~basic_ostream(); + virtual _UCXXEXPORT ~basic_ostream(); - class sentry; + class sentry; - _UCXXEXPORT basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)){ - return pf(*this); - } - _UCXXEXPORT basic_ostream& operator<<(basic_ios& (*pf)(basic_ios&)){ - pf(*this); - return *this; - } - _UCXXEXPORT basic_ostream& operator<<(ios_base& (*pf)(ios_base&)){ - pf(*this); - return *this; - } - basic_ostream& operator<<(bool n); - basic_ostream& operator<<(short n); - basic_ostream& operator<<(unsigned short n); - basic_ostream& operator<<(int n); - basic_ostream& operator<<(unsigned int n); - basic_ostream& operator<<(long n); - basic_ostream& operator<<(unsigned long n); - basic_ostream& operator<<(float f); - basic_ostream& operator<<(double f); - basic_ostream& operator<<(long double f); - basic_ostream& operator<<(void* p); - basic_ostream& operator<<(basic_streambuf* sb); + _UCXXEXPORT basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&)) + { + return pf(*this); + } - _UCXXEXPORT basic_ostream& put(char_type c){ - if(basic_ostream::traits_type::eq_int_type( - basic_ios::mstreambuf->sputc(c), - basic_ostream::traits_type::eof())) - { - basic_ios::setstate(ios_base::eofbit); - } - return *this; - } - _UCXXEXPORT basic_ostream& write(const char_type* s, streamsize n){ - if(basic_ostream::traits_type::eq_int_type( - basic_ios::mstreambuf->sputn(s, n), - basic_ostream::traits_type::eof()) - ){ - basic_ios::setstate(ios_base::eofbit); - } - return *this; - } - _UCXXEXPORT basic_ostream& flush(){ - if(basic_ios::mstreambuf->pubsync() == -1){ - basic_ios::setstate(ios_base::badbit); - } - return *this; - } - _UCXXEXPORT pos_type tellp(){ - if(basic_ios::fail() != false){ - return pos_type(-1); - } - return basic_ios::rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); - } - _UCXXEXPORT basic_ostream& seekp(pos_type pos){ - if( basic_ios::fail() != true ){ - basic_ios::rdbuf()->pubseekpos(pos); - } - return *this; - } - _UCXXEXPORT basic_ostream& seekp(off_type off, ios_base::seekdir dir){ - if( basic_ios::fail() != true){ - basic_ios::rdbuf()->pubseekoff(off, dir); - } - return *this; - } + _UCXXEXPORT basic_ostream& operator<<(basic_ios& (*pf)(basic_ios&)) + { + pf(*this); + return *this; + } - _UCXXEXPORT void printout(const char_type* s, streamsize n){ + _UCXXEXPORT basic_ostream& operator<<(ios_base& (*pf)(ios_base&)) + { + pf(*this); + return *this; + } + + basic_ostream& operator<<(bool n); + basic_ostream& operator<<(short n); + basic_ostream& operator<<(unsigned short n); + basic_ostream& operator<<(int n); + basic_ostream& operator<<(unsigned int n); + basic_ostream& operator<<(long n); + basic_ostream& operator<<(unsigned long n); + basic_ostream& operator<<(float f); + basic_ostream& operator<<(double f); + basic_ostream& operator<<(long double f); + basic_ostream& operator<<(void* p); + basic_ostream& operator<<(basic_streambuf* sb); + + _UCXXEXPORT basic_ostream& put(char_type c) + { + if (basic_ostream::traits_type::eq_int_type( + basic_ios::mstreambuf->sputc(c), + basic_ostream::traits_type::eof())) + { + basic_ios::setstate(ios_base::eofbit); + } + + return *this; + } + + _UCXXEXPORT basic_ostream& write(const char_type* s, streamsize n) + { + if (basic_ostream::traits_type::eq_int_type( + basic_ios::mstreambuf->sputn(s, n), + basic_ostream::traits_type::eof()) + ) + { + basic_ios::setstate(ios_base::eofbit); + } + + return *this; + } + + _UCXXEXPORT basic_ostream& flush() + { + if (basic_ios::mstreambuf->pubsync() == -1) + { + basic_ios::setstate(ios_base::badbit); + } + + return *this; + } + + _UCXXEXPORT pos_type tellp() + { + if (basic_ios::fail() != false) + { + return pos_type(-1); + } + + return basic_ios::rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out); + } + + _UCXXEXPORT basic_ostream& seekp(pos_type pos) + { + if (basic_ios::fail() != true) + { + basic_ios::rdbuf()->pubseekpos(pos); + } + + return *this; + } + + _UCXXEXPORT basic_ostream& seekp(off_type off, ios_base::seekdir dir) + { + if (basic_ios::fail() != true) + { + basic_ios::rdbuf()->pubseekoff(off, dir); + } + + return *this; + } + + _UCXXEXPORT void printout(const char_type* s, streamsize n) + { //david - streamsize extra = ios::width() - n; - if ((ios::flags()&ios::adjustfield) == ios::right){ - while (extra > 0) { - --extra; - put(ios::fill()); - } - } - write(s, n); - if ((ios::flags()&ios::adjustfield) == ios::left) { - while (extra > 0) { - --extra; - put(ios::fill()); - } - } - // Width value only applies for the next output operation. Reset to zero. - ios::width(0); - } + streamsize extra = ios::width() - n; + if ((ios::flags()&ios::adjustfield) == ios::right) + { + while (extra > 0) + { + --extra; + put(ios::fill()); + } + } - protected: - basic_ostream(const basic_ostream &){ } - basic_ostream & operator=(const basic_ostream &){ return *this; } - }; + write(s, n); + if ((ios::flags()&ios::adjustfield) == ios::left) + { + while (extra > 0) + { + --extra; + put(ios::fill()); + } + } - //Implementations of template functions. To allow for partial specialization + // Width value only applies for the next output operation. Reset to zero. - template _UCXXEXPORT basic_ostream::~basic_ostream(){ } - - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(bool n){ - sentry s(*this); - if( basic_ios::flags() & ios_base::boolalpha){ - if(n){ - printout("true", 4); - }else{ - printout("false", 5); - } - }else{ - if(n){ - printout("1", 1); - }else{ - printout("0", 1); - } - } - if(basic_ios::flags() & ios_base::unitbuf){ - flush(); - } - return *this; - } + ios::width(0); + } - template _UCXXEXPORT basic_ostream& - basic_ostream::operator<<(unsigned short n){ - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + protected: + basic_ostream(const basic_ostream &){ } + basic_ostream & operator=(const basic_ostream &){ return *this; } + }; - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(short n){ - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + // Implementations of template functions. To allow for partial specialization - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(int n){ - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + template _UCXXEXPORT basic_ostream::~basic_ostream(){ } + + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(bool n) + { + sentry s(*this); + if (basic_ios::flags() & ios_base::boolalpha) + { + if (n) + { + printout("true", 4); + } + else + { + printout("false", 5); + } + } + else + { + if (n) + { + printout("1", 1); + } + else + { + printout("0", 1); + } + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(unsigned int n){ - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + if (basic_ios::flags() & ios_base::unitbuf) + { + flush(); + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(long n){ - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + return *this; + } - template _UCXXEXPORT basic_ostream& - basic_ostream::operator<<(unsigned long n) - { - sentry s(*this); - __ostream_printout::printout(*this, n); - return *this; - } + template _UCXXEXPORT basic_ostream& + basic_ostream::operator<<(unsigned short n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(float f){ - sentry s(*this); - __ostream_printout::printout(*this, f); - return *this; - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(short n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(double f){ - sentry s(*this); - __ostream_printout::printout(*this, f); - return *this; - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(int n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(long double f){ - sentry s(*this); - __ostream_printout::printout(*this, f); - return *this; - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(unsigned int n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(void* p){ - sentry s(*this); - char buffer[20]; - printout(buffer, snprintf(buffer, 20, "%p", p) ); - if(basic_ios::flags() & ios_base::unitbuf){ - flush(); - } - return *this; - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(long n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - template _UCXXEXPORT basic_ostream& - basic_ostream::operator<<(basic_streambuf* sb) - { - sentry s(*this); - if(sb == 0){ - basic_ios::setstate(ios_base::badbit); - return *this; - } + template _UCXXEXPORT basic_ostream& + basic_ostream::operator<<(unsigned long n) + { + sentry s(*this); + __ostream_printout::printout(*this, n); + return *this; + } - typename traits::int_type c; + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(float f) + { + sentry s(*this); + __ostream_printout::printout(*this, f); + return *this; + } - while(basic_ios::good() && (c = sb->sbumpc()) != traits::eof() ){ - put(c); - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(double f) + { + sentry s(*this); + __ostream_printout::printout(*this, f); + return *this; + } - if(basic_ios::flags() & ios_base::unitbuf){ - flush(); - } - return *this; - } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(long double f) + { + sentry s(*this); + __ostream_printout::printout(*this, f); + return *this; + } - /*Template Specializations*/ + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(void* p) + { + sentry s(*this); + char buffer[20]; + printout(buffer, snprintf(buffer, 20, "%p", p)); + if (basic_ios::flags() & ios_base::unitbuf) + { + flush(); + } + + return *this; + } + + template _UCXXEXPORT basic_ostream& + basic_ostream::operator<<(basic_streambuf* sb) + { + sentry s(*this); + if (sb == 0) + { + basic_ios::setstate(ios_base::badbit); + return *this; + } + + typename traits::int_type c; + + while (basic_ios::good() && (c = sb->sbumpc()) != traits::eof()) + { + put(c); + } + + if (basic_ios::flags() & ios_base::unitbuf) + { + flush(); + } + + return *this; + } + + /* Template Specializations */ #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_OSTREAM__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT ostream::~basic_ostream(); + template <> _UCXXEXPORT ostream::~basic_ostream(); #endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT ostream & ostream::flush(); + template <> _UCXXEXPORT ostream & ostream::flush(); - template <> _UCXXEXPORT ostream & ostream::operator<<(bool n); - template <> _UCXXEXPORT ostream & ostream::operator<<(short int n); - template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned short int n); - template <> _UCXXEXPORT ostream & ostream::operator<<(int n); - template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned int n); - template <> _UCXXEXPORT ostream & ostream::operator<<(long n); - template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned long n); - template <> _UCXXEXPORT ostream & ostream::operator<<(float f); - template <> _UCXXEXPORT ostream & ostream::operator<<(double f); - template <> _UCXXEXPORT ostream & ostream::operator<<(long double f); - template <> _UCXXEXPORT ostream & ostream::operator<<(void* p); - template <> _UCXXEXPORT ostream & ostream::operator<<(basic_streambuf >* sb); + template <> _UCXXEXPORT ostream & ostream::operator<<(bool n); + template <> _UCXXEXPORT ostream & ostream::operator<<(short int n); + template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned short int n); + template <> _UCXXEXPORT ostream & ostream::operator<<(int n); + template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned int n); + template <> _UCXXEXPORT ostream & ostream::operator<<(long n); + template <> _UCXXEXPORT ostream & ostream::operator<<(unsigned long n); + template <> _UCXXEXPORT ostream & ostream::operator<<(float f); + template <> _UCXXEXPORT ostream & ostream::operator<<(double f); + template <> _UCXXEXPORT ostream & ostream::operator<<(long double f); + template <> _UCXXEXPORT ostream & ostream::operator<<(void* p); + template <> _UCXXEXPORT ostream & ostream::operator<<(basic_streambuf >* sb); #endif #endif - template > - class _UCXXEXPORT basic_ostream::sentry - { - bool ok; - public: - explicit _UCXXEXPORT sentry(basic_ostream& os): ok(true){ + template > + class _UCXXEXPORT basic_ostream::sentry + { + bool ok; + public: + explicit _UCXXEXPORT sentry(basic_ostream& os): ok(true){ //david - if(os.good() !=0){ //Prepare for output - } - //Flush any tied buffer - if(os.tie() !=0 ){ - os.tie()->flush(); - } - } - _UCXXEXPORT ~sentry() { } - _UCXXEXPORT operator bool() { - return ok; - } - }; + if (os.good() !=0) + { + // Prepare for output + } + // Flush any tied buffer + + if (os.tie() !=0) + { + os.tie()->flush(); + } + } + + _UCXXEXPORT ~sentry() { } + + _UCXXEXPORT operator bool() + { + return ok; + } + }; #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_OSTREAM__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT ostream::sentry::sentry(ostream & os); - template <> _UCXXEXPORT ostream::sentry::~sentry(); + template <> _UCXXEXPORT ostream::sentry::sentry(ostream & os); + template <> _UCXXEXPORT ostream::sentry::~sentry(); #endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ #endif #endif + // Non - class functions - //Non - class functions - - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, charT c) - { - typename basic_ostream::sentry s(out); - out.put(c); - return out; - } - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, char c) - { - typename basic_ostream::sentry s(out); - out.put(c); - return out; - } + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, charT c) + { + typename basic_ostream::sentry s(out); + out.put(c); + return out; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, char c) + { + typename basic_ostream::sentry s(out); + out.put(c); + return out; + } - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, char c) - { - typename basic_ostream::sentry s(out); - out.put(c); - return out; - } + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, char c) + { + typename basic_ostream::sentry s(out); + out.put(c); + return out; + } // signed and unsigned - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, signed char c) - { - typename basic_ostream::sentry s(out); - out.put(c); - return out; - } - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, unsigned char c) - { - typename basic_ostream::sentry s(out); - out.put(c); - return out; - } - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const charT* c) - { - typename basic_ostream::sentry s(out); - out.printout(c, traits::length(c) ); - return out; - } - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const char* c) - { - typename basic_ostream::sentry s(out); - out.printout(c, char_traits::length(c) ); - return out; - } -//david - // partial specializations - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const char* c) - { -//add by david - /* printf("hello\n"); - int i; - for(i=0;i::sentry s(out); - out.printout(c, traits::length(c)); - return out; - } + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, signed char c) + { + typename basic_ostream::sentry s(out); + out.put(c); + return out; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, unsigned char c) + { + typename basic_ostream::sentry s(out); + out.put(c); + return out; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const charT* c) + { + typename basic_ostream::sentry s(out); + out.printout(c, traits::length(c)); + return out; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const char* c) + { + typename basic_ostream::sentry s(out); + out.printout(c, char_traits::length(c)); + return out; + } + + // partial specializations + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const char* c) + { + typename basic_ostream::sentry s(out); + out.printout(c, traits::length(c)); + return out; + } #ifdef __UCLIBCXX_HAS_WCHAR__ - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const char* c) - { - typename basic_ostream::sentry s(out); - size_t numChars = char_traits::length(c); - wchar_t * temp = new wchar_t[numChars]; + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const char* c) + { + typename basic_ostream::sentry s(out); + size_t numChars = char_traits::length(c); + wchar_t * temp = new wchar_t[numChars]; - for(size_t i=0; i < numChars; ++i){ - temp[i] = out.widen(c[i]); - } + for (size_t i=0; i < numChars; ++i) + { + temp[i] = out.widen(c[i]); + } - out.printout(temp, numChars); - return out; - } + out.printout(temp, numChars); + return out; + } #endif - // signed and unsigned - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const signed char* c) - { - typename basic_ostream::sentry s(out); - out.printout(reinterpret_cast(c), traits::length( reinterpret_cast(c))); - return out; - } - - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& out, const unsigned char* c) - { - typename basic_ostream::sentry s(out); - out.printout(reinterpret_cast(c), traits::length( reinterpret_cast(c))); - return out; - } + // Signed and unsigned - template _UCXXEXPORT basic_ostream& - endl(basic_ostream& os) - { - typename basic_ostream::sentry s(os); - os.put('\n'); - os.flush(); - return os; - } + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const signed char* c) + { + typename basic_ostream::sentry s(out); + out.printout(reinterpret_cast(c), traits::length(reinterpret_cast(c))); + return out; + } + + template _UCXXEXPORT basic_ostream& + operator<<(basic_ostream& out, const unsigned char* c) + { + typename basic_ostream::sentry s(out); + out.printout(reinterpret_cast(c), traits::length(reinterpret_cast(c))); + return out; + } - template _UCXXEXPORT basic_ostream& - ends(basic_ostream& os) - { - typename basic_ostream::sentry s(os); - os.put(traits::eos()); - return os; - } + template _UCXXEXPORT basic_ostream& + endl(basic_ostream& os) + { + typename basic_ostream::sentry s(os); + os.put('\n'); + os.flush(); + return os; + } - template _UCXXEXPORT basic_ostream& flush(basic_ostream& os){ - typename basic_ostream::sentry s(os); - os.flush(); - return os; - } + template _UCXXEXPORT basic_ostream& + ends(basic_ostream& os) + { + typename basic_ostream::sentry s(os); + os.put(traits::eos()); + return os; + } + template _UCXXEXPORT basic_ostream& flush(basic_ostream& os){ + typename basic_ostream::sentry s(os); + os.flush(); + return os; + } #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_OSTREAM__ - template <> _UCXXEXPORT ostream & endl(ostream & os); - template <> _UCXXEXPORT ostream & flush(ostream & os); - template <> _UCXXEXPORT ostream & operator<<(ostream & out, char c); - template <> _UCXXEXPORT ostream & operator<<(ostream & out, const char* c); - template <> _UCXXEXPORT ostream & operator<<(ostream & out, unsigned char c); - template <> _UCXXEXPORT ostream & operator<<(ostream & out, unsigned const char* c); + template <> _UCXXEXPORT ostream & endl(ostream & os); + template <> _UCXXEXPORT ostream & flush(ostream & os); + template <> _UCXXEXPORT ostream & operator<<(ostream & out, char c); + template <> _UCXXEXPORT ostream & operator<<(ostream & out, const char* c); + template <> _UCXXEXPORT ostream & operator<<(ostream & out, unsigned char c); + template <> _UCXXEXPORT ostream & operator<<(ostream & out, unsigned const char* c); #endif #endif - #ifndef __STRICT_ANSI__ -//Support for output of long long data types +// Support for output of long long data types template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, signed long long int i) + operator<<(basic_ostream& os, signed long long int i) { - typename basic_ostream::sentry s(os); - __ostream_printout::printout(os, i); - return os; + typename basic_ostream::sentry s(os); + __ostream_printout::printout(os, i); + return os; } - template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, unsigned long long int i) + operator<<(basic_ostream& os, unsigned long long int i) { - typename basic_ostream::sentry s(os); - __ostream_printout::printout(os, i); - return os; + typename basic_ostream::sentry s(os); + __ostream_printout::printout(os, i); + return os; } +#endif //__STRICT_ANSI__ -#endif //__STRICT_ANSI__ - - - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/ostream_helpers b/misc/uClibc++/include/uClibc++/ostream_helpers index 6c3f9fc69c..214ec259d6 100644 --- a/misc/uClibc++/include/uClibc++/ostream_helpers +++ b/misc/uClibc++/include/uClibc++/ostream_helpers @@ -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 #include @@ -29,459 +29,663 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + /* We are making the following template class for serveral reasons. Firstly, + * we want to keep the main ostream code neat and tidy. Secondly, we want it + * to be easy to do partial specialization of the ostream code so that it can + * be expanded and put into the library. This will allow us to make application + * code smaller at the expense of increased library size. This is a fair + * trade-off when there are multiple applications being compiled. Also, this + * feature will be used optionally via configuration options. It will also + * allow us to keep the code bases in sync, dramatically simplifying the + * maintenance required. We specialized for char because wchar and others + * require different scanf functions + */ - /* We are making the following template class for serveral reasons. Firstly, - * we want to keep the main ostream code neat and tidy. Secondly, we want it - * to be easy to do partial specialization of the ostream code so that it can - * be expanded and put into the library. This will allow us to make application - * code smaller at the expense of increased library size. This is a fair - * trade-off when there are multiple applications being compiled. Also, this - * feature will be used optionally via configuration options. It will also - * allow us to keep the code bases in sync, dramatically simplifying the - * maintenance required. We specialized for char because wchar and others - * require different scanf functions - */ + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const dataType n); + }; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const signed long int n) + { + char buffer[20]; + const char * c_ld = "%ld"; + const char * c_lo = "%lo"; + const char * c_lX = "%lX"; + const char * c_lx = "%lx"; + const char * c_hashlo = "%#lo"; + const char * c_hashlX = "%#lX"; + const char * c_hashlx = "%#lx"; + const char * formatString=0; - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const dataType n); - }; + if (stream.flags() & ios_base::dec) + { + formatString = c_ld; + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + formatString = c_hashlo; + } + else + { + formatString = c_lo; + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + formatString = c_hashlX; + } + else + { + formatString = c_hashlx; + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + formatString = c_lX; + } + else + { + formatString = c_lx; + } + } + } - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const signed long int n) - { - char buffer[20]; - const char * c_ld = "%ld"; - const char * c_lo = "%lo"; - const char * c_lX = "%lX"; - const char * c_lx = "%lx"; - const char * c_hashlo = "%#lo"; - const char * c_hashlX = "%#lX"; - const char * c_hashlx = "%#lx"; + stream.printout(buffer, snprintf(buffer, 20, formatString, n)); - const char * formatString=0; + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; - if( stream.flags() & ios_base::dec){ - formatString = c_ld; - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - formatString = c_hashlo; - }else{ - formatString = c_lo; - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - formatString = c_hashlX; - }else{ - formatString = c_hashlx; - } - }else{ - if(stream.flags() & ios_base::uppercase){ - formatString = c_lX; - }else{ - formatString = c_lx; - } - } - } + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const unsigned long int n) + { + char buffer[20]; + const char * c_lo = "%lo"; + const char * c_lu = "%lu"; + const char * c_lX = "%lX"; + const char * c_lx = "%lx"; + const char * c_hashlo = "%#lo"; + const char * c_hashlX = "%#lX"; + const char * c_hashlx = "%#lx"; + const char * formatString=0; - stream.printout(buffer, snprintf(buffer, 20, formatString, n) ); + if (stream.flags() & ios_base::dec) + { + formatString = c_lu; + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + formatString = c_hashlo; + } + else + { + formatString = c_lo; + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + formatString = c_hashlX; + } + else + { + formatString = c_hashlx; + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + formatString = c_lX; + } + else + { + formatString = c_lx; + } + } + } - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - - } - }; - - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const unsigned long int n) - { - char buffer[20]; - const char * c_lo = "%lo"; - const char * c_lu = "%lu"; - const char * c_lX = "%lX"; - const char * c_lx = "%lx"; - const char * c_hashlo = "%#lo"; - const char * c_hashlX = "%#lX"; - const char * c_hashlx = "%#lx"; - const char * formatString=0; - - if( stream.flags() & ios_base::dec){ - formatString = c_lu; - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - formatString = c_hashlo; - }else{ - formatString = c_lo; - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - formatString = c_hashlX; - }else{ - formatString = c_hashlx; - } - }else{ - if(stream.flags() & ios_base::uppercase){ - formatString = c_lX; - }else{ - formatString = c_lx; - } - } - } - - stream.printout(buffer, snprintf(buffer, 20, formatString, n)); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + stream.printout(buffer, snprintf(buffer, 20, formatString, n)); + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; #ifndef __STRICT_ANSI__ - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const signed long long int n) - { - char buffer[28]; - const char * lld = "%lld"; - const char * llo = "%llo"; - const char * llX = "%llX"; - const char * llx = "%llx"; - const char * hashllo = "%#llo"; - const char * hashllX = "%#llX"; - const char * hashllx = "%#llx"; - const char * formatString=0; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const signed long long int n) + { + char buffer[28]; + const char * lld = "%lld"; + const char * llo = "%llo"; + const char * llX = "%llX"; + const char * llx = "%llx"; + const char * hashllo = "%#llo"; + const char * hashllX = "%#llX"; + const char * hashllx = "%#llx"; + const char * formatString=0; - if( stream.flags() & ios_base::dec){ - formatString = lld; - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - formatString = hashllo; - }else{ - formatString = llo; - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - formatString = hashllX; - }else{ - formatString = hashllx; - } - }else{ - if(stream.flags() & ios_base::uppercase){ - formatString = llX; - }else{ - formatString = llx; - } - } - } + if (stream.flags() & ios_base::dec) + { + formatString = lld; + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + formatString = hashllo; + } + else + { + formatString = llo; + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + formatString = hashllX; + } + else + { + formatString = hashllx; + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + formatString = llX; + } + else + { + formatString = llx; + } + } + } - stream.printout(buffer, snprintf(buffer, 27, formatString, n) ); + stream.printout(buffer, snprintf(buffer, 27, formatString, n)); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const unsigned long long int n) - { - char buffer[28]; - const char * llo = "%llo"; - const char * llu = "%llu"; - const char * llX = "%llX"; - const char * llx = "%llx"; - const char * hashllo = "%#llo"; - const char * hashllX = "%#llX"; - const char * hashllx = "%#llx"; - const char * formatString=0; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const unsigned long long int n) + { + char buffer[28]; + const char * llo = "%llo"; + const char * llu = "%llu"; + const char * llX = "%llX"; + const char * llx = "%llx"; + const char * hashllo = "%#llo"; + const char * hashllX = "%#llX"; + const char * hashllx = "%#llx"; + const char * formatString=0; - if( stream.flags() & ios_base::dec){ - formatString = llu; - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - formatString = hashllo; - }else{ - formatString = llo; - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - formatString = hashllX; - }else{ - formatString = hashllx; - } - }else{ - if(stream.flags() & ios_base::uppercase){ - formatString = llX; - }else{ - formatString = llx; - } - } - } + if (stream.flags() & ios_base::dec) + { + formatString = llu; + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + formatString = hashllo; + } + else + { + formatString = llo; + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + formatString = hashllX; + } + else + { + formatString = hashllx; + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + formatString = llX; + } + else + { + formatString = llx; + } + } + } - stream.printout(buffer, snprintf(buffer, 27, formatString, n) ); + stream.printout(buffer, snprintf(buffer, 27, formatString, n)); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; -#endif //__STRICT_ANSI__ +#endif //__STRICT_ANSI__ - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const double f) - { - char buffer[32]; - int length; - if(stream.flags() & ios_base::scientific){ - if(stream.flags() & ios_base::uppercase){ - length = snprintf(buffer, 32, "%*.*E", static_cast(stream.width()),static_cast(stream.precision()), f); - }else{ - length = snprintf(buffer, 32, "%*.*e", static_cast(stream.width()),static_cast(stream.precision()), f); - } - } else if(stream.flags() & ios_base::fixed){ - length = snprintf(buffer, 32, "%*.*f",static_cast(stream.width()),static_cast(stream.precision()), f); - } else { - length = snprintf(buffer, 32, "%*.*g",static_cast(stream.width()),static_cast(stream.precision()), f); - } - stream.printout(buffer, length); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const double f) + { + char buffer[32]; + int length; - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const long double f) - { - char buffer[32]; - int length; - if(stream.flags() & ios_base::scientific){ - if(stream.flags() & ios_base::uppercase){ - length = snprintf(buffer, 32, "%*.*LE", static_cast(stream.width()), static_cast(stream.precision()), f); - }else{ - length = snprintf(buffer, 32, "%*.*Le", static_cast(stream.width()), static_cast(stream.precision()), f); - } - } else if(stream.flags() & ios_base::fixed){ - length = snprintf(buffer, 32, "%*.*Lf", static_cast(stream.width()), static_cast(stream.precision()), f); - } else { - length = snprintf(buffer, 32, "%*.*Lg", static_cast(stream.width()), static_cast(stream.precision()), f); - } - stream.printout(buffer, length); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } + if (stream.flags() & ios_base::scientific) + { + if (stream.flags() & ios_base::uppercase) + { + length = snprintf(buffer, 32, "%*.*E", static_cast(stream.width()),static_cast(stream.precision()), f); + } + else + { + length = snprintf(buffer, 32, "%*.*e", static_cast(stream.width()),static_cast(stream.precision()), f); + } + } else if (stream.flags() & ios_base::fixed) + { + length = snprintf(buffer, 32, "%*.*f",static_cast(stream.width()),static_cast(stream.precision()), f); + } + else + { + length = snprintf(buffer, 32, "%*.*g",static_cast(stream.width()),static_cast(stream.precision()), f); + } - } - }; + stream.printout(buffer, length); + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; + + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const long double f) + { + char buffer[32]; + int length; + if (stream.flags() & ios_base::scientific) + { + if (stream.flags() & ios_base::uppercase) + { + length = snprintf(buffer, 32, "%*.*LE", static_cast(stream.width()), static_cast(stream.precision()), f); + } + else + { + length = snprintf(buffer, 32, "%*.*Le", static_cast(stream.width()), static_cast(stream.precision()), f); + } + } + else if (stream.flags() & ios_base::fixed) + { + length = snprintf(buffer, 32, "%*.*Lf", static_cast(stream.width()), static_cast(stream.precision()), f); + } + else + { + length = snprintf(buffer, 32, "%*.*Lg", static_cast(stream.width()), static_cast(stream.precision()), f); + } + + stream.printout(buffer, length); + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; #ifdef __UCLIBCXX_HAS_WCHAR__ - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const signed long int n) - { - wchar_t buffer[20]; - if( stream.flags() & ios_base::dec){ - stream.printout(buffer, swprintf(buffer, 20, L"%ld", n)); - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - stream.printout(buffer, swprintf(buffer, 20, L"%#lo", n)); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%lo", n) ); - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 20, L"%#lX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%#lx", n) ); - } - }else{ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 20, L"%lX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%lx", n) ); - } - } - } - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const signed long int n) + { + wchar_t buffer[20]; + if (stream.flags() & ios_base::dec) + { + stream.printout(buffer, swprintf(buffer, 20, L"%ld", n)); + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lo", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%lo", n)); + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lx", n)); + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%lX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%lx", n)); + } + } + } - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const unsigned long int n) - { - wchar_t buffer[20]; - if( stream.flags() & ios_base::dec){ - stream.printout(buffer, swprintf(buffer, 20, L"%lu", n)); - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - stream.printout(buffer, swprintf(buffer, 20, L"%#lo", n)); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%lo", n) ); - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 20, L"%#lX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%#lx", n) ); - } - }else{ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 20, L"%lX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 20, L"%lx", n) ); - } - } - } - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; + + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const unsigned long int n) + { + wchar_t buffer[20]; + + if (stream.flags() & ios_base::dec) + { + stream.printout(buffer, swprintf(buffer, 20, L"%lu", n)); + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lo", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%lo", n)); + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%#lx", n)); + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 20, L"%lX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 20, L"%lx", n)); + } + } + } + + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; #ifndef __STRICT_ANSI__ - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const signed long long int n) - { - wchar_t buffer[28]; - if( stream.flags() & ios_base::dec){ - stream.printout(buffer, swprintf(buffer, 27, L"%lld", n)); - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - stream.printout(buffer, swprintf(buffer, 27, L"%#llo", n)); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%llo", n) ); - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 27, L"%#llX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%#llx", n) ); - } - }else{ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 27, L"%llX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%llx", n) ); - } - } - } - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const signed long long int n) + { + wchar_t buffer[28]; + if (stream.flags() & ios_base::dec) + { + stream.printout(buffer, swprintf(buffer, 27, L"%lld", n)); + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llo", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%llo", n)); + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llx", n)); + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%llX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%llx", n)); + } + } + } - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const unsigned long long int n) - { - wchar_t buffer[28]; - if( stream.flags() & ios_base::dec){ - stream.printout(buffer, swprintf(buffer, 27, L"%llu", n)); - }else if( stream.flags() & ios_base::oct){ - if( stream.flags() & ios_base::showbase){ - stream.printout(buffer, swprintf(buffer, 27, L"%#llo", n)); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%llo", n) ); - } - }else if (stream.flags() & ios_base::hex){ - if(stream.flags() & ios_base::showbase){ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 27, L"%#llX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%#llx", n) ); - } - }else{ - if(stream.flags() & ios_base::uppercase){ - stream.printout(buffer, swprintf(buffer, 27, L"%llX", n) ); - }else{ - stream.printout(buffer, swprintf(buffer, 27, L"%llx", n) ); - } - } - } - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; + + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const unsigned long long int n) + { + wchar_t buffer[28]; + + if (stream.flags() & ios_base::dec) + { + stream.printout(buffer, swprintf(buffer, 27, L"%llu", n)); + } + else if (stream.flags() & ios_base::oct) + { + if (stream.flags() & ios_base::showbase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llo", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%llo", n)); + } + } + else if (stream.flags() & ios_base::hex) + { + if (stream.flags() & ios_base::showbase) + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%#llx", n)); + } + } + else + { + if (stream.flags() & ios_base::uppercase) + { + stream.printout(buffer, swprintf(buffer, 27, L"%llX", n)); + } + else + { + stream.printout(buffer, swprintf(buffer, 27, L"%llx", n)); + } + } + } + + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; -#endif //__STRICT_ANSI__ +#endif //__STRICT_ANSI__ - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const double f) - { - wchar_t buffer[32]; - wchar_t format_string[32]; - if(stream.flags() & ios_base::scientific){ - if(stream.flags() & ios_base::uppercase){ - swprintf(format_string, 32, L"%%%u.%uE", static_cast(stream.width()), static_cast(stream.precision())); - }else{ - swprintf(format_string, 32, L"%%%u.%ue", static_cast(stream.width()), static_cast(stream.precision())); - } - } else if(stream.flags() & ios_base::fixed){ - swprintf(format_string, 32, L"%%%u.%uf", static_cast(stream.width()), static_cast(stream.precision())); - } else { - swprintf(format_string, 32, L"%%%u.%ug", static_cast(stream.width()), static_cast(stream.precision())); - } - stream.printout(buffer, swprintf(buffer, 32, format_string, f) ); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const double f) + { + wchar_t buffer[32]; + wchar_t format_string[32]; - template class _UCXXEXPORT __ostream_printout{ - public: - static void printout(basic_ostream& stream, const long double f) - { - wchar_t buffer[32]; - wchar_t format_string[32]; - if(stream.flags() & ios_base::scientific){ - if(stream.flags() & ios_base::uppercase){ - swprintf(format_string, 32, L"%%%u.%uLE", static_cast(stream.width()), static_cast(stream.precision())); - }else{ - swprintf(format_string, 32, L"%%%u.%uLe", static_cast(stream.width()), static_cast(stream.precision())); - } - } else if(stream.flags() & ios_base::fixed){ - swprintf(format_string, 32, L"%%%u.%uLf", static_cast(stream.width()), static_cast(stream.precision())); - } else { - swprintf(format_string, 32, L"%%%u.%uLg", static_cast(stream.width()), static_cast(stream.precision())); - } - stream.printout(buffer, swprintf(buffer, 32, format_string, f) ); - if(stream.flags() & ios_base::unitbuf){ - stream.flush(); - } - } - }; + if (stream.flags() & ios_base::scientific) + { + if (stream.flags() & ios_base::uppercase) + { + swprintf(format_string, 32, L"%%%u.%uE", static_cast(stream.width()), static_cast(stream.precision())); + } + else + { + swprintf(format_string, 32, L"%%%u.%ue", static_cast(stream.width()), static_cast(stream.precision())); + } + } + else if (stream.flags() & ios_base::fixed) + { + swprintf(format_string, 32, L"%%%u.%uf", static_cast(stream.width()), static_cast(stream.precision())); + } + else + { + swprintf(format_string, 32, L"%%%u.%ug", static_cast(stream.width()), static_cast(stream.precision())); + } + + stream.printout(buffer, swprintf(buffer, 32, format_string, f)); + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; + + template class _UCXXEXPORT __ostream_printout + { + public: + static void printout(basic_ostream& stream, const long double f) + { + wchar_t buffer[32]; + wchar_t format_string[32]; + + if (stream.flags() & ios_base::scientific) + { + if (stream.flags() & ios_base::uppercase) + { + swprintf(format_string, 32, L"%%%u.%uLE", static_cast(stream.width()), static_cast(stream.precision())); + } + else + { + swprintf(format_string, 32, L"%%%u.%uLe", static_cast(stream.width()), static_cast(stream.precision())); + } + } + else if (stream.flags() & ios_base::fixed) + { + swprintf(format_string, 32, L"%%%u.%uLf", static_cast(stream.width()), static_cast(stream.precision())); + } + else + { + swprintf(format_string, 32, L"%%%u.%uLg", static_cast(stream.width()), static_cast(stream.precision())); + } + + stream.printout(buffer, swprintf(buffer, 32, format_string, f)); + if (stream.flags() & ios_base::unitbuf) + { + stream.flush(); + } + } + }; #endif //__UCLIBCXX_HAS_WCHAR__ -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/queue b/misc/uClibc++/include/uClibc++/queue index b817b1dfe7..51fe35cbe0 100644 --- a/misc/uClibc++/include/uClibc++/queue +++ b/misc/uClibc++/include/uClibc++/queue @@ -1,19 +1,20 @@ -/* 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 #include @@ -25,102 +26,114 @@ #pragma GCC visibility push(default) -namespace std{ - - template > class _UCXXEXPORT queue{ - protected: - Container c; - public: - typedef typename Container::value_type value_type; - typedef typename Container::size_type size_type; - typedef Container container_type; +extern "C++" +{ +namespace std +{ + template > class _UCXXEXPORT queue + { + protected: + Container c; - explicit queue(const Container& a = Container()) : c(a) { } + public: + typedef typename Container::value_type value_type; + typedef typename Container::size_type size_type; + typedef Container container_type; - bool empty() const { return c.empty(); } - size_type size() const { return c.size(); } - value_type& front() { return c.front(); } - const value_type& front() const { return c.front(); } - value_type& back() { return c.back(); } - const value_type& back() const { return c.back(); } - void push(const value_type& x) { c.push_back(x); } - void pop() { c.pop_front(); } - }; + explicit queue(const Container& a = Container()) : c(a) { } + bool empty() const { return c.empty(); } + size_type size() const { return c.size(); } + value_type& front() { return c.front(); } + const value_type& front() const { return c.front(); } + value_type& back() { return c.back(); } + const value_type& back() const { return c.back(); } + void push(const value_type& x) { c.push_back(x); } + void pop() { c.pop_front(); } + }; - template _UCXXEXPORT bool - operator==(const queue& x, const queue& y) - { - return (x.c == y.c); - } - template _UCXXEXPORT bool - operator< (const queue& x, const queue& y) - { - return (x.c < y.c); - } - template _UCXXEXPORT bool - operator!=(const queue& x, const queue& y) - { - return (x.c != y.c); - } - template _UCXXEXPORT bool - operator> (const queue& x, const queue& y) - { - return (x.c > y.c); - } - template _UCXXEXPORT bool - operator>=(const queue& x, const queue& y) - { - return (x.c >= y.c); - } - template _UCXXEXPORT bool - operator<=(const queue& x, const queue& y) - { - return (x.c <= y.c); - } + template _UCXXEXPORT bool + operator==(const queue& x, const queue& y) + { + return (x.c == y.c); + } + template _UCXXEXPORT bool + operator< (const queue& x, const queue& y) + { + return (x.c < y.c); + } - template , - class Compare = less - > class _UCXXEXPORT priority_queue { - protected: - Container c; - Compare comp; - public: - typedef typename Container::value_type value_type; - typedef typename Container::size_type size_type; - typedef Container container_type; + template _UCXXEXPORT bool + operator!=(const queue& x, const queue& y) + { + return (x.c != y.c); + } - explicit priority_queue(const Compare& x = Compare(), const Container& a = Container()) - : c(a), comp(x) { make_heap(c.begin(), c.end(), comp) ; } - template priority_queue(InputIterator first, - InputIterator last, - const Compare& x = Compare(), - const Container& y= Container()) - : c(y), comp(c) - { - c.insert(c.end(), first, last); - make_heap(c.begin(), c.end(), comp); - } + template _UCXXEXPORT bool + operator> (const queue& x, const queue& y) + { + return (x.c > y.c); + } - bool empty() const { return c.empty(); } - size_type size() const { return c.size(); } - const value_type& top() const { return c.front(); } - void push(const value_type& x){ - c.push_back(x); - push_heap(c.begin(), c.end(), comp); - } - void pop(){ - pop_heap(c.begin(), c.end(), comp); - c.pop_back(); - } - }; + template _UCXXEXPORT bool + operator>=(const queue& x, const queue& y) + { + return (x.c >= y.c); + } -} + template _UCXXEXPORT bool + operator<=(const queue& x, const queue& y) + { + return (x.c <= y.c); + } + + template , + class Compare = less + > class _UCXXEXPORT priority_queue + { + protected: + Container c; + Compare comp; + + public: + typedef typename Container::value_type value_type; + typedef typename Container::size_type size_type; + typedef Container container_type; + + explicit priority_queue(const Compare& x = Compare(), const Container& a = Container()) + : c(a), comp(x) { make_heap(c.begin(), c.end(), comp) ; } + template priority_queue(InputIterator first, + InputIterator last, + const Compare& x = Compare(), + const Container& y= Container()) + : c(y), comp(c) + { + c.insert(c.end(), first, last); + make_heap(c.begin(), c.end(), comp); + } + + bool empty() const { return c.empty(); } + size_type size() const { return c.size(); } + const value_type& top() const { return c.front(); } + + void push(const value_type& x) + { + c.push_back(x); + push_heap(c.begin(), c.end(), comp); + } + + void pop() + { + pop_heap(c.begin(), c.end(), comp); + c.pop_back(); + } + }; + +} // namespace +} // extern "C++" #pragma GCC visibility pop #endif - - diff --git a/misc/uClibc++/include/uClibc++/set b/misc/uClibc++/include/uClibc++/set index f376e47008..02f9251ccc 100644 --- a/misc/uClibc++/include/uClibc++/set +++ b/misc/uClibc++/include/uClibc++/set @@ -1,22 +1,20 @@ -/* 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 #include @@ -30,13 +28,14 @@ #pragma GCC visibility push(default) -namespace std{ - +extern "C++" +{ +namespace std +{ template, class Allocator = allocator > class set; template, class Allocator = allocator > class multiset; - /* This is the implementation for the set container. As noted above, it deviates * from ISO spec by deriving from a base class in order to reduce code redundancy. * More code could be reduced by convirting to virtual functions (thus allowing @@ -44,361 +43,405 @@ template, class Allocator = allocator * the specifications too much to be worth the risk. */ - -//Implementation of set - +// Implementation of set template class _UCXXEXPORT set - : public __single_associative + : public __single_associative { - //Default value of allocator does not meet C++ standard specs, but it works for this library - //Deal with it + //Default value of allocator does not meet C++ standard specs, but it works for this library + //Deal with it + public: + typedef __single_associative base; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - typedef __single_associative base; - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; +// using base::value_compare; -// using base::value_compare; + static const key_type v_t_k(const value_type v) + { + return v; + } - static const key_type v_t_k(const value_type v){ - return v; - } + explicit set(const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(comp, al, v_t_k) { } - explicit set(const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(comp, al, v_t_k) { } + template set(InputIterator first, InputIterator last, + const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(first, last, comp, al, v_t_k) { } - template set(InputIterator first, InputIterator last, - const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(first, last, comp, al, v_t_k) { } + set(const set& x) : base(x) { } + ~set() { } - set(const set& x) : base(x) { } - ~set() { } + using base::operator=; + using base::operator==; + using base::operator!=; - using base::operator=; - using base::operator==; - using base::operator!=; + using base::insert; + using base::erase; - using base::insert; - using base::erase; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::begin; - using base::end; - using base::rbegin; - using base::rend; + using base::empty; + using base::size; + using base::max_size; - using base::empty; - using base::size; - using base::max_size; - - - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; protected: - }; - -//Implementation of multiset - +// Implementation of multiset template class _UCXXEXPORT multiset - : public __multi_associative + : public __multi_associative { - //Default value of allocator does not meet C++ standard specs, but it works for this library - //Deal with it + //Default value of allocator does not meet C++ standard specs, but it works for this library + //Deal with it + public: + typedef __multi_associative base; + typedef typename base::key_type key_type; + typedef typename base::value_type value_type; + typedef typename base::key_compare key_compare; + typedef typename base::allocator_type allocator_type; + typedef typename base::reference reference; + typedef typename base::const_reference const_reference; + typedef typename base::iterator iterator; + typedef typename base::const_iterator const_iterator; + typedef typename base::size_type size_type; + typedef typename base::difference_type difference_type; + typedef typename base::pointer pointer; + typedef typename base::const_pointer const_pointer; + typedef typename base::reverse_iterator reverse_iterator; + typedef typename base::const_reverse_iterator const_reverse_iterator; - typedef __multi_associative base; - typedef typename base::key_type key_type; - typedef typename base::value_type value_type; - typedef typename base::key_compare key_compare; - typedef typename base::allocator_type allocator_type; - typedef typename base::reference reference; - typedef typename base::const_reference const_reference; - typedef typename base::iterator iterator; - typedef typename base::const_iterator const_iterator; - typedef typename base::size_type size_type; - typedef typename base::difference_type difference_type; - typedef typename base::pointer pointer; - typedef typename base::const_pointer const_pointer; - typedef typename base::reverse_iterator reverse_iterator; - typedef typename base::const_reverse_iterator const_reverse_iterator; + static const key_type v_t_k(const value_type v) + { + return v; + } - static const key_type v_t_k(const value_type v){ - return v; - } + explicit multiset(const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(comp, al, v_t_k) { } - explicit multiset(const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(comp, al, v_t_k) { } + template multiset(InputIterator first, InputIterator last, + const Compare& comp = Compare(), const Allocator& al = Allocator()) + : base(first, last, comp, al, v_t_k) { } - template multiset(InputIterator first, InputIterator last, - const Compare& comp = Compare(), const Allocator& al = Allocator()) - : base(first, last, comp, al, v_t_k) { } + multiset(const multiset& x) : base(x) { } + ~multiset() { } + using base::operator=; + using base::operator==; + using base::operator!=; - multiset(const multiset& x) : base(x) { } - ~multiset() { } + using base::insert; + using base::erase; - using base::operator=; - using base::operator==; - using base::operator!=; + using base::begin; + using base::end; + using base::rbegin; + using base::rend; - using base::insert; - using base::erase; - - using base::begin; - using base::end; - using base::rbegin; - using base::rend; - - using base::empty; - using base::size; - using base::max_size; - - using base::find; - using base::count; - using base::lower_bound; - using base::upper_bound; - using base::equal_range; + using base::empty; + using base::size; + using base::max_size; + using base::find; + using base::count; + using base::lower_bound; + using base::upper_bound; + using base::equal_range; protected: - }; - /* Non-member functions. These are at the end because they are not associated with any - particular class. These will be implemented as I figure out exactly what all of - them are supposed to do, and I have time. + * particular class. These will be implemented as I figure out exactly what all of + * them are supposed to do, and I have time. */ - template _UCXXEXPORT bool operator< - (const set& x, const set& y) - { - typename set::const_iterator first1 = x.begin(); - typename set::const_iterator first2 = y.begin(); - typename set::const_iterator last1 = x.end(); - typename set::const_iterator last2 = y.end(); + template _UCXXEXPORT bool operator< + (const set& x, const set& y) + { + typename set::const_iterator first1 = x.begin(); + typename set::const_iterator first2 = y.begin(); + typename set::const_iterator last1 = x.end(); + typename set::const_iterator last2 = y.end(); - while(first1 != last1 && first2 != last2){ - if( *first1 < *first2 ){ - return true; - } - if( *first2 < *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1==last1 && first2 != last2; - } + while (first1 != last1 && first2 != last2) + { + if (*first1 < *first2) + { + return true; + } - template _UCXXEXPORT bool operator> - (const set& x, const set& y) - { - typename set::const_iterator first1 = x.begin(); - typename set::const_iterator first2 = y.begin(); - typename set::const_iterator last1 = x.end(); - typename set::const_iterator last2 = y.end(); + if (*first2 < *first1) + { + return false; + } - while(first1 != last1 && first2 != last2){ - if( *first1 > *first2 ){ - return true; - } - if( *first2 > *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1!=last1 && first2 == last2; - } + ++first1; + ++first2; + } - template _UCXXEXPORT bool operator>= - (const set& x, const set& y) - { - typename set::const_iterator first1 = x.begin(); - typename set::const_iterator first2 = y.begin(); - typename set::const_iterator last1 = x.end(); - typename set::const_iterator last2 = y.end(); + return first1==last1 && first2 != last2; + } - while(first1 != last1 && first2 != last2){ - if( *first1 > *first2 ){ - return true; - } - if( *first2 > *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1!=last1; - } + template _UCXXEXPORT bool operator> + (const set& x, const set& y) + { + typename set::const_iterator first1 = x.begin(); + typename set::const_iterator first2 = y.begin(); + typename set::const_iterator last1 = x.end(); + typename set::const_iterator last2 = y.end(); - template _UCXXEXPORT bool operator<= - (const set& x, const set& y) - { - typename set::const_iterator first1 = x.begin(); - typename set::const_iterator first2 = y.begin(); - typename set::const_iterator last1 = x.end(); - typename set::const_iterator last2 = y.end(); + while (first1 != last1 && first2 != last2) + { + if (*first1 > *first2) + { + return true; + } - while(first1 != last1 && first2 != last2){ - if( *first1 < *first2 ){ - return true; - } - if( *first2 < *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first2!=last2; - } - template _UCXXEXPORT void swap - (set& x, set& y) - { - x.swap(y); - } + if (*first2 > *first1) + { + return false; + } + ++first1; + ++first2; + } - template _UCXXEXPORT bool operator== - (const multiset& x, const multiset& y) - { - if(x.data == y.data){ - return true; - } - return false; - } + return first1!=last1 && first2 == last2; + } - template _UCXXEXPORT bool operator< - (const multiset& x, const multiset& y) - { - typename multiset::const_iterator first1 = x.begin(); - typename multiset::const_iterator first2 = y.begin(); - typename multiset::const_iterator last1 = x.end(); - typename multiset::const_iterator last2 = y.end(); + template _UCXXEXPORT bool operator>= + (const set& x, const set& y) + { + typename set::const_iterator first1 = x.begin(); + typename set::const_iterator first2 = y.begin(); + typename set::const_iterator last1 = x.end(); + typename set::const_iterator last2 = y.end(); - while(first1 != last1 && first2 != last2){ - if( *first1 < *first2 ){ - return true; - } - if( *first2 < *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1==last1 && first2 != last2; - } + while (first1 != last1 && first2 != last2) + { + if (*first1 > *first2) + { + return true; + } - template _UCXXEXPORT bool operator!= - (const multiset& x, const multiset& y) - { - typename multiset::const_iterator first1 = x.begin(); - typename multiset::const_iterator first2 = y.begin(); - typename multiset::const_iterator last1 = x.end(); - typename multiset::const_iterator last2 = y.end(); + if (*first2 > *first1) + { + return false; + } - while(first1 != last1 && first2 != last2){ - if( *first1 != *first2 ){ - return true; - } - ++first1; - ++first2; - } - return first1!=last1 || first2 != last2; - } + ++first1; + ++first2; + } + return first1!=last1; + } - template _UCXXEXPORT bool operator> - (const multiset& x, const multiset& y) - { - typename multiset::const_iterator first1 = x.begin(); - typename multiset::const_iterator first2 = y.begin(); - typename multiset::const_iterator last1 = x.end(); - typename multiset::const_iterator last2 = y.end(); + template _UCXXEXPORT bool operator<= + (const set& x, const set& y) + { + typename set::const_iterator first1 = x.begin(); + typename set::const_iterator first2 = y.begin(); + typename set::const_iterator last1 = x.end(); + typename set::const_iterator last2 = y.end(); - while(first1 != last1 && first2 != last2){ - if( *first1 > *first2 ){ - return true; - } - if( *first2 > *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1!=last1 && first2 == last2; - } + while (first1 != last1 && first2 != last2) + { + if (*first1 < *first2) + { + return true; + } - template _UCXXEXPORT bool operator>= - (const multiset& x, const multiset& y) - { - typename multiset::const_iterator first1 = x.begin(); - typename multiset::const_iterator first2 = y.begin(); - typename multiset::const_iterator last1 = x.end(); - typename multiset::const_iterator last2 = y.end(); + if (*first2 < *first1) + { + return false; + } - while(first1 != last1 && first2 != last2){ - if( *first1 > *first2 ){ - return true; - } - if( *first2 > *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first1!=last1; - } + ++first1; + ++first2; + } - template _UCXXEXPORT bool operator<= - (const multiset& x, const multiset& y) - { - typename multiset::const_iterator first1 = x.begin(); - typename multiset::const_iterator first2 = y.begin(); - typename multiset::const_iterator last1 = x.end(); - typename multiset::const_iterator last2 = y.end(); + return first2!=last2; + } - while(first1 != last1 && first2 != last2){ - if( *first1 < *first2 ){ - return true; - } - if( *first2 < *first1 ){ - return false; - } - ++first1; - ++first2; - } - return first2!=last2; - } + template _UCXXEXPORT void swap + (set& x, set& y) + { + x.swap(y); + } - template _UCXXEXPORT void swap - (multiset& x, multiset& y) - { - x.swap(y); - } + template _UCXXEXPORT bool operator== + (const multiset& x, const multiset& y) + { + if (x.data == y.data) + { + return true; + } + return false; + } + template _UCXXEXPORT bool operator< + (const multiset& x, const multiset& y) + { + typename multiset::const_iterator first1 = x.begin(); + typename multiset::const_iterator first2 = y.begin(); + typename multiset::const_iterator last1 = x.end(); + typename multiset::const_iterator last2 = y.end(); -} + while (first1 != last1 && first2 != last2) + { + if (*first1 < *first2) + { + return true; + } + + if (*first2 < *first1) + { + return false; + } + + ++first1; + ++first2; + } + + return first1==last1 && first2 != last2; + } + + template _UCXXEXPORT bool operator!= + (const multiset& x, const multiset& y) + { + typename multiset::const_iterator first1 = x.begin(); + typename multiset::const_iterator first2 = y.begin(); + typename multiset::const_iterator last1 = x.end(); + typename multiset::const_iterator last2 = y.end(); + + while (first1 != last1 && first2 != last2) + { + if (*first1 != *first2) + { + return true; + } + + ++first1; + ++first2; + } + + return first1!=last1 || first2 != last2; + } + + template _UCXXEXPORT bool operator> + (const multiset& x, const multiset& y) + { + typename multiset::const_iterator first1 = x.begin(); + typename multiset::const_iterator first2 = y.begin(); + typename multiset::const_iterator last1 = x.end(); + typename multiset::const_iterator last2 = y.end(); + + while (first1 != last1 && first2 != last2) + { + if (*first1 > *first2) + { + return true; + } + + if (*first2 > *first1) + { + return false; + } + + ++first1; + ++first2; + } + + return first1!=last1 && first2 == last2; + } + + template _UCXXEXPORT bool operator>= + (const multiset& x, const multiset& y) + { + typename multiset::const_iterator first1 = x.begin(); + typename multiset::const_iterator first2 = y.begin(); + typename multiset::const_iterator last1 = x.end(); + typename multiset::const_iterator last2 = y.end(); + + while (first1 != last1 && first2 != last2) + { + if (*first1 > *first2) + { + return true; + } + + if (*first2 > *first1) + { + return false; + } + + ++first1; + ++first2; + } + + return first1!=last1; + } + + template _UCXXEXPORT bool operator<= + (const multiset& x, const multiset& y) + { + typename multiset::const_iterator first1 = x.begin(); + typename multiset::const_iterator first2 = y.begin(); + typename multiset::const_iterator last1 = x.end(); + typename multiset::const_iterator last2 = y.end(); + + while (first1 != last1 && first2 != last2) + { + if (*first1 < *first2) + { + return true; + } + + if (*first2 < *first1) + { + return false; + } + + ++first1; + ++first2; + } + + return first2!=last2; + } + + template _UCXXEXPORT void swap + (multiset& x, multiset& y) + { + x.swap(y); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/sstream b/misc/uClibc++/include/uClibc++/sstream index 296985374c..d06d1874f8 100644 --- a/misc/uClibc++/include/uClibc++/sstream +++ b/misc/uClibc++/include/uClibc++/sstream @@ -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 @@ -31,345 +31,431 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + template + class _UCXXEXPORT basic_stringbuf : public basic_streambuf + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef typename Allocator::size_type size_type; - template - class _UCXXEXPORT basic_stringbuf : public basic_streambuf - { - public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - typedef typename Allocator::size_type size_type; + explicit _UCXXEXPORT basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out) + : data(), ielement(0), oelement(0) + { + basic_streambuf::openedFor = which; + } - explicit _UCXXEXPORT basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out) - : data(), ielement(0), oelement(0) - { - basic_streambuf::openedFor = which; - } + explicit _UCXXEXPORT basic_stringbuf(const basic_string& str, + ios_base::openmode which = ios_base::in | ios_base::out) + : data(str), ielement(0), oelement(0) + { + if (which & ios_base::ate) + { + oelement = data.length(); + } - explicit _UCXXEXPORT basic_stringbuf(const basic_string& str, - ios_base::openmode which = ios_base::in | ios_base::out) - : data(str), ielement(0), oelement(0) - { - if(which & ios_base::ate){ - oelement = data.length(); - } - basic_streambuf::openedFor = which; - } + basic_streambuf::openedFor = which; + } - virtual _UCXXEXPORT ~basic_stringbuf() { } + virtual _UCXXEXPORT ~basic_stringbuf() { } - _UCXXEXPORT basic_string str() const{ - return data; - } + _UCXXEXPORT basic_string str() const + { + return data; + } - _UCXXEXPORT void str(const basic_string& s){ - data = s; - ielement = 0; - if(basic_streambuf::openedFor & ios_base::ate){ - oelement = data.length(); - }else{ - oelement = 0; - } - } + _UCXXEXPORT void str(const basic_string& s) + { + data = s; + ielement = 0; + if (basic_streambuf::openedFor & ios_base::ate) + { + oelement = data.length(); + } + else + { + oelement = 0; + } + } - protected: - virtual _UCXXEXPORT int sync(){ - return 0; - } - virtual _UCXXEXPORT int_type underflow(){ - if(ielement >= data.length()){ - return traits::eof(); - } - return traits::to_int_type(data[ielement]); - } + protected: + virtual _UCXXEXPORT int sync() + { + return 0; + } - virtual _UCXXEXPORT int_type uflow(){ - int_type retval = underflow(); - if(retval != traits::eof()){ - ++ielement; - } - return retval; - } + virtual _UCXXEXPORT int_type underflow() + { + if (ielement >= data.length()) + { + return traits::eof(); + } - virtual _UCXXEXPORT int_type pbackfail(int_type c = traits::eof()){ - //Error possibilities - if(ielement == 0){ - return traits::eof(); - } - if(ielement > data.length()){ - ielement = data.length(); - return traits::eof(); - } - //eof passed in - if(traits::eq_int_type(c,traits::eof())==true){ - --ielement; - return traits::not_eof(c); - } - if(traits::eq(traits::to_char_type(c),data[ielement-1]) == true){ - --ielement; - return c; - } - if(basic_streambuf::openedFor & ios_base::out){ - --ielement; - data[ielement] = c; - return c; - } - return traits::eof(); - } + return traits::to_int_type(data[ielement]); + } - virtual _UCXXEXPORT int showmanyc(){ - return data.length() - ielement; - } - virtual _UCXXEXPORT streamsize xsgetn(char_type* c, streamsize n){ - streamsize i = 0; - while(ielement < data.length() && i < n ){ - c[i] = data[ielement]; - ++i; - ++ielement; - } - return i; - } + virtual _UCXXEXPORT int_type uflow() + { + int_type retval = underflow(); + if (retval != traits::eof()) + { + ++ielement; + } - virtual _UCXXEXPORT int_type overflow (int_type c = traits::eof()){ - //Nothing to do - if(traits::eq_int_type(c,traits::eof())){ - return traits::not_eof(c); - } + return retval; + } - //Actually add character, if possible - if(basic_streambuf::openedFor & ios_base::out){ - if(oelement >= data.length()){ - data.push_back(c); - }else{ - data[oelement] = c; - } - ++oelement; - return c; - } - //Not possible - return traits::eof(); - } + virtual _UCXXEXPORT int_type pbackfail(int_type c = traits::eof()) + { + // Error possibilities - virtual _UCXXEXPORT basic_streambuf* setbuf(charT*, streamsize){ - //This function does nothing - return this; - } + if (ielement == 0) + { + return traits::eof(); + } - virtual _UCXXEXPORT streamsize xsputn(const char_type* s, streamsize n){ - data.replace(oelement, n, s, n); - oelement += n; - return n; - } + if (ielement > data.length()) + { + ielement = data.length(); + return traits::eof(); + } - virtual _UCXXEXPORT pos_type seekoff(off_type off, ios_base::seekdir way, - ios_base::openmode which = ios_base::in | ios_base::out) - { - //Test for invalid option - if( (which & ios_base::in) && (which & ios_base::out) && (way == ios_base::cur)){ - return -1; - } + // eof passed in - //Calculate new location - size_type newpos = 0; + if (traits::eq_int_type(c,traits::eof())==true) + { + --ielement; + return traits::not_eof(c); + } - if(way == ios_base::beg){ - newpos = off; - }else if(way == ios_base::cur){ - if(which & ios_base::out){ - newpos = data.length() + off; - } - if(which & ios_base::in){ - newpos = ielement + off; - } - - }else{ - newpos = data.length() + off; - } + if (traits::eq(traits::to_char_type(c),data[ielement-1]) == true) + { + --ielement; + return c; + } - //Test for error conditions - if(newpos > data.length()){ - return -1; - } + if (basic_streambuf::openedFor & ios_base::out) + { + --ielement; + data[ielement] = c; + return c; + } - //Shuffle pointers + return traits::eof(); + } - if(which & ios_base::in){ - ielement = newpos; - } - if(which & ios_base::out){ - data.resize(newpos); - if(ielement > data.length()){ - ielement = data.length(); - } - } + virtual _UCXXEXPORT int showmanyc() + { + return data.length() - ielement; + } - return newpos; - } - - virtual _UCXXEXPORT pos_type seekpos(pos_type sp, - ios_base::openmode which = ios_base::in | ios_base::out) - { - return seekoff(sp, ios_base::beg, which); - } + virtual _UCXXEXPORT streamsize xsgetn(char_type* c, streamsize n) + { + streamsize i = 0; + while (ielement < data.length() && i < n) + { + c[i] = data[ielement]; + ++i; + ++ielement; + } - basic_string data; - size_type ielement; - size_type oelement; - }; + return i; + } + + virtual _UCXXEXPORT int_type overflow (int_type c = traits::eof()) + { + // Nothing to do + + if (traits::eq_int_type(c,traits::eof())) + { + return traits::not_eof(c); + } + + // Actually add character, if possible + + if (basic_streambuf::openedFor & ios_base::out) + { + if (oelement >= data.length()) + { + data.push_back(c); + } + else + { + data[oelement] = c; + } + + ++oelement; + return c; + } + + // Not possible + + return traits::eof(); + } + + virtual _UCXXEXPORT basic_streambuf* setbuf(charT*, streamsize) + { + //This function does nothing + + return this; + } + + virtual _UCXXEXPORT streamsize xsputn(const char_type* s, streamsize n) + { + data.replace(oelement, n, s, n); + oelement += n; + return n; + } + + virtual _UCXXEXPORT pos_type seekoff(off_type off, ios_base::seekdir way, + ios_base::openmode which = ios_base::in | ios_base::out) + { + // Test for invalid option + + if ((which & ios_base::in) && (which & ios_base::out) && (way == ios_base::cur)) + { + return -1; + } + + // Calculate new location + + size_type newpos = 0; + + if (way == ios_base::beg) + { + newpos = off; + } + else if (way == ios_base::cur) + { + if (which & ios_base::out) + { + newpos = data.length() + off; + } + + if (which & ios_base::in) + { + newpos = ielement + off; + } + } + else + { + newpos = data.length() + off; + } + + // Test for error conditions + + if (newpos > data.length()) + { + return -1; + } + + // Shuffle pointers - template class _UCXXEXPORT basic_istringstream - : public basic_istream - { - public: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; + if (which & ios_base::in) + { + ielement = newpos; + } + + if (which & ios_base::out) + { + data.resize(newpos); + if (ielement > data.length()) + { + ielement = data.length(); + } + } + + return newpos; + } + + virtual _UCXXEXPORT pos_type seekpos(pos_type sp, + ios_base::openmode which = ios_base::in | ios_base::out) + { + return seekoff(sp, ios_base::beg, which); + } + + basic_string data; + size_type ielement; + size_type oelement; + }; + + template class _UCXXEXPORT basic_istringstream + : public basic_istream + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + + explicit _UCXXEXPORT basic_istringstream(ios_base::openmode m = ios_base::in) + : basic_ios(&sb), basic_istream(&sb), sb(m) + { + } + + explicit _UCXXEXPORT basic_istringstream(const basic_string& str, + ios_base::openmode which = ios_base::in) + : basic_ios(&sb), basic_istream(&sb), sb(str, which) + { + } + + virtual _UCXXEXPORT ~basic_istringstream() { } + + _UCXXEXPORT basic_stringbuf* rdbuf() const + { + return &sb; + } + + _UCXXEXPORT basic_string str() const + { + return sb.str(); + } + + _UCXXEXPORT void str(const basic_string& s){ + sb.str(s); + basic_istream::clear(); + } + + private: + basic_stringbuf sb; + }; + + template class _UCXXEXPORT basic_ostringstream + : public basic_ostream + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + + explicit _UCXXEXPORT basic_ostringstream(ios_base::openmode m = ios_base::out) + : basic_ios(&sb), basic_ostream(&sb), sb(m) + { + } + + explicit _UCXXEXPORT basic_ostringstream(const basic_string& str, + ios_base::openmode which = ios_base::out) + : basic_ios(&sb), basic_ostream(&sb), sb(str, which) + { + } + + virtual _UCXXEXPORT ~basic_ostringstream() { } + + _UCXXEXPORT basic_stringbuf* rdbuf() const + { + return &sb; + } + + _UCXXEXPORT basic_string str() const + { + return sb.str(); + } + + _UCXXEXPORT void str(const basic_string& s) + { + sb.str(s); + basic_ostream::clear(); + } + + private: + basic_stringbuf sb; + }; - explicit _UCXXEXPORT basic_istringstream(ios_base::openmode m = ios_base::in) - : basic_ios(&sb), basic_istream(&sb), sb(m) - { - } - explicit _UCXXEXPORT basic_istringstream( const basic_string& str, - ios_base::openmode which = ios_base::in) - : basic_ios(&sb), basic_istream(&sb), sb(str, which) - { - } - virtual _UCXXEXPORT ~basic_istringstream() { } - _UCXXEXPORT basic_stringbuf* rdbuf() const{ - return &sb; - } - _UCXXEXPORT basic_string str() const{ - return sb.str(); - } - _UCXXEXPORT void str(const basic_string& s){ - sb.str(s); - basic_istream::clear(); - } - private: - basic_stringbuf sb; - }; + template class _UCXXEXPORT basic_stringstream + : public basic_iostream + { + public: + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + explicit _UCXXEXPORT basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in) + : basic_ios(&sb), basic_iostream(&sb), sb(which) + { + } - template class _UCXXEXPORT basic_ostringstream - : public basic_ostream - { - public: + explicit _UCXXEXPORT basic_stringstream(const basic_string& str, + ios_base::openmode which = ios_base::out|ios_base::in) + : basic_ios(&sb), basic_iostream(&sb), sb(str, which) + { + } - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; + virtual _UCXXEXPORT ~basic_stringstream(){ } - explicit _UCXXEXPORT basic_ostringstream(ios_base::openmode m = ios_base::out) - : basic_ios(&sb), basic_ostream(&sb), sb(m) - { - } - explicit _UCXXEXPORT basic_ostringstream(const basic_string& str, - ios_base::openmode which = ios_base::out) - : basic_ios(&sb), basic_ostream(&sb), sb(str, which) - { - } - virtual _UCXXEXPORT ~basic_ostringstream() { } + _UCXXEXPORT basic_stringbuf* rdbuf() + { + return &sb; + } - _UCXXEXPORT basic_stringbuf* rdbuf() const{ - return &sb; - } - _UCXXEXPORT basic_string str() const{ - return sb.str(); - } - _UCXXEXPORT void str(const basic_string& s){ - sb.str(s); - basic_ostream::clear(); - } - private: - basic_stringbuf sb; - }; + _UCXXEXPORT basic_string str() const + { + return sb.str(); + } + _UCXXEXPORT void str(const basic_string& s) + { + sb.str(s); + basic_iostream::clear(); + } - template class _UCXXEXPORT basic_stringstream - : public basic_iostream - { - public: - - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - - explicit _UCXXEXPORT basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in) - : basic_ios(&sb), basic_iostream(&sb), sb(which) - { - } - - explicit _UCXXEXPORT basic_stringstream(const basic_string& str, - ios_base::openmode which = ios_base::out|ios_base::in) - : basic_ios(&sb), basic_iostream(&sb), sb(str, which) - { - } - virtual _UCXXEXPORT ~basic_stringstream(){ } - - _UCXXEXPORT basic_stringbuf* rdbuf(){ - return &sb; - } - _UCXXEXPORT basic_string str() const{ - return sb.str(); - } - _UCXXEXPORT void str(const basic_string& s){ - sb.str(s); - basic_iostream::clear(); - } - private: - basic_stringbuf sb; - }; + private: + basic_stringbuf sb; + }; #ifdef __UCLIBCXX_EXPAND_SSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_SSTREAM__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT basic_stringbuf, allocator >:: - basic_stringbuf(ios_base::openmode which); - template <> _UCXXEXPORT basic_stringbuf, allocator >::~basic_stringbuf(); + template <> _UCXXEXPORT basic_stringbuf, allocator >:: + basic_stringbuf(ios_base::openmode which); + template <> _UCXXEXPORT basic_stringbuf, allocator >::~basic_stringbuf(); #endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT basic_string, allocator > - basic_stringbuf, allocator >::str() const; + template <> _UCXXEXPORT basic_string, allocator > + basic_stringbuf, allocator >::str() const; - template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type - basic_stringbuf, allocator >:: - pbackfail(basic_stringbuf, allocator >::int_type c); + template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type + basic_stringbuf, allocator >:: + pbackfail(basic_stringbuf, allocator >::int_type c); - template <> _UCXXEXPORT basic_stringbuf, allocator >::pos_type - basic_stringbuf, allocator >:: - seekoff (basic_stringbuf, allocator >::off_type off, - ios_base::seekdir way, - ios_base::openmode which - ); + template <> _UCXXEXPORT basic_stringbuf, allocator >::pos_type + basic_stringbuf, allocator >:: + seekoff (basic_stringbuf, allocator >::off_type off, + ios_base::seekdir way, + ios_base::openmode which); - template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type - basic_stringbuf, allocator >:: - overflow (basic_stringbuf, allocator >::int_type c); + template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type + basic_stringbuf, allocator >:: + overflow (basic_stringbuf, allocator >::int_type c); - template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type - basic_stringbuf, allocator >::underflow (); + template <> _UCXXEXPORT basic_stringbuf, allocator >::int_type + basic_stringbuf, allocator >::underflow (); - template <> _UCXXEXPORT streamsize basic_stringbuf, allocator >:: - xsputn(const char* s, streamsize n); + template <> _UCXXEXPORT streamsize basic_stringbuf, allocator >:: + xsputn(const char* s, streamsize n); #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT basic_stringstream, allocator >:: - basic_stringstream(ios_base::openmode which); - template <> _UCXXEXPORT basic_stringstream, allocator >::~basic_stringstream(); - template <> _UCXXEXPORT basic_istringstream, allocator >::~basic_istringstream(); - template <> _UCXXEXPORT basic_ostringstream, allocator >::~basic_ostringstream(); + template <> _UCXXEXPORT basic_stringstream, allocator >:: + basic_stringstream(ios_base::openmode which); + + template <> _UCXXEXPORT basic_stringstream, allocator >::~basic_stringstream(); + + template <> _UCXXEXPORT basic_istringstream, allocator >::~basic_istringstream(); + + template <> _UCXXEXPORT basic_ostringstream, allocator >::~basic_ostringstream(); #endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ @@ -378,7 +464,7 @@ namespace std{ #pragma GCC visibility pop -} - +} // namespace +} // extern "C++" #endif diff --git a/misc/uClibc++/include/uClibc++/stack b/misc/uClibc++/include/uClibc++/stack index d4861b3a42..2321831ba4 100644 --- a/misc/uClibc++/include/uClibc++/stack +++ b/misc/uClibc++/include/uClibc++/stack @@ -1,19 +1,20 @@ -/* 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 #include @@ -23,59 +24,66 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + template > class _UCXXEXPORT stack + { + protected: + Container c; - template > class _UCXXEXPORT stack{ - protected: - Container c; + public: + typedef typename Container::value_type value_type; + typedef typename Container::size_type size_type; + typedef Container container_type; - public: - typedef typename Container::value_type value_type; - typedef typename Container::size_type size_type; - typedef Container container_type; + explicit stack(const Container& a = Container()) : c(a) { }; + bool empty() const { return c.empty(); } + size_type size() const { return c.size(); } + value_type& top() { return c.back(); } + const value_type& top() const { return c.back(); } + void push(const value_type& x) { c.push_back(x); } + void pop() { c.pop_back(); } - explicit stack(const Container& a = Container()) : c(a) { }; - bool empty() const { return c.empty(); } - size_type size() const { return c.size(); } - value_type& top() { return c.back(); } - const value_type& top() const { return c.back(); } - void push(const value_type& x) { c.push_back(x); } - void pop() { c.pop_back(); } + bool operator==(const stack &x) const + { + return x.c == c; + } + }; - bool operator==(const stack &x) const{ - return x.c == c; - } + template _UCXXEXPORT bool + operator< (const stack& x, const stack& y) + { + return (x.c < y.c); + } - }; + template _UCXXEXPORT bool + operator!=(const stack& x, const stack& y) + { + return (x.c != y.c); + } + template _UCXXEXPORT bool + operator> (const stack& x, const stack& y) + { + return (x.c > y.c); + } - template _UCXXEXPORT bool - operator< (const stack& x, const stack& y) - { - return (x.c < y.c); - } - template _UCXXEXPORT bool - operator!=(const stack& x, const stack& y) - { - return (x.c != y.c); - } - template _UCXXEXPORT bool - operator> (const stack& x, const stack& y) - { - return (x.c > y.c); - } - template _UCXXEXPORT bool - operator>=(const stack& x, const stack& y) - { - return (x.c >= y.c); - } - template _UCXXEXPORT bool - operator<=(const stack& x, const stack& y) - { - return (x.c <= y.c); - } + template _UCXXEXPORT bool + operator>=(const stack& x, const stack& y) + { + return (x.c >= y.c); + } -} + template _UCXXEXPORT bool + operator<=(const stack& x, const stack& y) + { + return (x.c <= y.c); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/streambuf b/misc/uClibc++/include/uClibc++/streambuf index 0daa388f06..2dfa213d0c 100644 --- a/misc/uClibc++/include/uClibc++/streambuf +++ b/misc/uClibc++/include/uClibc++/streambuf @@ -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 #include @@ -29,300 +29,379 @@ #pragma GCC visibility push(default) -namespace std{ - - template class _UCXXEXPORT basic_streambuf{ - public: +extern "C++" +{ +namespace std +{ + template class _UCXXEXPORT basic_streambuf{ + public: #ifdef __UCLIBCXX_SUPPORT_CDIR__ - friend ios_base::Init::Init(); + friend ios_base::Init::Init(); #endif - // Types: - typedef charT char_type; - typedef typename traits::int_type int_type; - typedef typename traits::pos_type pos_type; - typedef typename traits::off_type off_type; - typedef traits traits_type; + // Types: - virtual ~basic_streambuf(); + typedef charT char_type; + typedef typename traits::int_type int_type; + typedef typename traits::pos_type pos_type; + typedef typename traits::off_type off_type; + typedef traits traits_type; - locale pubimbue(const locale &loc); + virtual ~basic_streambuf(); - locale getloc() const{ - return myLocale; - } + locale pubimbue(const locale &loc); - basic_streambuf* pubsetbuf(char_type* s, streamsize n){ - return setbuf(s,n); - } - pos_type pubseekoff(off_type off, - typename ios_base::seekdir way, - ios_base::openmode which = ios_base::in | - ios_base::out - ) - { - return seekoff(off,way,which); - } - pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out){ - return seekpos(sp,which); - } - int pubsync(){ - return sync(); - } + locale getloc() const + { + return myLocale; + } - streamsize in_avail(); + basic_streambuf* pubsetbuf(char_type* s, streamsize n) + { + return setbuf(s,n); + } - int_type snextc(); + pos_type pubseekoff(off_type off, + typename ios_base::seekdir way, + ios_base::openmode which = ios_base::in | + ios_base::out) + { + return seekoff(off,way,which); + } - int_type sbumpc(); + pos_type pubseekpos(pos_type sp, ios_base::openmode which = ios_base::in | ios_base::out) + { + return seekpos(sp,which); + } - int_type sgetc(); + int pubsync() + { + return sync(); + } - streamsize sgetn(char_type* s, streamsize n){ - return xsgetn(s,n); - } + streamsize in_avail(); - int_type sputbackc(char_type c); + int_type snextc(); - int_type sungetc(); + int_type sbumpc(); - int_type sputc(char_type c); + int_type sgetc(); - streamsize sputn(const char_type* s, streamsize n){ - if(openedFor & ios_base::app){ - seekoff(0, ios_base::end, ios_base::out); - } - return xsputn(s, n); - } + streamsize sgetn(char_type* s, streamsize n) + { + return xsgetn(s,n); + } - protected: - locale myLocale; - //Pointers for the "get" buffers - charT * mgbeg; - charT * mgnext; - charT * mgend; + int_type sputbackc(char_type c); - //Pointers for the "put" buffers - charT * mpbeg; - charT * mpnext; - charT * mpend; + int_type sungetc(); - //In the event of null buffers Lets us know what the buffer is opened for - ios_base::openmode openedFor; - - basic_streambuf(); + int_type sputc(char_type c); - basic_streambuf(const basic_streambuf > &) - : myLocale(), - mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0), - openedFor(0) - { } - basic_streambuf > & operator=(const basic_streambuf > &){ - return *this; - } - - char_type* eback() const{ - return mgbeg; - } - char_type* gptr() const{ - return mgnext; - } - char_type* egptr() const{ - return mgend; - } - void gbump(int n){ - mgnext+=n; - } - void setg(char_type* gbeg, char_type* gnext, char_type* gend){ - mgbeg = gbeg; - mgnext = gnext; - mgend = gend; - } + streamsize sputn(const char_type* s, streamsize n) + { + if (openedFor & ios_base::app) + { + seekoff(0, ios_base::end, ios_base::out); + } - char_type* pbase() const{ - return mpbeg; - } - char_type* pptr() const{ - return mpnext; - } - char_type* epptr() const{ - return mpend; - } - void pbump(int n){ - mpnext+=n; - } - void setp(char_type* pbeg, char_type* pend){ - mpbeg = pbeg; - mpnext = pbeg; - mpend = pend; - } + return xsputn(s, n); + } - virtual void imbue(const locale &loc){ - myLocale = loc; - } + protected: + locale myLocale; - //Virtual functions which we will not implement + // Pointers for the "get" buffers - virtual basic_streambuf* setbuf(char_type* , streamsize){ - return 0; - } - virtual pos_type seekoff(off_type , ios_base::seekdir, - ios_base::openmode = ios_base::in | ios_base::out) - { - return 0; - } - virtual pos_type seekpos(pos_type , ios_base::openmode = ios_base::in | ios_base::out){ - return 0; - } - virtual int sync(){ - return 0; - } + charT * mgbeg; + charT * mgnext; + charT * mgend; - virtual int showmanyc(){ - return 0; - } - virtual streamsize xsgetn(char_type* , streamsize ){ - return 0; - } - virtual int_type underflow(){ - return traits_type::eof(); - } - virtual int_type uflow(){ - int_type ret = underflow(); - if (!traits_type::eq_int_type(ret, traits_type::eof())) - gbump(1); - return ret; - } + // Pointers for the "put" buffers - virtual int_type pbackfail(int_type c = traits::eof()){ - return c; - } - virtual streamsize xsputn(const char_type* c, streamsize n){ - //This function is designed to be replaced by subclasses - for(streamsize i = 0; i< n; ++i){ - if(sputc(c[i]) == traits::eof()){ - return i; - } - } - return n; - } - virtual int_type overflow (int_type c = traits::eof()){ - return c; - } - }; + charT * mpbeg; + charT * mpnext; + charT * mpend; - typedef basic_streambuf streambuf; + // In the event of null buffers Lets us know what the buffer is opened for + + ios_base::openmode openedFor; + + basic_streambuf(); + + basic_streambuf(const basic_streambuf > &) + : myLocale(), + mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0), + openedFor(0) + { } + + basic_streambuf > & operator=(const basic_streambuf > &) + { + return *this; + } + + char_type* eback() const + { + return mgbeg; + } + + char_type* gptr() const + { + return mgnext; + } + char_type* egptr() const + { + return mgend; + } + + void gbump(int n) + { + mgnext+=n; + } + + void setg(char_type* gbeg, char_type* gnext, char_type* gend) + { + mgbeg = gbeg; + mgnext = gnext; + mgend = gend; + } + + char_type* pbase() const + { + return mpbeg; + } + + char_type* pptr() const + { + return mpnext; + } + + char_type* epptr() const + { + return mpend; + } + + void pbump(int n) + { + mpnext+=n; + } + + void setp(char_type* pbeg, char_type* pend) + { + mpbeg = pbeg; + mpnext = pbeg; + mpend = pend; + } + + virtual void imbue(const locale &loc) + { + myLocale = loc; + } + + // Virtual functions which we will not implement + + virtual basic_streambuf* setbuf(char_type* , streamsize) + { + return 0; + } + + virtual pos_type seekoff(off_type , ios_base::seekdir, + ios_base::openmode = ios_base::in | ios_base::out) + { + return 0; + } + + virtual pos_type seekpos(pos_type , ios_base::openmode = ios_base::in | ios_base::out) + { + return 0; + } + + virtual int sync() + { + return 0; + } + + virtual int showmanyc() + { + return 0; + } + + virtual streamsize xsgetn(char_type* , streamsize) + { + return 0; + } + + virtual int_type underflow() + { + return traits_type::eof(); + } + + virtual int_type uflow() + { + int_type ret = underflow(); + if (!traits_type::eq_int_type(ret, traits_type::eof())) + { + gbump(1); + } + + return ret; + } + + virtual int_type pbackfail(int_type c = traits::eof()) + { + return c; + } + + virtual streamsize xsputn(const char_type* c, streamsize n) + { + // This function is designed to be replaced by subclasses + + for (streamsize i = 0; i< n; ++i) + { + if (sputc(c[i]) == traits::eof()) + { + return i; + } + } + + return n; + } + + virtual int_type overflow (int_type c = traits::eof()) + { + return c; + } + }; + + typedef basic_streambuf streambuf; #ifdef __UCLIBCXX_HAS_WCHAR__ - typedef basic_streambuf wstreambuf; + typedef basic_streambuf wstreambuf; #endif +// Definitions put below to allow for easy expansion of code -//Definitions put below to allow for easy expansion of code + template basic_streambuf::~basic_streambuf(){ } - template basic_streambuf::~basic_streambuf(){ } + template locale basic_streambuf::pubimbue(const locale &loc) + { + locale temp = myLocale; + myLocale = loc; + return temp; + } - template locale basic_streambuf::pubimbue(const locale &loc){ - locale temp = myLocale; - myLocale = loc; - return temp; - } + template streamsize basic_streambuf::in_avail() + { + if (mgend !=0 && mgnext !=0) + { + return mgend - mgnext; + } - template streamsize basic_streambuf::in_avail(){ - if(mgend !=0 && mgnext !=0){ - return mgend - mgnext; - } - return showmanyc(); - } + return showmanyc(); + } - template typename basic_streambuf::int_type basic_streambuf::sbumpc(){ - if(mgbeg == 0 || mgnext == mgend){ - return uflow(); - } - int_type retval = T::to_int_type(*gptr()); - gbump(1); - return retval; - } + template typename basic_streambuf::int_type basic_streambuf::sbumpc() + { + if (mgbeg == 0 || mgnext == mgend) + { + return uflow(); + } - template typename basic_streambuf::int_type basic_streambuf::snextc(){ - if(sbumpc() == T::eof() ){ - return T::eof() ; - } - return sgetc(); - } + int_type retval = T::to_int_type(*gptr()); + gbump(1); + return retval; + } - template typename basic_streambuf::int_type basic_streambuf::sgetc(){ - if(mgbeg == 0 || mgnext == mgend){ - return underflow(); - } - return T::to_int_type(*gptr()); - } + template typename basic_streambuf::int_type basic_streambuf::snextc() + { + if (sbumpc() == T::eof()) + { + return T::eof() ; + } - template typename basic_streambuf::int_type basic_streambuf::sputbackc(char_type c){ - if(mgbeg == 0 || mgnext == mgbeg || !T::eq(c, gptr()[-1] )){ - return pbackfail(T::to_int_type(c)); - } - gbump(-1); - return T::to_int_type(*gptr()); - } + return sgetc(); + } - template typename basic_streambuf::int_type basic_streambuf::sungetc(){ - if(mgbeg == 0 || mgnext == mgbeg){ - return ios_base::failbit; - } - gbump(-1); - return T::to_int_type(*gptr()); - } + template typename basic_streambuf::int_type basic_streambuf::sgetc() + { + if (mgbeg == 0 || mgnext == mgend) + { + return underflow(); + } - template typename basic_streambuf::int_type basic_streambuf::sputc(char_type c){ - if(openedFor & ios_base::app){ - seekoff(0, ios_base::end, ios_base::out); - } - if(mpnext < mpend){ - *mpnext = c; - ++mpnext; - }else{ - return overflow( T::to_int_type(c) ); - } - return T::to_int_type(c); - } + return T::to_int_type(*gptr()); + } - template basic_streambuf::basic_streambuf() - : myLocale(), - mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0), - openedFor(0) - { } + template typename basic_streambuf::int_type basic_streambuf::sputbackc(char_type c) + { + if (mgbeg == 0 || mgnext == mgbeg || !T::eq(c, gptr()[-1])) + { + return pbackfail(T::to_int_type(c)); + } + gbump(-1); + return T::to_int_type(*gptr()); + } + template typename basic_streambuf::int_type basic_streambuf::sungetc() + { + if (mgbeg == 0 || mgnext == mgbeg) + { + return ios_base::failbit; + } + gbump(-1); + return T::to_int_type(*gptr()); + } + template typename basic_streambuf::int_type basic_streambuf::sputc(char_type c) + { + if (openedFor & ios_base::app) + { + seekoff(0, ios_base::end, ios_base::out); + } + if (mpnext < mpend) + { + *mpnext = c; + ++mpnext; + } + else + { + return overflow(T::to_int_type(c)); + } + + return T::to_int_type(c); + } + + template basic_streambuf::basic_streambuf() + : myLocale(), + mgbeg(0), mgnext(0), mgend(0), mpbeg(0), mpnext(0), mpend(0), + openedFor(0) + { } #ifdef __UCLIBCXX_EXPAND_STREAMBUF_CHAR__ #ifndef __UCLIBCXX_COMPILE_STREAMBUF__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT streambuf::basic_streambuf(); - template <> _UCXXEXPORT streambuf::~basic_streambuf(); + template <> _UCXXEXPORT streambuf::basic_streambuf(); + template <> _UCXXEXPORT streambuf::~basic_streambuf(); #endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template <> _UCXXEXPORT locale streambuf::pubimbue(const locale &loc); - template <> _UCXXEXPORT streamsize streambuf::in_avail(); - template <> _UCXXEXPORT streambuf::int_type streambuf::sbumpc(); - template <> _UCXXEXPORT streambuf::int_type streambuf::snextc(); - template <> _UCXXEXPORT streambuf::int_type streambuf::sgetc(); - template <> _UCXXEXPORT streambuf::int_type streambuf::sputbackc(char_type c); - template <> _UCXXEXPORT streambuf::int_type streambuf::sungetc(); - template <> _UCXXEXPORT streambuf::int_type streambuf::sputc(char_type c); + template <> _UCXXEXPORT locale streambuf::pubimbue(const locale &loc); + template <> _UCXXEXPORT streamsize streambuf::in_avail(); + template <> _UCXXEXPORT streambuf::int_type streambuf::sbumpc(); + template <> _UCXXEXPORT streambuf::int_type streambuf::snextc(); + template <> _UCXXEXPORT streambuf::int_type streambuf::sgetc(); + template <> _UCXXEXPORT streambuf::int_type streambuf::sputbackc(char_type c); + template <> _UCXXEXPORT streambuf::int_type streambuf::sungetc(); + template <> _UCXXEXPORT streambuf::int_type streambuf::sputc(char_type c); #endif #endif - - - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/string b/misc/uClibc++/include/uClibc++/string index f128e7e5ad..47c2a9d517 100644 --- a/misc/uClibc++/include/uClibc++/string +++ b/misc/uClibc++/include/uClibc++/string @@ -35,6 +35,8 @@ #pragma GCC visibility push(default) +extern "C++" +{ namespace std { // Basic basic_string @@ -1331,7 +1333,9 @@ template <> _UCXXEXPORT bool operator< (const string & lhs, const string & rhs); #endif #endif + } // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/string_iostream b/misc/uClibc++/include/uClibc++/string_iostream index 4ef3b600c5..46a9893c17 100644 --- a/misc/uClibc++/include/uClibc++/string_iostream +++ b/misc/uClibc++/include/uClibc++/string_iostream @@ -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 #include @@ -31,114 +31,124 @@ #pragma GCC visibility push(default) -namespace std{ - - +extern "C++" +{ +namespace std +{ template _UCXXEXPORT basic_ostream& - operator<<(basic_ostream& os, const basic_string& str) + operator<<(basic_ostream& os, const basic_string& str) { - return os.write(str.data(), str.length()); + return os.write(str.data(), str.length()); } template _UCXXEXPORT basic_istream& - operator>>(basic_istream& is, basic_string& str) + operator>>(basic_istream& is, basic_string& str) { + typename basic_istream::sentry s(is); + if(s == false) + { + return is; + } - typename basic_istream::sentry s(is); - if(s == false){ - return is; - } + str.clear(); - str.clear(); + typename basic_istream::int_type c; + typename Allocator::size_type n = is.width(); + bool exitnow = false; + if (n == 0) + { + n = str.max_size(); + } - typename basic_istream::int_type c; - typename Allocator::size_type n = is.width(); - bool exitnow = false; - if(n == 0){ - n = str.max_size(); - } - -// //Clear out preliminary spaces first -// c = is.get(); -// while(isspace(c)){ -// c = is.get(); -// } +// //Clear out preliminary spaces first +// c = is.get(); +// while(isspace(c)){ +// c = is.get(); +// } // -// is.putback(c); +// is.putback(c); - do{ - c = is.get(); - if(c == traits::eof() || isspace(c) || n == 0){ - is.putback(c); - exitnow = true; - }else{ - str.append(1, traits::to_char_type(c) ); - --n; - } - }while(exitnow == false); - return is; + do + { + c = is.get(); + if(c == traits::eof() || isspace(c) || n == 0) + { + is.putback(c); + exitnow = true; + } + else + { + str.append(1, traits::to_char_type(c) ); + --n; + } + } + while(exitnow == false); + + return is; } template _UCXXEXPORT basic_istream& - getline(basic_istream& is, basic_string& str, charT delim) + getline(basic_istream& is, basic_string& str, charT delim) { - typename basic_istream::sentry s(is); - if(s == false){ - return is; - } + typename basic_istream::sentry s(is); + if (s == false) + { + return is; + } - str.erase(); + str.erase(); - streamsize i = 0; - typename basic_istream::int_type c_i; - charT c; - unsigned int n = str.max_size(); - for(i=0;i::int_type c_i; + charT c; + unsigned int n = str.max_size(); + for (i = 0; i < n; ++i) + { + c_i=is.get(); + if (c_i == traits::eof() ) + { + return is; + } + + c = traits::to_char_type(c_i); + if (c == delim) + { + return is; + } + + str.append(1, c); + } + return is; } template _UCXXEXPORT basic_istream& - getline(basic_istream& is, basic_string& str) + getline(basic_istream& is, basic_string& str) { - return getline(is, str, '\n'); + return getline(is, str, '\n'); } - #ifdef __UCLIBCXX_EXPAND_STRING_CHAR__ #ifndef __UCLIBCXX_COMPILE_STRING__ - #ifdef __UCLIBCXX_EXPAND_ISTREAM_CHAR__ template<> _UCXXEXPORT basic_istream >& operator>>( - basic_istream >& is, - basic_string, allocator >& str); + basic_istream >& is, + basic_string, allocator >& str); #endif - #ifdef __UCLIBCXX_EXPAND_OSTREAM_CHAR__ template<> _UCXXEXPORT basic_ostream >& - operator<<(basic_ostream >& os, - const basic_string, std::allocator >& str); + operator<<(basic_ostream >& os, + const basic_string, std::allocator >& str); #endif - #endif #endif - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/type_traits b/misc/uClibc++/include/uClibc++/type_traits index fa1de40cee..2a599f78b4 100644 --- a/misc/uClibc++/include/uClibc++/type_traits +++ b/misc/uClibc++/include/uClibc++/type_traits @@ -1,20 +1,20 @@ -/* Copyright (C) 2005 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) 2005 Garrett A. Kajmowicz + * + * This file is part of the uClibc++ Library. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ #include #include @@ -27,64 +27,75 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + struct _UCXXEXPORT __true_type{}; + struct _UCXXEXPORT __false_type{}; - struct _UCXXEXPORT __true_type{}; - struct _UCXXEXPORT __false_type{}; + template class _UCXXEXPORT __is_integer + { + public: + typedef __false_type value; + }; - template class _UCXXEXPORT __is_integer{ - public: - typedef __false_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; + template <> class _UCXXEXPORT __is_integer + { + public: + typedef __true_type value; + }; - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - - -} +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/utility b/misc/uClibc++/include/uClibc++/utility index b654679248..f5cb59f2f7 100644 --- a/misc/uClibc++/include/uClibc++/utility +++ b/misc/uClibc++/include/uClibc++/utility @@ -1,88 +1,107 @@ -/* 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 - #ifndef __STD_HEADER_UTILITY #define __STD_HEADER_UTILITY 1 #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ - namespace rel_ops { - template inline bool operator!=(const T& x, const T& y){ - return !(x == y); - } +namespace std +{ + namespace rel_ops + { + template inline bool operator!=(const T& x, const T& y) + { + return !(x == y); + } - template inline bool operator> (const T& x, const T& y){ - return ( y < x); - } + template inline bool operator> (const T& x, const T& y) + { + return ( y < x); + } - template inline bool operator<=(const T& x, const T& y){ - return !( y < x ); - } + template inline bool operator<=(const T& x, const T& y) + { + return !( y < x ); + } - template inline bool operator>=(const T& x, const T& y){ - return !(x < y); - } - } + template inline bool operator>=(const T& x, const T& y) + { + return !(x < y); + } + } // namespace - template struct _UCXXEXPORT pair { - typedef T1 first_type; - typedef T2 second_type; + template struct _UCXXEXPORT pair + { + typedef T1 first_type; + typedef T2 second_type; - T1 first; - T2 second; - pair() : first(), second() { } - pair(const T1& x, const T2& y) : first(x), second(y) { } - template pair(const pair &p) : first(p.first), second(p.second) { } - }; - - template bool operator==(const pair& x, const pair& y){ - using namespace rel_ops; - return (x.first == y.first && x.second==y.second); - } - template bool operator< (const pair& x, const pair& y){ - return x.first < y.first || (!(y.first < x.first) && x.second < y.second); - } - template bool operator!=(const pair& x, const pair& y){ - return !(x == y); - } - template bool operator> (const pair& x, const pair& y){ - return y < x; - } - template bool operator>=(const pair& x, const pair& y){ - return !(x < y); - } - template bool operator<=(const pair& x, const pair& y){ - return !(y < x); - } - template pair make_pair(const T1& x, const T2& y){ - return pair(x, y); - } + T1 first; + T2 second; + pair() : first(), second() { } + pair(const T1& x, const T2& y) : first(x), second(y) { } + template pair(const pair &p) : first(p.first), second(p.second) { } + }; + + template bool operator==(const pair& x, const pair& y) + { + using namespace rel_ops; + return (x.first == y.first && x.second==y.second); + } + template bool operator< (const pair& x, const pair& y) + { + return x.first < y.first || (!(y.first < x.first) && x.second < y.second); + } -} + template bool operator!=(const pair& x, const pair& y) + { + return !(x == y); + } + + template bool operator> (const pair& x, const pair& y) + { + return y < x; + } + + template bool operator>=(const pair& x, const pair& y) + { + return !(x < y); + } + + template bool operator<=(const pair& x, const pair& y) + { + return !(y < x); + } + + template pair make_pair(const T1& x, const T2& y) + { + return pair(x, y); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop -#endif //__STD_HEADER_UTILITY +#endif //__STD_HEADER_UTILITY diff --git a/misc/uClibc++/include/uClibc++/valarray b/misc/uClibc++/include/uClibc++/valarray index 09d929c49e..f28ad58745 100644 --- a/misc/uClibc++/include/uClibc++/valarray +++ b/misc/uClibc++/include/uClibc++/valarray @@ -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 @@ -27,1015 +27,1550 @@ #pragma GCC visibility push(default) -namespace std{ +extern "C++" +{ +namespace std +{ + template class valarray; + class slice; + template class slice_array; + class gslice; + template class gslice_array; + template class mask_array; + template class indirect_array; - template class valarray; - class slice; - template class slice_array; - class gslice; - template class gslice_array; - template class mask_array; - template class indirect_array; + // Actual class definitions - //Actual class definitions + class _UCXXEXPORT slice{ + protected: + size_t sta; + size_t siz; + size_t str; + public: + slice() : sta(0), siz(0), str(0){ } + slice(size_t a, size_t b, size_t c) : sta(a), siz(b), str(c) { } + slice(const slice& s) : sta(s.sta), siz(s.siz), str(s.str) { } + ~slice() { } - class _UCXXEXPORT slice { - protected: - size_t sta; - size_t siz; - size_t str; + size_t start() const + { + return sta; + } - public: - slice() : sta(0), siz(0), str(0){ } - slice(size_t a, size_t b, size_t c) : sta(a), siz(b), str(c) { } - slice(const slice& s) : sta(s.sta), siz(s.siz), str(s.str) { } - ~slice() { } - size_t start() const{ - return sta; - } - size_t size() const{ - return siz; - } - size_t stride() const{ - return str; - } - }; + size_t size() const + { + return siz; + } + size_t stride() const + { + return str; + } + }; + template class _UCXXEXPORT valarray + { + friend class slice_array; + protected: + T * data; + size_t length; - template class _UCXXEXPORT valarray { - friend class slice_array; - protected: - T * data; - size_t length; + public: + typedef T value_type; - public: - typedef T value_type; + valarray() : data(0), length(0) { } - valarray() : data(0), length(0) { } + explicit valarray(size_t t) : data(0), length(t) + { + data = new T[length]; + } - explicit valarray(size_t t) : data(0), length(t){ - data = new T[length]; - } + valarray(const T& v, size_t t) : data(0), length(t) + { + data = new T[length]; + for (size_t i = 0; i < length; ++i) + { + data[i] = v; + } + } - valarray(const T& v, size_t t) : data(0), length(t){ - data = new T[length]; - for(size_t i = 0; i < length; ++i){ - data[i] = v; - } - } - valarray(const T* p, size_t t) : data(0), length(t) { - data = new T[length]; - for(size_t i = 0; i < length; ++i){ - data[i] = p[i]; - } - } - valarray(const valarray& v) : data(0), length(v.length){ - data = new T[length]; - for(size_t i = 0; i < length; ++i){ - data[i] = v.data[i]; - } - } - valarray(const slice_array & sa) : data(0), length(sa.s.size()){ - data = new T[length]; - for(unsigned int i = 0; i < length; ++i){ - data[i] = sa.array->data[sa.s.start() + i * sa.s.stride()]; - } - } - valarray(const gslice_array&); - valarray(const mask_array&); - valarray(const indirect_array&); - ~valarray(){ - delete [] data; - data = 0; - length = 0; - } + valarray(const T* p, size_t t) : data(0), length(t) + { + data = new T[length]; + for (size_t i = 0; i < length; ++i){ + data[i] = p[i]; + } + } - valarray& operator=(const valarray& v){ - if (length != v.length) { // DR 630 - delete [] data; - length = v.length; - data = new T[length]; - } - for (size_t i = 0; i < length; ++i) { - data[i] = v.data[i]; - } - return *this; - } - valarray& operator=(const T& t){ - for(size_t i = 0; i < length; ++i){ - data[i] = t; - } - return *this; - } - valarray& operator=(const slice_array& sa){ - for(size_t i =0; i < length; ++i){ - data[i] = sa.data[sa.s.start() + i * sa.s.stride()]; - } - return *this; - } - valarray& operator=(const gslice_array&); - valarray& operator=(const mask_array&); - valarray& operator=(const indirect_array&); + valarray(const valarray& v) : data(0), length(v.length) + { + data = new T[length]; + for (size_t i = 0; i < length; ++i) + { + data[i] = v.data[i]; + } + } - const T& operator[](size_t t) const{ - return data[t]; - } - T& operator[](size_t t){ - return data[t]; - } + valarray(const slice_array & sa) : data(0), length(sa.s.size()) + { + data = new T[length]; + for (unsigned int i = 0; i < length; ++i) + { + data[i] = sa.array->data[sa.s.start() + i * sa.s.stride()]; + } + } - valarray operator[](slice s) const{ - valarray retval(s.size()); - for(unsigned int i = 0; i< s.size(); ++i){ - retval.data[i] = data[s.start() + i * s.stride()]; - } - return retval; - } + valarray(const gslice_array&); + valarray(const mask_array&); + valarray(const indirect_array&); - slice_array operator[](slice sl){ - slice_array retval; - retval.s = sl; - retval.array = this; - return retval; - } + ~valarray() + { + delete [] data; + data = 0; + length = 0; + } - valarray operator[](const gslice&) const; - gslice_array operator[](const gslice&); - valarray operator[](const valarray&) const; - mask_array operator[](const valarray&); - valarray operator[](const valarray&) const; - indirect_array operator[](const valarray&); + valarray& operator=(const valarray& v) + { + if (length != v.length) + { + // DR 630 + + delete [] data; + length = v.length; + data = new T[length]; + } + + for (size_t i = 0; i < length; ++i) + { + data[i] = v.data[i]; + } + + return *this; + } + + valarray& operator=(const T& t) + { + for (size_t i = 0; i < length; ++i) + { + data[i] = t; + } + + return *this; + } + + valarray& operator=(const slice_array& sa) + { + for (size_t i =0; i < length; ++i) + { + data[i] = sa.data[sa.s.start() + i * sa.s.stride()]; + } + + return *this; + } + + valarray& operator=(const gslice_array&); + valarray& operator=(const mask_array&); + valarray& operator=(const indirect_array&); + + const T& operator[](size_t t) const + { + return data[t]; + } + + T& operator[](size_t t) + { + return data[t]; + } + + valarray operator[](slice s) const + { + valarray retval(s.size()); + for (unsigned int i = 0; i< s.size(); ++i) + { + retval.data[i] = data[s.start() + i * s.stride()]; + } + + return retval; + } + + slice_array operator[](slice sl) + { + slice_array retval; + retval.s = sl; + retval.array = this; + return retval; + } + + valarray operator[](const gslice&) const; + gslice_array operator[](const gslice&); + valarray operator[](const valarray&) const; + mask_array operator[](const valarray&); + valarray operator[](const valarray&) const; + indirect_array operator[](const valarray&); + + valarray operator+() const + { + valarray retval(length); + for (size_t i = 0; i< length ; ++i) + { + retval.data[i] = +data[i]; + } + + return retval; + } + + valarray operator-() const + { + valarray retval(length); + for (size_t i = 0; i< length; ++i) + { + retval.data[i] = -data[i]; + } + + return retval; + } + + valarray operator~() const + { + valarray retval(length); + for (size_t i = 0; i< length ; ++i) + { + retval.data[i] = ~data[i]; + } + + return retval; + } + + valarray operator!() const + { + valarray retval(length); + for (size_t i = 0; i < length ; ++i) + { + retval[i] = !data[i]; + } + + return retval; + } + + valarray& operator*= (const T& t) + { + for (size_t i=0;i& operator/= (const T& t) + { + for (size_t i=0; i& operator%= (const T& t) + { + for (size_t i=0; i& operator+= (const T& t + ){ + for (size_t i=0; i& operator-= (const T& t) + { + for (size_t i=0; i& operator^= (const T& t) + { + for (size_t i=0; i& operator&= (const T& t) + { + for (size_t i=0; i& operator|= (const T& t) + { + for (size_t i=0; i& operator<<=(const T& t) + { + for (size_t i=0; i& operator>>=(const T& t) + { + for (size_t i=0; i>= t; + } + + return *this; + } + + valarray& operator*= (const valarray& a) + { + for (size_t i=0; i& operator/= (const valarray& a) + { + for (size_t i=0; i& operator%= (const valarray& a) + { + for (size_t i=0; i& operator+= (const valarray& a) + { + for (size_t i=0; i& operator-= (const valarray& a) + { + for (size_t i=0; i& operator^= (const valarray& a) + { + for (size_t i=0; i& operator|= (const valarray& a) + { + for (size_t i=0; i& operator&= (const valarray& a) + { + for (size_t i=0; i& operator<<=(const valarray& a) + { + for (size_t i=0; i& operator>>=(const valarray& a) + { + for (size_t i=0; i>= a.data[i]; + } + + return *this; + } - valarray operator+() const{ - valarray retval(length); - for(size_t i = 0; i< length ; ++i){ - retval.data[i] = +data[i]; - } - return retval; - } - valarray operator-() const{ - valarray retval(length); - for(size_t i = 0; i< length; ++i){ - retval.data[i] = -data[i]; - } - return retval; - } - valarray operator~() const{ - valarray retval(length); - for(size_t i = 0; i< length ; ++i){ - retval.data[i] = ~data[i]; - } - return retval; - } - valarray operator!() const{ - valarray retval(length); - for (size_t i = 0; i < length ; ++i){ - retval[i] = !data[i]; - } - return retval; - } - valarray& operator*= (const T& t){ - for(size_t i=0;i& operator/= (const T& t){ - for(size_t i=0;i& operator%= (const T& t){ - for(size_t i=0;i& operator+= (const T& t){ - for(size_t i=0;i& operator-= (const T& t){ - for(size_t i=0;i& operator^= (const T& t){ - for(size_t i=0;i& operator&= (const T& t){ - for(size_t i=0;i& operator|= (const T& t){ - for(size_t i=0;i& operator<<=(const T& t){ - for(size_t i=0;i& operator>>=(const T& t){ - for(size_t i=0;i>= t; - } - return *this; - } - valarray& operator*= (const valarray& a){ - for(size_t i=0;i& operator/= (const valarray& a){ - for(size_t i=0;i& operator%= (const valarray& a){ - for(size_t i=0;i& operator+= (const valarray& a){ - for(size_t i=0;i& operator-= (const valarray& a){ - for(size_t i=0;i& operator^= (const valarray& a){ - for(size_t i=0;i& operator|= (const valarray& a){ - for(size_t i=0;i& operator&= (const valarray& a){ - for(size_t i=0;i& operator<<=(const valarray& a){ - for(size_t i=0;i& operator>>=(const valarray& a){ - for(size_t i=0;i>= a.data[i]; - } - return *this; - } #if 0 - void swap(valarray& other) noexcept { - std::swap(length, other.length); - std::swap(data, other.data); - } + void swap(valarray& other) noexcept + { + std::swap(length, other.length); + std::swap(data, other.data); + } #endif - size_t size() const{ - return length; - } - T sum() const{ - T retval(data[0]); - for(size_t i = 1; i< length; ++i){ - retval += data[i]; - } - return retval; - } + size_t size() const + { + return length; + } - T min() const{ - T retval(data[0]); - for(size_t i = 1; i< length; ++i){ - if(data[i] < retval){ - retval = data[i]; - } - } - return retval; - } + T sum() const + { + T retval(data[0]); - T max() const{ - T retval(data[0]); - for(size_t i = 1; i< length; ++i){ - if(retval < data[i]){ - retval = data[i]; - } - } - return retval; - } + for (size_t i = 1; i< length; ++i) + { + retval += data[i]; + } - valarray shift (int n) const{ - valarray retval(length); - if (n < 0) { - if (-size_t(n) > length) - n = -int(length); - } else { - if (size_t(n) > length) - n = int(length); - } - for (size_t i = 0; i < length ; ++i) { - if ((n + i) < length) - retval.data[i] = data[n + i]; - } - return retval; - } - valarray cshift(int n) const{ - valarray retval(length); - if (length == 0) - return retval; - if (n < 0) { - if (-size_t(n) > length) - n = -int(-size_t(n) % length); - n = length + n; - } else { - if (size_t(n) > length) - n = int(size_t(n) % length); - } - for (size_t i = 0; i < length ; ++i){ - retval.data[i] = data[(n + i) % length]; - } - return retval; - } - valarray apply(T func(T) ) const{ - valarray retval(length); - for(size_t i = 0; i< length; ++i){ - retval.data[i] = func(data[i]); - } - return retval; - } - valarray apply(T func(const T&)) const{ - valarray retval(length); - for(size_t i = 0; i< length; ++i){ - retval.data[i] = func(data[i]); - } - return retval; - } - void resize(size_t sz, T c = T()){ - delete [] data; - data = 0; - if(sz > 0){ - data = new T[sz]; - for(size_t i = 0; i < sz; ++i){ - data[i] = c; - } - } - length = sz; - } - }; + return retval; + } + T min() const + { + T retval(data[0]); + for (size_t i = 1; i< length; ++i) + { + if (data[i] < retval) + { + retval = data[i]; + } + } - template class _UCXXEXPORT slice_array { - friend class valarray; - public: - typedef T value_type; + return retval; + } - void operator= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] = v[i]; - } - } - void operator= (const T & v){ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] = v; - } - } - void fill(const T & v){ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] = v; - } - } - void operator*= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] *= v[i]; - } - } - void operator/= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] /= v[i]; - } - } - void operator%= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] %= v[i]; - } - } - void operator+= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] += v[i]; - } - } - void operator-= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] -= v[i]; - } - } - void operator^= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] ^= v[i]; - } - } - void operator&= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] &= v[i]; - } - } - void operator|= (const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] |= v[i]; - } - } - void operator<<=(const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] <<= v[i]; - } - } - void operator>>=(const valarray& v) const{ - for(unsigned int i = 0; i < s.size(); ++i){ - array->data[s.start() + i * s.stride()] >>= v[i]; - } - } - ~slice_array(){ - array = 0; - } + T max() const + { + T retval(data[0]); - private: - slice_array() : array(0){ } + for (size_t i = 1; i< length; ++i) + { + if (retval < data[i]) + { + retval = data[i]; + } + } - public: - slice_array(const slice_array& sa) : array(sa.array), s(sa.s){ } - slice_array& operator=(const slice_array& sa){ - array = sa.array; - s = sa.s; - return *this; - } + return retval; + } - private: - valarray * array; - slice s; - }; + valarray shift (int n) const + { + valarray retval(length); + if (n < 0) + { + if (-size_t(n) > length) + { + n = -int(length); + } + } + else + { + if (size_t(n) > length) + { + n = int(length); + } + } - class _UCXXEXPORT gslice { - private: - size_t sta; - valarray siz; - valarray str; + for (size_t i = 0; i < length ; ++i) + { + if ((n + i) < length) + { + retval.data[i] = data[n + i]; + } + } - public: - gslice() : sta(0), siz(), str() { } // DR 543 - gslice(size_t s, const valarray& l, const valarray& d) - : sta(s), siz(l), str(d) { } + return retval; + } - size_t start() const{ - return sta; - } - valarray size() const{ - return siz; - } - valarray stride() const{ - return str; - } - }; + valarray cshift(int n) const + { + valarray retval(length); - template class gslice_array { - private: - friend class valarray; + if (length == 0) + { + return retval; + } - public: - ~gslice_array(); + if (n < 0) + { + if (-size_t(n) > length) + { + n = -int(-size_t(n) % length); + } - void operator=(const valarray& array) const; - void operator*=(const valarray& array) const; - void operator/=(const valarray& array) const; - void operator%=(const valarray& array) const; - void operator+=(const valarray& array) const; - void operator-=(const valarray& array) const; - void operator^=(const valarray& array) const; - void operator&=(const valarray& array) const; - void operator|=(const valarray& array) const; - void operator<<=(const valarray& array) const; - void operator>>=(const valarray& array) const; + n = length + n; + } + else + { + if (size_t(n) > length) + { + n = int(size_t(n) % length); + } + } + + for (size_t i = 0; i < length ; ++i) + { + retval.data[i] = data[(n + i) % length]; + } + + return retval; + } + + valarray apply(T func(T)) const + { + valarray retval(length); + + for (size_t i = 0; i< length; ++i) + { + retval.data[i] = func(data[i]); + } + + return retval; + } + + valarray apply(T func(const T&)) const + { + valarray retval(length); + + for (size_t i = 0; i< length; ++i) + { + retval.data[i] = func(data[i]); + } + + return retval; + } + + void resize(size_t sz, T c = T()) + { + delete [] data; + + data = 0; + if (sz > 0) + { + data = new T[sz]; + + for (size_t i = 0; i < sz; ++i) + { + data[i] = c; + } + } + + length = sz; + } + }; + + template class _UCXXEXPORT slice_array + { + friend class valarray; + public: + typedef T value_type; + + void operator= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] = v[i]; + } + } + + void operator= (const T & v) + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] = v; + } + } + + void fill(const T & v) + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] = v; + } + } + + void operator*= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] *= v[i]; + } + } + + void operator/= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] /= v[i]; + } + } + + void operator%= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] %= v[i]; + } + } + + void operator+= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] += v[i]; + } + } + + void operator-= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] -= v[i]; + } + } + + void operator^= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] ^= v[i]; + } + } + + void operator&= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] &= v[i]; + } + } + + void operator|= (const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] |= v[i]; + } + } + + void operator<<=(const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] <<= v[i]; + } + } + + void operator>>=(const valarray& v) const + { + for (unsigned int i = 0; i < s.size(); ++i) + { + array->data[s.start() + i * s.stride()] >>= v[i]; + } + } + + ~slice_array() + { + array = 0; + } + + private: + slice_array() : array(0){ } + + public: + slice_array(const slice_array& sa) : array(sa.array), s(sa.s){ } + + slice_array& operator=(const slice_array& sa) + { + array = sa.array; + s = sa.s; + return *this; + } + + private: + valarray * array; + slice s; + }; + + class _UCXXEXPORT gslice + { + private: + size_t sta; + valarray siz; + valarray str; + + public: + gslice() : sta(0), siz(), str() { } // DR 543 + gslice(size_t s, const valarray& l, const valarray& d) + : sta(s), siz(l), str(d) { } + + size_t start() const + { + return sta; + } + + valarray size() const + { + return siz; + } + + valarray stride() const + { + return str; + } + }; + + template class gslice_array + { + private: + friend class valarray; + + public: + ~gslice_array(); + + void operator=(const valarray& array) const; + void operator*=(const valarray& array) const; + void operator/=(const valarray& array) const; + void operator%=(const valarray& array) const; + void operator+=(const valarray& array) const; + void operator-=(const valarray& array) const; + void operator^=(const valarray& array) const; + void operator&=(const valarray& array) const; + void operator|=(const valarray& array) const; + void operator<<=(const valarray& array) const; + void operator>>=(const valarray& array) const; - void operator=(const T&); + void operator=(const T&); - private: - gslice_array(); - gslice_array(const gslice_array&); - gslice_array& operator= (const gslice_array& array); - }; + private: + gslice_array(); + gslice_array(const gslice_array&); + gslice_array& operator= (const gslice_array& array); + }; + template valarray operator* (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval *= rhs; + return retval; + } + template valarray operator* (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval *= rhs; + return retval; + } - template valarray operator* (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval *= rhs; - return retval; - } + template valarray operator* (const T& lhs, const valarray& rhs) + { + valarray retval(rhs); + retval *= lhs; + return retval; + } - template valarray operator* (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval *= rhs; - return retval; - } - template valarray operator* (const T& lhs, const valarray& rhs){ - valarray retval(rhs); - retval *= lhs; - return retval; - } - template valarray operator/ (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval /= rhs; - return retval; - } - template valarray operator/ (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval /= rhs; - return retval; - } - template valarray operator/ (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval /= rhs; - return retval; - } - template valarray operator% (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval %= rhs; - return retval; - } - template valarray operator% (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval %= rhs; - return retval; - } - template valarray operator% (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval %= rhs; - return retval; - } - template valarray operator+ (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval += rhs; - return retval; - } - template valarray operator+ (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval += rhs; - return retval; - } - template valarray operator+ (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval += rhs; - return retval; - } - template valarray operator- (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval -= rhs; - return retval; - } - template valarray operator- (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval -= rhs; - return retval; - } - template valarray operator- (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval -= rhs; - return retval; - } - template valarray operator^ (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval ^= rhs; - return retval; - } - template valarray operator^ (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval ^= rhs; - return retval; - } - template valarray operator^ (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval ^= rhs; - return retval; - } - template valarray operator& (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval &= rhs; - return retval; - } - template valarray operator& (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval &= rhs; - return retval; - } - template valarray operator& (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval &= rhs; - return retval; - } - template valarray operator| (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval |= rhs; - return retval; - } - template valarray operator| (const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval |= rhs; - return retval; - } - template valarray operator| (const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval |= rhs; - return retval; - } - template valarray operator<<(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval <<= rhs; - return retval; - } - template valarray operator<<(const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval <<= rhs; - return retval; - } - template valarray operator<<(const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval <<= rhs; - return retval; - } - template valarray operator>>(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs); - retval >>= rhs; - return retval; - } - template valarray operator>>(const valarray& lhs, const T& rhs){ - valarray retval(lhs); - retval >>= rhs; - return retval; - } - template valarray operator>>(const T& lhs, const valarray& rhs){ - valarray retval(lhs, rhs.size()); - retval >>= rhs; - return retval; - } + template valarray operator/ (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval /= rhs; + return retval; + } - template valarray operator&&(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = lhs[i] && rhs[i]; - } - return retval; - } - template valarray operator&&(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator&&(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i valarray operator||(const valarray&lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator||(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator||(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = lhs || rhs[i]; - } - return retval; - } + template valarray operator/ (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval /= rhs; + return retval; + } - template valarray operator==(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator==(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = lhs[i] == rhs; - } - return retval; - } - template valarray operator==(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = lhs == rhs[i]; - } - return retval; - } - template valarray operator!=(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator!=(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator!=(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i valarray operator< (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator< (const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator< (const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i valarray operator> (const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i rhs[i]; - } - return retval; - } - template valarray operator> (const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i rhs; - } - return retval; - } - template valarray operator> (const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i rhs[i]; - } - return retval; - } - template valarray operator<=(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator<=(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i valarray operator<=(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i valarray operator>=(const valarray& lhs, const valarray& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i = rhs[i]; - } - return retval; - } - template valarray operator>=(const valarray& lhs, const T& rhs){ - valarray retval(lhs.size()); - for(size_t i = 0; i = rhs; - } - return retval; - } - template valarray operator>=(const T& lhs, const valarray& rhs){ - valarray retval(rhs.size()); - for(size_t i = 0; i = rhs[i]; - } - return retval; - } - template T min(const valarray& x){ - T retval(x[0]); - for(size_t i = 1; i < x.size(); ++i){ - if(x[i] < retval){ - retval = x[i]; - } - } - } - template T max(const valarray& x){ - T retval(x[0]); - for(size_t i = 1; i < x.size(); ++i){ - if(x[i] > retval){ - retval = x[i]; - } - } - } + template valarray operator/ (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval /= rhs; + return retval; + } - template valarray abs (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = abs(x[i]); - } - return retval; - } - template valarray acos (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = acos(x[i]); - } - return retval; - } - template valarray asin (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = asin(x[i]); - } - return retval; - } - template valarray atan (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = atan(x[i]); - } - return retval; - } - template valarray atan2(const valarray& y, const valarray& x){ - valarray retval(y.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = atan2(y[i], x[i]); - } - return retval; - } - template valarray atan2(const valarray& y, const T& x){ - valarray retval(y.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = atan2(y[i], x); - } - return retval; - } - template valarray atan2(const T& y, const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = atan2(y, x[i]); - } - return retval; - } - template valarray cos (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = cos(x[i]); - } - return retval; - } - template valarray cosh (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = cosh(x[i]); - } - return retval; - } - template valarray exp (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = exp(x[i]); - } - return retval; - } - template valarray log (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = log(x[i]); - } - return retval; - } - template valarray log10(const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = log10(x[i]); - } - return retval; - } - template valarray pow (const valarray& x, const valarray& y){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = pow(x[i], y[i]); - } - return retval; - } - template valarray pow (const valarray& x, const T& y){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = pow(x[i], y); - } - return retval; - } - template valarray pow (const T& x, const valarray& y){ - valarray retval(y.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = pow(x, y[i]); - } - return retval; - } - template valarray sin (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = sin(x[i]); - } - return retval; - } - template valarray sinh (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = sinh(x[i]); - } - return retval; - } - template valarray sqrt (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = sqrt(x[i]); - } - return retval; - } - template valarray tan (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = tan(x[i]); - } - return retval; - } - template valarray tanh (const valarray& x){ - valarray retval(x.size()); - for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = tanh(x[i]); - } - return retval; - } -} + template valarray operator% (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval %= rhs; + return retval; + } + + template valarray operator% (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval %= rhs; + return retval; + } + + template valarray operator% (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval %= rhs; + return retval; + } + + template valarray operator+ (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval += rhs; + return retval; + } + + template valarray operator+ (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval += rhs; + return retval; + } + + template valarray operator+ (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval += rhs; + return retval; + } + + template valarray operator- (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval -= rhs; + return retval; + } + + template valarray operator- (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval -= rhs; + return retval; + } + + template valarray operator- (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval -= rhs; + return retval; + } + + template valarray operator^ (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval ^= rhs; + return retval; + } + + template valarray operator^ (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval ^= rhs; + return retval; + } + + template valarray operator^ (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval ^= rhs; + return retval; + } + + template valarray operator& (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval &= rhs; + return retval; + } + + template valarray operator& (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval &= rhs; + return retval; + } + + template valarray operator& (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval &= rhs; + return retval; + } + + template valarray operator| (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval |= rhs; + return retval; + } + + template valarray operator| (const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval |= rhs; + return retval; + } + + template valarray operator| (const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval |= rhs; + return retval; + } + + template valarray operator<<(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval <<= rhs; + return retval; + } + + template valarray operator<<(const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval <<= rhs; + return retval; + } + + template valarray operator<<(const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval <<= rhs; + return retval; + } + + template valarray operator>>(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs); + retval >>= rhs; + return retval; + } + + template valarray operator>>(const valarray& lhs, const T& rhs) + { + valarray retval(lhs); + retval >>= rhs; + return retval; + } + + template valarray operator>>(const T& lhs, const valarray& rhs) + { + valarray retval(lhs, rhs.size()); + retval >>= rhs; + return retval; + } + + template valarray operator&&(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = lhs[i] && rhs[i]; + } + + return retval; + } + + template valarray operator&&(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator&&(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i valarray operator||(const valarray&lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator||(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator||(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = lhs || rhs[i]; + } + + return retval; + } + + template valarray operator==(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator==(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = lhs[i] == rhs; + } + + return retval; + } + + template valarray operator==(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = lhs == rhs[i]; + } + + return retval; + } + + template valarray operator!=(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator!=(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator!=(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i valarray operator< (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator< (const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator< (const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i valarray operator> (const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i rhs[i]; + } + + return retval; + } + + template valarray operator> (const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i rhs; + } + + return retval; + } + + template valarray operator> (const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i rhs[i]; + } + + return retval; + } + + template valarray operator<=(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator<=(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i valarray operator<=(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i valarray operator>=(const valarray& lhs, const valarray& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i = rhs[i]; + } + + return retval; + } + + template valarray operator>=(const valarray& lhs, const T& rhs) + { + valarray retval(lhs.size()); + + for (size_t i = 0; i = rhs; + } + + return retval; + } + + template valarray operator>=(const T& lhs, const valarray& rhs) + { + valarray retval(rhs.size()); + + for (size_t i = 0; i = rhs[i]; + } + + return retval; + } + + template T min(const valarray& x) + { + T retval(x[0]); + + for (size_t i = 1; i < x.size(); ++i) + { + if (x[i] < retval) + { + retval = x[i]; + } + } + } + + template T max(const valarray& x) + { + T retval(x[0]); + + for (size_t i = 1; i < x.size(); ++i) + { + if (x[i] > retval) + { + retval = x[i]; + } + } + } + + template valarray abs (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = abs(x[i]); + } + + return retval; + } + + template valarray acos (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = acos(x[i]); + } + + return retval; + } + + template valarray asin (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = asin(x[i]); + } + + return retval; + } + + template valarray atan (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = atan(x[i]); + } + + return retval; + } + + template valarray atan2(const valarray& y, const valarray& x) + { + valarray retval(y.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = atan2(y[i], x[i]); + } + + return retval; + } + + template valarray atan2(const valarray& y, const T& x) + { + valarray retval(y.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = atan2(y[i], x); + } + + return retval; + } + + template valarray atan2(const T& y, const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = atan2(y, x[i]); + } + + return retval; + } + + template valarray cos (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = cos(x[i]); + } + + return retval; + } + + template valarray cosh (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = cosh(x[i]); + } + + return retval; + } + + template valarray exp (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = exp(x[i]); + } + + return retval; + } + + template valarray log (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = log(x[i]); + } + + return retval; + } + + template valarray log10(const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = log10(x[i]); + } + + return retval; + } + + template valarray pow (const valarray& x, const valarray& y) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = pow(x[i], y[i]); + } + + return retval; + } + + template valarray pow (const valarray& x, const T& y) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = pow(x[i], y); + } + + return retval; + } + + template valarray pow (const T& x, const valarray& y) + { + valarray retval(y.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = pow(x, y[i]); + } + + return retval; + } + + template valarray sin (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = sin(x[i]); + } + + return retval; + } + + template valarray sinh (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = sinh(x[i]); + } + + return retval; + } + + template valarray sqrt (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = sqrt(x[i]); + } + + return retval; + } + + template valarray tan (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i){ + retval[i] = tan(x[i]); + } + + return retval; + } + + template valarray tanh (const valarray& x) + { + valarray retval(x.size()); + + for (size_t i = 0; i < retval.size(); ++i) + { + retval[i] = tanh(x[i]); + } + + return retval; + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/include/uClibc++/vector b/misc/uClibc++/include/uClibc++/vector index 8310bc14e3..88adbd0117 100644 --- a/misc/uClibc++/include/uClibc++/vector +++ b/misc/uClibc++/include/uClibc++/vector @@ -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 #include @@ -25,491 +24,582 @@ #include #include - #ifndef __STD_HEADER_VECTOR #define __STD_HEADER_VECTOR #pragma GCC visibility push(default) -namespace std{ - - template > class vector; - template bool operator==(const vector& x, const vector& y); - template bool operator< (const vector& x, const vector& y); - template bool operator!=(const vector& x, const vector& y); - template bool operator> (const vector& x, const vector& y); - template bool operator>=(const vector& x, const vector& y); - template bool operator<=(const vector& x, const vector& y); - template void swap(vector& x, vector& y); - - template class _UCXXEXPORT vector { - public: - - typedef typename Allocator::reference reference; - typedef typename Allocator::const_reference const_reference; - typedef typename Allocator::size_type size_type; - typedef typename Allocator::difference_type difference_type; - typedef typename Allocator::pointer pointer; - typedef typename Allocator::const_pointer const_pointer; - - typedef T* iterator; - typedef const T* const_iterator; - typedef T value_type; - typedef Allocator allocator_type; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - explicit _UCXXEXPORT vector(const Allocator& al= Allocator()): data(0), //defaultValue(T()), - data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) - { - data = a.allocate(data_size); - } - - explicit _UCXXEXPORT vector(size_type n, const T& value = T(), const Allocator& al= Allocator()) : - data(0), data_size(0), elements(0), a(al) - { - data_size = n + __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - - resize(n, value); - } - - template _UCXXEXPORT - vector(InputIterator first, InputIterator last, const Allocator& al = Allocator()): - data(0), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) - { - data = a.allocate(data_size); - assign(first, last); - } - - _UCXXEXPORT vector(const vector& x){ - a = x.a; - - elements = x.elements; - data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__; - data = a.allocate(data_size); - - for(size_type i = 0; i < elements; i++){ - a.construct(data+i, x.data[i]); - } - } - - _UCXXEXPORT ~vector(); //Below - - _UCXXEXPORT vector& operator=(const vector& x){ - if(&x == this){ - return *this; - } - - reserve(x.elements); //Make sure that we have enough actual memory - - - //Copy as many elements as possible - - size_t minElements = elements; - if(minElements > x.elements){ - minElements = x.elements; - } - for(size_t i = 0; i < minElements; ++i){ - data[i] = x.data[i]; - } - - //If we need to add new elements - if(elements < x.elements){ - for(size_t i = elements; i< x.elements; ++i){ - a.construct(data+i, x.data[i]); - ++elements; - } - } - - if(elements > x.elements){ - downsize(x.elements); - } - - return *this; - } - - template _UCXXEXPORT void assign(InputIterator first, InputIterator last){ - clear(); - insert(begin(), first, last); - } - - template _UCXXEXPORT void assign(Size n, const U& u = U()){ - clear(); - resize(n, u); - } - - inline allocator_type get_allocator() const{ - return a; - } - - inline iterator begin(){ - return data; - } - - inline const_iterator begin() const{ - return data; - } - - inline iterator end(){ - return (data + elements); - } - - inline const_iterator end() const{ - return (data + elements); - } - - inline reverse_iterator rbegin(){ - return reverse_iterator(end()); - } - - inline const_reverse_iterator rbegin() const{ - return const_reverse_iterator(end()); - } - - inline reverse_iterator rend(){ - return reverse_iterator(begin()); - } - - inline const_reverse_iterator rend() const{ - return const_reverse_iterator(begin()); - } - - inline size_type size() const{ - return elements; - } - - _UCXXEXPORT size_type max_size() const{ - return ((size_type)(-1)) / sizeof(T); - } - - void downsize(size_type sz); - void resize(size_type sz, const T & c = T()); - - inline size_type capacity() const{ - return data_size; - } - - inline bool empty() const{ - return (size() == 0); - } - - void reserve(size_type n); - - inline reference operator[](size_type n){ - return data[n]; - } - - inline const_reference operator[](size_type n) const{ - return data[n]; - } - - _UCXXEXPORT const_reference at(size_type n) const{ - if(n >= elements){ - __throw_out_of_range("Invalid subscript"); - } - return data[n]; - } - - _UCXXEXPORT reference at(size_type n){ - if(n >= elements){ - __throw_out_of_range("Invalid subscript"); - } - return data[n]; - } - - inline reference front(){ - return data[0]; - } - - inline const_reference front() const{ - return data[0]; - } - - inline reference back(){ - return data[ size() - 1]; - } - - inline const_reference back() const{ - return data[ size() - 1 ]; - } - - inline void push_back(const T& x){ - resize( size() + 1, x); - } - - inline void pop_back(){ - downsize(size() - 1); - } - - _UCXXEXPORT iterator insert(iterator position, const T& x = T()){ - size_type index = position - data; - resize(size() + 1, x); - for(size_type i = elements - 1; i > index; --i){ - data[i] = data[i-1]; - } - data[index] = x; - return (data + index); - } - - _UCXXEXPORT void _insert_fill(iterator position, size_type n, const T & x){ - size_type index = position - data; - resize(size() + n, x); - - for(size_type i = elements -1; (i > (index+n-1)); --i){ - data[i] = data[i-n]; - } - for(size_type i = 0; i < n; i++){ - data[i + index] = x; - } - } - - template _UCXXEXPORT - void _insert_from_iterator(iterator position, InputIterator first, InputIterator last) - { - T temp; - while(first !=last){ - temp = *first; - position = insert(position, temp); - ++position; - ++first; - } - } - - template - inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __true_type) - { - _insert_fill(position, first, last); - } - - template - inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __false_type) - { - _insert_from_iterator(position, first, last); - } - - inline void insert(iterator position, size_type n, const T& x ){ - _insert_fill(position, n, x); - } - - template inline void insert(iterator position, InputIterator first, InputIterator last){ - typedef typename __is_integer::value __some_type; - _dispatch_insert(position, first, last, __some_type()); - } - - _UCXXEXPORT iterator erase(iterator position){ - size_type index = position - data; - for(size_type i = index; i < (elements - 1); ++i){ - data[i] = data[i+1]; - } - downsize(size() - 1); - return (data + index); - } - - _UCXXEXPORT iterator erase(iterator first, iterator last){ - size_type index = first - data; - size_type width = last - first; - for(size_type i = index; i < (elements - width) ;++i){ - data[i] = data[i+width]; - } - downsize(size() - width); - return (data + index); - } - - _UCXXEXPORT void swap(vector& v){ - if(this == &v){ //Avoid dv.swap(v) - return; - } - T* ptr; - size_type temp; - - //Swap pointers first - ptr = data; - data = v.data; - v.data = ptr; - - //Swap element counts - temp = elements; - elements = v.elements; - v.elements = temp; - - //Swap data size - temp = data_size; - data_size = v.data_size; - v.data_size = temp; - } - - _UCXXEXPORT void clear(){ - downsize(0); - } - - protected: - T* data; - size_type data_size; - size_type elements; - Allocator a; - }; - - - - //Here go template instantiations - - template _UCXXEXPORT vector::~vector(){ - for(size_t i = 0; i < elements; ++i){ - a.destroy(data + i); - } - a.deallocate(data, data_size); - } - - - template _UCXXEXPORT void vector::reserve(size_type n){ - if(n > data_size){ //We never shrink... - T * temp_ptr = data; - size_type temp_size = data_size; - - data_size = n; - data = a.allocate(data_size); - - for(size_type i = 0; i _UCXXEXPORT void vector::resize(size_type sz, const T & c){ - if(sz > elements){ //Need to actually call constructor - if(sz > data_size){ - reserve(sz + __UCLIBCXX_STL_BUFFER_SIZE__); - } - - for(size_type i = elements; i _UCXXEXPORT void vector::downsize(size_type sz){ - if(sz < elements){ //Actually are downsizing - for(size_t i = sz; i< elements; ++i){ - a.destroy(data+i); - } - elements = sz; - } - } - +extern "C++" +{ +namespace std +{ + template > class vector; + template bool operator==(const vector& x, const vector& y); + template bool operator< (const vector& x, const vector& y); + template bool operator!=(const vector& x, const vector& y); + template bool operator> (const vector& x, const vector& y); + template bool operator>=(const vector& x, const vector& y); + template bool operator<=(const vector& x, const vector& y); + template void swap(vector& x, vector& y); + + template class _UCXXEXPORT vector + { + public: + + typedef typename Allocator::reference reference; + typedef typename Allocator::const_reference const_reference; + typedef typename Allocator::size_type size_type; + typedef typename Allocator::difference_type difference_type; + typedef typename Allocator::pointer pointer; + typedef typename Allocator::const_pointer const_pointer; + + typedef T* iterator; + typedef const T* const_iterator; + typedef T value_type; + typedef Allocator allocator_type; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + + explicit _UCXXEXPORT vector(const Allocator& al= Allocator()): data(0), //defaultValue(T()), + data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) + { + data = a.allocate(data_size); + } + + explicit _UCXXEXPORT vector(size_type n, const T& value = T(), const Allocator& al= Allocator()) : + data(0), data_size(0), elements(0), a(al) + { + data_size = n + __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + + resize(n, value); + } + + template _UCXXEXPORT + vector(InputIterator first, InputIterator last, const Allocator& al = Allocator()): + data(0), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) + { + data = a.allocate(data_size); + assign(first, last); + } + + _UCXXEXPORT vector(const vector& x) + { + a = x.a; + + elements = x.elements; + data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__; + data = a.allocate(data_size); + + for (size_type i = 0; i < elements; i++) + { + a.construct(data+i, x.data[i]); + } + } + + _UCXXEXPORT ~vector(); // Below + + _UCXXEXPORT vector& operator=(const vector& x) + { + if (&x == this) + { + return *this; + } + + reserve(x.elements); // Make sure that we have enough actual memory + + // Copy as many elements as possible + + size_t minElements = elements; + if (minElements > x.elements) + { + minElements = x.elements; + } + + for (size_t i = 0; i < minElements; ++i) + { + data[i] = x.data[i]; + } + + // If we need to add new elements + + if (elements < x.elements) + { + for (size_t i = elements; i< x.elements; ++i) + { + a.construct(data+i, x.data[i]); + ++elements; + } + } + + if (elements > x.elements) + { + downsize(x.elements); + } + + return *this; + } + + template _UCXXEXPORT void assign(InputIterator first, InputIterator last) + { + clear(); + insert(begin(), first, last); + } + + template _UCXXEXPORT void assign(Size n, const U& u = U()) + { + clear(); + resize(n, u); + } + + inline allocator_type get_allocator() const + { + return a; + } + + inline iterator begin() + { + return data; + } + + inline const_iterator begin() const + { + return data; + } + + inline iterator end() + { + return (data + elements); + } + + inline const_iterator end() const + { + return (data + elements); + } + + inline reverse_iterator rbegin() + { + return reverse_iterator(end()); + } + + inline const_reverse_iterator rbegin() const + { + return const_reverse_iterator(end()); + } + + inline reverse_iterator rend() + { + return reverse_iterator(begin()); + } + + inline const_reverse_iterator rend() const + { + return const_reverse_iterator(begin()); + } + + inline size_type size() const + { + return elements; + } + + _UCXXEXPORT size_type max_size() const + { + return ((size_type)(-1)) / sizeof(T); + } + + void downsize(size_type sz); + void resize(size_type sz, const T & c = T()); + + inline size_type capacity() const + { + return data_size; + } + + inline bool empty() const + { + return (size() == 0); + } + + void reserve(size_type n); + + inline reference operator[](size_type n) + { + return data[n]; + } + + inline const_reference operator[](size_type n) const + { + return data[n]; + } + + _UCXXEXPORT const_reference at(size_type n) const + { + if (n >= elements) + { + __throw_out_of_range("Invalid subscript"); + } + + return data[n]; + } + + _UCXXEXPORT reference at(size_type n) + { + if (n >= elements) + { + __throw_out_of_range("Invalid subscript"); + } + + return data[n]; + } + + inline reference front() + { + return data[0]; + } + + inline const_reference front() const + { + return data[0]; + } + + inline reference back() + { + return data[ size() - 1]; + } + + inline const_reference back() const + { + return data[ size() - 1 ]; + } + + inline void push_back(const T& x) + { + resize(size() + 1, x); + } + + inline void pop_back() + { + downsize(size() - 1); + } + + _UCXXEXPORT iterator insert(iterator position, const T& x = T()) + { + size_type index = position - data; + resize(size() + 1, x); + for (size_type i = elements - 1; i > index; --i) + { + data[i] = data[i-1]; + } + + data[index] = x; + return (data + index); + } + + _UCXXEXPORT void _insert_fill(iterator position, size_type n, const T & x) + { + size_type index = position - data; + resize(size() + n, x); + + for (size_type i = elements -1; (i > (index+n-1)); --i) + { + data[i] = data[i-n]; + } + + for (size_type i = 0; i < n; i++) + { + data[i + index] = x; + } + } + + template _UCXXEXPORT + void _insert_from_iterator(iterator position, InputIterator first, InputIterator last) + { + T temp; + while (first !=last) + { + temp = *first; + position = insert(position, temp); + ++position; + ++first; + } + } + + template + inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __true_type) + { + _insert_fill(position, first, last); + } + + template + inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __false_type) + { + _insert_from_iterator(position, first, last); + } + + inline void insert(iterator position, size_type n, const T& x) + { + _insert_fill(position, n, x); + } + + template inline void insert(iterator position, InputIterator first, InputIterator last) + { + typedef typename __is_integer::value __some_type; + _dispatch_insert(position, first, last, __some_type()); + } + + _UCXXEXPORT iterator erase(iterator position) + { + size_type index = position - data; + for (size_type i = index; i < (elements - 1); ++i) + { + data[i] = data[i+1]; + } + + downsize(size() - 1); + return (data + index); + } + + _UCXXEXPORT iterator erase(iterator first, iterator last) + { + size_type index = first - data; + size_type width = last - first; + for (size_type i = index; i < (elements - width) ;++i) + { + data[i] = data[i+width]; + } + + downsize(size() - width); + return (data + index); + } + + _UCXXEXPORT void swap(vector& v) + { + if (this == &v) + { + // Avoid dv.swap(v) + + return; + } + + T* ptr; + size_type temp; + + // Swap pointers first + + ptr = data; + data = v.data; + v.data = ptr; + + // Swap element counts + + temp = elements; + elements = v.elements; + v.elements = temp; + + // Swap data size + + temp = data_size; + data_size = v.data_size; + v.data_size = temp; + } + + _UCXXEXPORT void clear() + { + downsize(0); + } + + protected: + T* data; + size_type data_size; + size_type elements; + Allocator a; + }; + + // Here go template instantiations + + template _UCXXEXPORT vector::~vector() + { + for (size_t i = 0; i < elements; ++i) + { + a.destroy(data + i); + } + + a.deallocate(data, data_size); + } + + template _UCXXEXPORT void vector::reserve(size_type n) + { + if (n > data_size) + { + // We never shrink... + + T * temp_ptr = data; + size_type temp_size = data_size; + + data_size = n; + data = a.allocate(data_size); + + for (size_type i = 0; i _UCXXEXPORT void vector::resize(size_type sz, const T & c) + { + if (sz > elements) + { + // Need to actually call constructor + + if (sz > data_size) + { + reserve(sz + __UCLIBCXX_STL_BUFFER_SIZE__); + } + + for (size_type i = elements; i _UCXXEXPORT void vector::downsize(size_type sz) + { + if (sz < elements) + { + // Actually are downsizing + + for (size_t i = sz; i< elements; ++i) + { + a.destroy(data+i); + } + + elements = sz; + } + } #ifndef __UCLIBCXX_COMPILE_VECTOR__ #ifdef __UCLIBCXX_EXPAND_VECTOR_BASIC__ - #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template<> _UCXXEXPORT vector >::vector(const allocator& al); - template<> _UCXXEXPORT vector >::vector(size_type n, const char & value, const allocator & al); - - template<> _UCXXEXPORT vector >::~vector(); - template<> _UCXXEXPORT vector >::~vector(); + template<> _UCXXEXPORT vector >::vector(const allocator& al); + template<> _UCXXEXPORT vector >::vector(size_type n, const char & value, const allocator & al); + template<> _UCXXEXPORT vector >::~vector(); + template<> _UCXXEXPORT vector >::~vector(); #endif //__UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const char & c); - template<> _UCXXEXPORT void - vector >::resize(size_type sz, const unsigned char & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const short & c); - template<> _UCXXEXPORT void - vector >::resize(size_type sz, const unsigned short int & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const int & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const unsigned int & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const long int & c); - template<> _UCXXEXPORT void - vector >::resize(size_type sz, const unsigned long int & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const float & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const double & c); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const bool & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const char & c); + template<> _UCXXEXPORT void + vector >::resize(size_type sz, const unsigned char & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const short & c); + template<> _UCXXEXPORT void + vector >::resize(size_type sz, const unsigned short int & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const int & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const unsigned int & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const long int & c); + template<> _UCXXEXPORT void + vector >::resize(size_type sz, const unsigned long int & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const float & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const double & c); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const bool & c); #elif defined __UCLIBCXX_EXPAND_STRING_CHAR__ #ifdef __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ - - template<> _UCXXEXPORT vector >::vector(const allocator& al); - template<> _UCXXEXPORT vector >::vector(size_type n, const char & value, const allocator & al); - template<> _UCXXEXPORT vector >::~vector(); - + template<> _UCXXEXPORT vector >::vector(const allocator& al); + template<> _UCXXEXPORT vector >::vector(size_type n, const char & value, const allocator & al); + template<> _UCXXEXPORT vector >::~vector(); #endif - template<> _UCXXEXPORT void vector >::reserve(size_type n); - template<> _UCXXEXPORT void vector >::resize(size_type sz, const char & c); + template<> _UCXXEXPORT void vector >::reserve(size_type n); + template<> _UCXXEXPORT void vector >::resize(size_type sz, const char & c); #endif #endif + template _UCXXEXPORT bool + operator==(const vector& x, const vector& y) + { + if (x.size() !=y.size()) + { + return false; + } + for (size_t i = 0; i < x.size(); ++i) + { + if (x[i] != y[i]) + { + return false; + } + } - template _UCXXEXPORT bool - operator==(const vector& x, const vector& y) - { - if(x.size() !=y.size() ){ - return false; - } - for(size_t i = 0; i < x.size(); ++i){ - if(x[i] != y[i]){ - return false; - } - } - return true; - } + return true; + } - template _UCXXEXPORT bool - operator< (const vector& x, const vector& y) - { - less::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); - } - template _UCXXEXPORT bool - operator!=(const vector& x, const vector& y) - { - return !(x == y); - } - template _UCXXEXPORT bool - operator> (const vector& x, const vector& y) - { - greater::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); - } - template _UCXXEXPORT bool - operator>=(const vector& x, const vector& y) - { - greater_equal::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); - } - template _UCXXEXPORT bool - operator<=(const vector& x, const vector& y) - { - less_equal::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); - } + template _UCXXEXPORT bool + operator< (const vector& x, const vector& y) + { + less::iterator >::value_type> c; + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + } - template _UCXXEXPORT void swap(vector& x, vector& y){ - x.swap(y); - } + template _UCXXEXPORT bool + operator!=(const vector& x, const vector& y) + { + return !(x == y); + } -} + template _UCXXEXPORT bool + operator> (const vector& x, const vector& y) + { + greater::iterator >::value_type> c; + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + } + + template _UCXXEXPORT bool + operator>=(const vector& x, const vector& y) + { + greater_equal::iterator >::value_type> c; + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + } + + template _UCXXEXPORT bool + operator<=(const vector& x, const vector& y) + { + less_equal::iterator >::value_type> c; + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + } + + template _UCXXEXPORT void swap(vector& x, vector& y) + { + x.swap(y); + } + +} // namespace +} // extern "C++" #pragma GCC visibility pop diff --git a/misc/uClibc++/libxx/uClibc++/associative_base.cxx b/misc/uClibc++/libxx/uClibc++/associative_base.cxx index cc2d20e549..6a7d786e4d 100644 --- a/misc/uClibc++/libxx/uClibc++/associative_base.cxx +++ b/misc/uClibc++/libxx/uClibc++/associative_base.cxx @@ -1,26 +1,24 @@ -/* Copyright (C) 2007 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) 2007 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 -namespace std{ - - - -} +namespace std +{ +} // namespace diff --git a/misc/uClibc++/libxx/uClibc++/bitset.cxx b/misc/uClibc++/libxx/uClibc++/bitset.cxx index f1ece31f9f..735d863fdf 100644 --- a/misc/uClibc++/libxx/uClibc++/bitset.cxx +++ b/misc/uClibc++/libxx/uClibc++/bitset.cxx @@ -1,26 +1,24 @@ -/* 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 -namespace std{ - - - -} +namespace std +{ +} // namespace diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 6fa9ffbfed..b357a629d2 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3554,3 +3554,11 @@ expects. That is usually the case if parameters are passed in registers. * libxx/libxx_cxa_atexit(): Implements __cxa_atexit() + * configs/stm32f4discovery/cxxtest: New test that will be used to + verify the uClibc++ port (eventually). The sim platform turned not + to be a good platform for testing uClibc++. The sim example will not + run because the simulator will attempt to execute the static + constructors before main() starts. BUT... NuttX is not initialized + and this results in a crash. On the STM324Discovery, I will have + better control over when the static constructors run. + diff --git a/nuttx/arch/arm/src/Makefile b/nuttx/arch/arm/src/Makefile index 49a651c4eb..7bba7315fc 100644 --- a/nuttx/arch/arm/src/Makefile +++ b/nuttx/arch/arm/src/Makefile @@ -36,58 +36,61 @@ -include $(TOPDIR)/Make.defs -include chip/Make.defs -ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src +ARCH_SRCDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src ifeq ($(CONFIG_ARCH_CORTEXM3),y) # Cortex-M3 is ARMv7-M -ARCH_SUBDIR = armv7-m +ARCH_SUBDIR = armv7-m else ifeq ($(CONFIG_ARCH_CORTEXM4),y) # Cortex-M4 is ARMv7E-M -ARCH_SUBDIR = armv7-m +ARCH_SUBDIR = armv7-m else -ARCH_SUBDIR = arm +ARCH_SUBDIR = arm endif endif ifeq ($(WINTOOL),y) - NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx}" - CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" \ - -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" \ - -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}" \ - -I "${shell cygpath -w $(TOPDIR)/sched}" + NUTTX = "${shell cygpath -w $(TOPDIR)/nuttx}" + CFLAGS += -I "${shell cygpath -w $(ARCH_SRCDIR)/chip}" \ + -I "${shell cygpath -w $(ARCH_SRCDIR)/common}" \ + -I "${shell cygpath -w $(ARCH_SRCDIR)/$(ARCH_SUBDIR)}" \ + -I "${shell cygpath -w $(TOPDIR)/sched}" else - NUTTX = $(TOPDIR)/nuttx - CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common \ - -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR) -I$(TOPDIR)/sched + NUTTX = $(TOPDIR)/nuttx + CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common \ + -I$(ARCH_SRCDIR)/$(ARCH_SUBDIR) -I$(TOPDIR)/sched endif -HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT)) +HEAD_OBJ = $(HEAD_ASRC:.S=$(OBJEXT)) -ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) -AOBJS = $(ASRCS:.S=$(OBJEXT)) +ASRCS = $(CHIP_ASRCS) $(CMN_ASRCS) +AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS) -COBJS = $(CSRCS:.c=$(OBJEXT)) +CSRCS = $(CHIP_CSRCS) $(CMN_CSRCS) +COBJS = $(CSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) -OBJS = $(AOBJS) $(COBJS) +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) -LDFLAGS = $(ARCHSCRIPT) -EXTRA_LIBS ?= +LDFLAGS = $(ARCHSCRIPT) -LINKLIBS = +EXTRA_LIBS ?= +EXTRA_LIBPATHS ?= + +LINKLIBS = ifeq ($(WINTOOL),y) - LIBPATHS = ${shell for path in $(LINKLIBS); do dir=`dirname $(TOPDIR)/$$path`;echo "-L\"`cygpath -w $$dir`\"";done} - LIBPATHS += -L"${shell cygpath -w $(BOARDDIR)}" + LIBPATHS = ${shell for path in $(LINKLIBS); do dir=`dirname $(TOPDIR)/$$path`;echo "-L\"`cygpath -w $$dir`\"";done} + LIBPATHS += -L"${shell cygpath -w $(BOARDDIR)}" else - LIBPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) - LIBPATHS += -L"$(BOARDDIR)" + LIBPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) + LIBPATHS += -L"$(BOARDDIR)" endif -LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) +LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) -BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board +BOARDDIR = $(TOPDIR)/arch/$(CONFIG_ARCH)/src/board -LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name}" +LIBGCC = "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name}" +GCC_LIBDIR := ${shell dirname $(LIBGCC)} -VPATH = chip:common:$(ARCH_SUBDIR) +VPATH = chip:common:$(ARCH_SUBDIR) all: $(HEAD_OBJ) libarch$(LIBEXT) @@ -101,7 +104,7 @@ $(COBJS): %$(OBJEXT): %.c libarch$(LIBEXT): $(OBJS) $(Q) ( for obj in $(OBJS) ; do \ - $(call ARCHIVE, $@, $${obj}); \ + $(call ARCHIVE, $@, $${obj}); \ done ; ) board/libboard$(LIBEXT): @@ -109,7 +112,8 @@ board/libboard$(LIBEXT): nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT) $(Q) echo "LD: nuttx" - $(Q) $(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \ + $(Q) $(LD) --entry=__start $(LDFLAGS) $(LIBPATHS) $(EXTRA_LIBPATHS) \ + -o $(NUTTX)$(EXEEXT) $(HEAD_OBJ) $(EXTRA_OBJS) \ --start-group $(LDLIBS) -lboard $(EXTRA_LIBS) $(LIBGCC) --end-group $(Q) $(NM) $(NUTTX)$(EXEEXT) | \ grep -v '\(compiled\)\|\(\$(OBJEXT)$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ @@ -122,10 +126,10 @@ nuttx: $(HEAD_OBJ) board/libboard$(LIBEXT) export_head: board/libboard$(LIBEXT) $(HEAD_OBJ) ifneq ($(HEAD_OBJ),) $(Q) if [ -d "$(EXPORT_DIR)/startup" ]; then \ - cp -f $(HEAD_OBJ) "$(EXPORT_DIR)/startup"; \ + cp -f $(HEAD_OBJ) "$(EXPORT_DIR)/startup"; \ else \ - echo "$(EXPORT_DIR)/startup does not exist"; \ - exit 1; \ + echo "$(EXPORT_DIR)/startup does not exist"; \ + exit 1; \ fi endif @@ -133,7 +137,7 @@ endif .depend: Makefile chip/Make.defs $(SRCS) $(Q) if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" depend ; \ + $(MAKE) -C board TOPDIR="$(TOPDIR)" depend ; \ fi $(Q) $(MKDEP) --dep-path chip --dep-path common --dep-path $(ARCH_SUBDIR) \ $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep @@ -143,14 +147,14 @@ depend: .depend clean: $(Q) if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" clean ; \ + $(MAKE) -C board TOPDIR="$(TOPDIR)" clean ; \ fi $(Q) rm -f libarch$(LIBEXT) *~ .*.swp $(call CLEAN) distclean: clean $(Q) if [ -e board/Makefile ]; then \ - $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean ; \ + $(MAKE) -C board TOPDIR="$(TOPDIR)" distclean ; \ fi $(Q) rm -f Make.dep .depend diff --git a/nuttx/arch/sim/src/Makefile b/nuttx/arch/sim/src/Makefile index cf8008b16b..1e4d08736b 100644 --- a/nuttx/arch/sim/src/Makefile +++ b/nuttx/arch/sim/src/Makefile @@ -101,6 +101,7 @@ endif endif EXTRA_LIBS ?= +EXTRA_LIBPATHS ?= ifeq ($(CONFIG_FS_FAT),y) STDLIBS += -lz @@ -108,9 +109,6 @@ endif STDLIBS += -lc -LIBGCC := "${shell $(CC) $(ARCHCPUFLAGS) -print-libgcc-file-name}" -GCC_LIBDIR := ${shell dirname $(LIBGCC)} - # Determine which objects are required in the link. The # up_head object normally draws in all that is needed, but # there are a fews that must be included because they @@ -134,7 +132,7 @@ LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) # Add the board-specific library and directory -LDPATHS += -L board -L $(GCC_LIBDIR) +LDPATHS += -L board LDLIBS += -lboard # Make targets begin here @@ -181,7 +179,7 @@ Cygwin-names.dat: nuttx-names.dat nuttx.rel : libarch$(LIBEXT) board/libboard$(LIBEXT) $(HOSTOS)-names.dat $(LINKOBJS) $(Q) echo "LD: nuttx.rel" - $(Q) $(LD) -r $(LDLINKFLAGS) $(LDPATHS) -o $@ $(REQUIREDOBJS) --start-group $(LDLIBS) $(EXTRA_LIBS) --end-group + $(Q) $(LD) -r $(LDLINKFLAGS) $(LDPATHS) $(EXTRA_LIBPATHS) -o $@ $(REQUIREDOBJS) --start-group $(LDLIBS) $(EXTRA_LIBS) --end-group $(Q) $(OBJCOPY) --redefine-syms=$(HOSTOS)-names.dat $@ # Generate the final NuttX binary by linking the host-specific objects with the NuttX diff --git a/nuttx/configs/sim/README.txt b/nuttx/configs/sim/README.txt index 654ce93146..39ace5495e 100644 --- a/nuttx/configs/sim/README.txt +++ b/nuttx/configs/sim/README.txt @@ -215,18 +215,18 @@ cxxtest b. Execute 'make menuconfig' in nuttx/ in order to start the reconfiguration process. - 3. At presenet (2012/11/02), this example builds only with exceptions + 3. At present (2012/11/02), this example builds only with exceptions disabled (CONFIG_UCLIBCXX_EXCEPTIONS=n). And even then, it will not run. - The reason that the example will will not run on the simulator has + The reason that the example will not run on the simulator has to do with when static constructors are enabled: In the simulator - it will attempt to execute the static constructros before main() + it will attempt to execute the static constructors before main() starts. BUT... NuttX is not initialized and this results in a crash. To really use this example, I will have to think of some way to postpone running C++ static initializers until NuttX has been - initialied. + initialized. mount diff --git a/nuttx/configs/sim/cxxtest/Make.defs b/nuttx/configs/sim/cxxtest/Make.defs index 7b0c524b4f..6f945cc519 100644 --- a/nuttx/configs/sim/cxxtest/Make.defs +++ b/nuttx/configs/sim/cxxtest/Make.defs @@ -93,6 +93,10 @@ LDLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(LD) CCLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(CC) LDFLAGS = $(ARCHSCRIPT) # For backward compatibility, same as CCLINKFLAGS +LIBSUPXX = ${shell $(CC) --print-file-name=libsupc++.a} +EXTRA_LIBPATHS = -L "${shell dirname "$(LIBSUPXX)"}" +EXTRA_LIBS = -lsupc++ + ifeq ($(CONFIG_DEBUG_SYMBOLS),y) LDLINKFLAGS += -g CCLINKFLAGS += -g @@ -105,8 +109,6 @@ ifeq ($(CONFIG_SIM_M32),y) LDFLAGS += -m32 endif -EXTRA_LIBS = -lsupc++ - MKDEP = $(TOPDIR)/tools/mkdeps.sh HOSTCC = gcc diff --git a/nuttx/configs/sim/cxxtest/defconfig b/nuttx/configs/sim/cxxtest/defconfig index d2fef0a554..1f99a63338 100644 --- a/nuttx/configs/sim/cxxtest/defconfig +++ b/nuttx/configs/sim/cxxtest/defconfig @@ -288,7 +288,7 @@ CONFIG_HAVE_CXX=y # uClibc++ Standard C++ Library # CONFIG_UCLIBCXX=y -CONFIG_UCLIBCXX_EXCEPTION=y +# CONFIG_UCLIBCXX_EXCEPTION is not set CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE=32 CONFIG_UCLIBCXX_HAVE_LIBSUPCXX=y diff --git a/nuttx/configs/sim/ostest/Make.defs b/nuttx/configs/sim/ostest/Make.defs index 201ff7a94f..975d59338e 100644 --- a/nuttx/configs/sim/ostest/Make.defs +++ b/nuttx/configs/sim/ostest/Make.defs @@ -36,76 +36,76 @@ include ${TOPDIR}/.config include ${TOPDIR}/tools/Config.mk -HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"} +HOSTOS = ${shell uname -o 2>/dev/null || echo "Other"} ifeq ($(CONFIG_DEBUG_SYMBOLS),y) - ARCHOPTIMIZATION = -g + ARCHOPTIMIZATION = -g else - ARCHOPTIMIZATION = -O2 + ARCHOPTIMIZATION = -O2 endif -ARCHCPUFLAGS = -fno-builtin -ARCHCPUFLAGSXX = -fno-builtin -fno-exceptions -fno-rtti -ARCHPICFLAGS = -fpic -ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -ARCHWARNINGSXX = -Wall -Wshadow -ARCHDEFINES = -ARCHINCLUDES = -I. -isystem $(TOPDIR)/include -ARCHINCLUDESXX = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx -ARCHSCRIPT = +ARCHCPUFLAGS = -fno-builtin +ARCHCPUFLAGSXX = -fno-builtin -fno-exceptions -fno-rtti +ARCHPICFLAGS = -fpic +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow +ARCHWARNINGSXX = -Wall -Wshadow +ARCHDEFINES = +ARCHINCLUDES = -I. -isystem $(TOPDIR)/include +ARCHINCLUDESXX = -I. -isystem $(TOPDIR)/include -isystem $(TOPDIR)/include/cxx +ARCHSCRIPT = ifeq ($(CONFIG_SIM_M32),y) - ARCHCPUFLAGS += -m32 - ARCHCPUFLAGSXX += -m32 + ARCHCPUFLAGS += -m32 + ARCHCPUFLAGSXX += -m32 endif -CROSSDEV = -CC = $(CROSSDEV)gcc -CXX = $(CROSSDEV)g++ -CPP = $(CROSSDEV)gcc -E -LD = $(CROSSDEV)ld -AR = $(CROSSDEV)ar rcs -NM = $(CROSSDEV)nm -OBJCOPY = $(CROSSDEV)objcopy -OBJDUMP = $(CROSSDEV)objdump +CROSSDEV = +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(CROSSDEV)ar rcs +NM = $(CROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump -CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \ - $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe -CXXFLAGS = $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \ - $(ARCHCPUFLAGSXX) $(ARCHINCLUDESXX) $(ARCHDEFINES) $(EXTRADEFINES) -pipe -CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -AFLAGS = $(CFLAGS) -D__ASSEMBLY__ +CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \ + $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXFLAGS = $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) \ + $(ARCHCPUFLAGSXX) $(ARCHINCLUDESXX) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ -OBJEXT = .o -LIBEXT = .a +OBJEXT = .o +LIBEXT = .a ifeq ($(HOSTOS),Cygwin) - EXEEXT = .exe + EXEEXT = .exe else - EXEEXT = + EXEEXT = endif -LDLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(LD) -CCLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(CC) -LDFLAGS = $(ARCHSCRIPT) # For backward compatibility, same as CCLINKFLAGS +LDLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(LD) +CCLINKFLAGS = $(ARCHSCRIPT) # Link flags used with $(CC) +LDFLAGS = $(ARCHSCRIPT) # For backward compatibility, same as CCLINKFLAGS ifeq ($(CONFIG_DEBUG_SYMBOLS),y) - LDLINKFLAGS += -g - CCLINKFLAGS += -g - LDFLAGS += -g + LDLINKFLAGS += -g + CCLINKFLAGS += -g + LDFLAGS += -g endif ifeq ($(CONFIG_SIM_M32),y) - LDLINKFLAGS += -melf_i386 - CCLINKFLAGS += -m32 - LDFLAGS += -m32 + LDLINKFLAGS += -melf_i386 + CCLINKFLAGS += -m32 + LDFLAGS += -m32 endif -MKDEP = $(TOPDIR)/tools/mkdeps.sh +MKDEP = $(TOPDIR)/tools/mkdeps.sh -HOSTCC = gcc -HOSTINCLUDES = -I. -HOSTCFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \ - $(ARCHCPUFLAGS) $(HOSTINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe -HOSTLDFLAGS = +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \ + $(ARCHCPUFLAGS) $(HOSTINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +HOSTLDFLAGS = diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt index 57db94e1e6..730bf66ef2 100644 --- a/nuttx/configs/stm32f4discovery/README.txt +++ b/nuttx/configs/stm32f4discovery/README.txt @@ -982,6 +982,35 @@ can be selected as follow: Where is one of the following: + cxxtest: + ------- + + The C++ standard libary test at apps/examples/cxxtest configuration. This + test is used to verify the uClibc++ port to NuttX. This configuration may + be selected as follows: + + cd /tools + ./configure.sh sim/cxxtest + + NOTES: + + 1. Before you can use this example, you must first install the uClibc++ + C++ library. This is located outside of the NuttX source tree at + misc/uClibc++ in SVN. See the README.txt file for instructions on + how to install uClibc++ + + 2. This configuration uses the mconf-based configuration tool. To + change this configuration using that tool, you should: + + a. Build and install the mconf tool. See nuttx/README.txt and + misc/tools/ + + b. Execute 'make menuconfig' in nuttx/ in order to start the + reconfiguration process. + + 3. At present (2012/11/02), this example builds only with exceptions + disabled (CONFIG_UCLIBCXX_EXCEPTIONS=n). + elf: --- diff --git a/nuttx/configs/stm32f4discovery/cxxtest/Make.defs b/nuttx/configs/stm32f4discovery/cxxtest/Make.defs new file mode 100644 index 0000000000..f81d6ec2c1 --- /dev/null +++ b/nuttx/configs/stm32f4discovery/cxxtest/Make.defs @@ -0,0 +1,184 @@ +############################################################################ +# configs/stm32f4discovery/cxxtest/Make.defs +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################ + +include ${TOPDIR}/.config +include ${TOPDIR}/tools/Config.mk + +# Setup for the selected toolchain + +ifeq ($(CONFIG_STM32_CODESOURCERYW),y) + # CodeSourcery under Windows + CROSSDEV = arm-none-eabi- + ARCROSSDEV = arm-none-eabi- + WINTOOL = y + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft +endif +ifeq ($(CONFIG_STM32_CODESOURCERYL),y) + # CodeSourcery under Linux + CROSSDEV = arm-none-eabi- + ARCROSSDEV = arm-none-eabi- + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft + MAXOPTIMIZATION = -O2 +endif +ifeq ($(CONFIG_STM32_ATOLLIC_LITE),y) + # Atollic toolchain under Windows + CROSSDEV = arm-atollic-eabi- + ARCROSSDEV = + WINTOOL = y +ifeq ($(CONFIG_ARCH_FPU),y) + ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard +else + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft +endif +endif +ifeq ($(CONFIG_STM32_ATOLLIC_PRO),y) + # Atollic toolchain under Windows + CROSSDEV = arm-atollic-eabi- + ARCROSSDEV = arm-atollic-eabi- + WINTOOL = y +ifeq ($(CONFIG_ARCH_FPU),y) + ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard +else + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft +endif +endif +ifeq ($(CONFIG_STM32_DEVKITARM),y) + # devkitARM under Windows + CROSSDEV = arm-eabi- + ARCROSSDEV = arm-eabi- + WINTOOL = y + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft +endif +ifeq ($(CONFIG_STM32_RAISONANCE),y) + # Raisonance RIDE7 under Windows + CROSSDEV = arm-none-eabi- + ARCROSSDEV = arm-none-eabi- + WINTOOL = y + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft +endif +ifeq ($(CONFIG_STM32_BUILDROOT),y) + # NuttX buildroot under Linux or Cygwin + # OABI + # CROSSDEV = arm-nuttx-elf- + # ARCROSSDEV = arm-nuttx-elf- + # ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft + # EABI + CROSSDEV = arm-nuttx-eabi- + ARCROSSDEV = arm-nuttx-eabi- + ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft + MAXOPTIMIZATION = -Os +endif + +CC = $(CROSSDEV)gcc +CXX = $(CROSSDEV)g++ +CPP = $(CROSSDEV)gcc -E +LD = $(CROSSDEV)ld +AR = $(ARCROSSDEV)ar rcs +NM = $(ARCROSSDEV)nm +OBJCOPY = $(CROSSDEV)objcopy +OBJDUMP = $(CROSSDEV)objdump + +ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'} +ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1} + +LDSCRIPT = ld.script +LIBSUPXX = ${shell $(CC) --print-file-name=libsupc++.a} +EXTRA_LIBPATHS = -L "${shell dirname "$(LIBSUPXX)"}" +EXTRA_LIBS = -lsupc++ + +ifeq ($(WINTOOL),y) + # Windows-native toolchains + DIRLINK = $(TOPDIR)/tools/winlink.sh + DIRUNLINK = $(TOPDIR)/tools/unlink.sh + MKDEP = $(TOPDIR)/tools/mknulldeps.sh + ARCHINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" + ARCHXXINCLUDES = -I. -isystem "${shell cygpath -w $(TOPDIR)/include}" \ + -isystem "${shell cygpath -w $(TOPDIR)/include/cxx}" \ + -isystem "${shell cygpath -w $(TOPDIR)/include/uClibc++}" + ARCHSCRIPT = -T "${shell cygpath -w $(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT)}" + MAXOPTIMIZATION = -O2 +else + # Linux/Cygwin-native toolchain + MKDEP = $(TOPDIR)/tools/mkdeps.sh + ARCHINCLUDES = -I. -isystem $(TOPDIR)/include + ARCHXXINCLUDES = -I. -isystem $(TOPDIR)/include \ + -isystem $(TOPDIR)/include/cxx -isystem $(TOPDIR)/include/uClibc++ + ARCHSCRIPT = -T$(TOPDIR)/configs/$(CONFIG_ARCH_BOARD)/scripts/$(LDSCRIPT) +endif + +ifeq ("${CONFIG_DEBUG_SYMBOLS}","y") + ARCHOPTIMIZATION = -g +else + ARCHOPTIMIZATION = $(MAXOPTIMIZATION) -fno-strict-aliasing -fno-strength-reduce -fomit-frame-pointer +endif + +ARCHCFLAGS = -fno-builtin +ifeq ($(CONFIG_UCLIBCXX_EXCEPTION),y) + ARCHCPUFLAGSXX = -fno-builtin +else + ARCHCPUFLAGSXX = -fno-builtin -fno-exceptions +endif +ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow +ARCHWARNINGSXX = -Wall -Wshadow +ARCHDEFINES = +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 + +CFLAGS = $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS) +CXXFLAGS = $(ARCHCXXFLAGS) $(ARCHWARNINGSXX) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) -pipe +CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS) +CPPFLAGS = $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRADEFINES) +AFLAGS = $(CFLAGS) -D__ASSEMBLY__ + +NXFLATLDFLAGS1 = -r -d -warn-common +NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) -T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections +LDNXFLATFLAGS = -e main -s 2048 + +OBJEXT = .o +LIBEXT = .a +EXEEXT = + +ifneq ($(CROSSDEV),arm-nuttx-elf-) + LDFLAGS += -nostartfiles -nodefaultlibs +endif +ifeq ($(CONFIG_DEBUG_SYMBOLS),y) + LDFLAGS += -g +endif + +HOSTCC = gcc +HOSTINCLUDES = -I. +HOSTCFLAGS = -Wall -Wstrict-prototypes -Wshadow -g -pipe +HOSTLDFLAGS = + diff --git a/nuttx/configs/stm32f4discovery/cxxtest/defconfig b/nuttx/configs/stm32f4discovery/cxxtest/defconfig new file mode 100644 index 0000000000..85b04c0ff9 --- /dev/null +++ b/nuttx/configs/stm32f4discovery/cxxtest/defconfig @@ -0,0 +1,573 @@ +# +# Automatically generated file; DO NOT EDIT. +# Nuttx/ Configuration +# +CONFIG_NUTTX_NEWCONFIG=y + +# +# Build Setup +# +# CONFIG_EXPERIMENTAL is not set + +# +# Build Configuration +# +# CONFIG_APPS_DIR="../apps" +# CONFIG_BUILD_2PASS is not set + +# +# Binary Output Formats +# +# CONFIG_RRLOAD_BINARY is not set +CONFIG_INTELHEX_BINARY=y +# CONFIG_MOTOROLA_SREC is not set +CONFIG_RAW_BINARY=y + +# +# Customize Header Files +# +# CONFIG_ARCH_STDBOOL_H is not set +# CONFIG_ARCH_MATH_H is not set +CONFIG_ARCH_FLOAT_H=y +# CONFIG_ARCH_STDARG_H is not set + +# +# Debug Options +# +# CONFIG_DEBUG is not set +# CONFIG_DEBUG_SYMBOLS is not set + +# +# System Type +# +# CONFIG_ARCH_8051 is not set +CONFIG_ARCH_ARM=y +# CONFIG_ARCH_AVR is not set +# CONFIG_ARCH_HC is not set +# CONFIG_ARCH_MIPS is not set +# CONFIG_ARCH_RGMP is not set +# CONFIG_ARCH_SH is not set +# CONFIG_ARCH_SIM is not set +# CONFIG_ARCH_X86 is not set +# CONFIG_ARCH_Z16 is not set +# CONFIG_ARCH_Z80 is not set +CONFIG_ARCH="arm" + +# +# ARM Options +# +# CONFIG_ARCH_CHIP_C5471 is not set +# CONFIG_ARCH_CHIP_CALYPSO is not set +# CONFIG_ARCH_CHIP_DM320 is not set +# CONFIG_ARCH_CHIP_IMX is not set +# CONFIG_ARCH_CHIP_KINETIS is not set +# CONFIG_ARCH_CHIP_LM3S is not set +# CONFIG_ARCH_CHIP_LPC17XX is not set +# CONFIG_ARCH_CHIP_LPC214X is not set +# CONFIG_ARCH_CHIP_LPC2378 is not set +# CONFIG_ARCH_CHIP_LPC31XX is not set +# CONFIG_ARCH_CHIP_LPC43XX is not set +# CONFIG_ARCH_CHIP_SAM3U is not set +CONFIG_ARCH_CHIP_STM32=y +# CONFIG_ARCH_CHIP_STR71X is not set +CONFIG_ARCH_CORTEXM4=y +CONFIG_ARCH_FAMILY="armv7-m" +CONFIG_ARCH_CHIP="stm32" +# CONFIG_ARCH_FPU is not set +CONFIG_ARCH_HAVE_MPU=y +# CONFIG_ARMV7M_MPU is not set +CONFIG_ARCH_IRQPRIO=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +# CONFIG_ARCH_CALIBRATION is not set +# CONFIG_SERIAL_TERMIOS is not set + +# +# STM32 Configuration Options +# +# CONFIG_ARCH_CHIP_STM32F100C8 is not set +# CONFIG_ARCH_CHIP_STM32F100CB is not set +# CONFIG_ARCH_CHIP_STM32F100R8 is not set +# CONFIG_ARCH_CHIP_STM32F100RB is not set +# CONFIG_ARCH_CHIP_STM32F100V8 is not set +# CONFIG_ARCH_CHIP_STM32F100VB is not set +# CONFIG_ARCH_CHIP_STM32F103RET6 is not set +# CONFIG_ARCH_CHIP_STM32F103VCT6 is not set +# CONFIG_ARCH_CHIP_STM32F103VET6 is not set +# CONFIG_ARCH_CHIP_STM32F103ZET6 is not set +# CONFIG_ARCH_CHIP_STM32F105VBT7 is not set +# CONFIG_ARCH_CHIP_STM32F107VC is not set +# CONFIG_ARCH_CHIP_STM32F207IG is not set +# CONFIG_ARCH_CHIP_STM32F405RG is not set +# CONFIG_ARCH_CHIP_STM32F405VG is not set +# CONFIG_ARCH_CHIP_STM32F405ZG is not set +# CONFIG_ARCH_CHIP_STM32F407VE is not set +CONFIG_ARCH_CHIP_STM32F407VG=y +# CONFIG_ARCH_CHIP_STM32F407ZE is not set +# CONFIG_ARCH_CHIP_STM32F407ZG is not set +# CONFIG_ARCH_CHIP_STM32F407IE is not set +# CONFIG_ARCH_CHIP_STM32F407IG is not set +CONFIG_STM32_STM32F40XX=y +CONFIG_STM32_CODESOURCERYW=y +# CONFIG_STM32_CODESOURCERYL is not set +# CONFIG_STM32_ATOLLIC_LITE is not set +# CONFIG_STM32_ATOLLIC_PRO is not set +# CONFIG_STM32_DEVKITARM is not set +# CONFIG_STM32_RAISONANCE is not set +# CONFIG_STM32_BUILDROOT is not set +# CONFIG_STM32_DFU is not set + +# +# STM32 Peripheral Support +# +# CONFIG_STM32_ADC1 is not set +# CONFIG_STM32_ADC2 is not set +# CONFIG_STM32_ADC3 is not set +# CONFIG_STM32_CRC is not set +# CONFIG_STM32_DMA1 is not set +# CONFIG_STM32_DMA2 is not set +# CONFIG_STM32_BKPSRAM is not set +# CONFIG_STM32_CAN1 is not set +# CONFIG_STM32_CAN2 is not set +# CONFIG_STM32_CCMDATARAM is not set +# CONFIG_STM32_CRYP is not set +# CONFIG_STM32_DAC1 is not set +# CONFIG_STM32_DAC2 is not set +# CONFIG_STM32_DCMI is not set +# CONFIG_STM32_ETHMAC is not set +# CONFIG_STM32_FSMC is not set +# CONFIG_STM32_HASH is not set +# CONFIG_STM32_I2C1 is not set +# CONFIG_STM32_I2C2 is not set +# CONFIG_STM32_I2C3 is not set +# CONFIG_STM32_IWDG is not set +# CONFIG_STM32_OTGFS is not set +# CONFIG_STM32_OTGHS is not set +# CONFIG_STM32_PWR is not set +# CONFIG_STM32_RNG is not set +# CONFIG_STM32_SDIO is not set +# CONFIG_STM32_SPI1 is not set +# CONFIG_STM32_SPI2 is not set +# CONFIG_STM32_SPI3 is not set +CONFIG_STM32_SYSCFG=y +# CONFIG_STM32_TIM1 is not set +# CONFIG_STM32_TIM2 is not set +# CONFIG_STM32_TIM3 is not set +# CONFIG_STM32_TIM4 is not set +# CONFIG_STM32_TIM5 is not set +# CONFIG_STM32_TIM6 is not set +# CONFIG_STM32_TIM7 is not set +# CONFIG_STM32_TIM8 is not set +# CONFIG_STM32_TIM9 is not set +# CONFIG_STM32_TIM10 is not set +# CONFIG_STM32_TIM11 is not set +# CONFIG_STM32_TIM12 is not set +# CONFIG_STM32_TIM13 is not set +# CONFIG_STM32_TIM14 is not set +# CONFIG_STM32_USART1 is not set +CONFIG_STM32_USART2=y +# CONFIG_STM32_USART3 is not set +# CONFIG_STM32_UART4 is not set +# CONFIG_STM32_UART5 is not set +# CONFIG_STM32_USART6 is not set +# CONFIG_STM32_WWDG is not set + +# +# Alternate Pin Mapping +# +# CONFIG_STM32_JTAG_DISABLE is not set +# CONFIG_STM32_JTAG_FULL_ENABLE is not set +# CONFIG_STM32_JTAG_NOJNTRST_ENABLE is not set +CONFIG_STM32_JTAG_SW_ENABLE=y +# CONFIG_STM32_FORCEPOWER is not set +# CONFIG_ARCH_BOARD_STM32_CUSTOM_CLOCKCONFIG is not set +# CONFIG_STM32_CCMEXCLUDE is not set + +# +# USB Host Configuration +# + +# +# Architecture Options +# +# CONFIG_ARCH_NOINTC is not set +# CONFIG_ARCH_DMA is not set +CONFIG_ARCH_STACKDUMP=y + +# +# Board Settings +# +CONFIG_DRAM_START=0x20000000 +CONFIG_DRAM_SIZE=114688 +CONFIG_ARCH_HAVE_INTERRUPTSTACK=y +CONFIG_ARCH_INTERRUPTSTACK=0 + +# +# Boot options +# +# CONFIG_BOOT_RUNFROMEXTSRAM is not set +CONFIG_BOOT_RUNFROMFLASH=y +# CONFIG_BOOT_RUNFROMISRAM is not set +# CONFIG_BOOT_RUNFROMSDRAM is not set +# CONFIG_BOOT_COPYTORAM is not set + +# +# Board Selection +# +CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y +# CONFIG_ARCH_BOARD_CUSTOM is not set +CONFIG_ARCH_BOARD="stm32f4discovery" + +# +# Common Board Options +# +CONFIG_ARCH_HAVE_LEDS=y +CONFIG_ARCH_LEDS=y +CONFIG_ARCH_HAVE_BUTTONS=y +# CONFIG_ARCH_BUTTONS is not set +CONFIG_ARCH_HAVE_IRQBUTTONS=y + +# +# Board-Specific Options +# + +# +# RTOS Features +# +CONFIG_MSEC_PER_TICK=10 +CONFIG_RR_INTERVAL=200 +# CONFIG_SCHED_INSTRUMENTATION is not set +CONFIG_TASK_NAME_SIZE=0 +# CONFIG_JULIAN_TIME is not set +CONFIG_START_YEAR=2012 +CONFIG_START_MONTH=11 +CONFIG_START_DAY=2 +CONFIG_DEV_CONSOLE=y +# CONFIG_DEV_LOWCONSOLE is not set +# CONFIG_MUTEX_TYPES is not set +# CONFIG_PRIORITY_INHERITANCE is not set +# CONFIG_FDCLONE_DISABLE is not set +# CONFIG_FDCLONE_STDIO is not set +CONFIG_SDCLONE_DISABLE=y +# CONFIG_SCHED_WORKQUEUE is not set +# CONFIG_SCHED_WAITPID is not set +# CONFIG_SCHED_ATEXIT is not set +CONFIG_SCHED_ONEXIT=y +CONFIG_SCHED_ONEXIT_MAX=4 +CONFIG_USER_ENTRYPOINT="cxxtest_main" +CONFIG_DISABLE_OS_API=y +# CONFIG_DISABLE_CLOCK is not set +# CONFIG_DISABLE_POSIX_TIMERS is not set +# CONFIG_DISABLE_PTHREAD is not set +# CONFIG_DISABLE_SIGNALS is not set +# CONFIG_DISABLE_MQUEUE is not set +CONFIG_DISABLE_MOUNTPOINT=y +CONFIG_DISABLE_ENVIRON=y +CONFIG_DISABLE_POLL=y + +# +# Sizes of configurable things (0 disables) +# +CONFIG_MAX_TASKS=16 +CONFIG_MAX_TASK_ARGS=4 +CONFIG_NPTHREAD_KEYS=4 +CONFIG_NFILE_DESCRIPTORS=8 +CONFIG_NFILE_STREAMS=8 +CONFIG_NAME_MAX=32 +CONFIG_PREALLOC_MQ_MSGS=4 +CONFIG_MQ_MAXMSGSIZE=32 +CONFIG_MAX_WDOGPARMS=2 +CONFIG_PREALLOC_WDOGS=4 +CONFIG_PREALLOC_TIMERS=4 + +# +# Stack and heap information +# +# CONFIG_CUSTOM_STACK is not set +CONFIG_IDLETHREAD_STACKSIZE=1024 +CONFIG_USERMAIN_STACKSIZE=2048 +CONFIG_PTHREAD_STACK_MIN=256 +CONFIG_PTHREAD_STACK_DEFAULT=2048 + +# +# Device Drivers +# +CONFIG_DEV_NULL=y +# CONFIG_DEV_ZERO is not set +# CONFIG_LOOP is not set +# CONFIG_RAMDISK is not set +# CONFIG_CAN is not set +# CONFIG_PWM is not set +# CONFIG_I2C is not set +CONFIG_ARCH_HAVE_I2CRESET=y +# CONFIG_SPI is not set +# CONFIG_RTC is not set +# CONFIG_WATCHDOG is not set +# CONFIG_ANALOG is not set +# CONFIG_BCH is not set +# CONFIG_INPUT is not set +# CONFIG_LCD is not set +# CONFIG_MMCSD is not set +# CONFIG_MTD is not set +# CONFIG_PIPES is not set +# CONFIG_PM is not set +# CONFIG_POWER is not set +# CONFIG_SENSORS is not set +# CONFIG_SERCOMM_CONSOLE is not set +CONFIG_SERIAL=y +# CONFIG_LOWLEVEL_CONSOLE is not set +# CONFIG_16550_UART is not set +CONFIG_ARCH_HAVE_USART2=y +CONFIG_MCU_SERIAL=y +CONFIG_STANDARD_SERIAL=y +CONFIG_USART2_SERIAL_CONSOLE=y +# CONFIG_NO_SERIAL_CONSOLE is not set + +# +# USART2 Configuration +# +CONFIG_USART2_RXBUFSIZE=128 +CONFIG_USART2_TXBUFSIZE=128 +CONFIG_USART2_BAUD=115200 +CONFIG_USART2_BITS=8 +CONFIG_USART2_PARITY=0 +CONFIG_USART2_2STOP=0 +# CONFIG_USBDEV is not set +# CONFIG_USBHOST is not set +# CONFIG_WIRELESS is not set + +# +# System Logging Device Options +# + +# +# System Logging +# +# CONFIG_RAMLOG is not set + +# +# Networking Support +# +# CONFIG_NET is not set + +# +# File Systems +# + +# +# File system configuration +# +# CONFIG_FS_RAMMAP is not set + +# +# System Logging +# +# CONFIG_SYSLOG is not set + +# +# Graphics Support +# +# CONFIG_NX is not set + +# +# Memory Management +# +# CONFIG_MM_SMALL is not set +CONFIG_MM_REGIONS=2 +# CONFIG_GRAN is not set + +# +# Binary Formats +# +# CONFIG_BINFMT_DISABLE is not set +# CONFIG_NXFLAT is not set +# CONFIG_ELF is not set +CONFIG_SYMTAB_ORDEREDBYNAME=y + +# +# Library Routines +# +CONFIG_STDIO_BUFFER_SIZE=256 +CONFIG_STDIO_LINEBUFFER=y +CONFIG_NUNGET_CHARS=2 +CONFIG_LIBM=y +# CONFIG_NOPRINTF_FIELDWIDTH is not set +# CONFIG_LIBC_FLOATINGPOINT is not set +# CONFIG_EOL_IS_CR is not set +# CONFIG_EOL_IS_LF is not set +# CONFIG_EOL_IS_BOTH_CRLF is not set +CONFIG_EOL_IS_EITHER_CRLF=y +# CONFIG_LIBC_STRERROR is not set +# CONFIG_LIBC_PERROR_STDOUT is not set +CONFIG_ARCH_LOWPUTC=y +CONFIG_LIB_SENDFILE_BUFSIZE=512 +# CONFIG_ARCH_ROMGETC is not set +# CONFIG_ARCH_OPTIMIZED_FUNCTIONS is not set + +# +# Basic CXX Support +# +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +# CONFIG_CXX_NEWLONG is not set + +# +# uClibc++ Standard C++ Library +# +CONFIG_UCLIBCXX=y +# CONFIG_UCLIBCXX_EXCEPTION is not set +CONFIG_UCLIBCXX_IOSTREAM_BUFSIZE=32 +CONFIG_UCLIBCXX_HAVE_LIBSUPCXX=y + +# +# Application Configuration +# + +# +# Named Applications +# +# CONFIG_NAMEDAPP is not set + +# +# Examples +# +# CONFIG_EXAMPLES_BUTTONS is not set +# CONFIG_EXAMPLES_CAN is not set +# CONFIG_EXAMPLES_CDCACM is not set +# CONFIG_EXAMPLES_COMPOSITE is not set +CONFIG_EXAMPLES_CXXTEST=y +# CONFIG_EXAMPLES_DHCPD is not set +# CONFIG_EXAMPLES_ELF is not set +# CONFIG_EXAMPLES_FTPC is not set +# CONFIG_EXAMPLES_FTPD is not set +# CONFIG_EXAMPLES_HELLO is not set +# CONFIG_EXAMPLES_HELLOXX is not set +# CONFIG_EXAMPLES_JSON is not set +# CONFIG_EXAMPLES_HIDKBD is not set +# CONFIG_EXAMPLES_IGMP is not set +# CONFIG_EXAMPLES_LCDRW is not set +# CONFIG_EXAMPLES_MM is not set +# CONFIG_EXAMPLES_MOUNT is not set +# CONFIG_EXAMPLES_MODBUS is not set +# CONFIG_EXAMPLES_NETTEST is not set +# CONFIG_EXAMPLES_NSH is not set +# CONFIG_EXAMPLES_NULL is not set +# CONFIG_EXAMPLES_NX is not set +# CONFIG_EXAMPLES_NXCONSOLE is not set +# CONFIG_EXAMPLES_NXFFS is not set +# CONFIG_EXAMPLES_NXFLAT is not set +# CONFIG_EXAMPLES_NXHELLO is not set +# CONFIG_EXAMPLES_NXIMAGE is not set +# CONFIG_EXAMPLES_NXLINES is not set +# CONFIG_EXAMPLES_NXTEXT is not set +# CONFIG_EXAMPLES_OSTEST is not set +# CONFIG_EXAMPLES_PASHELLO is not set +# CONFIG_EXAMPLES_PIPE is not set +# CONFIG_EXAMPLES_POLL is not set +# CONFIG_EXAMPLES_QENCODER is not set +# CONFIG_EXAMPLES_RGMP is not set +# CONFIG_EXAMPLES_ROMFS is not set +# CONFIG_EXAMPLES_SENDMAIL is not set +# CONFIG_EXAMPLES_SERLOOP is not set +# CONFIG_EXAMPLES_TELNETD is not set +# CONFIG_EXAMPLES_THTTPD is not set +# CONFIG_EXAMPLES_TIFF is not set +# CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_UDP is not set +# CONFIG_EXAMPLES_UIP is not set +# CONFIG_EXAMPLES_USBSERIAL is not set +# CONFIG_EXAMPLES_USBMSC is not set +# CONFIG_EXAMPLES_USBTERM is not set +# CONFIG_EXAMPLES_WATCHDOG is not set +# CONFIG_EXAMPLES_WLAN is not set + +# +# Interpreters +# + +# +# Interpreters +# +# CONFIG_FICL is not set +# CONFIG_PCODE is not set + +# +# Network Utilities +# + +# +# Networking Utilities +# +# CONFIG_NETUTILS_CODECS is not set +# CONFIG_NETUTILS_DHCPC is not set +# CONFIG_NETUTILS_DHCPD is not set +# CONFIG_NETUTILS_FTPC is not set +# CONFIG_NETUTILS_FTPD is not set +# CONFIG_NETUTILS_JSON is not set +# CONFIG_NETUTILS_RESOLV is not set +# CONFIG_NETUTILS_SMTP is not set +# CONFIG_NETUTILS_TELNETD is not set +# CONFIG_NETUTILS_TFTPC is not set +# CONFIG_NETUTILS_THTTPD is not set +# CONFIG_NETUTILS_UIPLIB is not set +# CONFIG_NETUTILS_WEBCLIENT is not set + +# +# ModBus +# + +# +# FreeModbus +# +# CONFIG_MODBUS is not set + +# +# NSH Library +# +# CONFIG_NSH_LIBRARY is not set + +# +# NxWidgets/NxWM +# + +# +# System NSH Add-Ons +# + +# +# Custom Free Memory Command +# +# CONFIG_SYSTEM_FREE is not set + +# +# I2C tool +# + +# +# FLASH Program Installation +# +# CONFIG_SYSTEM_INSTALL is not set + +# +# readline() +# +# CONFIG_SYSTEM_READLINE is not set + +# +# Power Off +# +# CONFIG_SYSTEM_POWEROFF is not set + +# +# RAMTRON +# +# CONFIG_SYSTEM_RAMTRON is not set + +# +# SD Card +# +# CONFIG_SYSTEM_SDCARD is not set + +# +# Sysinfo +# +# CONFIG_SYSTEM_SYSINFO is not set diff --git a/nuttx/configs/stm32f4discovery/cxxtest/setenv.sh b/nuttx/configs/stm32f4discovery/cxxtest/setenv.sh new file mode 100755 index 0000000000..a3c297c766 --- /dev/null +++ b/nuttx/configs/stm32f4discovery/cxxtest/setenv.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# configs/stm32f4discovery/cxxtest/setenv.sh +# +# Copyright (C) 2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# 3. Neither the name NuttX nor the names of its contributors may be +# used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +if [ "$_" = "$0" ] ; then + echo "You must source this script, not run it!" 1>&2 + exit 1 +fi + +WD=`pwd` +if [ ! -x "setenv.sh" ]; then + echo "This script must be executed from the top-level NuttX build directory" + exit 1 +fi + +if [ -z "${PATH_ORIG}" ]; then + export PATH_ORIG="${PATH}" +fi + +# This is the Cygwin path to the location where I installed the RIDE +# toolchain under windows. You will also have to edit this if you install +# the RIDE toolchain in any other location +#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin" + +# This is the Cygwin path to the location where I installed the CodeSourcery +# toolchain under windows. You will also have to edit this if you install +# the CodeSourcery toolchain in any other location +export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin" + +# These are the Cygwin paths to the locations where I installed the Atollic +# toolchain under windows. You will also have to edit this if you install +# the Atollic toolchain in any other location. /usr/bin is added before +# the Atollic bin path because there is are binaries named gcc.exe and g++.exe +# at those locations as well. +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin" +#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin" + +# This is the Cygwin path to the location where I build the buildroot +# toolchain. +#export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin" + +# Add the path to the toolchain to the PATH varialble +export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}" + +echo "PATH : ${PATH}" diff --git a/nuttx/configs/stm32f4discovery/ostest/defconfig b/nuttx/configs/stm32f4discovery/ostest/defconfig index 29d6b30eba..a644b42eca 100644 --- a/nuttx/configs/stm32f4discovery/ostest/defconfig +++ b/nuttx/configs/stm32f4discovery/ostest/defconfig @@ -251,7 +251,7 @@ CONFIG_SDCLONE_DISABLE=y # CONFIG_SCHED_WAITPID is not set # CONFIG_SCHED_ATEXIT is not set # CONFIG_SCHED_ONEXIT is not set -CONFIG_USER_ENTRYPOINT="elf_main" +CONFIG_USER_ENTRYPOINT="ostest_main" CONFIG_DISABLE_OS_API=y # CONFIG_DISABLE_CLOCK is not set # CONFIG_DISABLE_POSIX_TIMERS is not set