This commit is contained in:
romkazvo
2023-08-07 19:29:24 +08:00
commit 34d6c5d489
4832 changed files with 1389451 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
/*
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ABBREVS_H
# define _STLP_INTERNAL_ABBREVS_H
// ugliness is intentional - to reduce conflicts
# define input_iterator_tag _In__ItT
# define output_iterator_tag _Ou__ItT
# define bidirectional_iterator_tag _Bd__ItT
# define random_access_iterator_tag _Ra__ItT
# define input_iterator _In__It
# define output_iterator _Ou__It
# define bidirectional_iterator _Bd__It
# define random_access_iterator _Ra__It
# define reverse_bidirectional_iterator _rBd__It
# define reverse_iterator _r__It
# define back_insert_iterator _bI__It
# define front_insert_iterator _fI__It
# define raw_storage_iterator _rS__It
# define _Const_traits _C_Tr
# define _Nonconst_traits _N_Tr
// ugliness is intentional - to reduce conflicts probability
# define __malloc_alloc M__A
# define __node_alloc D__A
# define __new_alloc N__A
# define __debug_alloc G__A
# define __deque_iterator _dQ__It
# define _Buf_traits _dQ__BTr
# define _Deque_iterator _Dq__It
# define _Select1st _S1st
# define _Select2nd _S2nd
# define _Hashtable_iterator _hT__It
# define _Hashtable_const_iterator _hT__cIt
# define _Hashtable_node _hT__N
# define _Hashtable_base _hT__B
# define _Ht_iterator _Ht_It
# define __list_iterator _L__It
# define __slist_iterator _SL__It
# define _Rb_tree_node_base _rbT__NB
# define _Rb_tree_node _rbT__N
# define _Rb_base_iterator _rbTB__It
# define _Rb_tree_base_iterator _rbT__It
# define _Rb_tree_base _rbT__B
#endif
File diff suppressed because it is too large Load Diff
+740
View File
@@ -0,0 +1,740 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ALGO_H
#define _STLP_INTERNAL_ALGO_H
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_INTERNAL_TEMPBUF_H
# include <stl/_tempbuf.h>
# endif
# ifndef _STLP_INTERNAL_HEAP_H
# include <stl/_heap.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_FUNCTION_BASE_H
# include <stl/_function_base.h>
# endif
# ifdef __SUNPRO_CC
// remove() conflict
# include <cstdio>
# endif
_STLP_BEGIN_NAMESPACE
// for_each. Apply a function to every element of a range.
template <class _InputIter, class _Function>
_STLP_INLINE_LOOP _Function
for_each(_InputIter __first, _InputIter __last, _Function __f) {
for ( ; __first != __last; ++__first)
__f(*__first);
return __f;
}
// count_if
template <class _InputIter, class _Predicate>
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
count_if(_InputIter __first, _InputIter __last, _Predicate __pred) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
_STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
return __n;
}
// adjacent_find.
template <class _ForwardIter, class _BinaryPredicate>
_STLP_INLINE_LOOP _ForwardIter
adjacent_find(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
if (__first == __last)
return __last;
_ForwardIter __next = __first;
while(++__next != __last) {
if (__binary_pred(*__first, *__next))
return __first;
__first = __next;
}
return __last;
}
template <class _ForwardIter>
_STLP_INLINE_LOOP _ForwardIter
adjacent_find(_ForwardIter __first, _ForwardIter __last) {
return adjacent_find(__first, __last,
__equal_to(_STLP_VALUE_TYPE(__first, _ForwardIter)));
}
# ifndef _STLP_NO_ANACHRONISMS
template <class _InputIter, class _Tp, class _Size>
_STLP_INLINE_LOOP void
count(_InputIter __first, _InputIter __last, const _Tp& __val, _Size& __n) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (*__first == __val)
++__n;
}
template <class _InputIter, class _Predicate, class _Size>
_STLP_INLINE_LOOP void
count_if(_InputIter __first, _InputIter __last, _Predicate __pred, _Size& __n) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (__pred(*__first))
++__n;
}
# endif
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2);
// search_n. Search for __count consecutive copies of __val.
template <class _ForwardIter, class _Integer, class _Tp>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val);
template <class _ForwardIter, class _Integer, class _Tp, class _BinaryPred>
_ForwardIter search_n(_ForwardIter __first, _ForwardIter __last,
_Integer __count, const _Tp& __val, _BinaryPred __binary_pred);
template <class _InputIter, class _ForwardIter>
inline _InputIter find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
return __find_first_of(__first1, __last1, __first2, __last2,__equal_to(_STLP_VALUE_TYPE(__first1, _InputIter)));
}
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
inline _InputIter
find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2,_BinaryPredicate __comp) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
return __find_first_of(__first1, __last1, __first2, __last2,__comp);
}
template <class _ForwardIter1, class _ForwardIter2>
_ForwardIter1
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2);
// swap_ranges
template <class _ForwardIter1, class _ForwardIter2>
_STLP_INLINE_LOOP _ForwardIter2
swap_ranges(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2)
iter_swap(__first1, __first2);
return __first2;
}
// transform
template <class _InputIter, class _OutputIter, class _UnaryOperation>
_STLP_INLINE_LOOP _OutputIter
transform(_InputIter __first, _InputIter __last, _OutputIter __result, _UnaryOperation __opr) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first, ++__result)
*__result = __opr(*__first);
return __result;
}
template <class _InputIter1, class _InputIter2, class _OutputIter, class _BinaryOperation>
_STLP_INLINE_LOOP _OutputIter
transform(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _OutputIter __result,_BinaryOperation __binary_op) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2, ++__result)
*__result = __binary_op(*__first1, *__first2);
return __result;
}
// replace_if, replace_copy, replace_copy_if
template <class _ForwardIter, class _Predicate, class _Tp>
_STLP_INLINE_LOOP void
replace_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred, const _Tp& __new_value) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (__pred(*__first))
*__first = __new_value;
}
template <class _InputIter, class _OutputIter, class _Tp>
_STLP_INLINE_LOOP _OutputIter
replace_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
const _Tp& __old_value, const _Tp& __new_value) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first, ++__result)
*__result = *__first == __old_value ? __new_value : *__first;
return __result;
}
template <class _Iterator, class _OutputIter, class _Predicate, class _Tp>
_STLP_INLINE_LOOP _OutputIter
replace_copy_if(_Iterator __first, _Iterator __last,
_OutputIter __result,
_Predicate __pred, const _Tp& __new_value) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first, ++__result)
*__result = __pred(*__first) ? __new_value : *__first;
return __result;
}
// generate and generate_n
template <class _ForwardIter, class _Generator>
_STLP_INLINE_LOOP void
generate(_ForwardIter __first, _ForwardIter __last, _Generator __gen) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
*__first = __gen();
}
template <class _OutputIter, class _Size, class _Generator>
_STLP_INLINE_LOOP _OutputIter
generate_n(_OutputIter __first, _Size __n, _Generator __gen) {
for ( ; __n > 0; --__n, ++__first)
*__first = __gen();
return __first;
}
// remove, remove_if, remove_copy, remove_copy_if
template <class _InputIter, class _OutputIter, class _Tp>
_STLP_INLINE_LOOP _OutputIter
remove_copy(_InputIter __first, _InputIter __last,_OutputIter __result, const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (!(*__first == __val)) {
*__result = *__first;
++__result;
}
return __result;
}
template <class _InputIter, class _OutputIter, class _Predicate>
_STLP_INLINE_LOOP _OutputIter
remove_copy_if(_InputIter __first, _InputIter __last, _OutputIter __result, _Predicate __pred) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (!__pred(*__first)) {
*__result = *__first;
++__result;
}
return __result;
}
template <class _ForwardIter, class _Tp>
_STLP_INLINE_LOOP _ForwardIter
remove(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
__first = find(__first, __last, __val);
if (__first == __last)
return __first;
else {
_ForwardIter __next = __first;
return remove_copy(++__next, __last, __first, __val);
}
}
template <class _ForwardIter, class _Predicate>
_STLP_INLINE_LOOP _ForwardIter
remove_if(_ForwardIter __first, _ForwardIter __last, _Predicate __pred) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
__first = find_if(__first, __last, __pred);
if ( __first == __last )
return __first;
else {
_ForwardIter __next = __first;
return remove_copy_if(++__next, __last, __first, __pred);
}
}
// unique and unique_copy
template <class _InputIter, class _OutputIter>
_OutputIter unique_copy(_InputIter __first, _InputIter __last, _OutputIter __result);
template <class _InputIter, class _OutputIter, class _BinaryPredicate>
_OutputIter unique_copy(_InputIter __first, _InputIter __last,_OutputIter __result,
_BinaryPredicate __binary_pred);
template <class _ForwardIter>
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last) {
__first = adjacent_find(__first, __last);
return unique_copy(__first, __last, __first);
}
template <class _ForwardIter, class _BinaryPredicate>
inline _ForwardIter unique(_ForwardIter __first, _ForwardIter __last,
_BinaryPredicate __binary_pred) {
__first = adjacent_find(__first, __last, __binary_pred);
return unique_copy(__first, __last, __first, __binary_pred);
}
// reverse and reverse_copy, and their auxiliary functions
template <class _BidirectionalIter>
_STLP_INLINE_LOOP void
__reverse(_BidirectionalIter __first, _BidirectionalIter __last, const bidirectional_iterator_tag &) {
for(; __first != __last && __first != --__last; ++__first)
iter_swap(__first,__last);
}
template <class _RandomAccessIter>
_STLP_INLINE_LOOP void
__reverse(_RandomAccessIter __first, _RandomAccessIter __last, const random_access_iterator_tag &) {
for (; __first < __last; ++__first) iter_swap(__first, --__last);
}
template <class _BidirectionalIter>
inline void
reverse(_BidirectionalIter __first, _BidirectionalIter __last) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
__reverse(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _BidirectionalIter));
}
template <class _BidirectionalIter, class _OutputIter>
_STLP_INLINE_LOOP
_OutputIter reverse_copy(_BidirectionalIter __first,
_BidirectionalIter __last,
_OutputIter __result) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
while (__first != __last) {
--__last;
*__result = *__last;
++__result;
}
return __result;
}
// rotate and rotate_copy, and their auxiliary functions
template <class _EuclideanRingElement>
_STLP_INLINE_LOOP
_EuclideanRingElement __gcd(_EuclideanRingElement __m,
_EuclideanRingElement __n)
{
while (__n != 0) {
_EuclideanRingElement __t = __m % __n;
__m = __n;
__n = __t;
}
return __m;
}
template <class _ForwardIter>
_ForwardIter
rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last);
template <class _ForwardIter, class _OutputIter>
inline _OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle,
_ForwardIter __last, _OutputIter __result) {
return copy(__first, __middle, copy(__middle, __last, __result));
}
// random_shuffle
template <class _RandomAccessIter>
void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last);
template <class _RandomAccessIter, class _RandomNumberGenerator>
void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last,
_RandomNumberGenerator& __rand);
# ifndef _STLP_NO_EXTENSIONS
// random_sample and random_sample_n (extensions, not part of the standard).
template <class _ForwardIter, class _OutputIter, class _Distance>
_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
_OutputIter __out, const _Distance __n);
template <class _ForwardIter, class _OutputIter, class _Distance,
class _RandomNumberGenerator>
_OutputIter random_sample_n(_ForwardIter __first, _ForwardIter __last,
_OutputIter __out, const _Distance __n,
_RandomNumberGenerator& __rand);
template <class _InputIter, class _RandomAccessIter>
_RandomAccessIter
random_sample(_InputIter __first, _InputIter __last,
_RandomAccessIter __out_first, _RandomAccessIter __out_last);
template <class _InputIter, class _RandomAccessIter,
class _RandomNumberGenerator>
_RandomAccessIter
random_sample(_InputIter __first, _InputIter __last,
_RandomAccessIter __out_first, _RandomAccessIter __out_last,
_RandomNumberGenerator& __rand);
# endif /* _STLP_NO_EXTENSIONS */
// partition, stable_partition, and their auxiliary functions
template <class _ForwardIter, class _Predicate>
_ForwardIter partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
template <class _ForwardIter, class _Predicate>
_ForwardIter
stable_partition(_ForwardIter __first, _ForwardIter __last, _Predicate __pred);
// sort() and its auxiliary functions.
template <class _Size>
inline _Size __lg(_Size __n) {
_Size __k;
for (__k = 0; __n != 1; __n >>= 1) ++__k;
return __k;
}
template <class _RandomAccessIter>
void sort(_RandomAccessIter __first, _RandomAccessIter __last);
template <class _RandomAccessIter, class _Compare>
void sort(_RandomAccessIter __first, _RandomAccessIter __last, _Compare __comp);
// stable_sort() and its auxiliary functions.
template <class _RandomAccessIter>
void stable_sort(_RandomAccessIter __first,
_RandomAccessIter __last);
template <class _RandomAccessIter, class _Compare>
void stable_sort(_RandomAccessIter __first,
_RandomAccessIter __last, _Compare __comp);
// partial_sort, partial_sort_copy, and auxiliary functions.
template <class _RandomAccessIter>
void
partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle, _RandomAccessIter __last);
template <class _RandomAccessIter, class _Compare>
void
partial_sort(_RandomAccessIter __first,_RandomAccessIter __middle,
_RandomAccessIter __last, _Compare __comp);
template <class _InputIter, class _RandomAccessIter>
_RandomAccessIter
partial_sort_copy(_InputIter __first, _InputIter __last,
_RandomAccessIter __result_first, _RandomAccessIter __result_last);
template <class _InputIter, class _RandomAccessIter, class _Compare>
_RandomAccessIter
partial_sort_copy(_InputIter __first, _InputIter __last,
_RandomAccessIter __result_first,
_RandomAccessIter __result_last, _Compare __comp);
// nth_element() and its auxiliary functions.
template <class _RandomAccessIter>
void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
_RandomAccessIter __last);
template <class _RandomAccessIter, class _Compare>
void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth,
_RandomAccessIter __last, _Compare __comp);
// auxiliary class for lower_bound, etc.
template <class _T1, class _T2>
struct __less_2 {
bool operator() (const _T1& __x, const _T2 __y) const { return __x < __y ; }
};
template <class _T1, class _T2>
__less_2<_T1,_T2> __less2(_T1*, _T2* ) { return __less_2<_T1, _T2>(); }
#ifdef _STLP_FUNCTION_PARTIAL_ORDER
template <class _Tp>
less<_Tp> __less2(_Tp*, _Tp* ) { return less<_Tp>(); }
#endif
// Binary search (lower_bound, upper_bound, equal_range, binary_search).
template <class _ForwardIter, class _Tp>
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __lower_bound(__first, __last, __val,
__less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp, class _Compare>
inline _ForwardIter lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __lower_bound(__first, __last, __val, __comp, _STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
_ForwardIter __upper_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp, _Distance*);
template <class _ForwardIter, class _Tp>
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __upper_bound(__first, __last, __val,
__less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp, class _Compare>
inline _ForwardIter upper_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __upper_bound(__first, __last, __val, __comp,
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
pair<_ForwardIter, _ForwardIter>
__equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
_Compare __comp, _Distance*);
template <class _ForwardIter, class _Tp>
inline pair<_ForwardIter, _ForwardIter>
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __equal_range(__first, __last, __val,
__less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp, class _Compare>
inline pair<_ForwardIter, _ForwardIter>
equal_range(_ForwardIter __first, _ForwardIter __last, const _Tp& __val,
_Compare __comp) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __equal_range(__first, __last, __val, __comp,
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
}
template <class _ForwardIter, class _Tp>
inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
_ForwardIter __i = __lower_bound(__first, __last, __val,
__less2(_STLP_VALUE_TYPE(__first, _ForwardIter), (_Tp*)0),
_STLP_DISTANCE_TYPE(__first, _ForwardIter));
return __i != __last && !(__val < *__i);
}
template <class _ForwardIter, class _Tp, class _Compare>
inline bool binary_search(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val,
_Compare __comp) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
_ForwardIter __i = __lower_bound(__first, __last, __val, __comp, _STLP_DISTANCE_TYPE(__first, _ForwardIter));
return __i != __last && !__comp(__val, *__i);
}
// merge, with and without an explicitly supplied comparison function.
template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _Compare>
_OutputIter merge(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp);
// inplace_merge and its auxiliary functions.
template <class _BidirectionalIter>
void inplace_merge(_BidirectionalIter __first,
_BidirectionalIter __middle,
_BidirectionalIter __last) ;
template <class _BidirectionalIter, class _Compare>
void inplace_merge(_BidirectionalIter __first,
_BidirectionalIter __middle,
_BidirectionalIter __last, _Compare __comp);
// Set algorithms: includes, set_union, set_intersection, set_difference,
// set_symmetric_difference. All of these algorithms have the precondition
// that their input ranges are sorted and the postcondition that their output
// ranges are sorted.
template <class _InputIter1, class _InputIter2>
bool includes(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2);
template <class _InputIter1, class _InputIter2, class _Compare>
bool includes(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2, _Compare __comp);
template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _Compare>
_OutputIter set_union(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp);
template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _Compare>
_OutputIter set_intersection(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp);
template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _Compare>
_OutputIter set_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result, _Compare __comp);
template <class _InputIter1, class _InputIter2, class _OutputIter>
_OutputIter
set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result);
template <class _InputIter1, class _InputIter2, class _OutputIter,
class _Compare>
_OutputIter
set_symmetric_difference(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_OutputIter __result,
_Compare __comp);
// min_element and max_element, with and without an explicitly supplied
// comparison function.
template <class _ForwardIter>
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last);
template <class _ForwardIter, class _Compare>
_ForwardIter max_element(_ForwardIter __first, _ForwardIter __last,
_Compare __comp);
template <class _ForwardIter>
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last);
template <class _ForwardIter, class _Compare>
_ForwardIter min_element(_ForwardIter __first, _ForwardIter __last,
_Compare __comp);
// next_permutation and prev_permutation, with and without an explicitly
// supplied comparison function.
template <class _BidirectionalIter>
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
template <class _BidirectionalIter, class _Compare>
bool next_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
_Compare __comp);
template <class _BidirectionalIter>
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last);
template <class _BidirectionalIter, class _Compare>
bool prev_permutation(_BidirectionalIter __first, _BidirectionalIter __last,
_Compare __comp);
# ifndef _STLP_NO_EXTENSIONS
// is_heap, a predicate testing whether or not a range is
// a heap. This function is an extension, not part of the C++
// standard.
template <class _RandomAccessIter>
bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last);
template <class _RandomAccessIter, class _StrictWeakOrdering>
bool is_heap(_RandomAccessIter __first, _RandomAccessIter __last,
_StrictWeakOrdering __comp);
// is_sorted, a predicated testing whether a range is sorted in
// nondescending order. This is an extension, not part of the C++
// standard.
template <class _ForwardIter, class _StrictWeakOrdering>
bool __is_sorted(_ForwardIter __first, _ForwardIter __last,
_StrictWeakOrdering __comp);
template <class _ForwardIter>
inline bool is_sorted(_ForwardIter __first, _ForwardIter __last) {
return __is_sorted(__first, __last, __less(_STLP_VALUE_TYPE(__first, _ForwardIter)));
}
template <class _ForwardIter, class _StrictWeakOrdering>
inline bool is_sorted(_ForwardIter __first, _ForwardIter __last,
_StrictWeakOrdering __comp) {
return __is_sorted(__first, __last, __comp);
}
# endif
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_algo.c>
# endif
#endif /* _STLP_INTERNAL_ALGO_H */
// Local Variables:
// mode:C++
// End:
+392
View File
@@ -0,0 +1,392 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_ALGOBASE_C
#define _STLP_ALGOBASE_C
# if !defined (_STLP_INTERNAL_ALGOBASE_H)
# include <stl/_algobase.h>
# endif
_STLP_BEGIN_NAMESPACE
template <class _InputIter1, class _InputIter2>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) {
if (*__first1 < *__first2)
return true;
if (*__first2 < *__first1)
return false;
}
return __first1 == __last1 && __first2 != __last2;
}
template <class _InputIter1, class _InputIter2, class _Compare>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_Compare __comp) {
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
for ( ; __first1 != __last1 && __first2 != __last2
; ++__first1, ++__first2) {
if (__comp(*__first1, *__first2))
return true;
if (__comp(*__first2, *__first1))
return false;
}
return __first1 == __last1 && __first2 != __last2;
}
# ifndef _STLP_NO_EXTENSIONS
template <class _InputIter1, class _InputIter2>
int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2)
{
while (__first1 != __last1 && __first2 != __last2) {
if (*__first1 < *__first2)
return -1;
if (*__first2 < *__first1)
return 1;
++__first1;
++__first2;
}
if (__first2 == __last2) {
return !(__first1 == __last1);
}
else {
return -1;
}
}
template <class _InputIter1, class _InputIter2>
int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
return __lexicographical_compare_3way(__first1, __last1, __first2, __last2);
}
# endif
template <class _RandomAccessIter, class _Tp>
_STLP_INLINE_LOOP _RandomAccessIter __find(_RandomAccessIter __first, _RandomAccessIter __last,
const _Tp& __val,
const random_access_iterator_tag &)
{
_STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
for ( ; __trip_count > 0 ; --__trip_count) {
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
if (*__first == __val) return __first;
++__first;
}
switch(__last - __first) {
case 3:
if (*__first == __val) return __first;
++__first;
case 2:
if (*__first == __val) return __first;
++__first;
case 1:
if (*__first == __val) return __first;
++__first;
case 0:
default:
return __last;
}
}
template <class _RandomAccessIter, class _Predicate>
_STLP_INLINE_LOOP _RandomAccessIter __find_if(_RandomAccessIter __first, _RandomAccessIter __last,
_Predicate __pred,
const random_access_iterator_tag &)
{
_STLP_DIFFERENCE_TYPE(_RandomAccessIter) __trip_count = (__last - __first) >> 2;
for ( ; __trip_count > 0 ; --__trip_count) {
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
if (__pred(*__first)) return __first;
++__first;
}
switch(__last - __first) {
case 3:
if (__pred(*__first)) return __first;
++__first;
case 2:
if (__pred(*__first)) return __first;
++__first;
case 1:
if (__pred(*__first)) return __first;
// ++__first;
case 0:
default:
return __last;
}
}
template <class _InputIter, class _Tp>
inline _InputIter __find(_InputIter __first, _InputIter __last,
const _Tp& __val,
const input_iterator_tag &)
{
while (__first != __last && !(*__first == __val))
++__first;
return __first;
}
template <class _InputIter, class _Predicate>
inline _InputIter __find_if(_InputIter __first, _STLP_MPW_EXTRA_CONST _InputIter __last,
_Predicate __pred,
const input_iterator_tag &)
{
while (__first != __last && !__pred(*__first))
++__first;
return __first;
}
template <class _InputIter, class _Predicate>
_InputIter find_if(_InputIter __first, _InputIter __last,
_Predicate __pred) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __find_if(__first, __last, __pred, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
}
template <class _InputIter, class _Tp>
_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val)
{
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __find(__first, __last, __val, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
}
template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPred __predicate)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
// Test for empty ranges
if (__first1 == __last1 || __first2 == __last2)
return __first1;
// Test for a pattern of length 1.
_ForwardIter2 __tmp(__first2);
++__tmp;
if (__tmp == __last2) {
while (__first1 != __last1 && !__predicate(*__first1, *__first2))
++__first1;
return __first1;
}
// General case.
_ForwardIter2 __p1, __p;
__p1 = __first2; ++__p1;
// _ForwardIter1 __current = __first1;
while (__first1 != __last1) {
while (__first1 != __last1) {
if (__predicate(*__first1, *__first2))
break;
++__first1;
}
while (__first1 != __last1 && !__predicate(*__first1, *__first2))
++__first1;
if (__first1 == __last1)
return __last1;
__p = __p1;
_ForwardIter1 __current = __first1;
if (++__current == __last1) return __last1;
while (__predicate(*__current, *__p)) {
if (++__p == __last2)
return __first1;
if (++__current == __last1)
return __last1;
}
++__first1;
}
return __first1;
}
// find_first_of, with and without an explicitly supplied comparison function.
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
_InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2,
_BinaryPredicate __comp) {
for ( ; __first1 != __last1; ++__first1)
for (_ForwardIter __iter = __first2; __iter != __last2; ++__iter)
if (__comp(*__first1, *__iter))
return __first1;
return __last1;
}
// find_end, with and without an explicitly supplied comparison function.
// Search [first2, last2) as a subsequence in [first1, last1), and return
// the *last* possible match. Note that find_end for bidirectional iterators
// is much faster than for forward iterators.
// find_end for forward iterators.
template <class _ForwardIter1, class _ForwardIter2,
class _BinaryPredicate>
_ForwardIter1 __find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2,
const forward_iterator_tag &, const forward_iterator_tag &,
_BinaryPredicate __comp)
{
if (__first2 == __last2)
return __last1;
else {
_ForwardIter1 __result = __last1;
while (1) {
_ForwardIter1 __new_result
= search(__first1, __last1, __first2, __last2, __comp);
if (__new_result == __last1)
return __result;
else {
__result = __new_result;
__first1 = __new_result;
++__first1;
}
}
}
}
// find_end for bidirectional iterators. Requires partial specialization.
#if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
#if ! defined (_STLP_INTERNAL_ITERATOR_H)
_STLP_END_NAMESPACE
# include <stl/_iterator.h>
_STLP_BEGIN_NAMESPACE
#endif
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _BinaryPredicate>
_BidirectionalIter1
__find_end(_BidirectionalIter1 __first1, _BidirectionalIter1 __last1,
_BidirectionalIter2 __first2, _BidirectionalIter2 __last2,
const bidirectional_iterator_tag &, const bidirectional_iterator_tag &,
_BinaryPredicate __comp)
{
typedef reverse_iterator<_BidirectionalIter1> _RevIter1;
typedef reverse_iterator<_BidirectionalIter2> _RevIter2;
_RevIter1 __rlast1(__first1);
_RevIter2 __rlast2(__first2);
_RevIter1 __rresult = search(_RevIter1(__last1), __rlast1,
_RevIter2(__last2), __rlast2,
__comp);
if (__rresult == __rlast1)
return __last1;
else {
_BidirectionalIter1 __result = __rresult.base();
advance(__result, -distance(__first2, __last2));
return __result;
}
}
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
template <class _ForwardIter1, class _ForwardIter2,
class _BinaryPredicate>
_ForwardIter1
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPredicate __comp)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
return __find_end(__first1, __last1, __first2, __last2,
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
_STLP_ITERATOR_CATEGORY(__first1, _ForwardIter1),
_STLP_ITERATOR_CATEGORY(__first2, _ForwardIter2),
# else
forward_iterator_tag(),
forward_iterator_tag(),
# endif
__comp);
}
template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp, _Distance*)
{
_Distance __len = distance(__first, __last);
_Distance __half;
_ForwardIter __middle;
while (__len > 0) {
__half = __len >> 1;
__middle = __first;
advance(__middle, __half);
if (__comp(*__middle, __val)) {
__first = __middle;
++__first;
__len = __len - __half - 1;
}
else
__len = __half;
}
return __first;
}
_STLP_END_NAMESPACE
#endif /* _STLP_ALGOBASE_C */
// Local Variables:
// mode:C++
// End:
+583
View File
@@ -0,0 +1,583 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ALGOBASE_H
#define _STLP_INTERNAL_ALGOBASE_H
# if ! defined (_STLP_CSTDDEF)
# include <cstddef>
# endif
#ifndef _STLP_CSTRING
# include <cstring>
#endif
#ifndef _STLP_CLIMITS
# include <climits>
#endif
# if ! defined (_STLP_CSTDLIB)
# include <cstdlib>
# endif
# ifndef _STLP_INTERNAL_PAIR_H
# include <stl/_pair.h>
# endif
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
// swap and iter_swap
template <class _Tp>
inline void swap(_Tp& __a, _Tp& __b) {
_Tp __tmp = __a;
__a = __b;
__b = __tmp;
}
template <class _ForwardIter1, class _ForwardIter2>
inline void iter_swap(_ForwardIter1 __i1, _ForwardIter2 __i2) {
_STLP_STD::swap(*__i1, *__i2);
}
//--------------------------------------------------
// min and max
# if !defined (__BORLANDC__) || defined (_STLP_USE_OWN_NAMESPACE)
template <class _Tp>
inline const _Tp& (min)(const _Tp& __a, const _Tp& __b) { return __b < __a ? __b : __a; }
template <class _Tp>
inline const _Tp& (max)(const _Tp& __a, const _Tp& __b) { return __a < __b ? __b : __a; }
#endif /* __BORLANDC__ */
# if defined (__BORLANDC__) && ( __BORLANDC__ < 0x530 || defined (_STLP_USE_OWN_NAMESPACE))
inline unsigned long (min) (unsigned long __a, unsigned long __b) { return __b < __a ? __b : __a; }
inline unsigned long (max) (unsigned long __a, unsigned long __b) { return __a < __b ? __b : __a; }
# endif
template <class _Tp, class _Compare>
inline const _Tp& (min)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
return __comp(__b, __a) ? __b : __a;
}
template <class _Tp, class _Compare>
inline const _Tp& (max)(const _Tp& __a, const _Tp& __b, _Compare __comp) {
return __comp(__a, __b) ? __b : __a;
}
//--------------------------------------------------
// copy
// All of these auxiliary functions serve two purposes. (1) Replace
// calls to copy with memmove whenever possible. (Memmove, not memcpy,
// because the input and output ranges are permitted to overlap.)
// (2) If we're using random access iterators, then write the loop as
// a for loop with an explicit count.
template <class _InputIter, class _OutputIter, class _Distance>
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
_OutputIter __result,
const input_iterator_tag &, _Distance*) {
for ( ; __first != __last; ++__result, ++__first)
*__result = *__first;
return __result;
}
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
template <class _InputIter, class _OutputIter, class _Distance>
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
_OutputIter __result, const forward_iterator_tag &, _Distance* ) {
for ( ; __first != __last; ++__result, ++__first)
*__result = *__first;
return __result;
}
template <class _InputIter, class _OutputIter, class _Distance>
inline _OutputIter __copy(_InputIter __first, _InputIter __last,
_OutputIter __result, const bidirectional_iterator_tag &, _Distance* __dis) {
for ( ; __first != __last; ++__result, ++__first)
*__result = *__first;
return __result;
}
# endif
template <class _RandomAccessIter, class _OutputIter, class _Distance>
inline _OutputIter
__copy(_RandomAccessIter __first, _RandomAccessIter __last,
_OutputIter __result, const random_access_iterator_tag &, _Distance*) {
for (_Distance __n = __last - __first; __n > 0; --__n) {
*__result = *__first;
++__first;
++__result;
}
return __result;
}
inline void*
__copy_trivial(const void* __first, const void* __last, void* __result) {
return (__last == __first) ? __result :
((char*)memmove(__result, __first, ((const char*)__last - (const char*)__first))) +
((const char*)__last - (const char*)__first);
}
//--------------------------------------------------
// copy_backward auxiliary functions
template <class _BidirectionalIter1, class _BidirectionalIter2,
class _Distance>
inline _BidirectionalIter2 __copy_backward(_BidirectionalIter1 __first,
_BidirectionalIter1 __last,
_BidirectionalIter2 __result,
const bidirectional_iterator_tag &,
_Distance*)
{
while (__first != __last)
*--__result = *--__last;
return __result;
}
template <class _RandomAccessIter, class _BidirectionalIter, class _Distance>
inline _BidirectionalIter __copy_backward(_RandomAccessIter __first,
_RandomAccessIter __last,
_BidirectionalIter __result,
const random_access_iterator_tag &,
_Distance*)
{
for (_Distance __n = __last - __first; __n > 0; --__n)
*--__result = *--__last;
return __result;
}
inline void*
__copy_trivial_backward(const void* __first, const void* __last, void* __result) {
const ptrdiff_t _Num = (const char*)__last - (const char*)__first;
return (_Num > 0) ? memmove((char*)__result - _Num, __first, _Num) : __result ;
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
return __copy(__first, __last, __result,
_STLP_ITERATOR_CATEGORY(__first, _InputIter),
_STLP_DISTANCE_TYPE(__first, _InputIter));
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
// we know they all pointers, so this cast is OK
// return (_OutputIter)__copy_trivial(&(*__first), &(*__last), &(*__result));
return (_OutputIter)__copy_trivial(__first, __last, __result);
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
return __copy_ptrs(__first, __last, __result,
_IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter),
_STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
return __copy(__first, __last, __result,
_STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
}
template <class _InputIter, class _OutputIter>
inline _OutputIter copy(_InputIter __first, _InputIter __last, _OutputIter __result) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __copy_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret());
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_backward_ptrs(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
return (_OutputIter)__copy_trivial_backward(__first, __last, __result);
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __false_type&) {
return __copy_backward(__first, __last, __result, _STLP_ITERATOR_CATEGORY(__first,_InputIter), _STLP_DISTANCE_TYPE(__first, _InputIter));
}
template <class _InputIter, class _OutputIter>
inline _OutputIter __copy_backward_aux(_InputIter __first, _InputIter __last, _OutputIter __result, const __true_type&) {
return __copy_backward_ptrs(__first, __last, __result,
_IsOKToMemCpy(_STLP_VALUE_TYPE(__first, _InputIter),
_STLP_VALUE_TYPE(__result, _OutputIter))._Ret());
}
template <class _InputIter, class _OutputIter>
inline _OutputIter copy_backward(_InputIter __first, _InputIter __last, _OutputIter __result) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
return __copy_backward_aux(__first, __last, __result, _BothPtrType< _InputIter, _OutputIter> :: _Ret() );
}
#if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined ( _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS )
#define _STLP_DECLARE_COPY_TRIVIAL(_Tp) \
inline _Tp* copy(const _Tp* __first, const _Tp* __last, _Tp* __result) \
{ return (_Tp*)__copy_trivial(__first, __last, __result); } \
inline _Tp* copy_backward(const _Tp* __first, const _Tp* __last, _Tp* __result) \
{ return (_Tp*)__copy_trivial_backward(__first, __last, __result); }
_STLP_DECLARE_COPY_TRIVIAL(char)
# ifndef _STLP_NO_SIGNED_BUILTINS
_STLP_DECLARE_COPY_TRIVIAL(signed char)
# endif
_STLP_DECLARE_COPY_TRIVIAL(unsigned char)
_STLP_DECLARE_COPY_TRIVIAL(short)
_STLP_DECLARE_COPY_TRIVIAL(unsigned short)
_STLP_DECLARE_COPY_TRIVIAL(int)
_STLP_DECLARE_COPY_TRIVIAL(unsigned int)
_STLP_DECLARE_COPY_TRIVIAL(long)
_STLP_DECLARE_COPY_TRIVIAL(unsigned long)
#if !defined(_STLP_NO_WCHAR_T) && !defined (_STLP_WCHAR_T_IS_USHORT)
_STLP_DECLARE_COPY_TRIVIAL(wchar_t)
#endif
#ifdef _STLP_LONG_LONG
_STLP_DECLARE_COPY_TRIVIAL(long long)
_STLP_DECLARE_COPY_TRIVIAL(unsigned long long)
#endif
_STLP_DECLARE_COPY_TRIVIAL(float)
_STLP_DECLARE_COPY_TRIVIAL(double)
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_DECLARE_COPY_TRIVIAL(long double)
# endif
#undef _STLP_DECLARE_COPY_TRIVIAL
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
//--------------------------------------------------
// copy_n (not part of the C++ standard)
template <class _InputIter, class _Size, class _OutputIter>
_STLP_INLINE_LOOP
pair<_InputIter, _OutputIter> __copy_n(_InputIter __first, _Size __count,
_OutputIter __result,
const input_iterator_tag &) {
for ( ; __count > 0; --__count) {
*__result = *__first;
++__first;
++__result;
}
return pair<_InputIter, _OutputIter>(__first, __result);
}
template <class _RAIter, class _Size, class _OutputIter>
inline pair<_RAIter, _OutputIter>
__copy_n(_RAIter __first, _Size __count,
_OutputIter __result,
const random_access_iterator_tag &) {
_RAIter __last = __first + __count;
return pair<_RAIter, _OutputIter>(__last, copy(__first, __last, __result));
}
template <class _InputIter, class _Size, class _OutputIter>
inline pair<_InputIter, _OutputIter>
__copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
_STLP_FIX_LITERAL_BUG(__first)
return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
}
template <class _InputIter, class _Size, class _OutputIter>
inline pair<_InputIter, _OutputIter>
copy_n(_InputIter __first, _Size __count, _OutputIter __result) {
_STLP_FIX_LITERAL_BUG(__first)
return __copy_n(__first, __count, __result, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
}
//--------------------------------------------------
// fill and fill_n
template <class _ForwardIter, class _Tp>
_STLP_INLINE_LOOP
void fill(_ForwardIter __first, _ForwardIter __last, const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
*__first = __val;
}
template <class _OutputIter, class _Size, class _Tp>
_STLP_INLINE_LOOP
_OutputIter fill_n(_OutputIter __first, _Size __n, const _Tp& __val) {
_STLP_FIX_LITERAL_BUG(__first)
for ( ; __n > 0; --__n, ++__first)
*__first = __val;
return __first;
}
// Specialization: for one-byte types we can use memset.
inline void fill(unsigned char* __first, unsigned char* __last,
const unsigned char& __val) {
unsigned char __tmp = __val;
memset(__first, __tmp, __last - __first);
}
# ifndef _STLP_NO_SIGNED_BUILTINS
inline void fill(signed char* __first, signed char* __last,
const signed char& __val) {
signed char __tmp = __val;
memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
}
# endif
inline void fill(char* __first, char* __last, const char& __val) {
char __tmp = __val;
memset(__first, __STATIC_CAST(unsigned char,__tmp), __last - __first);
}
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Size>
inline unsigned char* fill_n(unsigned char* __first, _Size __n,
const unsigned char& __val) {
fill(__first, __first + __n, __val);
return __first + __n;
}
template <class _Size>
inline signed char* fill_n(char* __first, _Size __n,
const signed char& __val) {
fill(__first, __first + __n, __val);
return __first + __n;
}
template <class _Size>
inline char* fill_n(char* __first, _Size __n, const char& __val) {
fill(__first, __first + __n, __val);
return __first + __n;
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
//--------------------------------------------------
// equal and mismatch
template <class _InputIter1, class _InputIter2>
_STLP_INLINE_LOOP
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2) {
_STLP_FIX_LITERAL_BUG(__first2)
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
while (__first1 != __last1 && *__first1 == *__first2) {
++__first1;
++__first2;
}
return pair<_InputIter1, _InputIter2>(__first1, __first2);
}
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
_STLP_INLINE_LOOP
pair<_InputIter1, _InputIter2> mismatch(_InputIter1 __first1,
_InputIter1 __last1,
_InputIter2 __first2,
_BinaryPredicate __binary_pred) {
_STLP_FIX_LITERAL_BUG(__first2)
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
while (__first1 != __last1 && __binary_pred(*__first1, *__first2)) {
++__first1;
++__first2;
}
return pair<_InputIter1, _InputIter2>(__first1, __first2);
}
template <class _InputIter1, class _InputIter2>
_STLP_INLINE_LOOP
bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2) {
_STLP_FIX_LITERAL_BUG(__first1) _STLP_FIX_LITERAL_BUG(__last1) _STLP_FIX_LITERAL_BUG(__first2)
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2)
if (!(*__first1 == *__first2))
return false;
return true;
}
template <class _InputIter1, class _InputIter2, class _BinaryPredicate>
_STLP_INLINE_LOOP
bool equal(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _BinaryPredicate __binary_pred) {
_STLP_FIX_LITERAL_BUG(__first2)
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2)
if (!__binary_pred(*__first1, *__first2))
return false;
return true;
}
//--------------------------------------------------
// lexicographical_compare and lexicographical_compare_3way.
// (the latter is not part of the C++ standard.)
template <class _InputIter1, class _InputIter2>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2);
template <class _InputIter1, class _InputIter2, class _Compare>
bool lexicographical_compare(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2,
_Compare __comp);
inline bool
lexicographical_compare(const unsigned char* __first1,
const unsigned char* __last1,
const unsigned char* __first2,
const unsigned char* __last2)
{
const size_t __len1 = __last1 - __first1;
const size_t __len2 = __last2 - __first2;
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
return __result != 0 ? (__result < 0) : (__len1 < __len2);
}
# if !(CHAR_MAX == SCHAR_MAX)
inline bool lexicographical_compare(const char* __first1, const char* __last1,
const char* __first2, const char* __last2)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
_STLP_DEBUG_CHECK(__check_range(__first2, __last2))
return lexicographical_compare((const unsigned char*) __first1,
(const unsigned char*) __last1,
(const unsigned char*) __first2,
(const unsigned char*) __last2);
}
#endif /* CHAR_MAX == SCHAR_MAX */
template <class _InputIter1, class _InputIter2>
int __lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2);
inline int
__lexicographical_compare_3way(const unsigned char* __first1,
const unsigned char* __last1,
const unsigned char* __first2,
const unsigned char* __last2)
{
const ptrdiff_t __len1 = __last1 - __first1;
const ptrdiff_t __len2 = __last2 - __first2;
const int __result = memcmp(__first1, __first2, (min) (__len1, __len2));
return __result != 0 ? __result
: (__len1 == __len2 ? 0 : (__len1 < __len2 ? -1 : 1));
}
# if !(CHAR_MAX == SCHAR_MAX)
inline int
__lexicographical_compare_3way(const char* __first1, const char* __last1,
const char* __first2, const char* __last2)
{
return __lexicographical_compare_3way((const unsigned char*) __first1,
(const unsigned char*) __last1,
(const unsigned char*) __first2,
(const unsigned char*) __last2);
}
# endif
# ifndef _STLP_NO_EXTENSIONS
template <class _InputIter1, class _InputIter2>
int lexicographical_compare_3way(_InputIter1 __first1, _InputIter1 __last1,
_InputIter2 __first2, _InputIter2 __last2);
# endif /* EXTENSIONS */
// count
template <class _InputIter, class _Tp>
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_InputIter)
count(_InputIter __first, _InputIter __last, const _Tp& __val) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
_STLP_DIFFERENCE_TYPE(_InputIter) __n = 0;
for ( ; __first != __last; ++__first)
if (*__first == __val)
++__n;
return __n;
}
// find and find_if. Note find may be expressed in terms of find_if if appropriate binder was available.
template <class _InputIter, class _Tp>
_InputIter find(_InputIter __first, _InputIter __last, const _Tp& __val);
template <class _InputIter, class _Predicate>
_InputIter find_if(_InputIter __first, _InputIter __last, _Predicate __pred);
// search.
template <class _ForwardIter1, class _ForwardIter2, class _BinaryPred>
_ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2, _BinaryPred __predicate);
// find_first_of
template <class _InputIter, class _ForwardIter, class _BinaryPredicate>
_InputIter __find_first_of(_InputIter __first1, _InputIter __last1,
_ForwardIter __first2, _ForwardIter __last2,
_BinaryPredicate __comp);
template <class _ForwardIter1, class _ForwardIter2,
class _BinaryPredicate>
_ForwardIter1
find_end(_ForwardIter1 __first1, _ForwardIter1 __last1,
_ForwardIter2 __first2, _ForwardIter2 __last2,
_BinaryPredicate __comp);
// replace
template <class _ForwardIter, class _Tp>
_STLP_INLINE_LOOP void
replace(_ForwardIter __first, _ForwardIter __last,
const _Tp& __old_value, const _Tp& __new_value) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
if (*__first == __old_value)
*__first = __new_value;
}
template <class _ForwardIter, class _Tp, class _Compare, class _Distance>
_ForwardIter __lower_bound(_ForwardIter __first, _ForwardIter __last,
const _Tp& __val, _Compare __comp, _Distance*);
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_algobase.c>
# endif
#endif /* _STLP_INTERNAL_ALGOBASE_H */
// Local Variables:
// mode:C++
// End:
+370
View File
@@ -0,0 +1,370 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_ALLOC_C
#define _STLP_ALLOC_C
#ifdef __WATCOMC__
#pragma warning 13 9
#pragma warning 367 9
#pragma warning 368 9
#endif
#ifndef _STLP_INTERNAL_ALLOC_H
# include <stl/_alloc.h>
#endif
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
# ifdef _STLP_SGI_THREADS
// We test whether threads are in use before locking.
// Perhaps this should be moved into stl_threads.h, but that
// probably makes it harder to avoid the procedure call when
// it isn't needed.
extern "C" {
extern int __us_rsthread_malloc;
}
# endif
// Specialised debug form of malloc which does not provide "false"
// memory leaks when run with debug CRT libraries.
#if defined(_STLP_MSVC) && (_STLP_MSVC>=1020 && defined(_STLP_DEBUG_ALLOC)) && ! defined (_STLP_WINCE)
# include <crtdbg.h>
inline void* __stlp_chunk_malloc(size_t __bytes) { _STLP_CHECK_NULL_ALLOC(_malloc_dbg(__bytes, _CRT_BLOCK, __FILE__, __LINE__)); }
#else // !_DEBUG
# ifdef _STLP_NODE_ALLOC_USE_MALLOC
# include <cstdlib>
inline void* __stlp_chunk_malloc(size_t __bytes) { _STLP_CHECK_NULL_ALLOC(_STLP_VENDOR_CSTD::malloc(__bytes)); }
# else
inline void* __stlp_chunk_malloc(size_t __bytes) { return _STLP_STD::__stl_new(__bytes); }
# endif
#endif // !_DEBUG
#define _S_FREELIST_INDEX(__bytes) ((__bytes-size_t(1))>>(int)_ALIGN_SHIFT)
_STLP_BEGIN_NAMESPACE
template <int __inst>
void * _STLP_CALL __malloc_alloc<__inst>::_S_oom_malloc(size_t __n)
{
__oom_handler_type __my_malloc_handler;
void * __result;
for (;;) {
__my_malloc_handler = __oom_handler;
if (0 == __my_malloc_handler) { __THROW_BAD_ALLOC; }
(*__my_malloc_handler)();
__result = malloc(__n);
if (__result) return(__result);
}
#if defined(_STLP_NEED_UNREACHABLE_RETURN)
return 0;
#endif
}
template <class _Alloc>
void * _STLP_CALL __debug_alloc<_Alloc>::allocate(size_t __n) {
size_t __real_n = __n + __extra_before_chunk() + __extra_after_chunk();
__alloc_header *__result = (__alloc_header *)__allocator_type::allocate(__real_n);
memset((char*)__result, __shred_byte, __real_n*sizeof(value_type));
__result->__magic = __magic;
__result->__type_size = sizeof(value_type);
__result->_M_size = (_STLP_UINT32_T)__n;
return ((char*)__result) + (long)__extra_before;
}
template <class _Alloc>
void _STLP_CALL
__debug_alloc<_Alloc>::deallocate(void *__p, size_t __n) {
__alloc_header * __real_p = (__alloc_header*)((char *)__p -(long)__extra_before);
// check integrity
_STLP_VERBOSE_ASSERT(__real_p->__magic != __deleted_magic, _StlMsg_DBA_DELETED_TWICE)
_STLP_VERBOSE_ASSERT(__real_p->__magic == __magic, _StlMsg_DBA_NEVER_ALLOCATED)
_STLP_VERBOSE_ASSERT(__real_p->__type_size == 1,_StlMsg_DBA_TYPE_MISMATCH)
_STLP_VERBOSE_ASSERT(__real_p->_M_size == __n, _StlMsg_DBA_SIZE_MISMATCH)
// check pads on both sides
unsigned char* __tmp;
for (__tmp= (unsigned char*)(__real_p+1); __tmp < (unsigned char*)__p; __tmp++) {
_STLP_VERBOSE_ASSERT(*__tmp==__shred_byte, _StlMsg_DBA_UNDERRUN)
}
size_t __real_n= __n + __extra_before_chunk() + __extra_after_chunk();
for (__tmp= ((unsigned char*)__p)+__n*sizeof(value_type);
__tmp < ((unsigned char*)__real_p)+__real_n ; __tmp++) {
_STLP_VERBOSE_ASSERT(*__tmp==__shred_byte, _StlMsg_DBA_OVERRUN)
}
// that may be unfortunate, just in case
__real_p->__magic=__deleted_magic;
memset((char*)__p, __shred_byte, __n*sizeof(value_type));
__allocator_type::deallocate(__real_p, __real_n);
}
// # ifdef _STLP_THREADS
template <bool __threads, int __inst>
class _Node_Alloc_Lock {
public:
_Node_Alloc_Lock() {
# ifdef _STLP_SGI_THREADS
if (__threads && __us_rsthread_malloc)
# else /* !_STLP_SGI_THREADS */
if (__threads)
# endif
_S_lock._M_acquire_lock();
}
~_Node_Alloc_Lock() {
# ifdef _STLP_SGI_THREADS
if (__threads && __us_rsthread_malloc)
# else /* !_STLP_SGI_THREADS */
if (__threads)
# endif
_S_lock._M_release_lock();
}
static _STLP_STATIC_MUTEX _S_lock;
};
// # endif /* _STLP_THREADS */
template <bool __threads, int __inst>
void* _STLP_CALL
__node_alloc<__threads, __inst>::_M_allocate(size_t __n) {
void* __r;
_Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
// # ifdef _STLP_THREADS
/*REFERENCED*/
_Node_Alloc_Lock<__threads, __inst> __lock_instance;
// # endif
// Acquire the lock here with a constructor call.
// This ensures that it is released in exit or during stack
// unwinding.
if ( (__r = *__my_free_list) != 0 ) {
*__my_free_list = ((_Obj*)__r) -> _M_free_list_link;
} else {
__r = _S_refill(__n);
}
// lock is released here
return __r;
}
template <bool __threads, int __inst>
void _STLP_CALL
__node_alloc<__threads, __inst>::_M_deallocate(void *__p, size_t __n) {
_Obj * _STLP_VOLATILE * __my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
// # ifdef _STLP_THREADS
/*REFERENCED*/
_Node_Alloc_Lock<__threads, __inst> __lock_instance;
// # endif /* _STLP_THREADS */
// acquire lock
((_Obj *)__p) -> _M_free_list_link = *__my_free_list;
*__my_free_list = (_Obj *)__p;
// lock is released here
}
/* We allocate memory in large chunks in order to avoid fragmenting */
/* the malloc heap too much. */
/* We assume that size is properly aligned. */
/* We hold the allocation lock. */
template <bool __threads, int __inst>
char* _STLP_CALL
__node_alloc<__threads, __inst>::_S_chunk_alloc(size_t _p_size,
int& __nobjs)
{
char* __result;
size_t __total_bytes = _p_size * __nobjs;
size_t __bytes_left = _S_end_free - _S_start_free;
if (__bytes_left >= __total_bytes) {
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else if (__bytes_left >= _p_size) {
__nobjs = (int)(__bytes_left/_p_size);
__total_bytes = _p_size * __nobjs;
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else {
size_t __bytes_to_get =
2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
// Try to make use of the left-over piece.
if (__bytes_left > 0) {
_Obj* _STLP_VOLATILE* __my_free_list =
_S_free_list + _S_FREELIST_INDEX(__bytes_left);
((_Obj*)_S_start_free) -> _M_free_list_link = *__my_free_list;
*__my_free_list = (_Obj*)_S_start_free;
}
_S_start_free = (char*)__stlp_chunk_malloc(__bytes_to_get);
if (0 == _S_start_free) {
size_t __i;
_Obj* _STLP_VOLATILE* __my_free_list;
_Obj* __p;
// Try to make do with what we have. That can't
// hurt. We do not try smaller requests, since that tends
// to result in disaster on multi-process machines.
for (__i = _p_size; __i <= (size_t)_MAX_BYTES; __i += (size_t)_ALIGN) {
__my_free_list = _S_free_list + _S_FREELIST_INDEX(__i);
__p = *__my_free_list;
if (0 != __p) {
*__my_free_list = __p -> _M_free_list_link;
_S_start_free = (char*)__p;
_S_end_free = _S_start_free + __i;
return(_S_chunk_alloc(_p_size, __nobjs));
// Any leftover piece will eventually make it to the
// right free list.
}
}
_S_end_free = 0; // In case of exception.
_S_start_free = (char*)__stlp_chunk_malloc(__bytes_to_get);
/*
(char*)malloc_alloc::allocate(__bytes_to_get);
*/
// This should either throw an
// exception or remedy the situation. Thus we assume it
// succeeded.
}
_S_heap_size += __bytes_to_get;
_S_end_free = _S_start_free + __bytes_to_get;
return(_S_chunk_alloc(_p_size, __nobjs));
}
}
/* Returns an object of size __n, and optionally adds to size __n free list.*/
/* We assume that __n is properly aligned. */
/* We hold the allocation lock. */
template <bool __threads, int __inst>
void* _STLP_CALL
__node_alloc<__threads, __inst>::_S_refill(size_t __n)
{
int __nobjs = 20;
__n = _S_round_up(__n);
char* __chunk = _S_chunk_alloc(__n, __nobjs);
_Obj* _STLP_VOLATILE* __my_free_list;
_Obj* __result;
_Obj* __current_obj;
_Obj* __next_obj;
int __i;
if (1 == __nobjs) return(__chunk);
__my_free_list = _S_free_list + _S_FREELIST_INDEX(__n);
/* Build free list in chunk */
__result = (_Obj*)__chunk;
*__my_free_list = __next_obj = (_Obj*)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
__next_obj = (_Obj*)((char*)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> _M_free_list_link = 0;
break;
} else {
__current_obj -> _M_free_list_link = __next_obj;
}
}
return(__result);
}
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
// malloc_alloc out-of-memory handling
template <int __inst>
__oom_handler_type __malloc_alloc<__inst>::__oom_handler=(__oom_handler_type)0 ;
// #ifdef _STLP_THREADS
template <bool __threads, int __inst>
_STLP_STATIC_MUTEX
_Node_Alloc_Lock<__threads, __inst>::_S_lock _STLP_MUTEX_INITIALIZER;
// #endif
template <bool __threads, int __inst>
_Node_alloc_obj * _STLP_VOLATILE
__node_alloc<__threads, __inst>::_S_free_list[_STLP_NFREELISTS]
= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
// The 16 zeros are necessary to make version 4.1 of the SunPro
// compiler happy. Otherwise it appears to allocate too little
// space for the array.
template <bool __threads, int __inst>
char *__node_alloc<__threads, __inst>::_S_start_free = 0;
template <bool __threads, int __inst>
char *__node_alloc<__threads, __inst>::_S_end_free = 0;
template <bool __threads, int __inst>
size_t __node_alloc<__threads, __inst>::_S_heap_size = 0;
# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
__DECLARE_INSTANCE(__oom_handler_type, __malloc_alloc<0>::__oom_handler, =0);
# define _STLP_ALLOC_NOTHREADS __node_alloc<false, 0>
# define _STLP_ALLOC_THREADS __node_alloc<true, 0>
# define _STLP_ALLOC_NOTHREADS_LOCK _Node_Alloc_Lock<false, 0>
# define _STLP_ALLOC_THREADS_LOCK _Node_Alloc_Lock<true, 0>
__DECLARE_INSTANCE(char *, _STLP_ALLOC_NOTHREADS::_S_start_free,=0);
__DECLARE_INSTANCE(char *, _STLP_ALLOC_NOTHREADS::_S_end_free,=0);
__DECLARE_INSTANCE(size_t, _STLP_ALLOC_NOTHREADS::_S_heap_size,=0);
__DECLARE_INSTANCE(_Node_alloc_obj * _STLP_VOLATILE,
_STLP_ALLOC_NOTHREADS::_S_free_list[_STLP_NFREELISTS],
={0});
__DECLARE_INSTANCE(char *, _STLP_ALLOC_THREADS::_S_start_free,=0);
__DECLARE_INSTANCE(char *, _STLP_ALLOC_THREADS::_S_end_free,=0);
__DECLARE_INSTANCE(size_t, _STLP_ALLOC_THREADS::_S_heap_size,=0);
__DECLARE_INSTANCE(_Node_alloc_obj * _STLP_VOLATILE,
_STLP_ALLOC_THREADS::_S_free_list[_STLP_NFREELISTS],
={0});
// # ifdef _STLP_THREADS
__DECLARE_INSTANCE(_STLP_STATIC_MUTEX,
_STLP_ALLOC_NOTHREADS_LOCK::_S_lock,
_STLP_MUTEX_INITIALIZER);
__DECLARE_INSTANCE(_STLP_STATIC_MUTEX,
_STLP_ALLOC_THREADS_LOCK::_S_lock,
_STLP_MUTEX_INITIALIZER);
// # endif
# undef _STLP_ALLOC_THREADS
# undef _STLP_ALLOC_NOTHREADS
# endif /* _STLP_STATIC_TEMPLATE_DATA */
_STLP_END_NAMESPACE
# undef _S_FREELIST_INDEX
# endif /* _STLP_EXPOSE_GLOBALS_IMPLEMENTATION */
#endif /* _STLP_ALLOC_C */
// Local Variables:
// mode:C++
// End:
+531
View File
@@ -0,0 +1,531 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ALLOC_H
#define _STLP_INTERNAL_ALLOC_H
# ifndef _STLP_CSTDDEF
# include <cstddef>
# endif
#if !defined (_STLP_DEBUG_H) && (defined (_STLP_DEBUG) || defined (_STLP_ASSERTIONS))
# include <stl/debug/_debug.h>
#endif
# ifndef _STLP_CSTDLIB
# include <cstdlib>
# endif
# ifndef _STLP_CSTRING
# include <cstring>
# endif
# ifndef __THROW_BAD_ALLOC
# if !defined(_STLP_USE_EXCEPTIONS)
# if !defined (_STLP_CSTDIO)
# include <cstdio>
# endif
# if !defined (_STLP_CSTDLIB)
# include <cstdlib>
# endif
# define __THROW_BAD_ALLOC puts("out of memory\n"); exit(1)
# else /* !defined(_STLP_USE_EXCEPTIONS) */
# define __THROW_BAD_ALLOC throw _STLP_STD::bad_alloc()
# endif /* !defined(_STLP_USE_EXCEPTIONS) */
# endif /* __THROW_BAD_ALLOC */
# ifndef _STLP_INTERNAL_NEW_HEADER
# include <stl/_new.h>
# endif
#if /* defined (_STLP_THREADS) && */ ! defined (_STLP_INTERNAL_THREADS_H)
# include <stl/_threads.h>
#endif
#ifndef _STLP_INTERNAL_CONSTRUCT_H
# include <stl/_construct.h>
#endif
#ifndef __ALLOC
# define __ALLOC __sgi_alloc
#endif
# ifndef __RESTRICT
# define __RESTRICT
# endif
#if defined (_STLP_THREADS) || (defined(_STLP_OWN_IOSTREAMS) && ! defined (_STLP_NO_THREADS) && ! defined (_NOTHREADS) )
# define _STLP_NODE_ALLOCATOR_THREADS true
#else
# define _STLP_NODE_ALLOCATOR_THREADS false
#endif
_STLP_BEGIN_NAMESPACE
# if defined (_STLP_USE_RAW_SGI_ALLOCATORS)
template <class _Tp, class _Alloc> struct __allocator;
# endif
// Malloc-based allocator. Typically slower than default alloc below.
// Typically thread-safe and more storage efficient.
typedef void (* __oom_handler_type)();
template <int __inst>
class __malloc_alloc {
private:
static void* _STLP_CALL _S_oom_malloc(size_t);
static __oom_handler_type __oom_handler;
public:
// this one is needed for proper simple_alloc wrapping
typedef char value_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, __malloc_alloc<__inst> > other;
};
# endif
static void* _STLP_CALL allocate(size_t __n) {
void* __result = malloc(__n);
if (0 == __result) __result = _S_oom_malloc(__n);
return __result;
}
static void _STLP_CALL deallocate(void* __p, size_t /* __n */) { free((char*)__p); }
static __oom_handler_type _STLP_CALL set_malloc_handler(__oom_handler_type __f) {
__oom_handler_type __old = __oom_handler;
__oom_handler = __f;
return(__old);
}
};
// New-based allocator. Typically slower than default alloc below.
// Typically thread-safe and more storage efficient.
class _STLP_CLASS_DECLSPEC __new_alloc {
public:
// this one is needed for proper simple_alloc wrapping
typedef char value_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined(_STLP_USE_RAW_SGI_ALLOCATORS)
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, __new_alloc > other;
};
# endif
static void* _STLP_CALL allocate(size_t __n) { return __stl_new(__n); }
static void _STLP_CALL deallocate(void* __p, size_t) { __stl_delete(__p); }
};
// Allocator adaptor to check size arguments for debugging.
// Reports errors using assert. Checking can be disabled with
// NDEBUG, but it's far better to just use the underlying allocator
// instead when no checking is desired.
// There is some evidence that this can confuse Purify.
// This adaptor can only be applied to raw allocators
template <class _Alloc>
class __debug_alloc : public _Alloc {
public:
typedef _Alloc __allocator_type;
typedef typename _Alloc::value_type value_type;
private:
struct __alloc_header {
size_t __magic: 16;
size_t __type_size:16;
_STLP_UINT32_T _M_size;
}; // that is 8 bytes for sure
// Sunpro CC has bug on enums, so extra_before/after set explicitly
enum { __pad=8, __magic=0xdeba, __deleted_magic = 0xdebd,
__shred_byte= _STLP_SHRED_BYTE
};
enum { __extra_before = 16, __extra_after = 8 };
// Size of space used to store size. Note
// that this must be large enough to preserve
// alignment.
static size_t _STLP_CALL __extra_before_chunk() {
return (long)__extra_before/sizeof(value_type)+
(size_t)((long)__extra_before%sizeof(value_type)>0);
}
static size_t _STLP_CALL __extra_after_chunk() {
return (long)__extra_after/sizeof(value_type)+
(size_t)((long)__extra_after%sizeof(value_type)>0);
}
public:
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
template <class _Tp1> struct rebind {
typedef __allocator< _Tp1, __debug_alloc<_Alloc> > other;
};
# endif
__debug_alloc() {}
~__debug_alloc() {}
static void * _STLP_CALL allocate(size_t);
static void _STLP_CALL deallocate(void *, size_t);
};
// Default node allocator.
// With a reasonable compiler, this should be roughly as fast as the
// original STL class-specific allocators, but with less fragmentation.
// Default_alloc_template parameters are experimental and MAY
// DISAPPEAR in the future. Clients should just use alloc for now.
//
// Important implementation properties:
// 1. If the client request an object of size > _MAX_BYTES, the resulting
// object will be obtained directly from malloc.
// 2. In all other cases, we allocate an object of size exactly
// _S_round_up(requested_size). Thus the client has enough size
// information that we can return the object to the proper free list
// without permanently losing part of the object.
//
// The first template parameter specifies whether more than one thread
// may use this allocator. It is safe to allocate an object from
// one instance of a default_alloc and deallocate it with another
// one. This effectively transfers its ownership to the second one.
// This may have undesirable effects on reference locality.
// The second parameter is unreferenced and serves only to allow the
// creation of multiple default_alloc instances.
# if defined(__OS400__)
enum {_ALIGN = 16, _ALIGN_SHIFT=4, _MAX_BYTES = 256};
# define _STLP_NFREELISTS 16
# else
enum {_ALIGN = 8, _ALIGN_SHIFT=3, _MAX_BYTES = 128};
# define _STLP_NFREELISTS 16
# endif /* __OS400__ */
class _STLP_CLASS_DECLSPEC _Node_alloc_obj {
public:
_Node_alloc_obj * _M_free_list_link;
};
template <bool __threads, int __inst>
class __node_alloc {
_STLP_PRIVATE:
static inline size_t _STLP_CALL _S_round_up(size_t __bytes) { return (((__bytes) + (size_t)_ALIGN-1) & ~((size_t)_ALIGN - 1)); }
typedef _Node_alloc_obj _Obj;
private:
// Returns an object of size __n, and optionally adds to size __n free list.
static void* _STLP_CALL _S_refill(size_t __n);
// Allocates a chunk for nobjs of size size. nobjs may be reduced
// if it is inconvenient to allocate the requested number.
static char* _STLP_CALL _S_chunk_alloc(size_t __p_size, int& __nobjs);
// Chunk allocation state.
static _Node_alloc_obj * _STLP_VOLATILE _S_free_list[_STLP_NFREELISTS];
static char* _S_start_free;
static char* _S_end_free;
static size_t _S_heap_size;
static void * _STLP_CALL _M_allocate(size_t __n);
/* __p may not be 0 */
static void _STLP_CALL _M_deallocate(void *__p, size_t __n);
public:
// this one is needed for proper simple_alloc wrapping
typedef char value_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_USE_RAW_SGI_ALLOCATORS)
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, __node_alloc<__threads, __inst> > other;
};
# endif
/* __n must be > 0 */
static void * _STLP_CALL allocate(size_t __n) { return (__n > (size_t)_MAX_BYTES) ? __stl_new(__n) : _M_allocate(__n); }
/* __p may not be 0 */
static void _STLP_CALL deallocate(void *__p, size_t __n) { if (__n > (size_t)_MAX_BYTES) __stl_delete(__p); else _M_deallocate(__p, __n); }
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS __malloc_alloc<0>;
_STLP_EXPORT_TEMPLATE_CLASS __node_alloc<_STLP_NODE_ALLOCATOR_THREADS, 0>;
# endif /* _STLP_USE_TEMPLATE_EXPORT */
typedef __node_alloc<_STLP_NODE_ALLOCATOR_THREADS, 0> _Node_alloc;
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<_Node_alloc>;
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__new_alloc>;
_STLP_EXPORT_TEMPLATE_CLASS __debug_alloc<__malloc_alloc<0> >;
# endif
# if defined (_STLP_USE_PERTHREAD_ALLOC)
_STLP_END_NAMESPACE
// include additional header here
# include <stl/_pthread_alloc.h>
_STLP_BEGIN_NAMESPACE
# if defined ( _STLP_DEBUG_ALLOC )
typedef __debug_alloc<__pthread_alloc> __sgi_alloc;
# else
typedef __pthread_alloc __sgi_alloc;
# endif /* _STLP_DEBUG_ALLOC */
typedef __pthread_alloc __single_client_alloc;
typedef __pthread_alloc __multithreaded_alloc;
# else
# if defined ( _STLP_USE_NEWALLOC )
# if defined ( _STLP_DEBUG_ALLOC )
typedef __debug_alloc<__new_alloc> __sgi_alloc;
# else
typedef __new_alloc __sgi_alloc;
# endif /* _STLP_DEBUG_ALLOC */
typedef __new_alloc __single_client_alloc;
typedef __new_alloc __multithreaded_alloc;
# elif defined (_STLP_USE_MALLOC)
# if defined ( _STLP_DEBUG_ALLOC )
typedef __debug_alloc<__malloc_alloc<0> > __sgi_alloc;
# else
typedef __malloc_alloc<0> __sgi_alloc;
# endif /* _STLP_DEBUG_ALLOC */
typedef __malloc_alloc<0> __single_client_alloc;
typedef __malloc_alloc<0> __multithreaded_alloc;
# else
# if defined ( _STLP_DEBUG_ALLOC )
typedef __debug_alloc<_Node_alloc> __sgi_alloc;
# else
typedef _Node_alloc __sgi_alloc;
# endif
typedef __node_alloc<false, 0> __single_client_alloc;
typedef __node_alloc<true, 0> __multithreaded_alloc;
# endif /* _STLP_USE_NEWALLOC */
# endif /* PTHREAD_ALLOC */
// This implements allocators as specified in the C++ standard.
//
// Note that standard-conforming allocators use many language features
// that are not yet widely implemented. In particular, they rely on
// member templates, partial specialization, partial ordering of function
// templates, the typename keyword, and the use of the template keyword
// to refer to a template member of a dependent type.
template <class _Tp>
class allocator {
public:
typedef _Tp value_type;
typedef value_type * pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
template <class _Tp1> struct rebind {
typedef allocator<_Tp1> other;
};
# endif
allocator() _STLP_NOTHROW {}
# if defined (_STLP_MEMBER_TEMPLATES)
template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
# endif
allocator(const allocator<_Tp>&) _STLP_NOTHROW {}
~allocator() _STLP_NOTHROW {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// __n is permitted to be 0. The C++ standard says nothing about what the return value is when __n == 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0 ? __REINTERPRET_CAST(value_type*,__sgi_alloc::allocate(__n * sizeof(value_type))) : 0;
}
// __p is permitted to be a null pointer, only if n==0.
void deallocate(pointer __p, size_type __n) {
_STLP_ASSERT( (__p == 0) == (__n == 0) )
if (__p != 0) __sgi_alloc::deallocate((void*)__p, __n * sizeof(value_type));
}
// backwards compatibility
void deallocate(pointer __p) const { if (__p != 0) __sgi_alloc::deallocate((void*)__p, sizeof(value_type)); }
size_type max_size() const _STLP_NOTHROW { return size_t(-1) / sizeof(value_type); }
void construct(pointer __p, const _Tp& __val) { _STLP_STD::_Construct(__p, __val); }
void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
# if defined(__MRC__)||(defined(__SC__) && !defined(__DMC__))
template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
# endif
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC allocator<void> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
typedef void value_type;
# endif
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
template <class _Tp1> struct rebind {
typedef allocator<_Tp1> other;
};
# endif
# if defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)) //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
template <class _T2> bool operator==(const allocator<_T2>&) const _STLP_NOTHROW { return true; }
template <class _T2> bool operator!=(const allocator<_T2>&) const _STLP_NOTHROW { return false; }
# endif
};
#if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))) //*ty 03/24/2001 - MPW compilers get confused on these operator definitions
template <class _T1, class _T2> inline bool _STLP_CALL operator==(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return true; }
template <class _T1, class _T2> inline bool _STLP_CALL operator!=(const allocator<_T1>&, const allocator<_T2>&) _STLP_NOTHROW { return false; }
#endif
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS allocator<char>;
# if defined (_STLP_HAS_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS allocator<wchar_t>;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
// Another allocator adaptor: _Alloc_traits. This serves two
// purposes. First, make it possible to write containers that can use
// either SGI-style allocators or standard-conforming allocator.
// The fully general version.
template <class _Tp, class _Allocator>
struct _Alloc_traits
{
typedef _Allocator _Orig;
# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
typedef typename _Rebind_type::other allocator_type;
static allocator_type create_allocator(const _Orig& __a) { return allocator_type(__a); }
# else
// this is not actually true, used only to pass this type through
// to dynamic overload selection in _STLP_alloc_proxy methods
typedef _Allocator allocator_type;
# endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
};
#ifndef _STLP_FORCE_ALLOCATORS
#define _STLP_FORCE_ALLOCATORS(a,y)
#endif
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (_STLP_MEMBER_TEMPLATE_CLASSES)
// The version for the default allocator, for rare occasion when we have partial spec w/o member template classes
template <class _Tp, class _Tp1>
struct _Alloc_traits<_Tp, allocator<_Tp1> > {
typedef allocator<_Tp1> _Orig;
typedef allocator<_Tp> allocator_type;
static allocator_type create_allocator(const allocator<_Tp1 >& __a) { return allocator_type(__a); }
};
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
/* macro to convert the allocator for initialization
* not using MEMBER_TEMPLATE_CLASSES as it should work given template constructor */
#if defined (_STLP_MEMBER_TEMPLATES) || ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
/* if _STLP_NO_TEMPLATE_CONVERSIONS is set, the member template constructor is
* not used implicitly to convert allocator parameter, so let us do it explicitly */
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES) && defined (_STLP_NO_TEMPLATE_CONVERSIONS)
# define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
# else
# define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
# endif
/* else convert, but only if partial specialization works, since else
* Container::allocator_type won't be different */
#else
# define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __stl_alloc_create(__a,(_Tp*)0)
#endif
# if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
template <class _Tp, class _Alloc>
inline _STLP_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type _STLP_CALL
__stl_alloc_create(const _Alloc& __a, const _Tp*) {
typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
return _Rebound_type(__a);
}
#else
// If custom allocators are being used without member template classes support :
// user (on purpose) is forced to define rebind/get operations !!!
template <class _Tp1, class _Tp2>
inline allocator<_Tp2>& _STLP_CALL
__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) { return (allocator<_Tp2>&)(__a); }
template <class _Tp1, class _Tp2>
inline allocator<_Tp2> _STLP_CALL
__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) { return allocator<_Tp2>(); }
#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
# ifdef _STLP_USE_RAW_SGI_ALLOCATORS
// move obsolete stuff out of the way
# include <stl/_alloc_old.h>
# endif
// inheritance is being used for EBO optimization
template <class _Value, class _Tp, class _MaybeReboundAlloc>
class _STLP_alloc_proxy : public _MaybeReboundAlloc {
private:
typedef _MaybeReboundAlloc _Base;
typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
public:
_Value _M_data;
inline _STLP_alloc_proxy(const _MaybeReboundAlloc& __a, _Value __p) : _MaybeReboundAlloc(__a), _M_data(__p) {}
# if 0
inline _STLP_alloc_proxy(const _Self& __x) : _MaybeReboundAlloc(__x), _M_data(__x._M_data) {}
// construction/destruction
inline _Self& operator = (const _Self& __x) {
*(_MaybeReboundAlloc*)this = *(_MaybeReboundAlloc*)__x;
_M_data = __x._M_data; return *this;
}
inline _Self& operator = (const _Base& __x) { ((_Base&)*this) = __x; return *this; }
# endif
// Unified interface to perform allocate()/deallocate() with limited
// language support
#if ! defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
// else it is rebound already, and allocate() member is accessible
inline _Tp* allocate(size_t __n) {
return __stl_alloc_rebind(__STATIC_CAST(_Base&,*this),(_Tp*)0).allocate(__n,0);
}
inline void deallocate(_Tp* __p, size_t __n) {
__stl_alloc_rebind(__STATIC_CAST(_Base&, *this),(_Tp*)0).deallocate(__p, __n);
}
#endif /* !_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<char *,char,allocator<char> >;
# if defined (_STLP_HAS_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<wchar_t *,wchar_t,allocator<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
# undef _STLP_NODE_ALLOCATOR_THREADS
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_alloc.c>
# endif
#endif /* _STLP_INTERNAL_ALLOC_H */
// Local Variables:
// mode:C++
// End:
+303
View File
@@ -0,0 +1,303 @@
template<class _Tp, class _Alloc>
class __simple_alloc {
typedef _Alloc __alloc_type;
public:
typedef typename _Alloc::value_type __alloc_value_type;
typedef _Tp value_type;
static size_t _STLP_CALL __chunk(size_t __n) {
return (sizeof(__alloc_value_type)==sizeof(value_type)) ? __n :
((__n*sizeof(value_type)+sizeof(__alloc_value_type)-1)/sizeof(__alloc_value_type));
}
static _Tp* _STLP_CALL allocate(size_t __n) { return 0 == __n ? 0 : (_Tp*) __alloc_type::allocate(__chunk(__n)); }
static void _STLP_CALL deallocate(_Tp * __p, size_t __n) {
__alloc_type::deallocate((__alloc_value_type*)__p, __chunk(__n)); }
};
// Allocator adaptor to turn an SGI-style allocator (e.g. alloc, malloc_alloc)
// into a standard-conforming allocator. Note that this adaptor does
// *not* assume that all objects of the underlying alloc class are
// identical, nor does it assume that all of the underlying alloc's
// member functions are static member functions. Note, also, that
// __allocator<_Tp, alloc> is essentially the same thing as allocator<_Tp>.
template <class _Tp, class _Alloc>
struct __allocator : public _Alloc {
typedef _Alloc __underlying_alloc;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
# if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, _Alloc> other;
};
# endif
__allocator() _STLP_NOTHROW {}
__allocator(const _Alloc& ) _STLP_NOTHROW {}
__allocator(const __allocator<_Tp, _Alloc>& __a) _STLP_NOTHROW
: _Alloc(__a) {}
# if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp1>
__allocator(const __allocator<_Tp1, _Alloc>& __a) _STLP_NOTHROW
: _Alloc(__a) {}
# endif
# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
~__allocator() _STLP_NOTHROW {}
# endif
pointer address(reference __x) const { return &__x; }
# if !defined (__WATCOM_CPLUSPLUS__)
const_pointer address(const_reference __x) const { return &__x; }
# endif
// __n is permitted to be 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0
? __STATIC_CAST(_Tp*,__underlying_alloc::allocate(__n * sizeof(_Tp)))
: 0;
}
// __p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ if (__p) __underlying_alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type max_size() const _STLP_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { _STLP_STD::_Construct(__p, __val); }
void destroy(pointer __p) { _STLP_STD::_Destroy(__p); }
const __underlying_alloc& __get_underlying_alloc() const { return *this; }
};
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Alloc>
class __allocator<void, _Alloc> {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _Tp1> struct rebind {
typedef __allocator<_Tp1, _Alloc> other;
};
#endif
};
#endif
template <class _Tp, class _Alloc>
inline bool _STLP_CALL operator==(const __allocator<_Tp, _Alloc>& __a1,
const __allocator<_Tp, _Alloc>& __a2)
{
return __a1.__get_underlying_alloc() == __a2.__get_underlying_alloc();
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Tp, class _Alloc>
inline bool _STLP_CALL operator!=(const __allocator<_Tp, _Alloc>& __a1,
const __allocator<_Tp, _Alloc>& __a2)
{
return __a1.__get_underlying_alloc() != __a2.__get_underlying_alloc();
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
// Comparison operators for all of the predifined SGI-style allocators.
// This ensures that __allocator<malloc_alloc> (for example) will
// work correctly.
#ifndef _STLP_NON_TYPE_TMPL_PARAM_BUG
template <int inst>
inline bool _STLP_CALL operator==(const __malloc_alloc<inst>&,
const __malloc_alloc<inst>&)
{
return true;
}
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
template <int __inst>
inline bool _STLP_CALL operator!=(const __malloc_alloc<__inst>&,
const __malloc_alloc<__inst>&)
{
return false;
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
inline bool _STLP_CALL operator==(const __new_alloc&, const __new_alloc&) { return true; }
# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
inline bool _STLP_CALL operator!=(const __new_alloc&, const __new_alloc&) { return false; }
# endif
template <bool __threads, int __inst>
inline bool _STLP_CALL operator==(const __node_alloc<__threads, __inst>&,
const __node_alloc<__threads, __inst>&)
{
return true;
}
#if defined( _STLP_FUNCTION_TMPL_PARTIAL_ORDER )
template <bool __threads, int __inst>
inline bool _STLP_CALL operator!=(const __node_alloc<__threads, __inst>&,
const __node_alloc<__threads, __inst>&)
{
return false;
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
#endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
template <class _Alloc>
inline bool _STLP_CALL operator==(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return true; }
# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Alloc>
inline bool _STLP_CALL operator!=(const __debug_alloc<_Alloc>&, const __debug_alloc<_Alloc>&) { return false; }
# endif
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
// Versions for the predefined SGI-style allocators.
template <class _Tp, int __inst>
struct _Alloc_traits<_Tp, __malloc_alloc<__inst> > {
typedef __allocator<_Tp, __malloc_alloc<__inst> > allocator_type;
};
template <class _Tp, bool __threads, int __inst>
struct _Alloc_traits<_Tp, __node_alloc<__threads, __inst> > {
typedef __allocator<_Tp, __node_alloc<__threads, __inst> >
allocator_type;
};
template <class _Tp, class _Alloc>
struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
};
// Versions for the __allocator adaptor used with the predefined
// SGI-style allocators.
template <class _Tp, class _Tp1, class _Alloc>
struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
typedef __allocator<_Tp, _Alloc > allocator_type;
};
#endif
#if !defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
// Versions for the predefined SGI-style allocators.
# if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
typedef __malloc_alloc<0> __malloc_alloc_dfl;
typedef __node_alloc<false, 0> __single_client_node_alloc;
typedef __node_alloc<true, 0> __multithreaded_node_alloc;
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc_dfl >& _STLP_CALL
__stl_alloc_rebind(__malloc_alloc_dfl& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc_dfl >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __single_client_node_alloc >& _STLP_CALL
__stl_alloc_rebind(__single_client_node_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __single_client_node_alloc >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __multithreaded_node_alloc >& _STLP_CALL
__stl_alloc_rebind(__multithreaded_node_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __multithreaded_node_alloc >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc_dfl > _STLP_CALL
__stl_alloc_create(const __malloc_alloc_dfl&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc_dfl > ();
}
template <class _Tp>
inline __allocator<_Tp, __single_client_node_alloc > _STLP_CALL
__stl_alloc_create(const __single_client_node_alloc&, const _Tp*) {
return __allocator<_Tp, __single_client_node_alloc >();
}
template <class _Tp>
inline __allocator<_Tp, __multithreaded_node_alloc > _STLP_CALL
__stl_alloc_create(const __multithreaded_node_alloc&, const _Tp*) {
return __allocator<_Tp, __multithreaded_node_alloc >();
}
# else
template <class _Tp, int __inst>
inline __allocator<_Tp, __malloc_alloc<__inst> >& _STLP_CALL
__stl_alloc_rebind(__malloc_alloc<__inst>& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc<__inst> >&)__a;
}
template <class _Tp, bool __threads, int __inst>
inline __allocator<_Tp, __node_alloc<__threads, __inst> >& _STLP_CALL
__stl_alloc_rebind(__node_alloc<__threads, __inst>& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc<__threads, __inst> >&)__a;
}
template <class _Tp, int __inst>
inline __allocator<_Tp, __malloc_alloc<__inst> > _STLP_CALL
__stl_alloc_create(const __malloc_alloc<__inst>&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc<__inst> >();
}
template <class _Tp, bool __threads, int __inst>
inline __allocator<_Tp, __node_alloc<__threads, __inst> > _STLP_CALL
__stl_alloc_create(const __node_alloc<__threads, __inst>&, const _Tp*) {
return __allocator<_Tp, __node_alloc<__threads, __inst> >();
}
# endif
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> > _STLP_CALL
__stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
return __allocator<_Tp, __debug_alloc<_Alloc> >();
}
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> >& _STLP_CALL
__stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __new_alloc > _STLP_CALL
__stl_alloc_create(const __new_alloc&, const _Tp*) {
return __allocator<_Tp, __new_alloc >();
}
template <class _Tp>
inline __allocator<_Tp, __new_alloc >& _STLP_CALL
__stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __new_alloc >&)__a;
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc>& _STLP_CALL
__stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
return (__allocator<_Tp2, _Alloc>&)__a;
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc> _STLP_CALL
__stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
return __allocator<_Tp2, _Alloc>();
}
#endif
+129
View File
@@ -0,0 +1,129 @@
/*
* Copyright (c) 1997-1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_AUTO_PTR_H
# define _STLP_AUTO_PTR_H
_STLP_BEGIN_NAMESPACE
// implementation primitive
class __ptr_base {
public:
void* _M_p;
void __set(const void* p) { _M_p = __CONST_CAST(void*,p); }
void __set(void* p) { _M_p = p; }
};
template <class _Tp> class auto_ptr_ref {
public:
__ptr_base& _M_r;
_Tp* const _M_p;
auto_ptr_ref(__ptr_base& __r, _Tp* __p) : _M_r(__r), _M_p(__p) { }
_Tp* release() const { _M_r.__set((void*)0); return _M_p; }
};
template<class _Tp> class auto_ptr : public __ptr_base {
public:
typedef _Tp element_type;
typedef auto_ptr<_Tp> _Self;
_Tp* release() {
_Tp* __px = this->get();
this->_M_p = 0;
return __px;
}
void reset(_Tp* __px=0) {
_Tp* __pt = this->get();
if (__px != __pt)
delete __pt;
this->__set(__px);
}
_Tp* get() const { return __REINTERPRET_CAST(_Tp*,__CONST_CAST(void*,_M_p)); }
# if !defined (_STLP_NO_ARROW_OPERATOR)
_Tp* operator->() const {
_STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
return get();
}
# endif
_Tp& operator*() const {
_STLP_VERBOSE_ASSERT(get()!=0, _StlMsg_AUTO_PTR_NULL)
return *get();
}
auto_ptr() { this->_M_p = 0; }
explicit auto_ptr(_Tp* __px) { this->__set(__px); }
#if defined (_STLP_MEMBER_TEMPLATES)
# if !defined (_STLP_NO_TEMPLATE_CONVERSIONS)
template<class _Tp1> auto_ptr(auto_ptr<_Tp1>& __r) {
_Tp* __conversionCheck = __r.release();
this->__set(__conversionCheck);
}
# endif
template<class _Tp1> auto_ptr<_Tp>& operator=(auto_ptr<_Tp1>& __r) {
_Tp* __conversionCheck = __r.release();
reset(__conversionCheck);
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
auto_ptr(_Self& __r) { this->__set(__r.release()); }
_Self& operator=(_Self& __r) {
reset(__r.release());
return *this;
}
~auto_ptr() { /* boris : reset(0) might be better */ delete this->get(); }
auto_ptr(auto_ptr_ref<_Tp> __r) {
this->__set(__r.release());
}
_Self& operator=(auto_ptr_ref<_Tp> __r) {
reset(__r.release());
return *this;
}
# if defined(_STLP_MEMBER_TEMPLATES) && !defined(_STLP_NO_TEMPLATE_CONVERSIONS)
template<class _Tp1> operator auto_ptr_ref<_Tp1>() {
return auto_ptr_ref<_Tp1>(*this, this->get());
}
template<class _Tp1> operator auto_ptr<_Tp1>() {
return auto_ptr<_Tp1>(release());
}
# else
operator auto_ptr_ref<_Tp>()
{ return auto_ptr_ref<_Tp>(*this, this->get()); }
# endif
};
_STLP_END_NAMESPACE
#endif /* _STLP_AUTO_PTR_H */
// Local Variables:
// mode:C++
// End:
+407
View File
@@ -0,0 +1,407 @@
/*
* Copyright (c) 1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_BITSET_C
# define _STLP_BITSET_C
# ifndef _STLP_BITSET_H
# include <stl/_bitset.h>
# endif
# define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
_STLP_BEGIN_NAMESPACE
//
// Definitions of non-inline functions from _Base_bitset.
//
template<size_t _Nw>
void _Base_bitset<_Nw>::_M_do_left_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORD;
const size_t __offset = __shift % __BITS_PER_WORD;
if (__offset == 0)
for (size_t __n = _Nw - 1; __n >= __wshift; --__n)
_M_w[__n] = _M_w[__n - __wshift];
else {
const size_t __sub_offset = __BITS_PER_WORD - __offset;
for (size_t __n = _Nw - 1; __n > __wshift; --__n)
_M_w[__n] = (_M_w[__n - __wshift] << __offset) |
(_M_w[__n - __wshift - 1] >> __sub_offset);
_M_w[__wshift] = _M_w[0] << __offset;
}
fill(_M_w + 0, _M_w + __wshift, __STATIC_CAST(_WordT,0));
}
}
template<size_t _Nw>
void _Base_bitset<_Nw>::_M_do_right_shift(size_t __shift)
{
if (__shift != 0) {
const size_t __wshift = __shift / __BITS_PER_WORD;
const size_t __offset = __shift % __BITS_PER_WORD;
const size_t __limit = _Nw - __wshift - 1;
if (__offset == 0)
for (size_t __n = 0; __n <= __limit; ++__n)
_M_w[__n] = _M_w[__n + __wshift];
else {
const size_t __sub_offset = __BITS_PER_WORD - __offset;
for (size_t __n = 0; __n < __limit; ++__n)
_M_w[__n] = (_M_w[__n + __wshift] >> __offset) |
(_M_w[__n + __wshift + 1] << __sub_offset);
_M_w[__limit] = _M_w[_Nw-1] >> __offset;
}
fill(_M_w + __limit + 1, _M_w + _Nw, __STATIC_CAST(_WordT,0));
}
}
template<size_t _Nw>
unsigned long _Base_bitset<_Nw>::_M_do_to_ulong() const
{
for (size_t __i = 1; __i < _Nw; ++__i)
if (_M_w[__i])
__stl_throw_overflow_error("bitset");
return _M_w[0];
} // End _M_do_to_ulong
template<size_t _Nw>
size_t _Base_bitset<_Nw>::_M_do_find_first(size_t __not_found) const
{
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_WordT __thisword = _M_w[__i];
if ( __thisword != __STATIC_CAST(_WordT,0) ) {
// find byte within word
for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
unsigned char __this_byte
= __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
if ( __this_byte )
return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_Bs_G<bool>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
}
// not found, so return an indication of failure.
return __not_found;
}
template<size_t _Nw>
size_t
_Base_bitset<_Nw>::_M_do_find_next(size_t __prev,
size_t __not_found) const
{
// make bound inclusive
++__prev;
// check out of bounds
if ( __prev >= _Nw * __BITS_PER_WORD )
return __not_found;
// search first word
size_t __i = _S_whichword(__prev);
_WordT __thisword = _M_w[__i];
// mask off bits below bound
__thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
if ( __thisword != __STATIC_CAST(_WordT,0) ) {
// find byte within word
// get first byte into place
__thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
unsigned char __this_byte
= __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
if ( __this_byte )
return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_Bs_G<bool>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
// check subsequent words
__i++;
for ( ; __i < _Nw; __i++ ) {
/* _WordT */ __thisword = _M_w[__i];
if ( __thisword != __STATIC_CAST(_WordT,0) ) {
// find byte within word
for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
unsigned char __this_byte
= __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
if ( __this_byte )
return __i*__BITS_PER_WORD + __j*CHAR_BIT +
_Bs_G<bool>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
}
// not found, so return an indication of failure.
return __not_found;
} // end _M_do_find_next
# if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
#if defined ( _STLP_USE_NEW_IOSTREAMS)
template <class _CharT, class _Traits, size_t _Nb>
basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x)
{
basic_string<_CharT, _Traits> __tmp;
__tmp.reserve(_Nb);
// Skip whitespace
typename basic_istream<_CharT, _Traits>::sentry __sentry(__is);
if (__sentry) {
basic_streambuf<_CharT, _Traits>* __buf = __is.rdbuf();
for (size_t __i = 0; __i < _Nb; ++__i) {
static typename _Traits::int_type __eof = _Traits::eof();
typename _Traits::int_type __c1 = __buf->sbumpc();
if (_Traits::eq_int_type(__c1, __eof)) {
__is.setstate(ios_base::eofbit);
break;
}
else {
char __c2 = _Traits::to_char_type(__c1);
char __c = __is.narrow(__c2, '*');
if (__c == '0' || __c == '1')
__tmp.push_back(__c);
else if (_Traits::eq_int_type(__buf->sputbackc(__c2), __eof)) {
__is.setstate(ios_base::failbit);
break;
}
}
}
if (__tmp.empty())
__is.setstate(ios_base::failbit);
else
__x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
}
return __is;
}
template <class _CharT, class _Traits, size_t _Nb>
basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os,
const bitset<_Nb>& __x)
{
basic_string<_CharT, _Traits> __tmp;
__x._M_copy_to_string(__tmp);
return __os << __tmp;
}
#elif ! defined ( _STLP_USE_NO_IOSTREAMS )
// (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
template <size_t _Nb>
_ISTREAM_DLL& _STLP_CALL
operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x) {
string __tmp;
__tmp.reserve(_Nb);
// In new templatized iostreams, use istream::sentry
if (__is.flags() & ios::skipws) {
char __c;
do
__is.get(__c);
while (__is && isspace(__c));
if (__is)
__is.putback(__c);
}
for (size_t __i = 0; __i < _Nb; ++__i) {
char __c;
__is.get(__c);
if (!__is)
break;
else if (__c != '0' && __c != '1') {
__is.putback(__c);
break;
}
else
__tmp.push_back(__c);
}
if (__tmp.empty())
__is.clear(__is.rdstate() | ios::failbit);
else
__x._M_copy_from_string(__tmp, __STATIC_CAST(size_t,0), _Nb);
return __is;
}
# endif /* _STLP_USE_NEW_IOSTREAMS */
# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
// ------------------------------------------------------------
// Lookup tables for find and count operations.
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template<class _Dummy>
unsigned char _Bs_G<_Dummy>::_S_bit_count[256] = {
# else
unsigned char _Bs_G<bool>::_S_bit_count[256] _STLP_WEAK = {
# endif
0, /* 0 */ 1, /* 1 */ 1, /* 2 */ 2, /* 3 */ 1, /* 4 */
2, /* 5 */ 2, /* 6 */ 3, /* 7 */ 1, /* 8 */ 2, /* 9 */
2, /* 10 */ 3, /* 11 */ 2, /* 12 */ 3, /* 13 */ 3, /* 14 */
4, /* 15 */ 1, /* 16 */ 2, /* 17 */ 2, /* 18 */ 3, /* 19 */
2, /* 20 */ 3, /* 21 */ 3, /* 22 */ 4, /* 23 */ 2, /* 24 */
3, /* 25 */ 3, /* 26 */ 4, /* 27 */ 3, /* 28 */ 4, /* 29 */
4, /* 30 */ 5, /* 31 */ 1, /* 32 */ 2, /* 33 */ 2, /* 34 */
3, /* 35 */ 2, /* 36 */ 3, /* 37 */ 3, /* 38 */ 4, /* 39 */
2, /* 40 */ 3, /* 41 */ 3, /* 42 */ 4, /* 43 */ 3, /* 44 */
4, /* 45 */ 4, /* 46 */ 5, /* 47 */ 2, /* 48 */ 3, /* 49 */
3, /* 50 */ 4, /* 51 */ 3, /* 52 */ 4, /* 53 */ 4, /* 54 */
5, /* 55 */ 3, /* 56 */ 4, /* 57 */ 4, /* 58 */ 5, /* 59 */
4, /* 60 */ 5, /* 61 */ 5, /* 62 */ 6, /* 63 */ 1, /* 64 */
2, /* 65 */ 2, /* 66 */ 3, /* 67 */ 2, /* 68 */ 3, /* 69 */
3, /* 70 */ 4, /* 71 */ 2, /* 72 */ 3, /* 73 */ 3, /* 74 */
4, /* 75 */ 3, /* 76 */ 4, /* 77 */ 4, /* 78 */ 5, /* 79 */
2, /* 80 */ 3, /* 81 */ 3, /* 82 */ 4, /* 83 */ 3, /* 84 */
4, /* 85 */ 4, /* 86 */ 5, /* 87 */ 3, /* 88 */ 4, /* 89 */
4, /* 90 */ 5, /* 91 */ 4, /* 92 */ 5, /* 93 */ 5, /* 94 */
6, /* 95 */ 2, /* 96 */ 3, /* 97 */ 3, /* 98 */ 4, /* 99 */
3, /* 100 */ 4, /* 101 */ 4, /* 102 */ 5, /* 103 */ 3, /* 104 */
4, /* 105 */ 4, /* 106 */ 5, /* 107 */ 4, /* 108 */ 5, /* 109 */
5, /* 110 */ 6, /* 111 */ 3, /* 112 */ 4, /* 113 */ 4, /* 114 */
5, /* 115 */ 4, /* 116 */ 5, /* 117 */ 5, /* 118 */ 6, /* 119 */
4, /* 120 */ 5, /* 121 */ 5, /* 122 */ 6, /* 123 */ 5, /* 124 */
6, /* 125 */ 6, /* 126 */ 7, /* 127 */ 1, /* 128 */ 2, /* 129 */
2, /* 130 */ 3, /* 131 */ 2, /* 132 */ 3, /* 133 */ 3, /* 134 */
4, /* 135 */ 2, /* 136 */ 3, /* 137 */ 3, /* 138 */ 4, /* 139 */
3, /* 140 */ 4, /* 141 */ 4, /* 142 */ 5, /* 143 */ 2, /* 144 */
3, /* 145 */ 3, /* 146 */ 4, /* 147 */ 3, /* 148 */ 4, /* 149 */
4, /* 150 */ 5, /* 151 */ 3, /* 152 */ 4, /* 153 */ 4, /* 154 */
5, /* 155 */ 4, /* 156 */ 5, /* 157 */ 5, /* 158 */ 6, /* 159 */
2, /* 160 */ 3, /* 161 */ 3, /* 162 */ 4, /* 163 */ 3, /* 164 */
4, /* 165 */ 4, /* 166 */ 5, /* 167 */ 3, /* 168 */ 4, /* 169 */
4, /* 170 */ 5, /* 171 */ 4, /* 172 */ 5, /* 173 */ 5, /* 174 */
6, /* 175 */ 3, /* 176 */ 4, /* 177 */ 4, /* 178 */ 5, /* 179 */
4, /* 180 */ 5, /* 181 */ 5, /* 182 */ 6, /* 183 */ 4, /* 184 */
5, /* 185 */ 5, /* 186 */ 6, /* 187 */ 5, /* 188 */ 6, /* 189 */
6, /* 190 */ 7, /* 191 */ 2, /* 192 */ 3, /* 193 */ 3, /* 194 */
4, /* 195 */ 3, /* 196 */ 4, /* 197 */ 4, /* 198 */ 5, /* 199 */
3, /* 200 */ 4, /* 201 */ 4, /* 202 */ 5, /* 203 */ 4, /* 204 */
5, /* 205 */ 5, /* 206 */ 6, /* 207 */ 3, /* 208 */ 4, /* 209 */
4, /* 210 */ 5, /* 211 */ 4, /* 212 */ 5, /* 213 */ 5, /* 214 */
6, /* 215 */ 4, /* 216 */ 5, /* 217 */ 5, /* 218 */ 6, /* 219 */
5, /* 220 */ 6, /* 221 */ 6, /* 222 */ 7, /* 223 */ 3, /* 224 */
4, /* 225 */ 4, /* 226 */ 5, /* 227 */ 4, /* 228 */ 5, /* 229 */
5, /* 230 */ 6, /* 231 */ 4, /* 232 */ 5, /* 233 */ 5, /* 234 */
6, /* 235 */ 5, /* 236 */ 6, /* 237 */ 6, /* 238 */ 7, /* 239 */
4, /* 240 */ 5, /* 241 */ 5, /* 242 */ 6, /* 243 */ 5, /* 244 */
6, /* 245 */ 6, /* 246 */ 7, /* 247 */ 5, /* 248 */ 6, /* 249 */
6, /* 250 */ 7, /* 251 */ 6, /* 252 */ 7, /* 253 */ 7, /* 254 */
8 /* 255 */
}; // end _Bitset_global
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template<class _Dummy>
unsigned char _Bs_G<_Dummy>::_S_first_one[256] = {
# else
unsigned char _Bs_G<bool>::_S_first_one[256] _STLP_WEAK = {
# endif
0, /* 0 */ 0, /* 1 */ 1, /* 2 */ 0, /* 3 */ 2, /* 4 */
0, /* 5 */ 1, /* 6 */ 0, /* 7 */ 3, /* 8 */ 0, /* 9 */
1, /* 10 */ 0, /* 11 */ 2, /* 12 */ 0, /* 13 */ 1, /* 14 */
0, /* 15 */ 4, /* 16 */ 0, /* 17 */ 1, /* 18 */ 0, /* 19 */
2, /* 20 */ 0, /* 21 */ 1, /* 22 */ 0, /* 23 */ 3, /* 24 */
0, /* 25 */ 1, /* 26 */ 0, /* 27 */ 2, /* 28 */ 0, /* 29 */
1, /* 30 */ 0, /* 31 */ 5, /* 32 */ 0, /* 33 */ 1, /* 34 */
0, /* 35 */ 2, /* 36 */ 0, /* 37 */ 1, /* 38 */ 0, /* 39 */
3, /* 40 */ 0, /* 41 */ 1, /* 42 */ 0, /* 43 */ 2, /* 44 */
0, /* 45 */ 1, /* 46 */ 0, /* 47 */ 4, /* 48 */ 0, /* 49 */
1, /* 50 */ 0, /* 51 */ 2, /* 52 */ 0, /* 53 */ 1, /* 54 */
0, /* 55 */ 3, /* 56 */ 0, /* 57 */ 1, /* 58 */ 0, /* 59 */
2, /* 60 */ 0, /* 61 */ 1, /* 62 */ 0, /* 63 */ 6, /* 64 */
0, /* 65 */ 1, /* 66 */ 0, /* 67 */ 2, /* 68 */ 0, /* 69 */
1, /* 70 */ 0, /* 71 */ 3, /* 72 */ 0, /* 73 */ 1, /* 74 */
0, /* 75 */ 2, /* 76 */ 0, /* 77 */ 1, /* 78 */ 0, /* 79 */
4, /* 80 */ 0, /* 81 */ 1, /* 82 */ 0, /* 83 */ 2, /* 84 */
0, /* 85 */ 1, /* 86 */ 0, /* 87 */ 3, /* 88 */ 0, /* 89 */
1, /* 90 */ 0, /* 91 */ 2, /* 92 */ 0, /* 93 */ 1, /* 94 */
0, /* 95 */ 5, /* 96 */ 0, /* 97 */ 1, /* 98 */ 0, /* 99 */
2, /* 100 */ 0, /* 101 */ 1, /* 102 */ 0, /* 103 */ 3, /* 104 */
0, /* 105 */ 1, /* 106 */ 0, /* 107 */ 2, /* 108 */ 0, /* 109 */
1, /* 110 */ 0, /* 111 */ 4, /* 112 */ 0, /* 113 */ 1, /* 114 */
0, /* 115 */ 2, /* 116 */ 0, /* 117 */ 1, /* 118 */ 0, /* 119 */
3, /* 120 */ 0, /* 121 */ 1, /* 122 */ 0, /* 123 */ 2, /* 124 */
0, /* 125 */ 1, /* 126 */ 0, /* 127 */ 7, /* 128 */ 0, /* 129 */
1, /* 130 */ 0, /* 131 */ 2, /* 132 */ 0, /* 133 */ 1, /* 134 */
0, /* 135 */ 3, /* 136 */ 0, /* 137 */ 1, /* 138 */ 0, /* 139 */
2, /* 140 */ 0, /* 141 */ 1, /* 142 */ 0, /* 143 */ 4, /* 144 */
0, /* 145 */ 1, /* 146 */ 0, /* 147 */ 2, /* 148 */ 0, /* 149 */
1, /* 150 */ 0, /* 151 */ 3, /* 152 */ 0, /* 153 */ 1, /* 154 */
0, /* 155 */ 2, /* 156 */ 0, /* 157 */ 1, /* 158 */ 0, /* 159 */
5, /* 160 */ 0, /* 161 */ 1, /* 162 */ 0, /* 163 */ 2, /* 164 */
0, /* 165 */ 1, /* 166 */ 0, /* 167 */ 3, /* 168 */ 0, /* 169 */
1, /* 170 */ 0, /* 171 */ 2, /* 172 */ 0, /* 173 */ 1, /* 174 */
0, /* 175 */ 4, /* 176 */ 0, /* 177 */ 1, /* 178 */ 0, /* 179 */
2, /* 180 */ 0, /* 181 */ 1, /* 182 */ 0, /* 183 */ 3, /* 184 */
0, /* 185 */ 1, /* 186 */ 0, /* 187 */ 2, /* 188 */ 0, /* 189 */
1, /* 190 */ 0, /* 191 */ 6, /* 192 */ 0, /* 193 */ 1, /* 194 */
0, /* 195 */ 2, /* 196 */ 0, /* 197 */ 1, /* 198 */ 0, /* 199 */
3, /* 200 */ 0, /* 201 */ 1, /* 202 */ 0, /* 203 */ 2, /* 204 */
0, /* 205 */ 1, /* 206 */ 0, /* 207 */ 4, /* 208 */ 0, /* 209 */
1, /* 210 */ 0, /* 211 */ 2, /* 212 */ 0, /* 213 */ 1, /* 214 */
0, /* 215 */ 3, /* 216 */ 0, /* 217 */ 1, /* 218 */ 0, /* 219 */
2, /* 220 */ 0, /* 221 */ 1, /* 222 */ 0, /* 223 */ 5, /* 224 */
0, /* 225 */ 1, /* 226 */ 0, /* 227 */ 2, /* 228 */ 0, /* 229 */
1, /* 230 */ 0, /* 231 */ 3, /* 232 */ 0, /* 233 */ 1, /* 234 */
0, /* 235 */ 2, /* 236 */ 0, /* 237 */ 1, /* 238 */ 0, /* 239 */
4, /* 240 */ 0, /* 241 */ 1, /* 242 */ 0, /* 243 */ 2, /* 244 */
0, /* 245 */ 1, /* 246 */ 0, /* 247 */ 3, /* 248 */ 0, /* 249 */
1, /* 250 */ 0, /* 251 */ 2, /* 252 */ 0, /* 253 */ 1, /* 254 */
0, /* 255 */
}; // end _Bitset_global
# endif /* defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) */
_STLP_END_NAMESPACE
# undef __BITS_PER_WORD
# undef bitset
#endif /* _STLP_BITSET_C */
+768
View File
@@ -0,0 +1,768 @@
/*
* Copyright (c) 1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_BITSET_H
#define _STLP_BITSET_H
// A bitset of size N has N % (sizeof(unsigned long) * CHAR_BIT) unused
// bits. (They are the high- order bits in the highest word.) It is
// a class invariant of class bitset<> that those unused bits are
// always zero.
// Most of the actual code isn't contained in bitset<> itself, but in the
// base class _Base_bitset. The base class works with whole words, not with
// individual bits. This allows us to specialize _Base_bitset for the
// important special case where the bitset is only a single word.
// The C++ standard does not define the precise semantics of operator[].
// In this implementation the const version of operator[] is equivalent
// to test(), except that it does no range checking. The non-const version
// returns a reference to a bit, again without doing any range checking.
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_INTERNAL_ALLOC_H
# include <stl/_alloc.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_UNINITIALIZED_H
# include <stl/_uninitialized.h>
# endif
# ifndef _STLP_RANGE_ERRORS_H
# include <stl/_range_errors.h>
# endif
# ifndef _STLP_STRING
# include <string>
# endif
# ifndef _STLP_ISTREAM
# include <istream>
# endif
#define __BITS_PER_WORD (CHAR_BIT*sizeof(unsigned long))
#define __BITSET_WORDS(__n) ((__n + __BITS_PER_WORD - 1)/__BITS_PER_WORD)
_STLP_BEGIN_NAMESPACE
// structure to aid in counting bits
template<class _Dummy>
class _Bs_G {
public:
static unsigned char _S_bit_count[256];
// Mapping from 8 bit unsigned integers to the index of the first one
// bit:
static unsigned char _S_first_one[256];
};
//
// Base class: general case.
//
template<size_t _Nw>
struct _Base_bitset {
typedef unsigned long _WordT;
_WordT _M_w[_Nw]; // 0 is the least significant word.
_Base_bitset( void ) { _M_do_reset(); }
_Base_bitset(unsigned long __val) {
_M_do_reset();
_M_w[0] = __val;
}
static size_t _STLP_CALL _S_whichword( size_t __pos ) {
return __pos / __BITS_PER_WORD;
}
static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
return (__pos % __BITS_PER_WORD) / CHAR_BIT;
}
static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
return __pos % __BITS_PER_WORD;
}
static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
return __STATIC_CAST(_WordT,1) << _S_whichbit(__pos);
}
_WordT& _M_getword(size_t __pos) { return _M_w[_S_whichword(__pos)]; }
_WordT _M_getword(size_t __pos) const { return _M_w[_S_whichword(__pos)]; }
_WordT& _M_hiword() { return _M_w[_Nw - 1]; }
_WordT _M_hiword() const { return _M_w[_Nw - 1]; }
void _M_do_and(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] &= __x._M_w[__i];
}
}
void _M_do_or(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] |= __x._M_w[__i];
}
}
void _M_do_xor(const _Base_bitset<_Nw>& __x) {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] ^= __x._M_w[__i];
}
}
void _M_do_left_shift(size_t __shift);
void _M_do_right_shift(size_t __shift);
void _M_do_flip() {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] = ~_M_w[__i];
}
}
void _M_do_set() {
for ( size_t __i = 0; __i < _Nw; __i++ ) {
_M_w[__i] = ~__STATIC_CAST(_WordT,0);
}
}
void _M_do_reset() { memset(_M_w, 0, _Nw * sizeof(_WordT)); }
bool _M_is_equal(const _Base_bitset<_Nw>& __x) const {
for (size_t __i = 0; __i < _Nw; ++__i) {
if (_M_w[__i] != __x._M_w[__i])
return false;
}
return true;
}
bool _M_is_any() const {
for ( size_t __i = 0; __i < _Nw ; __i++ ) {
if ( _M_w[__i] != __STATIC_CAST(_WordT,0) )
return true;
}
return false;
}
size_t _M_do_count() const {
size_t __result = 0;
const unsigned char* __byte_ptr = (const unsigned char*)_M_w;
const unsigned char* __end_ptr = (const unsigned char*)(_M_w+_Nw);
while ( __byte_ptr < __end_ptr ) {
__result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
__byte_ptr++;
}
return __result;
}
unsigned long _M_do_to_ulong() const;
// find first "on" bit
size_t _M_do_find_first(size_t __not_found) const;
// find the next "on" bit that follows "prev"
size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
};
//
// Base class: specialization for a single word.
//
_STLP_TEMPLATE_NULL
struct _Base_bitset<1UL> {
typedef unsigned long _WordT;
typedef _Base_bitset<1UL> _Self;
_WordT _M_w;
_Base_bitset( void ) : _M_w(0) {}
_Base_bitset(unsigned long __val) : _M_w(__val) {}
static size_t _STLP_CALL _S_whichword( size_t __pos ) {
return __pos / __BITS_PER_WORD ;
}
static size_t _STLP_CALL _S_whichbyte( size_t __pos ) {
return (__pos % __BITS_PER_WORD) / CHAR_BIT;
}
static size_t _STLP_CALL _S_whichbit( size_t __pos ) {
return __pos % __BITS_PER_WORD;
}
static _WordT _STLP_CALL _S_maskbit( size_t __pos ) {
return (__STATIC_CAST(_WordT,1)) << _S_whichbit(__pos);
}
_WordT& _M_getword(size_t) { return _M_w; }
_WordT _M_getword(size_t) const { return _M_w; }
_WordT& _M_hiword() { return _M_w; }
_WordT _M_hiword() const { return _M_w; }
void _M_do_and(const _Self& __x) { _M_w &= __x._M_w; }
void _M_do_or(const _Self& __x) { _M_w |= __x._M_w; }
void _M_do_xor(const _Self& __x) { _M_w ^= __x._M_w; }
void _M_do_left_shift(size_t __shift) { _M_w <<= __shift; }
void _M_do_right_shift(size_t __shift) { _M_w >>= __shift; }
void _M_do_flip() { _M_w = ~_M_w; }
void _M_do_set() { _M_w = ~__STATIC_CAST(_WordT,0); }
void _M_do_reset() { _M_w = 0; }
bool _M_is_equal(const _Self& __x) const {
return _M_w == __x._M_w;
}
bool _M_is_any() const {
return _M_w != 0;
}
size_t _M_do_count() const {
size_t __result = 0;
const unsigned char* __byte_ptr = (const unsigned char*)&_M_w;
const unsigned char* __end_ptr = ((const unsigned char*)&_M_w)+sizeof(_M_w);
while ( __byte_ptr < __end_ptr ) {
__result += _Bs_G<bool>::_S_bit_count[*__byte_ptr];
__byte_ptr++;
}
return __result;
}
unsigned long _M_do_to_ulong() const { return _M_w; }
inline size_t _M_do_find_first(size_t __not_found) const;
// find the next "on" bit that follows "prev"
inline size_t _M_do_find_next(size_t __prev, size_t __not_found) const;
};
// ------------------------------------------------------------
//
// Definitions of should-be-non-inline functions from the single-word version of
// _Base_bitset.
//
inline size_t
_Base_bitset<1UL>::_M_do_find_first(size_t __not_found) const
{
// typedef unsigned long _WordT;
_WordT __thisword = _M_w;
if ( __thisword != __STATIC_CAST(_WordT,0) ) {
// find byte within word
for ( size_t __j = 0; __j < sizeof(_WordT); __j++ ) {
unsigned char __this_byte
= __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
if ( __this_byte )
return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
// not found, so return a value that indicates failure.
return __not_found;
}
inline size_t
_Base_bitset<1UL>::_M_do_find_next(size_t __prev,
size_t __not_found ) const
{
// make bound inclusive
++__prev;
// check out of bounds
if ( __prev >= __BITS_PER_WORD )
return __not_found;
// search first (and only) word
_WordT __thisword = _M_w;
// mask off bits below bound
__thisword &= (~__STATIC_CAST(_WordT,0)) << _S_whichbit(__prev);
if ( __thisword != __STATIC_CAST(_WordT,0) ) {
// find byte within word
// get first byte into place
__thisword >>= _S_whichbyte(__prev) * CHAR_BIT;
for ( size_t __j = _S_whichbyte(__prev); __j < sizeof(_WordT); __j++ ) {
unsigned char __this_byte
= __STATIC_CAST(unsigned char,(__thisword & (~(unsigned char)0)));
if ( __this_byte )
return __j*CHAR_BIT + _Bs_G<bool>::_S_first_one[__this_byte];
__thisword >>= CHAR_BIT;
}
}
// not found, so return a value that indicates failure.
return __not_found;
} // end _M_do_find_next
// ------------------------------------------------------------
// Helper class to zero out the unused high-order bits in the highest word.
template <size_t _Extrabits> struct _Sanitize {
static void _STLP_CALL _M_do_sanitize(unsigned long& __val)
{ __val &= ~((~__STATIC_CAST(unsigned long,0)) << _Extrabits); }
};
_STLP_TEMPLATE_NULL struct _Sanitize<0UL> {
static void _STLP_CALL _M_do_sanitize(unsigned long) {}
};
// ------------------------------------------------------------
// Class bitset.
// _Nb may be any nonzero number of type size_t.
template<size_t _Nb>
class bitset : public _Base_bitset<__BITSET_WORDS(_Nb) >
{
public:
enum { _Words = __BITSET_WORDS(_Nb) } ;
private:
typedef _Base_bitset< _Words > _Base;
void _M_do_sanitize() {
_Sanitize<_Nb%__BITS_PER_WORD >::_M_do_sanitize(this->_M_hiword());
}
public:
typedef unsigned long _WordT;
struct reference;
friend struct reference;
// bit reference:
struct reference {
typedef _Base_bitset<_Words > _Bitset_base;
typedef bitset<_Nb> _Bitset;
// friend _Bitset;
_WordT *_M_wp;
size_t _M_bpos;
// should be left undefined
reference() {}
reference( _Bitset& __b, size_t __pos ) {
_M_wp = &__b._M_getword(__pos);
_M_bpos = _Bitset_base::_S_whichbit(__pos);
}
public:
~reference() {}
// for b[i] = __x;
reference& operator=(bool __x) {
if ( __x )
*_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
else
*_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
return *this;
}
// for b[i] = b[__j];
reference& operator=(const reference& __j) {
if ( (*(__j._M_wp) & _Bitset_base::_S_maskbit(__j._M_bpos)) )
*_M_wp |= _Bitset_base::_S_maskbit(_M_bpos);
else
*_M_wp &= ~_Bitset_base::_S_maskbit(_M_bpos);
return *this;
}
// flips the bit
bool operator~() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) == 0; }
// for __x = b[i];
operator bool() const { return (*(_M_wp) & _Bitset_base::_S_maskbit(_M_bpos)) != 0; }
// for b[i].flip();
reference& flip() {
*_M_wp ^= _Bitset_base::_S_maskbit(_M_bpos);
return *this;
}
};
// 23.3.5.1 constructors:
bitset() {}
bitset(unsigned long __val) : _Base_bitset<_Words>(__val) { _M_do_sanitize(); }
# ifdef _STLP_MEMBER_TEMPLATES
template<class _CharT, class _Traits, class _Alloc>
explicit bitset(const basic_string<_CharT,_Traits,_Alloc>& __s,
size_t __pos = 0)
: _Base_bitset<_Words >()
{
if (__pos > __s.size())
__stl_throw_out_of_range("bitset");
_M_copy_from_string(__s, __pos,
basic_string<_CharT, _Traits, _Alloc>::npos);
}
template<class _CharT, class _Traits, class _Alloc>
bitset(const basic_string<_CharT, _Traits, _Alloc>& __s,
size_t __pos,
size_t __n)
: _Base_bitset<_Words >()
{
if (__pos > __s.size())
__stl_throw_out_of_range("bitset");
_M_copy_from_string(__s, __pos, __n);
}
#else /* _STLP_MEMBER_TEMPLATES */
explicit bitset(const string& __s,
size_t __pos = 0,
size_t __n = (size_t)-1)
: _Base_bitset<_Words >()
{
if (__pos > __s.size())
__stl_throw_out_of_range("bitset");
_M_copy_from_string(__s, __pos, __n);
}
#endif /* _STLP_MEMBER_TEMPLATES */
// 23.3.5.2 bitset operations:
bitset<_Nb>& operator&=(const bitset<_Nb>& __rhs) {
this->_M_do_and(__rhs);
return *this;
}
bitset<_Nb>& operator|=(const bitset<_Nb>& __rhs) {
this->_M_do_or(__rhs);
return *this;
}
bitset<_Nb>& operator^=(const bitset<_Nb>& __rhs) {
this->_M_do_xor(__rhs);
return *this;
}
bitset<_Nb>& operator<<=(size_t __pos) {
this->_M_do_left_shift(__pos);
this->_M_do_sanitize();
return *this;
}
bitset<_Nb>& operator>>=(size_t __pos) {
this->_M_do_right_shift(__pos);
this->_M_do_sanitize();
return *this;
}
//
// Extension:
// Versions of single-bit set, reset, flip, test with no range checking.
//
bitset<_Nb>& _Unchecked_set(size_t __pos) {
this->_M_getword(__pos) |= _Base_bitset<_Words > ::_S_maskbit(__pos);
return *this;
}
bitset<_Nb>& _Unchecked_set(size_t __pos, int __val) {
if (__val)
this->_M_getword(__pos) |= this->_S_maskbit(__pos);
else
this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
return *this;
}
bitset<_Nb>& _Unchecked_reset(size_t __pos) {
this->_M_getword(__pos) &= ~ this->_S_maskbit(__pos);
return *this;
}
bitset<_Nb>& _Unchecked_flip(size_t __pos) {
this->_M_getword(__pos) ^= this->_S_maskbit(__pos);
return *this;
}
bool _Unchecked_test(size_t __pos) const {
return (this->_M_getword(__pos) & this->_S_maskbit(__pos)) != __STATIC_CAST(_WordT,0);
}
// Set, reset, and flip.
bitset<_Nb>& set() {
this->_M_do_set();
this->_M_do_sanitize();
return *this;
}
bitset<_Nb>& set(size_t __pos) {
if (__pos >= _Nb)
__stl_throw_out_of_range("bitset");
return _Unchecked_set(__pos);
}
bitset<_Nb>& set(size_t __pos, int __val) {
if (__pos >= _Nb)
__stl_throw_out_of_range("bitset");
return _Unchecked_set(__pos, __val);
}
bitset<_Nb>& reset() {
this->_M_do_reset();
return *this;
}
bitset<_Nb>& reset(size_t __pos) {
if (__pos >= _Nb)
__stl_throw_out_of_range("bitset");
return _Unchecked_reset(__pos);
}
bitset<_Nb>& flip() {
this->_M_do_flip();
this->_M_do_sanitize();
return *this;
}
bitset<_Nb>& flip(size_t __pos) {
if (__pos >= _Nb)
__stl_throw_out_of_range("bitset");
return _Unchecked_flip(__pos);
}
bitset<_Nb> operator~() const {
return bitset<_Nb>(*this).flip();
}
// element access:
//for b[i];
reference operator[](size_t __pos) { return reference(*this,__pos); }
bool operator[](size_t __pos) const { return _Unchecked_test(__pos); }
unsigned long to_ulong() const { return this->_M_do_to_ulong(); }
#if defined (_STLP_MEMBER_TEMPLATES) && ! defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS)
template <class _CharT, class _Traits, class _Alloc>
basic_string<_CharT, _Traits, _Alloc> to_string() const {
basic_string<_CharT, _Traits, _Alloc> __result;
_M_copy_to_string(__result);
return __result;
}
#else
string to_string() const {
string __result;
_M_copy_to_string(__result);
return __result;
}
#endif /* _STLP_EXPLICIT_FUNCTION_TMPL_ARGS */
size_t count() const { return this->_M_do_count(); }
size_t size() const { return _Nb; }
bool operator==(const bitset<_Nb>& __rhs) const {
return this->_M_is_equal(__rhs);
}
bool operator!=(const bitset<_Nb>& __rhs) const {
return !this->_M_is_equal(__rhs);
}
bool test(size_t __pos) const {
if (__pos >= _Nb)
__stl_throw_out_of_range("bitset");
return _Unchecked_test(__pos);
}
bool any() const { return this->_M_is_any(); }
bool none() const { return !this->_M_is_any(); }
bitset<_Nb> operator<<(size_t __pos) const {
bitset<_Nb> __result(*this);
__result <<= __pos ; return __result;
}
bitset<_Nb> operator>>(size_t __pos) const {
bitset<_Nb> __result(*this);
__result >>= __pos ; return __result;
}
//
// EXTENSIONS: bit-find operations. These operations are
// experimental, and are subject to change or removal in future
// versions.
//
// find the index of the first "on" bit
size_t _Find_first() const
{ return this->_M_do_find_first(_Nb); }
// find the index of the next "on" bit after prev
size_t _Find_next( size_t __prev ) const
{ return this->_M_do_find_next(__prev, _Nb); }
//
// Definitions of should-be non-inline member functions.
//
# if defined (_STLP_MEMBER_TEMPLATES)
template<class _CharT, class _Traits, class _Alloc>
void _M_copy_from_string(const basic_string<_CharT,_Traits,_Alloc>& __s,
size_t __pos,
size_t __n) {
#else
void _M_copy_from_string(const string& __s,
size_t __pos,
size_t __n) {
typedef char_traits<char> _Traits;
#endif
reset();
size_t __tmp = _Nb;
const size_t __Nbits = (min) (__tmp, (min) (__n, __s.size() - __pos));
for ( size_t __i= 0; __i < __Nbits; ++__i) {
typename _Traits::int_type __k = _Traits::to_int_type(__s[__pos + __Nbits - __i - 1]);
// boris : widen() ?
if (__k == '1')
set(__i);
else if (__k !='0')
__stl_throw_invalid_argument("bitset");
}
}
# if defined (_STLP_MEMBER_TEMPLATES)
template <class _CharT, class _Traits, class _Alloc>
void _M_copy_to_string(basic_string<_CharT, _Traits, _Alloc>& __s) const
# else
void _M_copy_to_string(string& __s) const
# endif
{
__s.assign(_Nb, '0');
for (size_t __i = 0; __i < _Nb; ++__i)
if (_Unchecked_test(__i))
__s[_Nb - 1 - __i] = '1';
}
# if defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
bitset<_Nb> operator&(const bitset<_Nb>& __y) const {
bitset<_Nb> __result(*this);
__result &= __y;
return __result;
}
bitset<_Nb> operator|(const bitset<_Nb>& __y) const {
bitset<_Nb> __result(*this);
__result |= __y;
return __result;
}
bitset<_Nb> operator^(const bitset<_Nb>& __y) const {
bitset<_Nb> __result(*this);
__result ^= __y;
return __result;
}
# endif
};
// ------------------------------------------------------------
//
// 23.3.5.3 bitset operations:
//
# if ! defined (_STLP_NON_TYPE_TMPL_PARAM_BUG)
template <size_t _Nb>
inline bitset<_Nb> _STLP_CALL
operator&(const bitset<_Nb>& __x,
const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result &= __y;
return __result;
}
template <size_t _Nb>
inline bitset<_Nb> _STLP_CALL
operator|(const bitset<_Nb>& __x,
const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result |= __y;
return __result;
}
template <size_t _Nb>
inline bitset<_Nb> _STLP_CALL
operator^(const bitset<_Nb>& __x,
const bitset<_Nb>& __y) {
bitset<_Nb> __result(__x);
__result ^= __y;
return __result;
}
#if defined ( _STLP_USE_NEW_IOSTREAMS )
template <class _CharT, class _Traits, size_t _Nb>
basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Nb>& __x);
template <class _CharT, class _Traits, size_t _Nb>
basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Nb>& __x);
#elif ! defined ( _STLP_USE_NO_IOSTREAMS )
// (reg) For Watcom IO, this tells if ostream class is in .exe or in .dll
template <size_t _Nb>
_ISTREAM_DLL& _STLP_CALL
operator>>(_ISTREAM_DLL& __is, bitset<_Nb>& __x);
template <size_t _Nb>
inline _OSTREAM_DLL& _STLP_CALL operator<<(_OSTREAM_DLL& __os, const bitset<_Nb>& __x) {
string __tmp;
__x._M_copy_to_string(__tmp);
return __os << __tmp;
}
#endif
# endif /* _STLP_NON_TYPE_TMPL_PARAM_BUG */
# undef bitset
_STLP_END_NAMESPACE
# undef __BITS_PER_WORD
# undef __BITSET_WORDS
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_bitset.c>
# endif
#endif /* _STLP_BITSET_H */
// Local Variables:
// mode:C++
// End:
+807
View File
@@ -0,0 +1,807 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_BVECTOR_H
#define _STLP_INTERNAL_BVECTOR_H
#ifndef _STLP_INTERNAL_VECTOR_H
# include <stl/_vector.h>
# endif
#define __WORD_BIT (int(CHAR_BIT*sizeof(unsigned int)))
_STLP_BEGIN_NAMESPACE
struct _Bit_reference {
unsigned int* _M_p;
unsigned int _M_mask;
_Bit_reference(unsigned int* __x, unsigned int __y)
: _M_p(__x), _M_mask(__y) {}
public:
_Bit_reference() : _M_p(0), _M_mask(0) {}
operator bool() const {
return !(!(*_M_p & _M_mask));
}
_Bit_reference& operator=(bool __x) {
if (__x) *_M_p |= _M_mask;
else *_M_p &= ~_M_mask;
return *this;
}
_Bit_reference& operator=(const _Bit_reference& __x) {
return *this = bool(__x);
}
bool operator==(const _Bit_reference& __x) const {
return bool(*this) == bool(__x);
}
bool operator<(const _Bit_reference& __x) const {
return !bool(*this) && bool(__x);
}
_Bit_reference& operator |= (bool __x) {
if (__x)
*_M_p |= _M_mask;
return *this;
}
_Bit_reference& operator &= (bool __x) {
if (!__x)
*_M_p &= ~_M_mask;
return *this;
}
void flip() { *_M_p ^= _M_mask; }
};
inline void swap(_Bit_reference& __x, _Bit_reference& __y)
{
bool __tmp = (bool)__x;
__x = __y;
__y = __tmp;
}
struct _Bit_iterator_base;
struct _Bit_iterator_base
{
typedef ptrdiff_t difference_type;
unsigned int* _M_p;
unsigned int _M_offset;
void _M_bump_up() {
if (_M_offset++ == __WORD_BIT - 1) {
_M_offset = 0;
++_M_p;
}
}
void _M_bump_down() {
if (_M_offset-- == 0) {
_M_offset = __WORD_BIT - 1;
--_M_p;
}
}
_Bit_iterator_base() : _M_p(0), _M_offset(0) {}
_Bit_iterator_base(unsigned int* __x, unsigned int __y) : _M_p(__x), _M_offset(__y) {}
// _Bit_iterator_base( const _Bit_iterator_base& __x) : _M_p(__x._M_p), _M_offset(__x._M_offset) {}
// _Bit_iterator_base& operator = ( const _Bit_iterator_base& __x) { _M_p = __x._M_p ; _M_offset = __x._M_offset ; return *this; }
void _M_advance (difference_type __i) {
difference_type __n = __i + _M_offset;
_M_p += __n / __WORD_BIT;
__n = __n % __WORD_BIT;
if (__n < 0) {
_M_offset = (unsigned int) __n + __WORD_BIT;
--_M_p;
} else
_M_offset = (unsigned int) __n;
}
difference_type _M_subtract(const _Bit_iterator_base& __x) const {
return __WORD_BIT * (_M_p - __x._M_p) + _M_offset - __x._M_offset;
}
};
inline bool _STLP_CALL operator==(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return __y._M_p == __x._M_p && __y._M_offset == __x._M_offset;
}
inline bool _STLP_CALL operator!=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return __y._M_p != __x._M_p || __y._M_offset != __x._M_offset;
}
inline bool _STLP_CALL operator<(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return __x._M_p < __y._M_p || (__x._M_p == __y._M_p && __x._M_offset < __y._M_offset);
}
inline bool _STLP_CALL operator>(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return operator <(__y , __x);
}
inline bool _STLP_CALL operator<=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return !(__y < __x);
}
inline bool _STLP_CALL operator>=(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) {
return !(__x < __y);
}
template <class _Ref, class _Ptr>
struct _Bit_iter : public _Bit_iterator_base
{
typedef _Ref reference;
typedef _Ptr pointer;
typedef _Bit_iter<_Ref, _Ptr> _Self;
typedef random_access_iterator_tag iterator_category;
typedef bool value_type;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
_Bit_iter(unsigned int* __x, unsigned int __y) : _Bit_iterator_base(__x, __y) {}
_Bit_iter() {}
_Bit_iter(const _Bit_iter<_Bit_reference, _Bit_reference*>& __x):
_Bit_iterator_base((const _Bit_iterator_base&)__x) {}
// _Self& operator = (const _Bit_iter<_Bit_reference, _Bit_reference*>& __x)
// { (_Bit_iterator_base&)*this = (const _Bit_iterator_base&)__x; return *this; }
reference operator*() const {
return _Bit_reference(_M_p, 1UL << _M_offset);
}
_Self& operator++() {
_M_bump_up();
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
_M_bump_up();
return __tmp;
}
_Self& operator--() {
_M_bump_down();
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
_M_bump_down();
return __tmp;
}
_Self& operator+=(difference_type __i) {
_M_advance(__i);
return *this;
}
_Self& operator-=(difference_type __i) {
*this += -__i;
return *this;
}
_Self operator+(difference_type __i) const {
_Self __tmp = *this;
return __tmp += __i;
}
_Self operator-(difference_type __i) const {
_Self __tmp = *this;
return __tmp -= __i;
}
difference_type operator-(const _Self& __x) const {
return _M_subtract(__x);
}
reference operator[](difference_type __i) { return *(*this + __i); }
};
template <class _Ref, class _Ptr>
inline _Bit_iter<_Ref,_Ptr> _STLP_CALL
operator+(ptrdiff_t __n, const _Bit_iter<_Ref, _Ptr>& __x) {
return __x + __n;
}
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
inline random_access_iterator_tag iterator_category(const _Bit_iterator_base&) {return random_access_iterator_tag();}
inline ptrdiff_t* distance_type(const _Bit_iterator_base&) {return (ptrdiff_t*)0;}
inline bool* value_type(const _Bit_iter<_Bit_reference, _Bit_reference*>&) {return (bool*)0;}
inline bool* value_type(const _Bit_iter<bool, const bool*>&) {return (bool*)0;}
# endif
typedef _Bit_iter<bool, const bool*> _Bit_const_iterator;
typedef _Bit_iter<_Bit_reference, _Bit_reference*> _Bit_iterator;
// Bit-vector base class, which encapsulates the difference between
// old SGI-style allocators and standard-conforming allocators.
template <class _Alloc>
class _Bvector_base
{
public:
_STLP_FORCE_ALLOCATORS(bool, _Alloc)
typedef typename _Alloc_traits<bool, _Alloc>::allocator_type allocator_type;
typedef unsigned int __chunk_type;
typedef typename _Alloc_traits<__chunk_type,
_Alloc>::allocator_type __chunk_allocator_type;
allocator_type get_allocator() const {
return _STLP_CONVERT_ALLOCATOR((const __chunk_allocator_type&)_M_end_of_storage, bool);
}
static allocator_type __get_dfl_allocator() { return allocator_type(); }
_Bvector_base(const allocator_type& __a)
: _M_start(), _M_finish(), _M_end_of_storage(_STLP_CONVERT_ALLOCATOR(__a, __chunk_type),
(__chunk_type*)0) {
}
~_Bvector_base() { _M_deallocate();
}
protected:
unsigned int* _M_bit_alloc(size_t __n)
{ return _M_end_of_storage.allocate((__n + __WORD_BIT - 1)/__WORD_BIT); }
void _M_deallocate() {
if (_M_start._M_p)
_M_end_of_storage.deallocate(_M_start._M_p,
_M_end_of_storage._M_data - _M_start._M_p);
}
_Bit_iterator _M_start;
_Bit_iterator _M_finish;
_STLP_alloc_proxy<__chunk_type*, __chunk_type, __chunk_allocator_type> _M_end_of_storage;
};
// The next few lines are confusing. What we're doing is declaring a
// partial specialization of vector<T, Alloc> if we have the necessary
// compiler support. Otherwise, we define a class bit_vector which uses
// the default allocator.
#if defined(_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined(_STLP_NO_BOOL) && ! defined (__SUNPRO_CC)
# define _STLP_VECBOOL_TEMPLATE
# define __BVEC_TMPL_HEADER template <class _Alloc>
#else
# undef _STLP_VECBOOL_TEMPLATE
# ifdef _STLP_NO_BOOL
# define __BVEC_TMPL_HEADER
# else
# define __BVEC_TMPL_HEADER _STLP_TEMPLATE_NULL
# endif
# if !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))) //*TY 12/17/2000 -
# define _Alloc _STLP_DEFAULT_ALLOCATOR(bool)
# else
# define _Alloc allocator<bool>
# endif
#endif
#ifdef _STLP_NO_BOOL
# define __BVECTOR_QUALIFIED bit_vector
# define __BVECTOR bit_vector
#else
# ifdef _STLP_VECBOOL_TEMPLATE
# define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, _Alloc>
# else
# define __BVECTOR_QUALIFIED __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> >
# endif
#if defined (_STLP_PARTIAL_SPEC_NEEDS_TEMPLATE_ARGS)
# define __BVECTOR __BVECTOR_QUALIFIED
#else
# define __BVECTOR __WORKAROUND_DBG_RENAME(vector)
#endif
#endif
__BVEC_TMPL_HEADER
class __BVECTOR_QUALIFIED : public _Bvector_base<_Alloc >
{
typedef _Bvector_base<_Alloc > _Base;
typedef __BVECTOR_QUALIFIED _Self;
public:
typedef bool value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Bit_reference reference;
typedef bool const_reference;
typedef _Bit_reference* pointer;
typedef const bool* const_pointer;
typedef random_access_iterator_tag _Iterator_category;
typedef _Bit_iterator iterator;
typedef _Bit_const_iterator const_iterator;
#if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
typedef _STLP_STD::reverse_iterator<const_iterator> const_reverse_iterator;
typedef _STLP_STD::reverse_iterator<iterator> reverse_iterator;
#else /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
# if defined (_STLP_MSVC50_COMPATIBILITY)
typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference,
const_pointer, difference_type> const_reverse_iterator;
typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, reference*,
difference_type> reverse_iterator;
# else
typedef _STLP_STD::reverse_iterator<const_iterator, value_type, const_reference,
difference_type> const_reverse_iterator;
typedef _STLP_STD::reverse_iterator<iterator, value_type, reference, difference_type>
reverse_iterator;
# endif
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
# ifdef _STLP_VECBOOL_TEMPLATE
typedef typename _Bvector_base<_Alloc >::allocator_type allocator_type;
typedef typename _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
# else
typedef _Bvector_base<_Alloc >::allocator_type allocator_type;
typedef _Bvector_base<_Alloc >::__chunk_type __chunk_type ;
# endif
protected:
void _M_initialize(size_type __n) {
unsigned int* __q = this->_M_bit_alloc(__n);
this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
this->_M_finish = this->_M_start + difference_type(__n);
}
void _M_insert_aux(iterator __position, bool __x) {
if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
__copy_backward(__position, this->_M_finish, this->_M_finish + 1, random_access_iterator_tag(), (difference_type*)0 );
*__position = __x;
++this->_M_finish;
}
else {
size_type __len = size() ? 2 * size() : __WORD_BIT;
unsigned int* __q = this->_M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
*__i++ = __x;
this->_M_finish = copy(__position, end(), __i);
this->_M_deallocate();
this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
}
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void _M_initialize_range(_InputIterator __first, _InputIterator __last,
const input_iterator_tag &) {
this->_M_start = iterator();
this->_M_finish = iterator();
this->_M_end_of_storage._M_data = 0;
for ( ; __first != __last; ++__first)
push_back(*__first);
}
template <class _ForwardIterator>
void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last,
const forward_iterator_tag &) {
size_type __n = distance(__first, __last);
_M_initialize(__n);
// copy(__first, __last, _M_start);
copy(__first, __last, this->_M_start); // dwa 12/22/99 -- resolving ambiguous reference.
}
template <class _InputIterator>
void _M_insert_range(iterator __pos,
_InputIterator __first, _InputIterator __last,
const input_iterator_tag &) {
for ( ; __first != __last; ++__first) {
__pos = insert(__pos, *__first);
++__pos;
}
}
template <class _ForwardIterator>
void _M_insert_range(iterator __position,
_ForwardIterator __first, _ForwardIterator __last,
const forward_iterator_tag &) {
if (__first != __last) {
size_type __n = distance(__first, __last);
if (capacity() - size() >= __n) {
__copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
copy(__first, __last, __position);
this->_M_finish += difference_type(__n);
}
else {
size_type __len = size() + (max)(size(), __n);
unsigned int* __q = this->_M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
__i = copy(__first, __last, __i);
this->_M_finish = copy(__position, end(), __i);
this->_M_deallocate();
this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
}
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
public:
iterator begin() { return this->_M_start; }
const_iterator begin() const { return this->_M_start; }
iterator end() { return this->_M_finish; }
const_iterator end() const { return this->_M_finish; }
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
size_type size() const { return size_type(end() - begin()); }
size_type max_size() const { return size_type(-1); }
size_type capacity() const {
return size_type(const_iterator(this->_M_end_of_storage._M_data, 0) - begin());
}
bool empty() const { return begin() == end(); }
reference operator[](size_type __n)
{ return *(begin() + difference_type(__n)); }
const_reference operator[](size_type __n) const
{ return *(begin() + difference_type(__n)); }
void _M_range_check(size_type __n) const {
if (__n >= this->size())
__stl_throw_range_error("vector<bool>");
}
reference at(size_type __n)
{ _M_range_check(__n); return (*this)[__n]; }
const_reference at(size_type __n) const
{ _M_range_check(__n); return (*this)[__n]; }
explicit __BVECTOR(const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc >(__a) {}
__BVECTOR(size_type __n, bool __val,
const allocator_type& __a =
allocator_type())
: _Bvector_base<_Alloc >(__a)
{
_M_initialize(__n);
fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __val ? ~0 : 0);
}
explicit __BVECTOR(size_type __n)
: _Bvector_base<_Alloc >(allocator_type())
{
_M_initialize(__n);
fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), 0);
}
__BVECTOR(const _Self& __x) : _Bvector_base<_Alloc >(__x.get_allocator()) {
_M_initialize(__x.size());
copy(__x.begin(), __x.end(), this->_M_start);
}
#if defined (_STLP_MEMBER_TEMPLATES)
template <class _Integer>
void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
_M_initialize(__n);
fill(this->_M_start._M_p, this->_M_end_of_storage._M_data, __x ? ~0 : 0);
}
template <class _InputIterator>
void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
const __false_type&) {
_M_initialize_range(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
__BVECTOR(_InputIterator __first, _InputIterator __last)
: _Base(allocator_type())
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
# endif
template <class _InputIterator>
__BVECTOR(_InputIterator __first, _InputIterator __last,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _Base(__a)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
#else /* _STLP_MEMBER_TEMPLATES */
__BVECTOR(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc >(__a)
{
size_type __n = distance(__first, __last);
_M_initialize(__n);
copy(__first, __last, this->_M_start);
}
__BVECTOR(const bool* __first, const bool* __last,
const allocator_type& __a = allocator_type())
: _Bvector_base<_Alloc >(__a)
{
size_type __n = distance(__first, __last);
_M_initialize(__n);
copy(__first, __last, this->_M_start);
}
#endif /* _STLP_MEMBER_TEMPLATES */
~__BVECTOR() { }
__BVECTOR_QUALIFIED& operator=(const __BVECTOR_QUALIFIED& __x) {
if (&__x == this) return *this;
if (__x.size() > capacity()) {
this->_M_deallocate();
_M_initialize(__x.size());
}
copy(__x.begin(), __x.end(), begin());
this->_M_finish = begin() + difference_type(__x.size());
return *this;
}
// assign(), a generalized assignment member function. Two
// versions: one that takes a count, and one that takes a range.
// The range version is a member template, so we dispatch on whether
// or not the type is an integer.
void _M_fill_assign(size_t __n, bool __x) {
if (__n > size()) {
fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
insert(end(), __n - size(), __x);
}
else {
erase(begin() + __n, end());
fill(this->_M_start._M_p, (__chunk_type*)(this->_M_end_of_storage._M_data), __x ? ~0 : 0);
}
}
void assign(size_t __n, bool __x) { _M_fill_assign(__n, __x); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
{ _M_fill_assign((size_t) __n, (bool) __val); }
template <class _InputIter>
void _M_assign_dispatch(_InputIter __first, _InputIter __last, const __false_type&)
{ _M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter)); }
template <class _InputIterator>
void _M_assign_aux(_InputIterator __first, _InputIterator __last,
const input_iterator_tag &) {
iterator __cur = begin();
for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
*__cur = *__first;
if (__first == __last)
erase(__cur, end());
else
insert(end(), __first, __last);
}
template <class _ForwardIterator>
void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
const forward_iterator_tag &) {
size_type __len = distance(__first, __last);
if (__len < size())
erase(copy(__first, __last, begin()), end());
else {
_ForwardIterator __mid = __first;
advance(__mid, size());
copy(__first, __mid, begin());
insert(end(), __mid, __last);
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
void reserve(size_type __n) {
if (capacity() < __n) {
unsigned int* __q = this->_M_bit_alloc(__n);
_Bit_iterator __z(__q, 0);
this->_M_finish = copy(begin(), end(), __z);
this->_M_deallocate();
this->_M_start = iterator(__q, 0);
this->_M_end_of_storage._M_data = __q + (__n + __WORD_BIT - 1)/__WORD_BIT;
}
}
reference front() { return *begin(); }
const_reference front() const { return *begin(); }
reference back() { return *(end() - 1); }
const_reference back() const { return *(end() - 1); }
void push_back(bool __x) {
if (this->_M_finish._M_p != this->_M_end_of_storage._M_data) {
*(this->_M_finish) = __x;
++this->_M_finish;
}
else
_M_insert_aux(end(), __x);
}
void swap(__BVECTOR_QUALIFIED& __x) {
_STLP_STD::swap(this->_M_start, __x._M_start);
_STLP_STD::swap(this->_M_finish, __x._M_finish);
_STLP_STD::swap(this->_M_end_of_storage, __x._M_end_of_storage);
}
iterator insert(iterator __position, bool __x = bool()) {
difference_type __n = __position - begin();
if (this->_M_finish._M_p != this->_M_end_of_storage._M_data && __position == end()) {
*(this->_M_finish) = __x;
++this->_M_finish;
}
else
_M_insert_aux(__position, __x);
return begin() + __n;
}
#if defined ( _STLP_MEMBER_TEMPLATES )
template <class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
const __true_type&) {
_M_fill_insert(__pos, (size_type) __n, (bool) __x);
}
template <class _InputIterator>
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
const __false_type&) {
_M_insert_range(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
void insert(iterator __position,
_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Is_Integral;
_M_insert_dispatch(__position, __first, __last, _Is_Integral());
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert(iterator __position,
const_iterator __first, const_iterator __last) {
if (__first == __last) return;
size_type __n = distance(__first, __last);
if (capacity() - size() >= __n) {
__copy_backward(__position, end(), this->_M_finish + __n,
random_access_iterator_tag(), (difference_type*)0 );
copy(__first, __last, __position);
this->_M_finish += __n;
}
else {
size_type __len = size() + (max)(size(), __n);
unsigned int* __q = this->_M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
__i = copy(__first, __last, __i);
this->_M_finish = copy(__position, end(), __i);
this->_M_deallocate();
this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
}
}
void insert(iterator __position, const bool* __first, const bool* __last) {
if (__first == __last) return;
size_type __n = distance(__first, __last);
if (capacity() - size() >= __n) {
__copy_backward(__position, end(), this->_M_finish + __n,
random_access_iterator_tag(), (difference_type*)0 );
copy(__first, __last, __position);
this->_M_finish += __n;
}
else {
size_type __len = size() + (max)(size(), __n);
unsigned int* __q = this->_M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
__i = copy(__first, __last, __i);
this->_M_finish = copy(__position, end(), __i);
this->_M_deallocate();
this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
void _M_fill_insert(iterator __position, size_type __n, bool __x) {
if (__n == 0) return;
if (capacity() - size() >= __n) {
__copy_backward(__position, end(), this->_M_finish + difference_type(__n), random_access_iterator_tag(), (difference_type*)0 );
fill(__position, __position + difference_type(__n), __x);
this->_M_finish += difference_type(__n);
}
else {
size_type __len = size() + (max)(size(), __n);
unsigned int* __q = this->_M_bit_alloc(__len);
iterator __i = copy(begin(), __position, iterator(__q, 0));
fill_n(__i, __n, __x);
this->_M_finish = copy(__position, end(), __i + difference_type(__n));
this->_M_deallocate();
this->_M_end_of_storage._M_data = __q + (__len + __WORD_BIT - 1)/__WORD_BIT;
this->_M_start = iterator(__q, 0);
}
}
void insert(iterator __position, size_type __n, bool __x) {
_M_fill_insert(__position, __n, __x);
}
void pop_back() {
--this->_M_finish;
}
iterator erase(iterator __position) {
if (__position + 1 != end())
copy(__position + 1, end(), __position);
--this->_M_finish;
return __position;
}
iterator erase(iterator __first, iterator __last) {
this->_M_finish = copy(__last, end(), __first);
return __first;
}
void resize(size_type __new_size, bool __x = bool()) {
if (__new_size < size())
erase(begin() + difference_type(__new_size), end());
else
insert(end(), __new_size - size(), __x);
}
void flip() {
for (unsigned int* __p = this->_M_start._M_p; __p != this->_M_end_of_storage._M_data; ++__p)
*__p = ~*__p;
}
void clear() { erase(begin(), end()); }
};
# if defined ( _STLP_NO_BOOL ) || defined (__HP_aCC) // fixed soon (03/17/2000)
#define _STLP_TEMPLATE_HEADER __BVEC_TMPL_HEADER
#define _STLP_TEMPLATE_CONTAINER __BVECTOR_QUALIFIED
#include <stl/_relops_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#undef _STLP_TEMPLATE_HEADER
# endif /* NO_BOOL */
#if !defined (_STLP_NO_BOOL)
// This typedef is non-standard. It is provided for backward compatibility.
typedef __WORKAROUND_DBG_RENAME(vector) <bool, allocator<bool> > bit_vector;
#endif
_STLP_END_NAMESPACE
#undef _Alloc
#undef _STLP_VECBOOL_TEMPLATE
#undef __BVECTOR
#undef __BVECTOR_QUALIFIED
#undef __BVEC_TMPL_HEADER
# undef __WORD_BIT
#endif /* _STLP_INTERNAL_BVECTOR_H */
// Local Variables:
// mode:C++
// End:
+37
View File
@@ -0,0 +1,37 @@
// This file is reserved to site configuration purpose
// and should NEVER be overridden by user
# if defined ( _STLP_NO_OWN_IOSTREAMS )
// User choose not to use SGI iostreams, which means no
// precompiled library will be used and he is free to override
// any STLport configuration flags
# else
// The following will be defined in stl_config.h :
// # define _STLP_OWN_IOSTREAMS 1
# endif
/*
* Consistency check : if we use SGI iostreams, we have to use consistent
* thread model (single-threaded or multi-threaded) with the compiled library
*
* Default is multithreaded build. If you want to build and use single-threaded
* STLport, please change _STLP_NOTHREADS configuration setting above and rebuild the library
*
*/
# if defined (_STLP_OWN_IOSTREAMS) \
&& !defined (_STLP_NO_THREADS) && !defined (_REENTRANT)
# if defined(_MSC_VER) && !defined(__MWERKS__) && !defined (__COMO__) && !defined(_MT)
# error "Only multi-threaded runtime library may be linked with STLport!"
# endif
// boris : you may change that to build non-threadsafe STLport library
# if defined (__BUILDING_STLPORT) /* || defined (_STLP_DEBUG) */
# define _REENTRANT 1
# endif
# endif
+208
View File
@@ -0,0 +1,208 @@
/*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_CMATH_H_HEADER
# define _STLP_CMATH_H_HEADER
# include <cmath>
_STLP_BEGIN_NAMESPACE
# ifdef _STLP_SAME_FUNCTION_NAME_RESOLUTION_BUG
// this proxy is needed for some compilers to resolve problems
// calling sqrt() from within sqrt(), etc.
template <class _Tp>
struct _STL_math_proxy {
static inline _Tp _do_abs(const _Tp& __x) { return _STLP_VENDOR_CSTD::fabs(__x); }
static inline _Tp _do_acos(const _Tp& __x) { return _STLP_VENDOR_CSTD::acos(__x); }
static inline _Tp _do_asin(const _Tp& __x) { return _STLP_VENDOR_CSTD::asin(__x); }
static inline _Tp _do_atan(const _Tp& __x) { return _STLP_VENDOR_CSTD::atan(__x); }
static inline _Tp _do_atan2(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::atan2(__x, __y); }
static inline _Tp _do_cos(const _Tp& __x) { return _STLP_VENDOR_CSTD::cos(__x); }
static inline _Tp _do_cosh(const _Tp& __x) { return _STLP_VENDOR_CSTD::cosh(__x); }
static inline _Tp _do_floor(const _Tp& __x) { return _STLP_VENDOR_CSTD::floor(__x); }
static inline _Tp _do_ceil(const _Tp& __x) { return _STLP_VENDOR_CSTD::ceil(__x); }
static inline _Tp _do_fmod(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::fmod(__x, __y); }
static inline _Tp _do_frexp(const _Tp& __x, int* __y) { return _STLP_VENDOR_CSTD::frexp(__x, __y); }
static inline _Tp _do_ldexp(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::ldexp(__x, __y); }
static inline _Tp _do_modf(const _Tp& __x, double* __y) { return _STLP_VENDOR_CSTD::modf(__x, __y); }
static inline _Tp _do_log(const _Tp& __x) { return _STLP_VENDOR_CSTD::log(__x); }
static inline _Tp _do_log10(const _Tp& __x) { return _STLP_VENDOR_CSTD::log10(__x); }
static inline _Tp _do_pow(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); }
static inline _Tp _do_pow(const _Tp& __x, int __y) { return _STLP_VENDOR_CSTD::pow(__x, __y); }
static inline _Tp _do_sin(const _Tp& __x) { return _STLP_VENDOR_CSTD::sin(__x); }
static inline _Tp _do_sinh(const _Tp& __x) { return _STLP_VENDOR_CSTD::sinh(__x); }
static inline _Tp _do_sqrt(const _Tp& __x) { return _STLP_VENDOR_CSTD::sqrt(__x); }
static inline _Tp _do_tan(const _Tp& __x) { return _STLP_VENDOR_CSTD::tan(__x); }
static inline _Tp _do_tanh(const _Tp& __x) { return _STLP_VENDOR_CSTD::tanh(__x); }
static inline _Tp _do_exp(const _Tp& __x) { return _STLP_VENDOR_CSTD::exp(__x); }
static inline _Tp _do_hypot(const _Tp& __x, const _Tp& __y) { return _STLP_VENDOR_CSTD::hypot(__x, __y); }
};
# define _STLP_DO_ABS(_Tp) _STL_math_proxy<_Tp>::_do_abs
# define _STLP_DO_ACOS(_Tp) _STL_math_proxy<_Tp>::_do_acos
# define _STLP_DO_ASIN(_Tp) _STL_math_proxy<_Tp>::_do_asin
# define _STLP_DO_ATAN(_Tp) _STL_math_proxy<_Tp>::_do_atan
# define _STLP_DO_ATAN2(_Tp) _STL_math_proxy<_Tp>::_do_atan2
# define _STLP_DO_COS(_Tp) _STL_math_proxy<_Tp>::_do_cos
# define _STLP_DO_COSH(_Tp) _STL_math_proxy<_Tp>::_do_cosh
# define _STLP_DO_FLOOR(_Tp) _STL_math_proxy<_Tp>::_do_floor
# define _STLP_DO_CEIL(_Tp) _STL_math_proxy<_Tp>::_do_ceil
# define _STLP_DO_FMOD(_Tp) _STL_math_proxy<_Tp>::_do_fmod
# define _STLP_DO_FREXP(_Tp) _STL_math_proxy<_Tp>::_do_frexp
# define _STLP_DO_LDEXP(_Tp) _STL_math_proxy<_Tp>::_do_ldexp
# define _STLP_DO_MODF(_Tp) _STL_math_proxy<_Tp>::_do_modf
# define _STLP_DO_LOG(_Tp) _STL_math_proxy<_Tp>::_do_log
# define _STLP_DO_LOG10(_Tp) _STL_math_proxy<_Tp>::_do_log10
# define _STLP_DO_POW(_Tp) _STL_math_proxy<_Tp>::_do_pow
# define _STLP_DO_SIN(_Tp) _STL_math_proxy<_Tp>::_do_sin
# define _STLP_DO_SINH(_Tp) _STL_math_proxy<_Tp>::_do_sinh
# define _STLP_DO_SQRT(_Tp) _STL_math_proxy<_Tp>::_do_sqrt
# define _STLP_DO_TAN(_Tp) _STL_math_proxy<_Tp>::_do_tan
# define _STLP_DO_TANH(_Tp) _STL_math_proxy<_Tp>::_do_tanh
# define _STLP_DO_EXP(_Tp) _STL_math_proxy<_Tp>::_do_exp
# define _STLP_DO_HYPOT(_Tp) _STL_math_proxy<_Tp>::_do_hypot
# else
# define _STLP_DO_ABS(_Tp) _STLP_VENDOR_CSTD::fabs
# define _STLP_DO_ACOS(_Tp) _STLP_VENDOR_CSTD::acos
# define _STLP_DO_ASIN(_Tp) _STLP_VENDOR_CSTD::asin
# define _STLP_DO_ATAN(_Tp) _STLP_VENDOR_CSTD::atan
# define _STLP_DO_ATAN2(_Tp) _STLP_VENDOR_CSTD::atan2
# define _STLP_DO_COS(_Tp) _STLP_VENDOR_CSTD::cos
# define _STLP_DO_COSH(_Tp) _STLP_VENDOR_CSTD::cosh
# define _STLP_DO_FLOOR(_Tp) _STLP_VENDOR_CSTD::floor
# define _STLP_DO_CEIL(_Tp) _STLP_VENDOR_CSTD::ceil
# define _STLP_DO_FMOD(_Tp) _STLP_VENDOR_CSTD::fmod
# define _STLP_DO_FREXP(_Tp) _STLP_VENDOR_CSTD::frexp
# define _STLP_DO_LDEXP(_Tp) _STLP_VENDOR_CSTD::ldexp
# define _STLP_DO_MODF(_Tp) _STLP_VENDOR_CSTD::modf
# define _STLP_DO_LOG(_Tp) _STLP_VENDOR_CSTD::log
# define _STLP_DO_LOG10(_Tp) _STLP_VENDOR_CSTD::log10
# define _STLP_DO_POW(_Tp) _STLP_VENDOR_CSTD::pow
# define _STLP_DO_SIN(_Tp) _STLP_VENDOR_CSTD::sin
# define _STLP_DO_SINH(_Tp) _STLP_VENDOR_CSTD::sinh
# define _STLP_DO_SQRT(_Tp) _STLP_VENDOR_CSTD::sqrt
# define _STLP_DO_TAN(_Tp) _STLP_VENDOR_CSTD::tan
# define _STLP_DO_TANH(_Tp) _STLP_VENDOR_CSTD::tanh
# define _STLP_DO_EXP(_Tp) _STLP_VENDOR_CSTD::exp
//# if defined (__GNUC__) || defined ( __IBMCPP__ ) || defined (__SUNPRO_CC) || defined (__HP_aCC) || (_MSC_VER >= 1310)
# define _STLP_DO_HYPOT(_Tp) ::hypot
// # else
// # define _STLP_DO_HYPOT(_Tp) _STLP_VENDOR_CSTD::hypot
// # endif
# endif
_STLP_END_NAMESPACE
# if (defined (_STLP_HAS_NO_NEW_C_HEADERS) || defined(_STLP_MSVC) || defined (__ICL)) && !defined (_STLP_HAS_NO_NAMESPACES)
#if ! defined (_STLP_USE_NEW_C_HEADERS)
_STLP_BEGIN_NAMESPACE
# ifndef _STLP_HAS_NATIVE_FLOAT_ABS
inline double abs(double __x) { return _STLP_DO_ABS(double)(__x); }
inline float abs (float __x) { return _STLP_DO_ABS(float)(__x); }
# endif
inline double pow(double __x, int __y) { return _STLP_DO_POW(double)(__x, __y); }
inline float acos (float __x) { return _STLP_DO_ACOS(float)(__x); }
inline float asin (float __x) { return _STLP_DO_ASIN(float)(__x); }
inline float atan (float __x) { return _STLP_DO_ATAN(float)(__x); }
inline float atan2(float __x, float __y) { return _STLP_DO_ATAN2(float)(__x, __y); }
inline float ceil (float __x) { return _STLP_DO_CEIL(float)(__x); }
inline float cos (float __x) { return _STLP_DO_COS(float)(__x); }
inline float cosh (float __x) { return _STLP_DO_COSH(float)(__x); }
inline float exp (float __x) { return _STLP_DO_EXP(float)(__x); }
# ifdef _STLP_USE_NAMESPACES
inline float fabs (float __x) { return _STLP_DO_ABS(float)(__x); }
# endif
inline float floor(float __x) { return _STLP_DO_FLOOR(float)(__x); }
inline float fmod (float __x, float __y) { return _STLP_DO_FMOD(float)(__x, __y); }
inline float frexp(float __x, int* __y) { return _STLP_DO_FREXP(float)(__x, __y); }
inline float ldexp(float __x, int __y) { return _STLP_DO_LDEXP(float)(__x, __y); }
// fbp : float versions are not always available
#if !defined(_STLP_VENDOR_LONG_DOUBLE_MATH) //*ty 11/25/2001 -
inline float modf (float __x, float* __y) {
double __dd[2];
double __res = _STLP_DO_MODF(double)((double)__x, __dd);
__y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1];
return (float)__res;
}
#else //*ty 11/25/2001 - i.e. for apple SCpp
inline float modf (float __x, float* __y) {
long double __dd[2];
long double __res = _STLP_DO_MODF(long double)((long double)__x, __dd);
__y[0] = (float)__dd[0] ; __y[1] = (float)__dd[1];
return (float)__res;
}
#endif //*ty 11/25/2001 -
inline float log (float __x) { return _STLP_DO_LOG(float)(__x); }
inline float log10(float __x) { return _STLP_DO_LOG10(float)(__x); }
inline float pow (float __x, float __y) { return _STLP_DO_POW(float)(__x, __y); }
inline float pow (float __x, int __y) { return _STLP_DO_POW(float)(__x, __y); }
inline float sin (float __x) { return _STLP_DO_SIN(float)(__x); }
inline float sinh (float __x) { return _STLP_DO_SINH(float)(__x); }
inline float sqrt (float __x) { return _STLP_DO_SQRT(float)(__x); }
inline float tan (float __x) { return _STLP_DO_TAN(float)(__x); }
inline float tanh (float __x) { return _STLP_DO_TANH(float)(__x); }
# if ! (defined (_STLP_NO_LONG_DOUBLE) || defined(_STLP_VENDOR_LONG_DOUBLE_MATH))
#if !defined (__MVS__)
inline long double abs (long double __x) { return _STLP_DO_ABS(long double)((double)__x); }
#endif
inline long double acos (long double __x) { return _STLP_DO_ACOS(long double)(__x); }
inline long double asin (long double __x) { return _STLP_DO_ASIN(long double)(__x); }
inline long double atan (long double __x) { return _STLP_DO_ATAN(long double)(__x); }
inline long double atan2(long double __x, long double __y) { return _STLP_DO_ATAN2(long double)(__x, __y); }
inline long double ceil (long double __x) { return _STLP_DO_CEIL(long double)(__x); }
inline long double cos (long double __x) { return _STLP_DO_COS(long double)(__x); }
inline long double cosh (long double __x) { return _STLP_DO_COSH(long double)(__x); }
inline long double exp (long double __x) { return _STLP_DO_EXP(long double)(__x); }
inline long double fabs (long double __x) { return _STLP_DO_ABS(long double)(__x); }
inline long double floor(long double __x) { return _STLP_DO_FLOOR(long double)(__x); }
inline long double fmod (long double __x, long double __y) { return _STLP_DO_FMOD(long double)(__x, __y); }
inline long double frexp(long double __x, int* __y) { return _STLP_DO_FREXP(long double)(__x, __y); }
inline long double ldexp(long double __x, int __y) { return _STLP_DO_LDEXP(long double)(__x, __y); }
// fbp : long double versions are not available
inline long double modf (long double __x, long double* __y) {
double __dd[2];
double __res = _STLP_DO_MODF(double)((double)__x, __dd);
__y[0] = (long double)__dd[0] ; __y[1] = (long double)__dd[1];
return (long double)__res;
}
inline long double log (long double __x) { return _STLP_DO_LOG(long double)(__x); }
inline long double log10(long double __x) { return _STLP_DO_LOG10(long double)(__x); }
inline long double pow (long double __x, long double __y) { return _STLP_DO_POW(long double)(__x, __y); }
inline long double pow (long double __x, int __y) { return _STLP_DO_POW(long double)(__x, __y); }
inline long double sin (long double __x) { return _STLP_DO_SIN(long double)(__x); }
inline long double sinh (long double __x) { return _STLP_DO_SINH(long double)(__x); }
inline long double sqrt (long double __x) { return _STLP_DO_SQRT(long double)(__x); }
inline long double tan (long double __x) { return _STLP_DO_TAN(long double)(__x); }
inline long double tanh (long double __x) { return _STLP_DO_TANH(long double)(__x); }
# endif
_STLP_END_NAMESPACE
# endif /* NEW_C_HEADERS */
# endif /* NEW_C_HEADERS */
#endif /* CMATH_H */
+307
View File
@@ -0,0 +1,307 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_CODECVT_H
#define _STLP_INTERNAL_CODECVT_H
# ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
# endif
# ifndef _STLP_INTERNAL_LOCALE_H
# include <stl/_locale.h>
# endif
_STLP_BEGIN_NAMESPACE
class _STLP_CLASS_DECLSPEC codecvt_base {
public:
enum result {ok, partial, error, noconv};
};
template <class _InternT, class _ExternT, class _StateT>
class codecvt : public locale::facet, public codecvt_base {
typedef _InternT intern_type;
typedef _ExternT extern_type;
typedef _StateT state_type;
};
template <class _InternT, class _ExternT, class _StateT>
class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
: public locale::facet, public codecvt_base
{
friend class _Locale;
public:
typedef char intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
explicit codecvt(size_t __refs = 0) : _BaseFacet(__refs) {}
result out(state_type& __state,
const char* __from,
const char* __from_end,
const char*& __from_next,
char* __to,
char* __to_limit,
char*& __to_next) const {
return do_out(__state,
__from, __from_end, __from_next,
__to, __to_limit, __to_next);
}
result unshift(mbstate_t& __state,
char* __to, char* __to_limit, char*& __to_next) const
{ return do_unshift(__state, __to, __to_limit, __to_next); }
result in(state_type& __state,
const char* __from,
const char* __from_end,
const char*& __from_next,
char* __to,
char* __to_limit,
char*& __to_next) const {
return do_in(__state,
__from, __from_end, __from_next,
__to, __to_limit, __to_next);
}
int encoding() const _STLP_NOTHROW { return do_encoding(); }
bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
int length(const state_type& __state,
const char* __from, const char* __end,
size_t __max) const
{ return do_length(__state, __from, __end, __max); }
int max_length() const _STLP_NOTHROW { return do_max_length(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~codecvt();
virtual result do_out(mbstate_t& /* __state */,
const char* __from,
const char* /* __from_end */,
const char*& __from_next,
char* __to,
char* /* __to_limit */,
char*& __to_next) const;
virtual result do_in (mbstate_t& /* __state */ ,
const char* __from,
const char* /* __from_end */,
const char*& __from_next,
char* __to,
char* /* __to_end */,
char*& __to_next) const;
virtual result do_unshift(mbstate_t& /* __state */,
char* __to,
char* /* __to_limit */,
char*& __to_next) const;
virtual int do_encoding() const _STLP_NOTHROW;
virtual bool do_always_noconv() const _STLP_NOTHROW;
virtual int do_length(const mbstate_t& __state,
const char* __from,
const char* __end,
size_t __max) const;
virtual int do_max_length() const _STLP_NOTHROW;
private:
codecvt(const codecvt<char, char, mbstate_t>&);
codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
: public locale::facet, public codecvt_base
{
friend class _Locale;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
explicit codecvt(size_t __refs = 0) : _BaseFacet(__refs) {}
result out(mbstate_t __state,
const wchar_t* __from,
const wchar_t* __from_end,
const wchar_t*& __from_next,
char* __to,
char* __to_limit,
char*& __to_next) const {
return do_out(__state,
__from, __from_end, __from_next,
__to, __to_limit, __to_next);
}
result unshift(mbstate_t& __state,
char* __to, char* __to_limit, char*& __to_next) const {
return do_unshift(__state, __to, __to_limit, __to_next);
}
result in(mbstate_t __state,
const char* __from,
const char* __from_end,
const char*& __from_next,
wchar_t* __to,
wchar_t* __to_limit,
wchar_t*& __to_next) const {
return do_in(__state,
__from, __from_end, __from_next,
__to, __to_limit, __to_next);
}
int encoding() const _STLP_NOTHROW { return do_encoding(); }
bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
int length(const mbstate_t& __state,
const char* __from,
const char* __end,
size_t __max) const
{ return do_length(__state, __from, __end, __max); }
int max_length() const _STLP_NOTHROW { return do_max_length(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~codecvt();
virtual result do_out(mbstate_t& __state,
const wchar_t* __from,
const wchar_t* __from_end,
const wchar_t*& __from_next,
char* __to,
char* __to_limit,
char*& __to_next) const;
virtual result do_in (mbstate_t& __state,
const char* __from,
const char* __from_end,
const char*& __from_next,
wchar_t* __to,
wchar_t* __to_limit,
wchar_t*& __to_next) const;
virtual result do_unshift(mbstate_t& __state,
char* __to,
char* __to_limit,
char*& __to_next) const;
virtual int do_encoding() const _STLP_NOTHROW;
virtual bool do_always_noconv() const _STLP_NOTHROW;
virtual int do_length(const mbstate_t& __state,
const char* __from,
const char* __end,
size_t __max) const;
virtual int do_max_length() const _STLP_NOTHROW;
private:
codecvt(const codecvt<wchar_t, char, mbstate_t>&);
codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
};
# endif
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
: public codecvt<char, char, mbstate_t> {
public:
explicit codecvt_byname(const char* __name, size_t __refs = 0);
~codecvt_byname();
private:
codecvt_byname(const codecvt_byname<char, char, mbstate_t>&);
codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&);
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class codecvt_byname<wchar_t, char, mbstate_t>
: public codecvt<wchar_t, char, mbstate_t>
{
public:
explicit codecvt_byname(const char * __name, size_t __refs = 0);
protected:
~codecvt_byname();
virtual result do_out(mbstate_t& __state,
const wchar_t* __from,
const wchar_t* __from_end,
const wchar_t*& __from_next,
char* __to,
char* __to_limit,
char*& __to_next) const;
virtual result do_in (mbstate_t& __state,
const char* __from,
const char* __from_end,
const char*& __from_next,
wchar_t* __to,
wchar_t* __to_limit,
wchar_t*& __to_next) const;
virtual result do_unshift(mbstate_t& __state,
char* __to,
char* __to_limit,
char*& __to_next) const;
virtual int do_encoding() const _STLP_NOTHROW;
virtual bool do_always_noconv() const _STLP_NOTHROW;
virtual int do_length(const mbstate_t& __state,
const char* __from,
const char* __end,
size_t __max) const;
virtual int do_max_length() const _STLP_NOTHROW;
private:
_Locale_ctype* _M_ctype;
codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&);
codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&);
};
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_CODECVT_H */
// Local Variables:
// mode:C++
// End:
+182
View File
@@ -0,0 +1,182 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_COLLATE_H
#define _STLP_INTERNAL_COLLATE_H
#ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
#endif
#ifndef _STLP_INTERNAL_LOCALE_H
# include <stl/_locale.h>
#endif
#ifndef _STLP_STRING_H
# include <stl/_string.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _CharT> class collate {};
template <class _CharT> class collate_byname {};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC collate<char> : public locale::facet
{
friend class _Locale;
public:
typedef char char_type;
typedef string string_type;
explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
int compare(const char* __low1, const char* __high1,
const char* __low2, const char* __high2) const {
return do_compare( __low1, __high1, __low2, __high2);
}
string_type transform(const char* __low, const char* __high) const {
return do_transform(__low, __high);
}
long hash(const char* __low, const char* __high) const
{ return do_hash(__low, __high); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~collate();
virtual int do_compare(const char*, const char*,
const char*, const char*) const;
virtual string_type do_transform(const char*, const char*) const;
virtual long do_hash(const char*, const char*) const;
private:
collate(const collate<char>&);
collate<char>& operator =(const collate<char>&);
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC collate<wchar_t> : public locale::facet
{
friend class _Locale;
public:
typedef wchar_t char_type;
typedef wstring string_type;
explicit collate(size_t __refs = 0) : _BaseFacet(__refs) {}
int compare(const wchar_t* __low1, const wchar_t* __high1,
const wchar_t* __low2, const wchar_t* __high2) const {
return do_compare( __low1, __high1, __low2, __high2);
}
string_type transform(const wchar_t* __low, const wchar_t* __high) const {
return do_transform(__low, __high);
}
long hash(const wchar_t* __low, const wchar_t* __high) const
{ return do_hash(__low, __high); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~collate();
virtual int do_compare(const wchar_t*, const wchar_t*,
const wchar_t*, const wchar_t*) const;
virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
virtual long do_hash(const wchar_t* __low, const wchar_t* __high) const;
private:
collate(const collate<wchar_t>&);
collate<wchar_t>& operator = (const collate<wchar_t>&);
};
# endif /* NO_WCHAR_T */
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC collate_byname<char>: public collate<char>
{
public:
explicit collate_byname(const char* __name, size_t __refs = 0);
protected:
~collate_byname();
virtual int do_compare(const char*, const char*,
const char*, const char*) const;
virtual string_type do_transform(const char*, const char*) const;
private:
_Locale_collate* _M_collate;
collate_byname(const collate_byname<char>&);
collate_byname<char>& operator =(const collate_byname<char>&);
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>: public collate<wchar_t>
{
public:
explicit collate_byname(const char * __name, size_t __refs = 0);
protected:
~collate_byname();
virtual int do_compare(const wchar_t*, const wchar_t*,
const wchar_t*, const wchar_t*) const;
virtual string_type do_transform(const wchar_t*, const wchar_t*) const;
private:
_Locale_collate* _M_collate;
collate_byname(const collate_byname<wchar_t>&);
collate_byname<wchar_t>& operator =(const collate_byname<wchar_t>&);
};
# endif /* NO_WCHAR_T */
template <class _CharT>
bool
__locale_do_operator_call (const locale* __that,
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y)
{
collate<_CharT>* __f = (collate<_CharT>*)__that->_M_get_facet(collate<_CharT>::id);
if (!__f)
__that->_M_throw_runtime_error();
return __f->compare(__x.data(), __x.data() + __x.size(),
__y.data(), __y.data() + __y.size()) < 0;
}
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_COLLATE_H */
// Local Variables:
// mode:C++
// End:
+169
View File
@@ -0,0 +1,169 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_COMPLEX_C
#define _STLP_COMPLEX_C
# ifndef _STLP_internal_complex_h
# include <stl/_complex.h>
# endif
#include <istream>
#ifdef _STLP_USE_NEW_IOSTREAMS
# include <sstream>
#endif
_STLP_BEGIN_NAMESPACE
// Non-inline member functions.
template <class _Tp>
void complex<_Tp>::_div(const _Tp& __z1_r, const _Tp& __z1_i,
const _Tp& __z2_r, const _Tp& __z2_i,
_Tp& __res_r, _Tp& __res_i) {
_Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
_Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
if (__ar <= __ai) {
_Tp __ratio = __z2_r / __z2_i;
_Tp __denom = __z2_i * (1 + __ratio * __ratio);
__res_r = (__z1_r * __ratio + __z1_i) / __denom;
__res_i = (__z1_i * __ratio - __z1_r) / __denom;
}
else {
_Tp __ratio = __z2_i / __z2_r;
_Tp __denom = __z2_r * (1 + __ratio * __ratio);
__res_r = (__z1_r + __z1_i * __ratio) / __denom;
__res_i = (__z1_i - __z1_r * __ratio) / __denom;
}
}
template <class _Tp>
void complex<_Tp>::_div(const _Tp& __z1_r,
const _Tp& __z2_r, const _Tp& __z2_i,
_Tp& __res_r, _Tp& __res_i) {
_Tp __ar = __z2_r >= 0 ? __z2_r : -__z2_r;
_Tp __ai = __z2_i >= 0 ? __z2_i : -__z2_i;
if (__ar <= __ai) {
_Tp __ratio = __z2_r / __z2_i;
_Tp __denom = __z2_i * (1 + __ratio * __ratio);
__res_r = (__z1_r * __ratio) / __denom;
__res_i = - __z1_r / __denom;
}
else {
_Tp __ratio = __z2_i / __z2_r;
_Tp __denom = __z2_r * (1 + __ratio * __ratio);
__res_r = __z1_r / __denom;
__res_i = - (__z1_r * __ratio) / __denom;
}
}
// I/O.
#ifdef _STLP_USE_NEW_IOSTREAMS
// Complex output, in the form (re,im). We use a two-step process
// involving stringstream so that we get the padding right.
template <class _Tp, class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z)
{
basic_ostringstream<_CharT, _Traits, allocator<_CharT> > __tmp;
__tmp.flags(__os.flags());
__tmp.imbue(__os.getloc());
__tmp.precision(__os.precision());
__tmp << '(' << __z.real() << ',' << __z.imag() << ')';
return __os << __tmp.str();
}
// Complex input from arbitrary streams. Note that results in some
// locales may be confusing, since the decimal character varies with
// locale and the separator between real and imaginary parts does not.
template <class _Tp, class _CharT, class _Traits>
basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z)
{
_Tp __re = 0;
_Tp __im = 0;
// typedef ctype<_CharT> _Ctype;
// locale __loc = __is.getloc();
//const _Ctype& __c_type = use_facet<_Ctype>(__loc);
const ctype<_CharT>& __c_type = *(const ctype<_CharT>*)__is._M_ctype_facet();
char __punct[4] = "(,)";
_CharT __wpunct[3];
__c_type.widen(__punct, __punct + 3, __wpunct);
_CharT __c;
__is >> __c;
if (_Traits::eq(__c, __wpunct[0])) { // Left paren
__is >> __re >> __c;
if (_Traits::eq(__c, __wpunct[1])) // Comma
__is >> __im >> __c;
if (!_Traits::eq(__c, __wpunct[2])) // Right paren
__is.setstate(ios_base::failbit);
}
else {
__is.putback(__c);
__is >> __re;
}
if (__is)
__z = complex<_Tp>(__re, __im);
return __is;
}
#else /* _STLP_USE_NEW_IOSTREAMS */
template <class _Tp>
ostream& _STLP_CALL operator<<(ostream& s, const complex<_Tp>& __z)
{
return s << "( " << __z._M_re <<", " << __z._M_im <<")";
}
template <class _Tp>
istream& _STLP_CALL operator>>(istream& s, complex<_Tp>& a)
{
_Tp re = 0, im = 0;
char c = 0;
s >> c;
if (c == '(') {
s >> re >> c;
if (c == ',') s >> im >> c;
if (c != ')') s.clear(ios::badbit);
}
else {
s.putback(c);
s >> re;
}
if (s) a = complex<_Tp>(re, im);
return s;
}
#endif /* _STLP_USE_NEW_IOSTREAMS */
_STLP_END_NAMESPACE
#endif /* _STLP_COMPLEX_C */
+969
View File
@@ -0,0 +1,969 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_internal_complex_h
#define _STLP_internal_complex_h
// This header declares the template class complex, as described in
// in the draft C++ standard. Single-precision complex numbers
// are complex<float>, double-precision are complex<double>, and
// quad precision are complex<long double>.
// Note that the template class complex is declared within namespace
// std, as called for by the draft C++ standard.
#include <stl/_cmath.h>
#include <iosfwd>
_STLP_BEGIN_NAMESPACE
#if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS) //*TY 02/25/2000 - added for MPW compiler workaround
template <class _Tp> struct complex;
_STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<float>;
_STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<double>;
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<long double>;
# endif
# endif
template <class _Tp>
struct complex {
typedef _Tp value_type;
typedef complex<_Tp> _Self;
// Constructors, destructor, assignment operator.
complex() : _M_re(0), _M_im(0) {}
complex(const value_type& __x)
: _M_re(__x), _M_im(0) {}
complex(const value_type& __x, const value_type& __y)
: _M_re(__x), _M_im(__y) {}
complex(const _Self& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
#if defined (_STLP_MEMBER_TEMPLATES) && ( defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined(_STLP_NO_COMPLEX_SPECIALIZATIONS))
template <class _Tp2>
explicit complex(const complex<_Tp2>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
template <class _Tp2>
_Self& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
// Element access.
value_type real() const { return _M_re; }
value_type imag() const { return _M_im; }
// Arithmetic op= operations involving one real argument.
_Self& operator= (const value_type& __x) {
_M_re = __x;
_M_im = 0;
return *this;
}
_Self& operator+= (const value_type& __x) {
_M_re += __x;
return *this;
}
_Self& operator-= (const value_type& __x) {
_M_re -= __x;
return *this;
}
_Self& operator*= (const value_type& __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
_Self& operator/= (const value_type& __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static void _STLP_CALL _div(const value_type& __z1_r, const value_type& __z1_i,
const value_type& __z2_r, const value_type& __z2_i,
value_type& __res_r, value_type& __res_i);
static void _STLP_CALL _div(const value_type& __z1_r,
const value_type& __z2_r, const value_type& __z2_i,
value_type& __res_r, value_type& __res_i);
#if defined ( _STLP_MEMBER_TEMPLATES ) // && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp2> _Self& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2> _Self& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2> _Self& operator*= (const complex<_Tp2>& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2> _Self& operator/= (const complex<_Tp2>& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
_Self& operator-= (const _Self& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
_Self& operator*= (const _Self& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
_Self& operator/= (const _Self& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
// Data members.
value_type _M_re;
value_type _M_im;
};
#if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS) //*TY 02/25/2000 - added for MPW compiler workaround
// Explicit specializations for float, double, long double. The only
// reason for these specializations is to enable automatic conversions
// from complex<float> to complex<double>, and complex<double> to
// complex<long double>.
_STLP_TEMPLATE_NULL
struct _STLP_CLASS_DECLSPEC complex<float> {
typedef float value_type;
typedef complex<float> _Self;
// Constructors, destructor, assignment operator.
complex(value_type __x = 0.0, value_type __y = 0.0)
: _M_re(__x), _M_im(__y) {}
complex(const complex<float>& __z) : _M_re(__z._M_re), _M_im(__z._M_im) {}
inline explicit complex(const complex<double>& __z);
# ifndef _STLP_NO_LONG_DOUBLE
inline explicit complex(const complex<long double>& __z);
# endif
// Element access.
value_type real() const { return _M_re; }
value_type imag() const { return _M_im; }
// Arithmetic op= operations involving one real argument.
_Self& operator= (value_type __x) {
_M_re = __x;
_M_im = 0;
return *this;
}
_Self& operator+= (value_type __x) {
_M_re += __x;
return *this;
}
_Self& operator-= (value_type __x) {
_M_re -= __x;
return *this;
}
_Self& operator*= (value_type __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
_Self& operator/= (value_type __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static void _STLP_CALL _div(const float& __z1_r, const float& __z1_i,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i);
static void _STLP_CALL _div(const float& __z1_r,
const float& __z2_r, const float& __z2_i,
float& __res_r, float& __res_i);
#if defined (_STLP_MEMBER_TEMPLATES)
template <class _Tp2>
complex<float>& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
complex<float>& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2>
complex<float>& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2>
complex<float>& operator*= (const complex<_Tp2>& __z) {
float __r = _M_re * __z._M_re - _M_im * __z._M_im;
float __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2>
complex<float>& operator/= (const complex<_Tp2>& __z) {
float __r;
float __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
_Self& operator-= (const _Self& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
_Self& operator*= (const _Self& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
_Self& operator/= (const _Self& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
// Data members.
value_type _M_re;
value_type _M_im;
};
_STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<double> {
typedef double value_type;
typedef complex<double> _Self;
// Constructors, destructor, assignment operator.
complex(value_type __x = 0.0, value_type __y = 0.0)
: _M_re(__x), _M_im(__y) {}
complex(const complex<double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex(const complex<float>& __z);
# ifndef _STLP_NO_LONG_DOUBLE
explicit inline complex(const complex<long double>& __z);
# endif
// Element access.
value_type real() const { return _M_re; }
value_type imag() const { return _M_im; }
// Arithmetic op= operations involving one real argument.
_Self& operator= (value_type __x) {
_M_re = __x;
_M_im = 0;
return *this;
}
_Self& operator+= (value_type __x) {
_M_re += __x;
return *this;
}
_Self& operator-= (value_type __x) {
_M_re -= __x;
return *this;
}
_Self& operator*= (value_type __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
_Self& operator/= (value_type __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static void _STLP_CALL _div(const double& __z1_r, const double& __z1_i,
const double& __z2_r, const double& __z2_i,
double& __res_r, double& __res_i);
static void _STLP_CALL _div(const double& __z1_r,
const double& __z2_r, const double& __z2_i,
double& __res_r, double& __res_i);
#if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp2>
complex<double>& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
complex<double>& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2>
complex<double>& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2>
complex<double>& operator*= (const complex<_Tp2>& __z) {
double __r = _M_re * __z._M_re - _M_im * __z._M_im;
double __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2>
complex<double>& operator/= (const complex<_Tp2>& __z) {
double __r;
double __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
_Self& operator-= (const _Self& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
_Self& operator*= (const _Self& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
_Self& operator/= (const _Self& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
// Data members.
value_type _M_re;
value_type _M_im;
};
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<long double> {
typedef long double value_type;
typedef complex<long double> _Self;
// Constructors, destructor, assignment operator.
complex(value_type __x = 0.0, value_type __y = 0.0)
: _M_re(__x), _M_im(__y) {}
complex(const complex<long double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex(const complex<float>& __z);
inline complex(const complex<double>& __z);
// Element access.
value_type real() const { return _M_re; }
value_type imag() const { return _M_im; }
// Arithmetic op= operations involving one real argument.
_Self& operator= (value_type __x) {
_M_re = __x;
_M_im = 0;
return *this;
}
_Self& operator+= (value_type __x) {
_M_re += __x;
return *this;
}
_Self& operator-= (value_type __x) {
_M_re -= __x;
return *this;
}
_Self& operator*= (value_type __x) {
_M_re *= __x;
_M_im *= __x;
return *this;
}
_Self& operator/= (value_type __x) {
_M_re /= __x;
_M_im /= __x;
return *this;
}
// Arithmetic op= operations involving two complex arguments.
static void _STLP_CALL _div(const long double& __z1_r, const long double& __z1_i,
const long double& __z2_r, const long double& __z2_i,
long double& __res_r, long double& __res_i);
static void _STLP_CALL _div(const long double& __z1_r,
const long double& __z2_r, const long double& __z2_i,
long double& __res_r, long double& __res_i);
#if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
template <class _Tp2>
complex<long double>& operator=(const complex<_Tp2>& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
template <class _Tp2>
complex<long double>& operator+= (const complex<_Tp2>& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
template <class _Tp2>
complex<long double>& operator-= (const complex<_Tp2>& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
template <class _Tp2>
complex<long double>& operator*= (const complex<_Tp2>& __z) {
long double __r = _M_re * __z._M_re - _M_im * __z._M_im;
long double __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
template <class _Tp2>
complex<long double>& operator/= (const complex<_Tp2>& __z) {
long double __r;
long double __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
#endif /* _STLP_MEMBER_TEMPLATES */
_Self& operator=(const _Self& __z) {
_M_re = __z._M_re;
_M_im = __z._M_im;
return *this;
}
_Self& operator+= (const _Self& __z) {
_M_re += __z._M_re;
_M_im += __z._M_im;
return *this;
}
_Self& operator-= (const _Self& __z) {
_M_re -= __z._M_re;
_M_im -= __z._M_im;
return *this;
}
_Self& operator*= (const _Self& __z) {
value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
_M_re = __r;
_M_im = __i;
return *this;
}
_Self& operator/= (const _Self& __z) {
value_type __r;
value_type __i;
_div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
_M_re = __r;
_M_im = __i;
return *this;
}
// Data members.
value_type _M_re;
value_type _M_im;
};
# endif /* _STLP_NO_LONG_DOUBLE */
// Converting constructors from one of these three specialized types
// to another.
inline complex<float>::complex(const complex<double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex<double>::complex(const complex<float>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
# ifndef _STLP_NO_LONG_DOUBLE
inline complex<float>::complex(const complex<long double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex<double>::complex(const complex<long double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex<long double>::complex(const complex<float>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
inline complex<long double>::complex(const complex<double>& __z)
: _M_re(__z._M_re), _M_im(__z._M_im) {}
# endif
# endif /* SPECIALIZATIONS */
// Unary non-member arithmetic operators.
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z) {
return __z;
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z) {
return complex<_Tp>(-__z._M_re, -__z._M_im);
}
// Non-member arithmetic operations involving one real argument.
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator+(const _Tp& __x, const complex<_Tp>& __z) {
return complex<_Tp>(__x + __z._M_re, __z._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z, const _Tp& __x) {
return complex<_Tp>(__z._M_re + __x, __z._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator-(const _Tp& __x, const complex<_Tp>& __z) {
return complex<_Tp>(__x - __z._M_re, -__z._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z, const _Tp& __x) {
return complex<_Tp>(__z._M_re - __x, __z._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator*(const _Tp& __x, const complex<_Tp>& __z) {
return complex<_Tp>(__x * __z._M_re, __x * __z._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator*(const complex<_Tp>& __z, const _Tp& __x) {
return complex<_Tp>(__z._M_re * __x, __z._M_im * __x);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator/(const _Tp& __x, const complex<_Tp>& __z) {
complex<_Tp> __result;
complex<_Tp>::_div(__x,
__z._M_re, __z._M_im,
__result._M_re, __result._M_im);
return __result;
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL operator/(const complex<_Tp>& __z, const _Tp& __x) {
return complex<_Tp>(__z._M_re / __x, __z._M_im / __x);
}
// Non-member arithmetic operations involving two complex arguments
template <class _Tp>
inline complex<_Tp> _STLP_CALL
operator+(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
return complex<_Tp>(__z1._M_re + __z2._M_re, __z1._M_im + __z2._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL
operator-(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
return complex<_Tp>(__z1._M_re - __z2._M_re, __z1._M_im - __z2._M_im);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL
operator*(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
return complex<_Tp>(__z1._M_re * __z2._M_re - __z1._M_im * __z2._M_im,
__z1._M_re * __z2._M_im + __z1._M_im * __z2._M_re);
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL
operator/(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
complex<_Tp> __result;
complex<_Tp>::_div(__z1._M_re, __z1._M_im,
__z2._M_re, __z2._M_im,
__result._M_re, __result._M_im);
return __result;
}
// Comparison operators.
template <class _Tp>
inline bool _STLP_CALL operator==(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
return __z1._M_re == __z2._M_re && __z1._M_im == __z2._M_im;
}
template <class _Tp>
inline bool _STLP_CALL operator==(const complex<_Tp>& __z, const _Tp& __x) {
return __z._M_re == __x && __z._M_im == 0;
}
template <class _Tp>
inline bool _STLP_CALL operator==(const _Tp& __x, const complex<_Tp>& __z) {
return __x == __z._M_re && 0 == __z._M_im;
}
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Tp>
inline bool _STLP_CALL operator!=(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
return __z1._M_re != __z2._M_re || __z1._M_im != __z2._M_im;
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
template <class _Tp>
inline bool _STLP_CALL operator!=(const complex<_Tp>& __z, const _Tp& __x) {
return __z._M_re != __x || __z._M_im != 0;
}
template <class _Tp>
inline bool _STLP_CALL operator!=(const _Tp& __x, const complex<_Tp>& __z) {
return __x != __z._M_re || 0 != __z._M_im;
}
// Other basic arithmetic operations
template <class _Tp>
inline _Tp _STLP_CALL real(const complex<_Tp>& __z) {
return __z._M_re;
}
template <class _Tp>
inline _Tp _STLP_CALL imag(const complex<_Tp>& __z) {
return __z._M_im;
}
template <class _Tp>
_Tp _STLP_CALL abs(const complex<_Tp>& __z) {
return _Tp(abs(complex<double>(double(__z.real()), double(__z.imag()))));
}
template <class _Tp>
_Tp _STLP_CALL arg(const complex<_Tp>& __z) {
return _Tp(arg(complex<double>(double(__z.real()), double(__z.imag()))));
}
template <class _Tp>
inline _Tp _STLP_CALL norm(const complex<_Tp>& __z) {
return __z._M_re * __z._M_re + __z._M_im * __z._M_im;
}
template <class _Tp>
inline complex<_Tp> _STLP_CALL conj(const complex<_Tp>& __z) {
return complex<_Tp>(__z._M_re, -__z._M_im);
}
template <class _Tp>
complex<_Tp> _STLP_CALL polar(const _Tp& __rho) {
return complex<_Tp>(__rho, 0);
}
template <class _Tp>
complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi) {
complex<double> __tmp = polar(double(__rho), double(__phi));
return complex<_Tp>(_Tp(__tmp.real()), _Tp(__tmp.imag()));
}
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC float _STLP_CALL abs(const complex<float>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC double _STLP_CALL abs(const complex<double>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC float _STLP_CALL arg(const complex<float>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC double _STLP_CALL arg(const complex<double>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<float> _STLP_CALL polar(const float& __rho, const float& __phi);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<double> _STLP_CALL polar(const double& __rho, const double& __phi);
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC long double _STLP_CALL arg(const complex<long double>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC long double _STLP_CALL abs(const complex<long double>&);
_STLP_TEMPLATE_NULL
_STLP_DECLSPEC complex<long double> _STLP_CALL polar(const long double&, const long double&);
# endif
#ifdef _STLP_USE_NEW_IOSTREAMS
// Complex output, in the form (re,im). We use a two-step process
// involving stringstream so that we get the padding right.
template <class _Tp, class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z);
template <class _Tp, class _CharT, class _Traits>
basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z);
// Specializations for narrow characters; lets us avoid widen.
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z);
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z);
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<float>& __z);
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<double>& __z);
# if ! defined (_STLP_NO_LONG_DOUBLE)
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL
operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z);
_STLP_OPERATOR_TEMPLATE
_STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<long double>& __z);
# endif
# if defined (_STLP_USE_TEMPLATE_EXPORT) && ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
_STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
# endif
# endif /* USE_TEMPLATE_EXPORT */
#else /* _STLP_USE_NEW_IOSTREAMS */
template <class _Tp>
ostream& _STLP_CALL operator<<(ostream& s, const complex<_Tp>& __z);
template <class _Tp>
istream& _STLP_CALL operator>>(istream& s, complex<_Tp>& a);
#endif /* _STLP_USE_NEW_IOSTREAMS */
// Transcendental functions. These are defined only for float,
// double, and long double. (Sqrt isn't transcendental, of course,
// but it's included in this section anyway.)
_STLP_DECLSPEC complex<float> _STLP_CALL sqrt(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL exp(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL log(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, int);
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const float&);
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const float&, const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>&);
_STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>&);
_STLP_DECLSPEC complex<double> _STLP_CALL sqrt(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, int);
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const double&);
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const double&, const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>&);
_STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>&);
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_DECLSPEC complex<long double> _STLP_CALL sqrt(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, int);
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, const long double&);
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const long double&, const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&,
const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>&);
_STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>&);
# endif
_STLP_END_NAMESPACE
# ifndef _STLP_LINK_TIME_INSTANTIATION
# include <stl/_complex.c>
# endif
#endif /* _STLP_template_complex */
// Local Variables:
// mode:C++
// End:
File diff suppressed because it is too large Load Diff
+89
View File
@@ -0,0 +1,89 @@
/*
* Compatibility section
* This section sets new-style macros based on old-style ones, for compatibility
*/
# if (defined (__STL_NO_SGI_IOSTREAMS) || defined (_STLP_NO_SGI_IOSTREAMS)) \
&& ! defined ( _STLP_NO_OWN_IOSTREAMS )
# define _STLP_NO_OWN_IOSTREAMS
# endif
# if defined (__STL_NO_NEW_IOSTREAMS) && ! defined ( _STLP_NO_NEW_IOSTREAMS )
# define _STLP_NO_NEW_IOSTREAMS __STL_NO_NEW_IOSTREAMS
# endif
# if defined (__STL_NO_IOSTREAMS) && ! defined ( _STLP_NO_IOSTREAMS )
# define _STLP_NO_IOSTREAMS __STL_NO_IOSTREAMS
# endif
# if defined (__STL_DEBUG) && ! defined ( _STLP_DEBUG )
# define _STLP_DEBUG __STL_DEBUG
# endif
# if defined (__STL_NO_ANACHRONISMS) && ! defined ( _STLP_NO_ANACHRONISMS )
# define _STLP_NO_ANACHRONISMS __STL_NO_ANACHRONISMS
# endif
# if defined (__STL_NO_EXTENSIONS) && ! defined ( _STLP_NO_EXTENSIONS )
# define _STLP_NO_EXTENSIONS __STL_NO_EXTENSIONS
# endif
# if defined (__STL_NO_EXCEPTIONS) && ! defined ( _STLP_NO_EXCEPTIONS )
# define _STLP_NO_EXCEPTIONS __STL_NO_EXCEPTIONS
# endif
# if defined (__STL_NO_NAMESPACES) && ! defined ( _STLP_NO_NAMESPACES )
# define _STLP_NO_NAMESPACES __STL_NO_NAMESPACES
# endif
# if defined (__STL_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
# define _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS __STL_MINIMUM_DEFAULT_TEMPLATE_PARAMS
# endif
# if defined (__STL_NO_OWN_NAMESPACE) && ! defined ( _STLP_NO_OWN_NAMESPACE )
# define _STLP_NO_OWN_NAMESPACE __STL_NO_OWN_NAMESPACE
# endif
# if defined (__STL_NO_RELOPS_NAMESPACE) && ! defined ( _STLP_NO_RELOPS_NAMESPACE )
# define _STLP_NO_RELOPS_NAMESPACE __STL_NO_RELOPS_NAMESPACE
# endif
# if defined (__STL_DEBUG_UNINITIALIZED) && ! defined ( _STLP_DEBUG_UNINITIALIZED )
# define _STLP_DEBUG_UNINITIALIZED __STL_DEBUG_UNINITIALIZED
# endif
# if defined (__STL_SHRED_BYTE) && ! defined ( _STLP_SHRED_BYTE )
# define _STLP_SHRED_BYTE __STL_SHRED_BYTE
# endif
# if defined (__STL_USE_MFC) && ! defined ( _STLP_USE_MFC )
# define _STLP_USE_MFC __STL_USE_MFC
# endif
# if defined (__STL_USE_NEWALLOC) && ! defined ( _STLP_USE_NEWALLOC )
# define _STLP_USE_NEWALLOC __STL_USE_NEWALLOC
# endif
# if defined (__STL_USE_MALLOC) && ! defined ( _STLP_USE_MALLOC )
# define _STLP_USE_MALLOC __STL_USE_MALLOC
# endif
# if defined (__STL_DEBUG_ALLOC) && ! defined ( _STLP_DEBUG_ALLOC )
# define _STLP_DEBUG_ALLOC __STL_DEBUG_ALLOC
# endif
# if defined (__STL_DEBUG_MESSAGE) && ! defined ( _STLP_DEBUG_MESSAGE )
# define _STLP_DEBUG_MESSAGE __STL_DEBUG_MESSAGE
# endif
# if defined (__STL_DEBUG_TERMINATE) && ! defined ( _STLP_DEBUG_TERMINATE )
# define _STLP_DEBUG_TERMINATE __STL_DEBUG_TERMINATE
# endif
# if defined (__STL_NO_DEBUG_EXCEPTIONS) && ! defined ( _STLP_NO_DEBUG_EXCEPTIONS )
# define _STLP_NO_DEBUG_EXCEPTIONS __STL_NO_DEBUG_EXCEPTIONS
# endif
# if defined (__STL_USE_ABBREVS) && ! defined ( _STLP_USE_ABBREVS )
# define _STLP_USE_ABBREVS __STL_USE_ABBREVS
# endif
# if defined (__STL_NO_MSVC50_COMPATIBILITY) && ! defined ( _STLP_NO_MSVC50_COMPATIBILITY )
# define _STLP_NO_MSVC50_COMPATIBILITY __STL_NO_MSVC50_COMPATIBILITY
# endif
# if defined (__STL_USE_RAW_SGI_ALLOCATORS) && ! defined ( _STLP_USE_RAW_SGI_ALLOCATORS )
# define _STLP_USE_RAW_SGI_ALLOCATORS __STL_USE_RAW_SGI_ALLOCATORS
# endif
+35
View File
@@ -0,0 +1,35 @@
//==========================================
# define __SGI_STL_PORT _STLPORT_VERSION
# if defined (_STLP_DEBUG) && ! defined ( __STL_DEBUG )
# define __STL_DEBUG _STLP_DEBUG
# endif
# if defined (_STLP_USE_NAMESPACES)
# undef __STL_USE_NAMESPACES
# define __STL_USE_NAMESPACES _STLP_USE_NAMESPACES
# endif
# if defined (_STLP_USE_EXCEPTIONS)
# undef __STL_USE_EXCEPTIONS
# define __STL_USE_EXCEPTIONS _STLP_USE_EXCEPTIONS
# endif
# if defined (_STLP_USE_NEW_IOSTREAMS) && ! defined ( __STL_USE_NEW_IOSTREAMS )
# define __STL_USE_NEW_IOSTREAMS _STLP_USE_NEW_IOSTREAMS
# endif
# if defined (_STLP_BEGIN_NAMESPACE) && ! defined ( __STL_BEGIN_NAMESPACE )
# define __STL_BEGIN_NAMESPACE _STLP_BEGIN_NAMESPACE
# define __STL_END_NAMESPACE _STLP_END_NAMESPACE
# define __STL_VENDOR_STD _STLP_VENDOR_STD
# define __STL_VENDOR_CSTD _STLP_VENDOR_CSTD
# endif
/*
# if defined (_STLP_XXX) && ! defined ( __STL_XXX )
# define __STL_XXX _STLP_XXX
# endif
*/
+167
View File
@@ -0,0 +1,167 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_CONSTRUCT_H
#define _STLP_INTERNAL_CONSTRUCT_H
# if defined (_STLP_DEBUG_UNINITIALIZED) && ! defined (_STLP_CSTRING)
# include <cstring>
# endif
# ifndef _STLP_INTERNAL_NEW_HEADER
# include <stl/_new.h>
# endif
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
template <class _Tp>
inline void __destroy_aux(_Tp* __pointer, const __false_type&) { __pointer->~_Tp(); }
template <class _Tp>
inline void __destroy_aux(_Tp* __pointer, const __true_type&) {}
# endif
template <class _Tp>
inline void _Destroy(_Tp* __pointer) {
# if _MSC_VER >= 1010
__pointer;
# endif // _MSC_VER >= 1000
# ifdef _STLP_TRIVIAL_DESTRUCTOR_BUG
typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
__destroy_aux(__pointer, _Trivial_destructor());
# else
# if ( defined (__BORLANDC__) && ( __BORLANDC__ < 0x500 ) )
__pointer->_Tp::~_Tp();
# else
__pointer->~_Tp();
# endif
# endif
# ifdef _STLP_DEBUG_UNINITIALIZED
memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
# endif
}
# if defined (new)
# define _STLP_NEW_REDEFINE new
# undef new
# endif
# ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
template <class _T1>
inline void _Construct_aux (_T1* __p, const __false_type&) {
_STLP_PLACEMENT_NEW (__p) _T1();
}
template <class _T1>
inline void _Construct_aux (_T1* __p, const __true_type&) {
_STLP_PLACEMENT_NEW (__p) _T1(0);
}
# endif
template <class _T1, class _T2>
inline void _Construct(_T1* __p, const _T2& __val) {
# ifdef _STLP_DEBUG_UNINITIALIZED
memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
# endif
_STLP_PLACEMENT_NEW (__p) _T1(__val);
}
template <class _T1>
inline void _Construct(_T1* __p) {
# ifdef _STLP_DEBUG_UNINITIALIZED
memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
# endif
# ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
typedef typename _Is_integer<_T1>::_Integral _Is_Integral;
_Construct_aux (__p, _Is_Integral() );
# else
_STLP_PLACEMENT_NEW (__p) _T1();
# endif
}
# if defined(_STLP_NEW_REDEFINE)
# ifdef DEBUG_NEW
# define new DEBUG_NEW
# endif
# undef _STLP_NEW_REDEFINE
# endif
template <class _ForwardIterator>
_STLP_INLINE_LOOP void
__destroy_aux(_ForwardIterator __first, _ForwardIterator __last, const __false_type&) {
for ( ; __first != __last; ++__first)
_STLP_STD::_Destroy(&*__first);
}
template <class _ForwardIterator>
inline void __destroy_aux(_ForwardIterator, _ForwardIterator, const __true_type&) {}
template <class _ForwardIterator, class _Tp>
inline void
__destroy(_ForwardIterator __first, _ForwardIterator __last, _Tp*) {
typedef typename __type_traits<_Tp>::has_trivial_destructor _Trivial_destructor;
__destroy_aux(__first, __last, _Trivial_destructor());
}
template <class _ForwardIterator>
inline void _Destroy(_ForwardIterator __first, _ForwardIterator __last) {
__destroy(__first, __last, _STLP_VALUE_TYPE(__first, _ForwardIterator));
}
inline void _Destroy(char*, char*) {}
# ifdef _STLP_HAS_WCHAR_T // dwa 8/15/97
inline void _Destroy(wchar_t*, wchar_t*) {}
inline void _Destroy(const wchar_t*, const wchar_t*) {}
# endif
# ifndef _STLP_NO_ANACHRONISMS
// --------------------------------------------------
// Old names from the HP STL.
template <class _T1, class _T2>
inline void construct(_T1* __p, const _T2& __val) {_Construct(__p, __val); }
template <class _T1>
inline void construct(_T1* __p) { _Construct(__p); }
template <class _Tp>
inline void destroy(_Tp* __pointer) { _STLP_STD::_Destroy(__pointer); }
template <class _ForwardIterator>
inline void destroy(_ForwardIterator __first, _ForwardIterator __last) { _STLP_STD::_Destroy(__first, __last); }
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_CONSTRUCT_H */
// Local Variables:
// mode:C++
// End:
+95
View File
@@ -0,0 +1,95 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
#define _STLP_INTERNAL_CTRAITS_FUNCTIONS_H
# ifndef _STLP_INTERNAL_FUNCTION_H
# include <stl/_function_base.h>
# endif
// This file contains a few small adapters that allow a character
// traits class to be used as a function object.
_STLP_BEGIN_NAMESPACE
template <class _Traits>
struct _Eq_traits
: public binary_function<typename _Traits::char_type,
typename _Traits::char_type,
bool>
{
bool operator()(const typename _Traits::char_type& __x,
const typename _Traits::char_type& __y) const
{ return _Traits::eq(__x, __y); }
};
template <class _Traits>
struct _Eq_char_bound
: public unary_function<typename _Traits::char_type, bool>
{
typename _Traits::char_type __val;
_Eq_char_bound(typename _Traits::char_type __c) : __val(__c) {}
bool operator()(const typename _Traits::char_type& __x) const
{ return _Traits::eq(__x, __val); }
};
template <class _Traits>
struct _Neq_char_bound
: public unary_function<typename _Traits::char_type, bool>
{
typename _Traits::char_type __val;
_Neq_char_bound(typename _Traits::char_type __c) : __val(__c) {}
bool operator()(const typename _Traits::char_type& __x) const
{ return !_Traits::eq(__x, __val); }
};
template <class _Traits>
struct _Eq_int_bound
: public unary_function<typename _Traits::char_type, bool>
{
typename _Traits::int_type __val;
_Eq_int_bound(typename _Traits::int_type __c) : __val(__c) {}
bool operator()(const typename _Traits::char_type& __x) const
{ return _Traits::eq_int_type(_Traits::to_int_type(__x), __val); }
};
# if 0
template <class _Traits>
struct _Lt_traits
: public binary_function<typename _Traits::char_type,
typename _Traits::char_type,
bool>
{
bool operator()(const typename _Traits::char_type& __x,
const typename _Traits::char_type& __y) const
{ return _Traits::lt(__x, __y); }
};
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_CTRAITS_FUNCTIONS_H */
// Local Variables:
// mode:C++
// End:
+269
View File
@@ -0,0 +1,269 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_CTYPE_H
#define _STLP_INTERNAL_CTYPE_H
# ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
# endif
# ifndef _STLP_INTERNAL_LOCALE_H
# include <stl/_locale.h>
# endif
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
_STLP_BEGIN_NAMESPACE
class _STLP_CLASS_DECLSPEC ctype_base {
public:
enum mask {
space = _Locale_SPACE,
print = _Locale_PRINT,
cntrl = _Locale_CNTRL,
upper = _Locale_UPPER,
lower = _Locale_LOWER,
alpha = _Locale_ALPHA,
digit = _Locale_DIGIT,
punct = _Locale_PUNCT,
xdigit = _Locale_XDIGIT,
alnum = alpha | digit,
graph = alnum | punct
};
};
// ctype<> template
template <class charT> class ctype {};
template <class charT> class ctype_byname {};
//ctype specializations
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype<char> : public locale::facet, public ctype_base
{
# ifndef _STLP_NO_WCHAR_T
# ifdef _STLP_MSVC
typedef ctype<wchar_t> _Wctype;
friend _Wctype;
# else
friend class ctype<wchar_t>;
# endif
# endif
friend class _Locale;
public:
typedef char char_type;
explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
bool is(mask __m, char __c) const
{ return ((*(_M_ctype_table+(unsigned char)__c)) & __m) != 0; }
const char* is(const char* __low, const char* __high, mask* __vec) const {
for (const char* __p = __low;__p != __high; ++__p, ++__vec) {
*__vec = _M_ctype_table[(unsigned char)*__p];
}
return __high;
}
const char* scan_is(mask __m, const char* __low, const char* __high) const;
const char* scan_not(mask __m, const char* __low, const char* __high) const;
char (toupper)(char __c) const { return do_toupper(__c); }
const char* (toupper)(char* __low, const char* __high) const {
return do_toupper(__low, __high);
}
char (tolower)(char __c) const { return do_tolower(__c); }
const char* (tolower)(char* __low, const char* __high) const {
return do_tolower(__low, __high);
}
char widen(char __c) const { return do_widen(__c); }
const char* widen(const char* __low, const char* __high, char* __to) const {
return do_widen(__low, __high, __to);
}
char narrow(char __c, char __dfault) const {
return do_narrow(__c, __dfault);
}
const char* narrow(const char* __low, const char* __high,
char __dfault, char* __to) const {
return do_narrow(__low, __high, __dfault, __to);
}
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# if defined(_STLP_STATIC_CONST_INIT_BUG)
enum __TableSize { table_size = 256 };
# else
static const size_t table_size = 256;
# endif
protected:
const mask* table() const _STLP_NOTHROW {return _M_ctype_table;}
static const mask* _STLP_CALL classic_table() _STLP_NOTHROW { return & _S_classic_table [1]; }
~ctype();
virtual char do_toupper(char __c) const;
virtual char do_tolower(char __c) const;
virtual const char* do_toupper(char* __low, const char* __high) const;
virtual const char* do_tolower(char* __low, const char* __high) const;
virtual char do_widen(char __c) const;
virtual const char* do_widen(const char* __low, const char* __high,
char* __to) const;
virtual char do_narrow(char __c, char /* dfault */ ) const;
virtual const char* do_narrow(const char* __low, const char* __high,
char /* dfault */, char* __to) const;
private:
struct _Is_mask {
mask __m;
_Is_mask(mask __x): __m(__x) {}
bool operator()(char __c) {return (__m & (unsigned char) __c) != 0;}
};
static const mask _S_classic_table[257 /* table_size + 1 */];
const mask* _M_ctype_table;
bool _M_delete;
static const unsigned char _S_upper[256 /* table_size */];
static const unsigned char _S_lower[256 /* table_size */];
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype_byname<char>: public ctype<char> {
public:
explicit ctype_byname(const char*, size_t = 0);
~ctype_byname();
virtual char do_toupper(char __c) const;
virtual char do_tolower(char __c) const;
virtual const char* do_toupper(char*, const char*) const;
virtual const char* do_tolower(char*, const char*) const;
private:
mask _M_byname_table[table_size + 1];
_Locale_ctype* _M_ctype;
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype<wchar_t> : public locale::facet, public ctype_base
{
friend class _Locale;
public:
typedef wchar_t char_type;
explicit ctype(size_t __refs = 0) : _BaseFacet(__refs) {}
bool is(mask __m, wchar_t __c) const
{ return do_is(__m, __c); }
const wchar_t* is(const wchar_t* __low, const wchar_t* __high,
mask* __vec) const
{ return do_is(__low, __high, __vec); }
const wchar_t* scan_is(mask __m,
const wchar_t* __low, const wchar_t* __high) const
{ return do_scan_is(__m, __low, __high); }
const wchar_t* scan_not (mask __m,
const wchar_t* __low, const wchar_t* __high) const
{ return do_scan_not(__m, __low, __high); }
wchar_t (toupper)(wchar_t __c) const { return do_toupper(__c); }
const wchar_t* (toupper)(wchar_t* __low, const wchar_t* __high) const
{ return do_toupper(__low, __high); }
wchar_t (tolower)(wchar_t __c) const { return do_tolower(__c); }
const wchar_t* (tolower)(wchar_t* __low, const wchar_t* __high) const
{ return do_tolower(__low, __high); }
wchar_t widen(char __c) const { return do_widen(__c); }
const char* widen(const char* __low, const char* __high,
wchar_t* __to) const
{ return do_widen(__low, __high, __to); }
char narrow(wchar_t __c, char __dfault) const
{ return do_narrow(__c, __dfault); }
const wchar_t* narrow(const wchar_t* __low, const wchar_t* __high,
char __dfault, char* __to) const
{ return do_narrow(__low, __high, __dfault, __to); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~ctype();
virtual bool do_is(mask __m, wchar_t __c) const;
virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
virtual const wchar_t* do_scan_is(mask,
const wchar_t*, const wchar_t*) const;
virtual const wchar_t* do_scan_not(mask,
const wchar_t*, const wchar_t*) const;
virtual wchar_t do_toupper(wchar_t __c) const;
virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
virtual wchar_t do_tolower(wchar_t c) const;
virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
virtual wchar_t do_widen(char c) const;
virtual const char* do_widen(const char*, const char*, wchar_t*) const;
virtual char do_narrow(wchar_t __c, char __dfault) const;
virtual const wchar_t* do_narrow(const wchar_t*, const wchar_t*,
char, char*) const;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>: public ctype<wchar_t> {
public:
explicit ctype_byname(const char* __name, size_t __refs = 0);
protected:
~ctype_byname();
virtual bool do_is(mask __m, wchar_t __c) const;
virtual const wchar_t* do_is(const wchar_t*, const wchar_t*, mask*) const;
virtual const wchar_t* do_scan_is(mask,
const wchar_t*, const wchar_t*) const;
virtual const wchar_t* do_scan_not(mask,
const wchar_t*, const wchar_t*) const;
virtual wchar_t do_toupper(wchar_t __c) const;
virtual const wchar_t* do_toupper(wchar_t*, const wchar_t*) const;
virtual wchar_t do_tolower(wchar_t c) const;
virtual const wchar_t* do_tolower(wchar_t*, const wchar_t*) const;
private:
_Locale_ctype* _M_ctype;
};
# endif /* WCHAR_T */
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_CTYPE_H */
// Local Variables:
// mode:C++
// End:
+112
View File
@@ -0,0 +1,112 @@
/*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_CWCHAR_H
# define _STLP_CWCHAR_H
#ifndef _STLP_NO_WCHAR_T
#ifdef __cplusplus
# include <cwchar>
#else
# include <wchar.h>
#endif
#endif
# if defined (__MRC__) || defined (__SC__) || defined (__BORLANDC__) || defined(__FreeBSD__) || (defined (__GNUC__) && defined (__APPLE__) || defined( __Lynx__ )) || defined (_STLP_NO_WCHAR_T)
# include _STLP_NATIVE_C_HEADER(stddef.h)
# if defined (__FreeBSD__) || defined (__Lynx__)
# ifndef _WINT_T
typedef long int wint_t;
# define _WINT_T
# endif /* _WINT_T */
# endif
# endif
# if defined ( _STLP_OWN_IOSTREAMS ) && defined (_STLP_NO_NATIVE_MBSTATE_T) && ! defined (_STLP_NO_MBSTATE_T) && ! defined (_MBSTATE_T) && ! defined (__mbstate_t_defined)
# define _STLP_USE_OWN_MBSTATE_T
# define _MBSTATE_T
# endif
# ifdef _STLP_USE_OWN_MBSTATE_T
// to be compatible across different SUN platforms
#ifdef __sun
# define __stl_mbstate_t __mbstate_t
#endif
struct __stl_mbstate_t;
# ifdef __cplusplus
struct __stl_mbstate_t {
__stl_mbstate_t( long __st = 0 ) { _M_state[0] = __st ; }
__stl_mbstate_t& operator=(const long __st) {
_M_state[0] = __st;
return *this;
}
__stl_mbstate_t(const __stl_mbstate_t& __x) {_M_state[0]= __x._M_state[0]; }
__stl_mbstate_t& operator=(const __stl_mbstate_t& __x) {
_M_state[0]= __x._M_state[0];
return *this;
}
# if defined (__sun)
# ifdef _LP64
long _M_state[4];
# else
int _M_state[6];
# endif
# else
long _M_state[1];
# endif
};
inline bool operator==(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y) {
return ( __x._M_state[0] == __y._M_state[0] );
}
inline bool operator!=(const __stl_mbstate_t& __x, const __stl_mbstate_t& __y) {
return ( __x._M_state[0] == __y._M_state[0] );
}
# endif
_STLP_BEGIN_NAMESPACE
typedef __stl_mbstate_t mbstate_t;
_STLP_END_NAMESPACE
# endif /* _STLP_USE_OWN_MBSTATE_T */
#if !defined (_STLP_NO_WCHAR_T)
# ifndef WCHAR_MIN
# define WCHAR_MIN 0
// SUNpro has some bugs with casts. wchar_t is size of int there anyway.
# if defined (__SUNPRO_CC) || defined (__DJGPP)
# define WCHAR_MAX (~0)
# else
# define WCHAR_MAX ((wchar_t)~0)
# endif
# endif
#endif
# if defined (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
_STLP_BEGIN_NAMESPACE
using namespace _STLP_VENDOR_CSTD;
_STLP_END_NAMESPACE
#endif /* _STLP_IMPORT_VENDOR_CSTD */
#endif /* _STLP_CWCHAR_H */
+676
View File
@@ -0,0 +1,676 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_DEQUE_C
# define _STLP_DEQUE_C
# ifndef _STLP_INTERNAL_DEQUE_H
# include <stl/_deque.h>
# endif
_STLP_BEGIN_NAMESPACE
// Non-inline member functions from _Deque_base.
template <class _Tp, class _Alloc >
_Deque_base<_Tp,_Alloc >::~_Deque_base() {
if (_M_map._M_data) {
_M_destroy_nodes(_M_start._M_node, this->_M_finish._M_node + 1);
_M_map.deallocate(_M_map._M_data, _M_map_size._M_data);
}
}
template <class _Tp, class _Alloc >
void
_Deque_base<_Tp,_Alloc>::_M_initialize_map(size_t __num_elements)
{
size_t __num_nodes =
__num_elements / this->buffer_size() + 1 ;
_M_map_size._M_data = (max)((size_t) _S_initial_map_size, __num_nodes + 2);
_M_map._M_data = _M_map.allocate(_M_map_size._M_data);
_Tp** __nstart = _M_map._M_data + (_M_map_size._M_data - __num_nodes) / 2;
_Tp** __nfinish = __nstart + __num_nodes;
_STLP_TRY {
_M_create_nodes(__nstart, __nfinish);
}
_STLP_UNWIND((_M_map.deallocate(_M_map._M_data, _M_map_size._M_data),
_M_map._M_data = 0, _M_map_size._M_data = 0));
_M_start._M_set_node(__nstart);
this->_M_finish._M_set_node(__nfinish - 1);
_M_start._M_cur = _M_start._M_first;
this->_M_finish._M_cur = this->_M_finish._M_first +
__num_elements % this->buffer_size();
}
template <class _Tp, class _Alloc >
void
_Deque_base<_Tp,_Alloc>::_M_create_nodes(_Tp** __nstart,
_Tp** __nfinish)
{
_Tp** __cur;
_STLP_TRY {
for (__cur = __nstart; __cur < __nfinish; ++__cur)
*__cur = _M_map_size.allocate(this->buffer_size());
}
_STLP_UNWIND(_M_destroy_nodes(__nstart, __cur));
}
template <class _Tp, class _Alloc >
void
_Deque_base<_Tp,_Alloc>::_M_destroy_nodes(_Tp** __nstart,
_Tp** __nfinish)
{
for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
_M_map_size.deallocate(*__n, this->buffer_size());
}
// Non-inline member functions
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
// qualified references
# define __iterator__ _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >
# define const_iterator _Deque_iterator<_Tp, _Const_traits<_Tp> >
# define iterator __iterator__
# define size_type size_t
# define value_type _Tp
# else
# define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE __deque__<_Tp, _Alloc>::iterator
# endif
template <class _Tp, class _Alloc >
__deque__<_Tp, _Alloc >&
__deque__<_Tp, _Alloc >::operator= (const __deque__<_Tp, _Alloc >& __x) {
const size_type __len = size();
if (&__x != this) {
if (__len >= __x.size())
erase(_STLP_STD::copy(__x.begin(), __x.end(), this->_M_start), this->_M_finish);
else {
const_iterator __mid = __x.begin() + difference_type(__len);
_STLP_STD::copy(__x.begin(), __mid, this->_M_start);
insert(this->_M_finish, __mid, __x.end());
}
}
return *this;
}
template <class _Tp, class _Alloc >
void
__deque__<_Tp, _Alloc >::_M_fill_insert(iterator __pos,
size_type __n, const value_type& __x)
{
if (__pos._M_cur == this->_M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
_STLP_TRY {
uninitialized_fill(__new_start, this->_M_start, __x);
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
this->_M_start = __new_start;
}
else if (__pos._M_cur == this->_M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
_STLP_TRY {
uninitialized_fill(this->_M_finish, __new_finish, __x);
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node+1, __new_finish._M_node+1));
this->_M_finish = __new_finish;
}
else
_M_insert_aux(__pos, __n, __x);
}
#ifndef _STLP_MEMBER_TEMPLATES
template <class _Tp, class _Alloc >
void __deque__<_Tp, _Alloc>::insert(iterator __pos,
const value_type* __first,
const value_type* __last) {
size_type __n = __last - __first;
if (__pos._M_cur == this->_M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, __new_start);
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
this->_M_start = __new_start;
}
else if (__pos._M_cur == this->_M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, this->_M_finish);
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1,
__new_finish._M_node + 1));
this->_M_finish = __new_finish;
}
else
_M_insert_aux(__pos, __first, __last, __n);
}
template <class _Tp, class _Alloc >
void __deque__<_Tp,_Alloc>::insert(iterator __pos,
const_iterator __first,
const_iterator __last)
{
size_type __n = __last - __first;
if (__pos._M_cur == this->_M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, __new_start);
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
this->_M_start = __new_start;
}
else if (__pos._M_cur == this->_M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
_STLP_TRY {
uninitialized_copy(__first, __last, this->_M_finish);
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1,__new_finish._M_node + 1));
this->_M_finish = __new_finish;
}
else
_M_insert_aux(__pos, __first, __last, __n);
}
#endif /* _STLP_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc >
__iterator__
__deque__<_Tp,_Alloc>::erase(iterator __first, iterator __last)
{
if (__first == this->_M_start && __last == this->_M_finish) {
clear();
return this->_M_finish;
}
else {
difference_type __n = __last - __first;
difference_type __elems_before = __first - this->_M_start;
if (__elems_before < difference_type(this->size() - __n) / 2) {
_STLP_STD::copy_backward(this->_M_start, __first, __last);
iterator __new_start = this->_M_start + __n;
_STLP_STD::_Destroy(this->_M_start, __new_start);
this->_M_destroy_nodes(this->_M_start._M_node, __new_start._M_node);
this->_M_start = __new_start;
}
else {
_STLP_STD::copy(__last, this->_M_finish, __first);
iterator __new_finish = this->_M_finish - __n;
_STLP_STD::_Destroy(__new_finish, this->_M_finish);
this->_M_destroy_nodes(__new_finish._M_node + 1, this->_M_finish._M_node + 1);
this->_M_finish = __new_finish;
}
return this->_M_start + __elems_before;
}
}
template <class _Tp, class _Alloc >
void __deque__<_Tp,_Alloc>::clear()
{
for (_Map_pointer __node = this->_M_start._M_node + 1;
__node < this->_M_finish._M_node;
++__node) {
_STLP_STD::_Destroy(*__node, *__node + this->buffer_size());
this->_M_map_size.deallocate(*__node, this->buffer_size());
}
if (this->_M_start._M_node != this->_M_finish._M_node) {
_STLP_STD::_Destroy(this->_M_start._M_cur, this->_M_start._M_last);
_STLP_STD::_Destroy(this->_M_finish._M_first, this->_M_finish._M_cur);
this->_M_map_size.deallocate(this->_M_finish._M_first, this->buffer_size());
}
else
_STLP_STD::_Destroy(this->_M_start._M_cur, this->_M_finish._M_cur);
this->_M_finish = this->_M_start;
}
// Precondition: this->_M_start and this->_M_finish have already been initialized,
// but none of the deque's elements have yet been constructed.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_fill_initialize(const value_type& __val) {
_Map_pointer __cur;
_STLP_TRY {
for (__cur = this->_M_start._M_node; __cur < this->_M_finish._M_node; ++__cur)
uninitialized_fill(*__cur, *__cur + this->buffer_size(), __val);
uninitialized_fill(this->_M_finish._M_first, this->_M_finish._M_cur, __val);
}
_STLP_UNWIND(_STLP_STD::_Destroy(this->_M_start, iterator(*__cur, __cur)));
}
// Called only if this->_M_finish._M_cur == this->_M_finish._M_last - 1.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_push_back_aux_v(const value_type& __t)
{
value_type __t_copy = __t;
_M_reserve_map_at_back();
*(this->_M_finish._M_node + 1) = this->_M_map_size.allocate(this->buffer_size());
_STLP_TRY {
_STLP_STD::_Construct(this->_M_finish._M_cur, __t_copy);
this->_M_finish._M_set_node(this->_M_finish._M_node + 1);
this->_M_finish._M_cur = this->_M_finish._M_first;
}
_STLP_UNWIND(this->_M_map_size.deallocate(*(this->_M_finish._M_node + 1),
this->buffer_size()));
}
# ifndef _STLP_NO_ANACHRONISMS
// Called only if this->_M_finish._M_cur == this->_M_finish._M_last - 1.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_push_back_aux()
{
_M_reserve_map_at_back();
*(this->_M_finish._M_node + 1) = this->_M_map_size.allocate(this->buffer_size());
_STLP_TRY {
_STLP_STD::_Construct(this->_M_finish._M_cur);
this->_M_finish._M_set_node(this->_M_finish._M_node + 1);
this->_M_finish._M_cur = this->_M_finish._M_first;
}
_STLP_UNWIND(this->_M_map_size.deallocate(*(this->_M_finish._M_node + 1),
this->buffer_size()));
}
# endif
// Called only if this->_M_start._M_cur == this->_M_start._M_first.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_push_front_aux_v(const value_type& __t)
{
value_type __t_copy = __t;
_M_reserve_map_at_front();
*(this->_M_start._M_node - 1) = this->_M_map_size.allocate(this->buffer_size());
_STLP_TRY {
this->_M_start._M_set_node(this->_M_start._M_node - 1);
this->_M_start._M_cur = this->_M_start._M_last - 1;
_STLP_STD::_Construct(this->_M_start._M_cur, __t_copy);
}
_STLP_UNWIND((++this->_M_start,
this->_M_map_size.deallocate(*(this->_M_start._M_node - 1), this->buffer_size())));
}
# ifndef _STLP_NO_ANACHRONISMS
// Called only if this->_M_start._M_cur == this->_M_start._M_first.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_push_front_aux()
{
_M_reserve_map_at_front();
*(this->_M_start._M_node - 1) = this->_M_map_size.allocate(this->buffer_size());
_STLP_TRY {
this->_M_start._M_set_node(this->_M_start._M_node - 1);
this->_M_start._M_cur = this->_M_start._M_last - 1;
_STLP_STD::_Construct(this->_M_start._M_cur);
}
_STLP_UNWIND((++this->_M_start, this->_M_map_size.deallocate(*(this->_M_start._M_node - 1),
this->buffer_size() )));
}
# endif
// Called only if this->_M_finish._M_cur == this->_M_finish._M_first.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_pop_back_aux()
{
this->_M_map_size.deallocate(this->_M_finish._M_first, this->buffer_size());
this->_M_finish._M_set_node(this->_M_finish._M_node - 1);
this->_M_finish._M_cur = this->_M_finish._M_last - 1;
_STLP_STD::_Destroy(this->_M_finish._M_cur);
}
// Called only if this->_M_start._M_cur == this->_M_start._M_last - 1. Note that
// if the deque has at least one element (a precondition for this member
// function), and if this->_M_start._M_cur == this->_M_start._M_last, then the deque
// must have at least two nodes.
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_pop_front_aux()
{
_STLP_STD::_Destroy(this->_M_start._M_cur);
this->_M_map_size.deallocate(this->_M_start._M_first, this->buffer_size());
this->_M_start._M_set_node(this->_M_start._M_node + 1);
this->_M_start._M_cur = this->_M_start._M_first;
}
template <class _Tp, class _Alloc >
__iterator__
__deque__<_Tp,_Alloc>::_M_insert_aux_prepare(iterator __pos) {
difference_type __index = __pos - this->_M_start;
if (__index < difference_type(size() / 2)) {
push_front(front());
iterator __front1 = this->_M_start;
++__front1;
iterator __front2 = __front1;
++__front2;
__pos = this->_M_start + __index;
iterator __pos1 = __pos;
++__pos1;
copy(__front2, __pos1, __front1);
}
else {
push_back(back());
iterator __back1 = this->_M_finish;
--__back1;
iterator __back2 = __back1;
--__back2;
__pos = this->_M_start + __index;
copy_backward(__pos, __back2, __back1);
}
return __pos;
}
template <class _Tp, class _Alloc >
__iterator__
__deque__<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
const value_type& __x) {
value_type __x_copy = __x;
_STLP_MPWFIX_TRY //*TY 06/01/2000 - mpw forget to call dtor on __x_copy without this try block
__pos = _M_insert_aux_prepare(__pos);
*__pos = __x_copy;
return __pos;
_STLP_MPWFIX_CATCH //*TY 06/01/2000 -
}
template <class _Tp, class _Alloc >
__iterator__
__deque__<_Tp,_Alloc>::_M_insert_aux(iterator __pos)
{
__pos = _M_insert_aux_prepare(__pos);
*__pos = value_type();
return __pos;
}
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
size_type __n,
const value_type& __x)
{
const difference_type __elems_before = __pos - this->_M_start;
size_type __length = this->size();
value_type __x_copy = __x;
if (__elems_before < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start;
__pos = this->_M_start + __elems_before;
_STLP_TRY {
if (__elems_before >= difference_type(__n)) {
iterator __start_n = this->_M_start + difference_type(__n);
uninitialized_copy(this->_M_start, __start_n, __new_start);
this->_M_start = __new_start;
copy(__start_n, __pos, __old_start);
fill(__pos - difference_type(__n), __pos, __x_copy);
}
else {
__uninitialized_copy_fill(this->_M_start, __pos, __new_start,
this->_M_start, __x_copy);
this->_M_start = __new_start;
fill(__old_start, __pos, __x_copy);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish;
const difference_type __elems_after =
difference_type(__length) - __elems_before;
__pos = this->_M_finish - __elems_after;
_STLP_TRY {
if (__elems_after > difference_type(__n)) {
iterator __finish_n = this->_M_finish - difference_type(__n);
uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
this->_M_finish = __new_finish;
copy_backward(__pos, __finish_n, __old_finish);
fill(__pos, __pos + difference_type(__n), __x_copy);
}
else {
__uninitialized_fill_copy(this->_M_finish, __pos + difference_type(__n),
__x_copy, __pos, this->_M_finish);
this->_M_finish = __new_finish;
fill(__pos, __old_finish, __x_copy);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
}
#ifndef _STLP_MEMBER_TEMPLATES
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
const value_type* __first,
const value_type* __last,
size_type __n)
{
const difference_type __elemsbefore = __pos - this->_M_start;
size_type __length = size();
if (__elemsbefore < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start;
__pos = this->_M_start + __elemsbefore;
_STLP_TRY {
if (__elemsbefore >= difference_type(__n)) {
iterator __start_n = this->_M_start + difference_type(__n);
uninitialized_copy(this->_M_start, __start_n, __new_start);
this->_M_start = __new_start;
copy(__start_n, __pos, __old_start);
copy(__first, __last, __pos - difference_type(__n));
}
else {
const value_type* __mid =
__first + (difference_type(__n) - __elemsbefore);
__uninitialized_copy_copy(this->_M_start, __pos, __first, __mid,
__new_start, _IsPODType());
this->_M_start = __new_start;
copy(__mid, __last, __old_start);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish;
const difference_type __elemsafter =
difference_type(__length) - __elemsbefore;
__pos = this->_M_finish - __elemsafter;
_STLP_TRY {
if (__elemsafter > difference_type(__n)) {
iterator __finish_n = this->_M_finish - difference_type(__n);
uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
this->_M_finish = __new_finish;
copy_backward(__pos, __finish_n, __old_finish);
copy(__first, __last, __pos);
}
else {
const value_type* __mid = __first + __elemsafter;
__uninitialized_copy_copy(__mid, __last, __pos, this->_M_finish, this->_M_finish, _IsPODType());
this->_M_finish = __new_finish;
copy(__first, __mid, __pos);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
}
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_insert_aux(iterator __pos,
const_iterator __first,
const_iterator __last,
size_type __n)
{
const difference_type __elemsbefore = __pos - this->_M_start;
size_type __length = size();
if (__elemsbefore < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start;
__pos = this->_M_start + __elemsbefore;
_STLP_TRY {
if (__elemsbefore >= difference_type(__n)) {
iterator __start_n = this->_M_start + __n;
uninitialized_copy(this->_M_start, __start_n, __new_start);
this->_M_start = __new_start;
copy(__start_n, __pos, __old_start);
copy(__first, __last, __pos - difference_type(__n));
}
else {
const_iterator __mid = __first + (__n - __elemsbefore);
__uninitialized_copy_copy(this->_M_start, __pos, __first, __mid,
__new_start, _IsPODType());
this->_M_start = __new_start;
copy(__mid, __last, __old_start);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish;
const difference_type __elemsafter = __length - __elemsbefore;
__pos = this->_M_finish - __elemsafter;
_STLP_TRY {
if (__elemsafter > difference_type(__n)) {
iterator __finish_n = this->_M_finish - difference_type(__n);
uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
this->_M_finish = __new_finish;
copy_backward(__pos, __finish_n, __old_finish);
copy(__first, __last, __pos);
}
else {
const_iterator __mid = __first + __elemsafter;
__uninitialized_copy_copy(__mid, __last, __pos, this->_M_finish, this->_M_finish, _IsPODType());
this->_M_finish = __new_finish;
copy(__first, __mid, __pos);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_new_elements_at_front(size_type __new_elems)
{
size_type __new_nodes
= (__new_elems + this->buffer_size() - 1) / this->buffer_size();
_M_reserve_map_at_front(__new_nodes);
size_type __i =1;
_STLP_TRY {
for (; __i <= __new_nodes; ++__i)
*(this->_M_start._M_node - __i) = this->_M_map_size.allocate(this->buffer_size());
}
# ifdef _STLP_USE_EXCEPTIONS
catch(...) {
for (size_type __j = 1; __j < __i; ++__j)
this->_M_map_size.deallocate(*(this->_M_start._M_node - __j), this->buffer_size());
throw;
}
# endif /* _STLP_USE_EXCEPTIONS */
}
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_new_elements_at_back(size_type __new_elems)
{
size_type __new_nodes
= (__new_elems + this->buffer_size() - 1) / this->buffer_size();
_M_reserve_map_at_back(__new_nodes);
size_type __i = 1;
_STLP_TRY {
for (; __i <= __new_nodes; ++__i)
*(this->_M_finish._M_node + __i) = this->_M_map_size.allocate(this->buffer_size());
}
# ifdef _STLP_USE_EXCEPTIONS
catch(...) {
for (size_type __j = 1; __j < __i; ++__j)
this->_M_map_size.deallocate(*(this->_M_finish._M_node + __j), this->buffer_size());
throw;
}
# endif /* _STLP_USE_EXCEPTIONS */
}
template <class _Tp, class _Alloc >
void
__deque__<_Tp,_Alloc>::_M_reallocate_map(size_type __nodes_to_add,
bool __add_at_front)
{
size_type __old_num_nodes = this->_M_finish._M_node - this->_M_start._M_node + 1;
size_type __new_num_nodes = __old_num_nodes + __nodes_to_add;
_Map_pointer __new_nstart;
if (this->_M_map_size._M_data > 2 * __new_num_nodes) {
__new_nstart = this->_M_map._M_data + (this->_M_map_size._M_data - __new_num_nodes) / 2
+ (__add_at_front ? __nodes_to_add : 0);
if (__new_nstart < this->_M_start._M_node)
_STLP_STD::copy(this->_M_start._M_node, this->_M_finish._M_node + 1, __new_nstart);
else
_STLP_STD::copy_backward(this->_M_start._M_node, this->_M_finish._M_node + 1,
__new_nstart + __old_num_nodes);
}
else {
size_type __new_map_size =
this->_M_map_size._M_data + (max)((size_t)this->_M_map_size._M_data, __nodes_to_add) + 2;
_Map_pointer __new_map = this->_M_map.allocate(__new_map_size);
__new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
+ (__add_at_front ? __nodes_to_add : 0);
_STLP_STD::copy(this->_M_start._M_node, this->_M_finish._M_node + 1, __new_nstart);
this->_M_map.deallocate(this->_M_map._M_data, this->_M_map_size._M_data);
this->_M_map._M_data = __new_map;
this->_M_map_size._M_data = __new_map_size;
}
this->_M_start._M_set_node(__new_nstart);
this->_M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
}
_STLP_END_NAMESPACE
# undef __iterator__
# undef iterator
# undef const_iterator
# undef size_type
# undef value_type
#endif /* _STLP_DEQUE_C */
// Local Variables:
// mode:C++
// End:
+953
View File
@@ -0,0 +1,953 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_DEQUE_H
#define _STLP_INTERNAL_DEQUE_H
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_INTERNAL_ALLOC_H
# include <stl/_alloc.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_UNINITIALIZED_H
# include <stl/_uninitialized.h>
# endif
# ifndef _STLP_RANGE_ERRORS_H
# include <stl/_range_errors.h>
# endif
/* Class invariants:
* For any nonsingular iterator i:
* i.node is the address of an element in the map array. The
* contents of i.node is a pointer to the beginning of a node.
* i.first == *(i.node)
* i.last == i.first + node_size
* i.cur is a pointer in the range [i.first, i.last). NOTE:
* the implication of this is that i.cur is always a dereferenceable
* pointer, even if i is a past-the-end iterator.
* Start and Finish are always nonsingular iterators. NOTE: this means
* that an empty deque must have one node, and that a deque
* with N elements, where N is the buffer size, must have two nodes.
* For every node other than start.node and finish.node, every element
* in the node is an initialized object. If start.node == finish.node,
* then [start.cur, finish.cur) are initialized objects, and
* the elements outside that range are uninitialized storage. Otherwise,
* [start.cur, start.last) and [finish.first, finish.cur) are initialized
* objects, and [start.first, start.cur) and [finish.cur, finish.last)
* are uninitialized storage.
* [map, map + map_size) is a valid, non-empty range.
* [start.node, finish.node] is a valid range contained within
* [map, map + map_size).
* A pointer in the range [map, map + map_size) points to an allocated node
* if and only if the pointer is in the range [start.node, finish.node].
*/
# undef deque
# define deque __WORKAROUND_DBG_RENAME(deque)
_STLP_BEGIN_NAMESPACE
template <class _Tp>
struct _Deque_iterator_base {
enum _Constants {
_blocksize = _MAX_BYTES,
__buffer_size = (sizeof(_Tp) < (size_t)_blocksize ?
( (size_t)_blocksize / sizeof(_Tp)) : size_t(1))
};
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef value_type** _Map_pointer;
typedef _Deque_iterator_base< _Tp > _Self;
value_type* _M_cur;
value_type* _M_first;
value_type* _M_last;
_Map_pointer _M_node;
_Deque_iterator_base(value_type* __x, _Map_pointer __y)
: _M_cur(__x), _M_first(*__y),
_M_last(*__y + __buffer_size), _M_node(__y) {}
_Deque_iterator_base() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
difference_type _M_subtract(const _Self& __x) const {
return difference_type(__buffer_size) * (_M_node - __x._M_node - 1) +
(_M_cur - _M_first) + (__x._M_last - __x._M_cur);
}
void _M_increment() {
if (++_M_cur == _M_last) {
_M_set_node(_M_node + 1);
_M_cur = _M_first;
}
}
void _M_decrement() {
if (_M_cur == _M_first) {
_M_set_node(_M_node - 1);
_M_cur = _M_last;
}
--_M_cur;
}
void _M_advance(difference_type __n)
{
difference_type __offset = __n + (_M_cur - _M_first);
if (__offset >= 0 && __offset < difference_type(__buffer_size))
_M_cur += __n;
else {
difference_type __node_offset =
__offset > 0 ? __offset / __buffer_size
: -difference_type((-__offset - 1) / __buffer_size) - 1;
_M_set_node(_M_node + __node_offset);
_M_cur = _M_first +
(__offset - __node_offset * difference_type(__buffer_size));
}
}
void _M_set_node(_Map_pointer __new_node) {
_M_last = (_M_first = *(_M_node = __new_node)) + difference_type(__buffer_size);
}
};
template <class _Tp, class _Traits>
struct _Deque_iterator : public _Deque_iterator_base< _Tp> {
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef typename _Traits::reference reference;
typedef typename _Traits::pointer pointer;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef value_type** _Map_pointer;
typedef _Deque_iterator_base< _Tp > _Base;
typedef _Deque_iterator<_Tp, _Traits> _Self;
typedef _Deque_iterator<_Tp, _Nonconst_traits<_Tp> > _Nonconst_self;
typedef _Deque_iterator<_Tp, _Const_traits<_Tp> > _Const_self;
_Deque_iterator(value_type* __x, _Map_pointer __y) :
_Deque_iterator_base<value_type>(__x,__y) {}
_Deque_iterator() {}
_Deque_iterator(const _Nonconst_self& __x) :
_Deque_iterator_base<value_type>(__x) {}
reference operator*() const {
return *this->_M_cur;
}
_STLP_DEFINE_ARROW_OPERATOR
difference_type operator-(const _Self& __x) const { return this->_M_subtract(__x); }
_Self& operator++() { this->_M_increment(); return *this; }
_Self operator++(int) {
_Self __tmp = *this;
++*this;
return __tmp;
}
_Self& operator--() { this->_M_decrement(); return *this; }
_Self operator--(int) {
_Self __tmp = *this;
--*this;
return __tmp;
}
_Self& operator+=(difference_type __n) { this->_M_advance(__n); return *this; }
_Self operator+(difference_type __n) const
{
_Self __tmp = *this;
return __tmp += __n;
}
_Self& operator-=(difference_type __n) { return *this += -__n; }
_Self operator-(difference_type __n) const {
_Self __tmp = *this;
return __tmp -= __n;
}
reference operator[](difference_type __n) const { return *(*this + __n); }
};
template <class _Tp, class _Traits>
inline _Deque_iterator<_Tp, _Traits> _STLP_CALL
operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Traits>& __x)
{
return __x + __n;
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Tp>
inline bool _STLP_CALL
operator==(const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return __x._M_cur == __y._M_cur;
}
template <class _Tp>
inline bool _STLP_CALL
operator < (const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return (__x._M_node == __y._M_node) ?
(__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
}
template <class _Tp>
inline bool _STLP_CALL
operator!=(const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return __x._M_cur != __y._M_cur;
}
template <class _Tp>
inline bool _STLP_CALL
operator>(const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return __y < __x;
}
template <class _Tp>
inline bool _STLP_CALL operator>=(const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return !(__x < __y);
}
template <class _Tp>
inline bool _STLP_CALL operator<=(const _Deque_iterator_base<_Tp >& __x,
const _Deque_iterator_base<_Tp >& __y) {
return !(__y < __x);
}
# else
template <class _Tp, class _Traits1, class _Traits2>
inline bool _STLP_CALL
operator==(const _Deque_iterator<_Tp, _Traits1 >& __x,
const _Deque_iterator<_Tp, _Traits2 >& __y) {
return __x._M_cur == __y._M_cur;
}
template <class _Tp, class _Traits1, class _Traits2>
inline bool _STLP_CALL
operator < (const _Deque_iterator<_Tp, _Traits1 >& __x,
const _Deque_iterator<_Tp, _Traits2 >& __y) {
return (__x._M_node == __y._M_node) ?
(__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
}
template <class _Tp>
inline bool _STLP_CALL
operator!=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y) {
return __x._M_cur != __y._M_cur;
}
template <class _Tp>
inline bool _STLP_CALL
operator>(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y) {
return __y < __x;
}
template <class _Tp>
inline bool _STLP_CALL
operator>=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y) {
return !(__x < __y);
}
template <class _Tp>
inline bool _STLP_CALL
operator<=(const _Deque_iterator<_Tp, _Nonconst_traits<_Tp> >& __x,
const _Deque_iterator<_Tp, _Const_traits<_Tp> >& __y) {
return !(__y < __x);
}
# endif
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Tp, class _Traits> inline _Tp* _STLP_CALL value_type(const _Deque_iterator<_Tp, _Traits >&) { return (_Tp*)0; }
template <class _Tp, class _Traits> inline random_access_iterator_tag _STLP_CALL
iterator_category(const _Deque_iterator<_Tp, _Traits >&) { return random_access_iterator_tag(); }
template <class _Tp, class _Traits> inline ptrdiff_t* _STLP_CALL
distance_type(const _Deque_iterator<_Tp, _Traits >&) { return 0; }
#endif
// Deque base class. It has two purposes. First, its constructor
// and destructor allocate (but don't initialize) storage. This makes
// exception safety easier. Second, the base class encapsulates all of
// the differences between SGI-style allocators and standard-conforming
// allocators.
template <class _Tp, class _Alloc>
class _Deque_base {
public:
typedef _Tp value_type;
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
typedef typename _Alloc_traits<_Tp*, _Alloc>::allocator_type _Map_alloc_type;
typedef _Deque_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
typedef _Deque_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
static size_t _STLP_CALL buffer_size() { return (size_t)_Deque_iterator_base<_Tp>::__buffer_size; }
_Deque_base(const allocator_type& __a, size_t __num_elements)
: _M_start(), _M_finish(), _M_map(_STLP_CONVERT_ALLOCATOR(__a, _Tp*), 0),
_M_map_size(__a, (size_t)0) {
_M_initialize_map(__num_elements);
}
_Deque_base(const allocator_type& __a)
: _M_start(), _M_finish(), _M_map(_STLP_CONVERT_ALLOCATOR(__a, _Tp*), 0),
_M_map_size(__a, (size_t)0) {
}
~_Deque_base();
protected:
void _M_initialize_map(size_t);
void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
enum { _S_initial_map_size = 8 };
protected:
iterator _M_start;
iterator _M_finish;
_STLP_alloc_proxy<value_type**, value_type*, _Map_alloc_type> _M_map;
_STLP_alloc_proxy<size_t, value_type, allocator_type> _M_map_size;
};
template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
class deque : protected _Deque_base<_Tp, _Alloc> {
typedef _Deque_base<_Tp, _Alloc> _Base;
typedef deque<_Tp, _Alloc> _Self;
public: // Basic types
typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef random_access_iterator_tag _Iterator_category;
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Base::allocator_type allocator_type;
public: // Iterators
typedef typename _Base::iterator iterator;
typedef typename _Base::const_iterator const_iterator;
_STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
protected: // Internal typedefs
typedef pointer* _Map_pointer;
typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _TrivialAss;
typedef typename __type_traits<_Tp>::has_trivial_assignment_operator _IsPODType;
public: // Basic accessors
iterator begin() { return this->_M_start; }
iterator end() { return this->_M_finish; }
const_iterator begin() const { return const_iterator(this->_M_start); }
const_iterator end() const { return const_iterator(this->_M_finish); }
reverse_iterator rbegin() { return reverse_iterator(this->_M_finish); }
reverse_iterator rend() { return reverse_iterator(this->_M_start); }
const_reverse_iterator rbegin() const
{ return const_reverse_iterator(this->_M_finish); }
const_reverse_iterator rend() const
{ return const_reverse_iterator(this->_M_start); }
reference operator[](size_type __n)
{ return this->_M_start[difference_type(__n)]; }
const_reference operator[](size_type __n) const
{ return this->_M_start[difference_type(__n)]; }
void _M_range_check(size_type __n) const {
if (__n >= this->size())
__stl_throw_out_of_range("deque");
}
reference at(size_type __n)
{ _M_range_check(__n); return (*this)[__n]; }
const_reference at(size_type __n) const
{ _M_range_check(__n); return (*this)[__n]; }
reference front() { return *this->_M_start; }
reference back() {
iterator __tmp = this->_M_finish;
--__tmp;
return *__tmp;
}
const_reference front() const { return *this->_M_start; }
const_reference back() const {
const_iterator __tmp = this->_M_finish;
--__tmp;
return *__tmp;
}
size_type size() const { return this->_M_finish - this->_M_start; }
size_type max_size() const { return size_type(-1); }
bool empty() const { return this->_M_finish == this->_M_start; }
allocator_type get_allocator() const { return this->_M_map_size; }
public: // Constructor, destructor.
explicit deque(const allocator_type& __a = allocator_type())
: _Deque_base<_Tp, _Alloc>(__a, 0) {}
deque(const _Self& __x) :
_Deque_base<_Tp, _Alloc>(__x.get_allocator(), __x.size()) {
__uninitialized_copy(__x.begin(), __x.end(), this->_M_start, _IsPODType());
}
deque(size_type __n, const value_type& __val,
const allocator_type& __a = allocator_type()) :
_Deque_base<_Tp, _Alloc>(__a, __n)
{ _M_fill_initialize(__val); }
// int,long variants may be needed
explicit deque(size_type __n) : _Deque_base<_Tp, _Alloc>(allocator_type(), __n)
{ _M_fill_initialize(value_type()); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _Integer>
void _M_initialize_dispatch(_Integer __n, _Integer __x, const __true_type&) {
this->_M_initialize_map(__n);
_M_fill_initialize(__x);
}
template <class _InputIter>
void _M_initialize_dispatch(_InputIter __first, _InputIter __last,
const __false_type&) {
_M_range_initialize(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIter));
}
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
// VC++ needs this
template <class _InputIterator>
deque(_InputIterator __first, _InputIterator __last) :
_Deque_base<_Tp, _Alloc>(allocator_type()) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
# endif
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
deque(_InputIterator __first, _InputIterator __last,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) :
_Deque_base<_Tp, _Alloc>(__a) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
# else
deque(const value_type* __first, const value_type* __last,
const allocator_type& __a = allocator_type() )
: _Deque_base<_Tp, _Alloc>(__a, __last - __first) {
__uninitialized_copy(__first, __last, this->_M_start, _IsPODType());
}
deque(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type() )
: _Deque_base<_Tp, _Alloc>(__a, __last - __first) {
__uninitialized_copy(__first, __last, this->_M_start, _IsPODType());
}
#endif /* _STLP_MEMBER_TEMPLATES */
~deque() {
_STLP_STD::_Destroy(this->_M_start, this->_M_finish);
}
_Self& operator= (const _Self& __x);
void swap(_Self& __x) {
_STLP_STD::swap(this->_M_start, __x._M_start);
_STLP_STD::swap(this->_M_finish, __x._M_finish);
_STLP_STD::swap(this->_M_map, __x._M_map);
_STLP_STD::swap(this->_M_map_size, __x._M_map_size);
}
public:
// assign(), a generalized assignment member function. Two
// versions: one that takes a count, and one that takes a range.
// The range version is a member template, so we dispatch on whether
// or not the type is an integer.
void _M_fill_assign(size_type __n, const _Tp& __val) {
if (__n > size()) {
_STLP_STD::fill(begin(), end(), __val);
insert(end(), __n - size(), __val);
}
else {
erase(begin() + __n, end());
_STLP_STD::fill(begin(), end(), __val);
}
}
void assign(size_type __n, const _Tp& __val) {
_M_fill_assign(__n, __val);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
private: // helper functions for assign()
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
{ _M_fill_assign((size_type) __n, (_Tp) __val); }
template <class _InputIterator>
void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
const __false_type&) {
_M_assign_aux(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
template <class _InputIter>
void _M_assign_aux(_InputIter __first, _InputIter __last, const input_iterator_tag &) {
iterator __cur = begin();
for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
*__cur = *__first;
if (__first == __last)
erase(__cur, end());
else
insert(end(), __first, __last);
}
template <class _ForwardIterator>
void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
const forward_iterator_tag &) {
size_type __len = _STLP_STD::distance(__first, __last);
if (__len > size()) {
_ForwardIterator __mid = __first;
_STLP_STD::advance(__mid, size());
_STLP_STD::copy(__first, __mid, begin());
insert(end(), __mid, __last);
}
else
erase(copy(__first, __last, begin()), end());
}
#endif /* _STLP_MEMBER_TEMPLATES */
public: // push_* and pop_*
void push_back(const value_type& __t) {
if (this->_M_finish._M_cur != this->_M_finish._M_last - 1) {
_STLP_STD::_Construct(this->_M_finish._M_cur, __t);
++this->_M_finish._M_cur;
}
else
_M_push_back_aux_v(__t);
}
void push_front(const value_type& __t) {
if (this->_M_start._M_cur != this->_M_start._M_first) {
_STLP_STD::_Construct(this->_M_start._M_cur - 1, __t);
--this->_M_start._M_cur;
}
else
_M_push_front_aux_v(__t);
}
# ifndef _STLP_NO_ANACHRONISMS
void push_back() {
if (this->_M_finish._M_cur != this->_M_finish._M_last - 1) {
_STLP_STD::_Construct(this->_M_finish._M_cur);
++this->_M_finish._M_cur;
}
else
_M_push_back_aux();
}
void push_front() {
if (this->_M_start._M_cur != this->_M_start._M_first) {
_STLP_STD::_Construct(this->_M_start._M_cur - 1);
--this->_M_start._M_cur;
}
else
_M_push_front_aux();
}
# endif
void pop_back() {
if (this->_M_finish._M_cur != this->_M_finish._M_first) {
--this->_M_finish._M_cur;
_STLP_STD::_Destroy(this->_M_finish._M_cur);
}
else
_M_pop_back_aux();
}
void pop_front() {
if (this->_M_start._M_cur != this->_M_start._M_last - 1) {
_STLP_STD::_Destroy(this->_M_start._M_cur);
++this->_M_start._M_cur;
}
else
_M_pop_front_aux();
}
public: // Insert
iterator insert(iterator __position, const value_type& __x) {
if (__position._M_cur == this->_M_start._M_cur) {
push_front(__x);
return this->_M_start;
}
else if (__position._M_cur == this->_M_finish._M_cur) {
push_back(__x);
iterator __tmp = this->_M_finish;
--__tmp;
return __tmp;
}
else {
return _M_insert_aux(__position, __x);
}
}
iterator insert(iterator __position)
{ return insert(__position, value_type()); }
void insert(iterator __pos, size_type __n, const value_type& __x) {
_M_fill_insert(__pos, __n, __x);
}
void _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
#ifdef _STLP_MEMBER_TEMPLATES
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InputIterator>
void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
template <class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
const __true_type&) {
_M_fill_insert(__pos, (size_type) __n, (value_type) __x);
}
template <class _InputIterator>
void _M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
const __false_type&) {
insert(__pos, __first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert(iterator __pos,
const value_type* __first, const value_type* __last);
void insert(iterator __pos,
const_iterator __first, const_iterator __last);
#endif /* _STLP_MEMBER_TEMPLATES */
void resize(size_type __new_size, value_type __x) {
const size_type __len = size();
if (__new_size < __len)
erase(this->_M_start + __new_size, this->_M_finish);
else
insert(this->_M_finish, __new_size - __len, __x);
}
void resize(size_type new_size) { resize(new_size, value_type()); }
public: // Erase
iterator erase(iterator __pos) {
iterator __next = __pos;
++__next;
difference_type __index = __pos - this->_M_start;
if (size_type(__index) < this->size() >> 1) {
_STLP_STD::copy_backward(this->_M_start, __pos, __next);
pop_front();
}
else {
_STLP_STD::copy(__next, this->_M_finish, __pos);
pop_back();
}
return this->_M_start + __index;
}
iterator erase(iterator __first, iterator __last);
void clear();
protected: // Internal construction/destruction
void _M_fill_initialize(const value_type& __val);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void _M_range_initialize(_InputIterator __first,
_InputIterator __last,
const input_iterator_tag &) {
this->_M_initialize_map(0);
_STLP_TRY {
for ( ; __first != __last; ++__first)
push_back(*__first);
}
_STLP_UNWIND(clear());
}
template <class _ForwardIterator>
void _M_range_initialize(_ForwardIterator __first,
_ForwardIterator __last,
const forward_iterator_tag &) {
size_type __n = _STLP_STD::distance(__first, __last);
this->_M_initialize_map(__n);
_Map_pointer __cur_node;
_STLP_TRY {
for (__cur_node = this->_M_start._M_node;
__cur_node < this->_M_finish._M_node;
++__cur_node) {
_ForwardIterator __mid = __first;
advance(__mid, this->buffer_size());
_STLP_STD::uninitialized_copy(__first, __mid, *__cur_node);
__first = __mid;
}
_STLP_STD::uninitialized_copy(__first, __last, this->_M_finish._M_first);
}
_STLP_UNWIND(_STLP_STD::_Destroy(this->_M_start, iterator(*__cur_node, __cur_node)));
}
#endif /* _STLP_MEMBER_TEMPLATES */
protected: // Internal push_* and pop_*
void _M_push_back_aux_v(const value_type&);
void _M_push_front_aux_v(const value_type&);
# ifndef _STLP_NO_ANACHRONISMS
void _M_push_back_aux();
void _M_push_front_aux();
# endif
void _M_pop_back_aux();
void _M_pop_front_aux();
protected: // Internal insert functions
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void
insert(iterator __pos,
_InputIterator __first,
_InputIterator __last,
const input_iterator_tag &)
{
_STLP_STD::copy(__first, __last, inserter(*this, __pos));
}
template <class _ForwardIterator>
void insert(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
const forward_iterator_tag &)
{
size_type __n = _STLP_STD::distance(__first, __last);
if (__pos._M_cur == this->_M_start._M_cur) {
iterator __new_start = _M_reserve_elements_at_front(__n);
_STLP_TRY {
_STLP_STD::uninitialized_copy(__first, __last, __new_start);
this->_M_start = __new_start;
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else if (__pos._M_cur == this->_M_finish._M_cur) {
iterator __new_finish = _M_reserve_elements_at_back(__n);
_STLP_TRY {
_STLP_STD::uninitialized_copy(__first, __last, this->_M_finish);
this->_M_finish = __new_finish;
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
else
_M_insert_aux(__pos, __first, __last, __n);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator _M_insert_aux(iterator __pos, const value_type& __x);
iterator _M_insert_aux(iterator __pos);
iterator _M_insert_aux_prepare(iterator __pos);
void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _ForwardIterator>
void _M_insert_aux(iterator __pos,
_ForwardIterator __first,
_ForwardIterator __last,
size_type __n) {
const difference_type __elemsbefore = __pos - this->_M_start;
size_type __length = size();
if (__elemsbefore < difference_type(__length / 2)) {
iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start;
__pos = this->_M_start + __elemsbefore;
_STLP_TRY {
if (__elemsbefore >= difference_type(__n)) {
iterator __start_n = this->_M_start + difference_type(__n);
_STLP_STD::uninitialized_copy(this->_M_start, __start_n, __new_start);
this->_M_start = __new_start;
_STLP_STD::copy(__start_n, __pos, __old_start);
_STLP_STD::copy(__first, __last, __pos - difference_type(__n));
}
else {
_ForwardIterator __mid = __first;
_STLP_STD::advance(__mid, difference_type(__n) - __elemsbefore);
__uninitialized_copy_copy(this->_M_start, __pos, __first, __mid,
__new_start, _IsPODType());
this->_M_start = __new_start;
_STLP_STD::copy(__mid, __last, __old_start);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node));
}
else {
iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish;
const difference_type __elemsafter =
difference_type(__length) - __elemsbefore;
__pos = this->_M_finish - __elemsafter;
_STLP_TRY {
if (__elemsafter > difference_type(__n)) {
iterator __finish_n = this->_M_finish - difference_type(__n);
_STLP_STD::uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish);
this->_M_finish = __new_finish;
_STLP_STD::copy_backward(__pos, __finish_n, __old_finish);
_STLP_STD::copy(__first, __last, __pos);
}
else {
_ForwardIterator __mid = __first;
_STLP_STD::advance(__mid, __elemsafter);
__uninitialized_copy_copy(__mid, __last, __pos, this->_M_finish, this->_M_finish, _IsPODType());
this->_M_finish = __new_finish;
_STLP_STD::copy(__first, __mid, __pos);
}
}
_STLP_UNWIND(this->_M_destroy_nodes(this->_M_finish._M_node + 1, __new_finish._M_node + 1));
}
}
#else /* _STLP_MEMBER_TEMPLATES */
void _M_insert_aux(iterator __pos,
const value_type* __first, const value_type* __last,
size_type __n);
void _M_insert_aux(iterator __pos,
const_iterator __first, const_iterator __last,
size_type __n);
#endif /* _STLP_MEMBER_TEMPLATES */
iterator _M_reserve_elements_at_front(size_type __n) {
size_type __vacancies = this->_M_start._M_cur - this->_M_start._M_first;
if (__n > __vacancies)
_M_new_elements_at_front(__n - __vacancies);
return this->_M_start - difference_type(__n);
}
iterator _M_reserve_elements_at_back(size_type __n) {
size_type __vacancies = (this->_M_finish._M_last - this->_M_finish._M_cur) - 1;
if (__n > __vacancies)
_M_new_elements_at_back(__n - __vacancies);
return this->_M_finish + difference_type(__n);
}
void _M_new_elements_at_front(size_type __new_elements);
void _M_new_elements_at_back(size_type __new_elements);
protected: // Allocation of _M_map and nodes
// Makes sure the _M_map has space for new nodes. Does not actually
// add the nodes. Can invalidate _M_map pointers. (And consequently,
// deque iterators.)
void _M_reserve_map_at_back (size_type __nodes_to_add = 1) {
if (__nodes_to_add + 1 > this->_M_map_size._M_data - (this->_M_finish._M_node - this->_M_map._M_data))
_M_reallocate_map(__nodes_to_add, false);
}
void _M_reserve_map_at_front (size_type __nodes_to_add = 1) {
if (__nodes_to_add > size_type(this->_M_start._M_node - this->_M_map._M_data))
_M_reallocate_map(__nodes_to_add, true);
}
void _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
};
# define _STLP_TEMPLATE_CONTAINER deque<_Tp, _Alloc>
# define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
_STLP_END_NAMESPACE
// do a cleanup
# undef deque
# undef __deque__
# define __deque__ __WORKAROUND_DBG_RENAME(deque)
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_deque.c>
# endif
#if defined (_STLP_DEBUG)
# include <stl/debug/_deque.h>
#endif
# if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
# include <stl/wrappers/_deque.h>
# endif
#endif /* _STLP_INTERNAL_DEQUE_H */
// Local Variables:
// mode:C++
// End:
+44
View File
@@ -0,0 +1,44 @@
/* NOTE : this header has no guards and is MEANT for multiple inclusion !
* If you are using "header protection" option with your compiler,
* please also find #pragma which disables it and put it here, to
* allow reentrancy of this header.
*/
/* If the platform provides any specific epilog actions,
like #pragmas, do include platform-specific prolog file */
# if defined (_STLP_HAS_SPECIFIC_PROLOG_EPILOG)
# include <config/_epilog.h>
# endif
# ifndef _STLP_NO_POST_COMPATIBLE_SECTION
# include <stl/_config_compat_post.h>
# endif
/* provide a mechanism to redefine std:: namespace in a way that is transparent to the
* user. _STLP_REDEFINE_STD is being used for wrapper files that include native headers
* to temporary undef the std macro. */
# if defined ( _STLP_USE_NAMESPACES ) && (defined ( _STLP_USE_OWN_NAMESPACE ) && !defined ( _STLP_REDEFINE_STD ) )
# undef _STLP_REDEFINE_STD
# define _STLP_REDEFINE_STD 1
# endif
# if defined (_STLP_REDEFINE_STD)
/* We redefine "std" to "stlport", so that user code may use std:: transparently */
# undef std
# define std STLPORT
# else
# if defined(__cplusplus)
# ifndef _STLP_CONFIG_H
# include <stl/_config.h>
# endif
# endif /* __cplusplus */
# endif
View File
+749
View File
@@ -0,0 +1,749 @@
/*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_FSTREAM_C
#define _STLP_FSTREAM_C
# ifndef _STLP_INTERNAL_FSTREAM_H
# include <stl/_fstream.h>
# endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
_STLP_BEGIN_NAMESPACE
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
// no wchar_t is supported for this mode
# define __BF_int_type__ int
# define __BF_pos_type__ streampos
# define __BF_off_type__ streamoff
# else
# define __BF_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_filebuf<_CharT, _Traits>::int_type
# define __BF_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_filebuf<_CharT, _Traits>::pos_type
# define __BF_off_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_filebuf<_CharT, _Traits>::off_type
# endif
//----------------------------------------------------------------------
// Public basic_filebuf<> member functions
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::basic_filebuf()
: basic_streambuf<_CharT, _Traits>(), _M_base(),
_M_constant_width(false), _M_always_noconv(false),
_M_int_buf_dynamic(false),
_M_in_input_mode(false), _M_in_output_mode(false),
_M_in_error_mode(false), _M_in_putback_mode(false),
_M_int_buf(0), _M_int_buf_EOS(0),
_M_ext_buf(0), _M_ext_buf_EOS(0),
_M_ext_buf_converted(0), _M_ext_buf_end(0),
_M_state(_STLP_DEFAULT_CONSTRUCTED(_State_type)),
_M_end_state(_STLP_DEFAULT_CONSTRUCTED(_State_type)),
_M_mmap_base(0), _M_mmap_len(0),
_M_saved_eback(0), _M_saved_gptr(0), _M_saved_egptr(0),
_M_codecvt(0),
_M_width(1), _M_max_width(1)
{
this->_M_setup_codecvt(locale());
}
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::~basic_filebuf() {
this->close();
_M_deallocate_buffers();
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::underflow()
{
return _Underflow<_CharT, _Traits>::_M_doit(this);
}
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::close()
{
bool __ok = this->is_open();
if (_M_in_output_mode) {
__ok = __ok && !_Traits::eq_int_type(this->overflow(traits_type::eof()),
traits_type::eof());
__ok == __ok && this->_M_unshift();
}
else if (_M_in_input_mode)
this->_M_exit_input_mode();
// Note order of arguments. We close the file even if __ok is false.
__ok = _M_base._M_close() && __ok;
// Restore the initial state, except that we don't deallocate the buffer
// or mess with the cached codecvt information.
_M_state = _M_end_state = _State_type();
_M_ext_buf_converted = _M_ext_buf_end = 0;
_M_mmap_base = 0;
_M_mmap_len = 0;
this->setg(0, 0, 0);
this->setp(0, 0);
_M_saved_eback = _M_saved_gptr = _M_saved_egptr = 0;
_M_in_input_mode = _M_in_output_mode = _M_in_error_mode = _M_in_putback_mode
= false;
return __ok ? this : 0;
}
// This member function is called whenever we exit input mode.
// It unmaps the memory-mapped file, if any, and sets
// _M_in_input_mode to false.
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::_M_exit_input_mode()
{
if (_M_mmap_base != 0)
_M_base._M_unmap(_M_mmap_base, _M_mmap_len);
_M_in_input_mode = false;
_M_mmap_base = 0;
}
//----------------------------------------------------------------------
// basic_filebuf<> overridden protected virtual member functions
template <class _CharT, class _Traits>
streamsize basic_filebuf<_CharT, _Traits>::showmanyc()
{
// Is there any possibility that reads can succeed?
if (!this->is_open() || _M_in_output_mode || _M_in_error_mode)
return -1;
else if (_M_in_putback_mode)
return this->egptr() - this->gptr();
else if (_M_constant_width) {
streamoff __pos = _M_base._M_seek(0, ios_base::cur);
streamoff __size = _M_base._M_file_size();
return __pos >= 0 && __size > __pos ? __size - __pos : 0;
}
else
return 0;
}
// Make a putback position available, if necessary, by switching to a
// special internal buffer used only for putback. The buffer is
// [_M_pback_buf, _M_pback_buf + _S_pback_buf_size), but the base
// class only sees a piece of it at a time. (We want to make sure
// that we don't try to read a character that hasn't been initialized.)
// The end of the putback buffer is always _M_pback_buf + _S_pback_buf_size,
// but the beginning is usually not _M_pback_buf.
template <class _CharT, class _Traits>
__BF_int_type__
basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c)
{
const int_type __eof = traits_type::eof();
// If we aren't already in input mode, pushback is impossible.
if (!_M_in_input_mode)
return __eof;
// We can use the ordinary get buffer if there's enough space, and
// if it's a buffer that we're allowed to write to.
if (this->gptr() != this->eback() &&
(traits_type::eq_int_type(__c, __eof) ||
traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]) ||
!_M_mmap_base)) {
this->gbump(-1);
if (traits_type::eq_int_type(__c, __eof) ||
traits_type::eq(traits_type::to_char_type(__c), *this->gptr()))
return traits_type::to_int_type(*this->gptr());
}
else if (!traits_type::eq_int_type(__c, __eof)) {
// Are we in the putback buffer already?
_CharT* __pback_end = _M_pback_buf + __STATIC_CAST(int,_S_pback_buf_size);
if (_M_in_putback_mode) {
// Do we have more room in the putback buffer?
if (this->eback() != _M_pback_buf)
this->setg(this->egptr() - 1, this->egptr() - 1, __pback_end);
else
return __eof; // No more room in the buffer, so fail.
}
else { // We're not yet in the putback buffer.
_M_saved_eback = this->eback();
_M_saved_gptr = this->gptr();
_M_saved_egptr = this->egptr();
this->setg(__pback_end - 1, __pback_end - 1, __pback_end);
_M_in_putback_mode = true;
}
}
else
return __eof;
// We have made a putback position available. Assign to it, and return.
*this->gptr() = traits_type::to_char_type(__c);
return __c;
}
// This member function flushes the put area, and also outputs the
// character __c (unless __c is eof). Invariant: we always leave room
// in the internal buffer for one character more than the base class knows
// about. We see the internal buffer as [_M_int_buf, _M_int_buf_EOS), but
// the base class only sees [_M_int_buf, _M_int_buf_EOS - 1).
template <class _CharT, class _Traits>
__BF_int_type__
basic_filebuf<_CharT, _Traits>::overflow(int_type __c)
{
// Switch to output mode, if necessary.
if (!_M_in_output_mode)
if (!_M_switch_to_output_mode())
return traits_type::eof();
_CharT* __ibegin = this->_M_int_buf;
_CharT* __iend = this->pptr();
this->setp(_M_int_buf, _M_int_buf_EOS - 1);
// Put __c at the end of the internal buffer.
if (!traits_type::eq_int_type(__c, traits_type::eof()))
*__iend++ = __c;
// For variable-width encodings, output may take more than one pass.
while (__ibegin != __iend) {
const _CharT* __inext = __ibegin;
char* __enext = _M_ext_buf;
typename _Codecvt::result __status
= _M_codecvt->out(_M_state, __ibegin, __iend, __inext,
_M_ext_buf, _M_ext_buf_EOS, __enext);
if (__status == _Codecvt::noconv)
return _Noconv_output<_Traits>::_M_doit(this, __ibegin, __iend)
? traits_type::not_eof(__c)
: _M_output_error();
// For a constant-width encoding we know that the external buffer
// is large enough, so failure to consume the entire internal buffer
// or to produce the correct number of external characters, is an error.
// For a variable-width encoding, however, we require only that we
// consume at least one internal character
else if (__status != _Codecvt::error &&
((__inext == __iend && (__enext - _M_ext_buf ==
_M_width * (__iend - __ibegin))) ||
(!_M_constant_width && __inext != __ibegin))) {
// We successfully converted part or all of the internal buffer.
ptrdiff_t __n = __enext - _M_ext_buf;
if (_M_write(_M_ext_buf, __n))
__ibegin += __inext - __ibegin;
else
return _M_output_error();
}
else
return _M_output_error();
}
return traits_type::not_eof(__c);
}
// This member function must be called before any I/O has been
// performed on the stream, otherwise it has no effect.
//
// __buf == 0 && __n == 0 means to make ths stream unbuffered.
// __buf != 0 && __n > 0 means to use __buf as the stream's internal
// buffer, rather than the buffer that would otherwise be allocated
// automatically. __buf must be a pointer to an array of _CharT whose
// size is at least __n.
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::setbuf(_CharT* __buf, streamsize __n)
{
if (!_M_in_input_mode &&! _M_in_output_mode && !_M_in_error_mode &&
_M_int_buf == 0) {
if (__buf == 0 && __n == 0)
_M_allocate_buffers(0, 1);
else if (__buf != 0 && __n > 0)
_M_allocate_buffers(__buf, __n);
}
return this;
}
template <class _CharT, class _Traits>
__BF_pos_type__
basic_filebuf<_CharT, _Traits>::seekoff(off_type __off,
ios_base::seekdir __whence,
ios_base::openmode /* dummy */)
{
if (this->is_open() &&
(__off == 0 || (_M_constant_width && this->_M_base._M_in_binary_mode()))) {
if (!_M_seek_init(__off != 0 || __whence != ios_base::cur))
return pos_type(-1);
// Seek to beginning or end, regardless of whether we're in input mode.
if (__whence == ios_base::beg || __whence == ios_base::end)
return _M_seek_return(_M_base._M_seek(_M_width * __off, __whence),
_State_type());
// Seek relative to current position. Complicated if we're in input mode.
else if (__whence == ios_base::cur) {
if (!_M_in_input_mode)
return _M_seek_return(_M_base._M_seek(_M_width * __off, __whence),
_State_type());
else if (_M_mmap_base != 0) {
// __off is relative to gptr(). We need to do a bit of arithmetic
// to get an offset relative to the external file pointer.
streamoff __adjust = _M_mmap_len - (this->gptr() - (_CharT*) _M_mmap_base);
// if __off == 0, we do not need to exit input mode and to shift file pointer
if (__off == 0) {
return pos_type(_M_base._M_seek(0, ios_base::cur) - __adjust);
}
else
return _M_seek_return(_M_base._M_seek(__off - __adjust, ios_base::cur), _State_type());
}
else if (_M_constant_width) { // Get or set the position.
streamoff __iadj = _M_width * (this->gptr() - this->eback());
// Compensate for offset relative to gptr versus offset relative
// to external pointer. For a text-oriented stream, where the
// compensation is more than just pointer arithmetic, we may get
// but not set the current position.
if (__iadj <= _M_ext_buf_end - _M_ext_buf) {
streamoff __eadj = _M_base._M_get_offset(_M_ext_buf + __iadj, _M_ext_buf_end);
if (__off == 0) {
return pos_type(_M_base._M_seek(0, ios_base::cur) - __eadj);
} else {
return _M_seek_return(_M_base._M_seek(__off - __eadj, ios_base::cur), _State_type());
}
}
else
return pos_type(-1);
}
else { // Get the position. Encoding is var width.
// Get position in internal buffer.
ptrdiff_t __ipos = this->gptr() - this->eback();
// Get corresponding position in external buffer.
_State_type __state = _M_state;
int __epos = _M_codecvt->length(__state, _M_ext_buf, _M_ext_buf_end,
__ipos);
// Sanity check (expensive): make sure __epos is the right answer.
_State_type __tmp_state = _M_state;
_Filebuf_Tmp_Buf<_CharT> __buf(__ipos);
_CharT* __ibegin = __buf._M_ptr;
_CharT* __inext = __ibegin;
const char* __dummy;
typename _Codecvt::result __status
= _M_codecvt->in(__tmp_state,
_M_ext_buf, _M_ext_buf + __epos, __dummy,
__ibegin, __ibegin + __ipos, __inext);
if (__status != _Codecvt::error &&
(__status == _Codecvt::noconv ||
(__inext == __ibegin + __ipos &&
equal(this->gptr(), this->eback(), __ibegin,
_Eq_traits<traits_type>())))) {
// Get the current position (at the end of the external buffer),
// then adjust it. Again, it might be a text-oriented stream.
streamoff __cur = _M_base._M_seek(0, ios_base::cur);
streamoff __adj =
_M_base._M_get_offset(_M_ext_buf, _M_ext_buf + __epos) -
_M_base._M_get_offset(_M_ext_buf, _M_ext_buf_end);
if (__cur != -1 && __cur + __adj >= 0)
return _M_seek_return(__cur + __adj, __state);
else
return pos_type(-1);
}
else // We failed the sanity check.
return pos_type(-1);
}
}
else // Unrecognized value for __whence.
return pos_type(-1);
}
else
return pos_type(-1);
}
template <class _CharT, class _Traits>
__BF_pos_type__
basic_filebuf<_CharT, _Traits>::seekpos(pos_type __pos,
ios_base::openmode /* dummy */)
{
if (this->is_open()) {
if (!_M_seek_init(true))
return pos_type(-1);
streamoff __off = off_type(__pos);
if (__off != -1 && _M_base._M_seek(__off, ios_base::beg) != -1) {
_M_state = __pos.state();
return _M_seek_return(__off, __pos.state());
}
else
return pos_type(-1);
}
else
return pos_type(-1);
}
template <class _CharT, class _Traits>
int basic_filebuf<_CharT, _Traits>::sync()
{
if (_M_in_output_mode)
return traits_type::eq_int_type(this->overflow(traits_type::eof()),
traits_type::eof())
? -1
: 0;
else
return 0;
}
// Change the filebuf's locale. This member function has no effect
// unless it is called before any I/O is performed on the stream.
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc)
{
if (!_M_in_input_mode &&! _M_in_output_mode && !_M_in_error_mode) {
this->_M_setup_codecvt(__loc);
}
}
//----------------------------------------------------------------------
// basic_filebuf<> helper functions.
//----------------------------------------
// Helper functions for switching between modes.
// This member function is called if we're performing the first I/O
// operation on a filebuf, or if we're performing an input operation
// immediately after a seek.
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::_M_switch_to_input_mode()
{
if (this->is_open() && (((int)_M_base.__o_mode() & (int)ios_base::in) !=0)
&& (_M_in_output_mode == 0) && (_M_in_error_mode == 0)) {
if (!_M_int_buf && !_M_allocate_buffers())
return false;
_M_ext_buf_converted = _M_ext_buf;
_M_ext_buf_end = _M_ext_buf;
_M_end_state = _M_state;
_M_in_input_mode = true;
return true;
}
else
return false;
}
// This member function is called if we're performing the first I/O
// operation on a filebuf, or if we're performing an output operation
// immediately after a seek.
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::_M_switch_to_output_mode()
{
if (this->is_open() && (_M_base.__o_mode() & (int)ios_base::out) &&
_M_in_input_mode == 0 && _M_in_error_mode == 0) {
if (!_M_int_buf && !_M_allocate_buffers())
return false;
// In append mode, every write does an implicit seek to the end
// of the file. Whenever leaving output mode, the end of file
// get put in the initial shift state.
if (_M_base.__o_mode() & ios_base::app)
_M_state = _State_type();
this->setp(_M_int_buf, _M_int_buf_EOS - 1);
_M_in_output_mode = true;
return true;
}
else
return false;
}
//----------------------------------------
// Helper functions for input
// This member function is called if there is an error during input.
// It puts the filebuf in error mode, clear the get area buffer, and
// returns eof.
// returns eof. Error mode is sticky; it is cleared only by close or
// seek.
template <class _CharT, class _Traits>
__BF_int_type__
basic_filebuf<_CharT, _Traits>::_M_input_error()
{
this->_M_exit_input_mode();
_M_in_output_mode = false;
_M_in_error_mode = true;
this->setg(0, 0, 0);
return traits_type::eof();
}
template <class _CharT, class _Traits>
__BF_int_type__
basic_filebuf<_CharT, _Traits>::_M_underflow_aux()
{
// We have the state and file position from the end of the internal
// buffer. This round, they become the beginning of the internal buffer.
_M_state = _M_end_state;
// Fill the external buffer. Start with any leftover characters that
// didn't get converted last time.
if (_M_ext_buf_end > _M_ext_buf_converted)
_M_ext_buf_end = copy(_M_ext_buf_converted, _M_ext_buf_end, _M_ext_buf);
// boris : copy_backward did not work
//_M_ext_buf_end = copy_backward(_M_ext_buf_converted, _M_ext_buf_end,
//_M_ext_buf+ (_M_ext_buf_end - _M_ext_buf_converted));
else
_M_ext_buf_end = _M_ext_buf;
// Now fill the external buffer with characters from the file. This is
// a loop because occasonally we don't get enough external characters
// to make progress.
while (true) {
ptrdiff_t __n = _M_base._M_read(_M_ext_buf_end, _M_ext_buf_EOS - _M_ext_buf_end);
// Don't enter error mode for a failed read. Error mode is sticky,
// and we might succeed if we try again.
if (__n <= 0)
return traits_type::eof();
// Convert the external buffer to internal characters.
_M_ext_buf_end += __n;
const char* __enext;
_CharT* __inext;
typename _Codecvt::result __status
= _M_codecvt->in(_M_end_state,
_M_ext_buf, _M_ext_buf_end, __enext,
_M_int_buf, _M_int_buf_EOS, __inext);
// Error conditions: (1) Return value of error. (2) Producing internal
// characters without consuming external characters. (3) In fixed-width
// encodings, producing an internal sequence whose length is inconsistent
// with that of the internal sequence. (4) Failure to produce any
// characters if we have enough characters in the external buffer, where
// "enough" means the largest possible width of a single character.
if (__status == _Codecvt::noconv)
return _Noconv_input<_Traits>::_M_doit(this);
else if (__status == _Codecvt::error ||
(__inext != _M_int_buf && __enext == _M_ext_buf) ||
(_M_constant_width &&
// __inext - _M_int_buf != _M_width * (__enext - _M_ext_buf)) ||
(__inext - _M_int_buf) * _M_width != (__enext - _M_ext_buf)) ||
(__inext == _M_int_buf && __enext - _M_ext_buf >= _M_max_width))
return _M_input_error();
else if (__inext != _M_int_buf) {
_M_ext_buf_converted = _M_ext_buf + (__enext - _M_ext_buf);
this->setg(_M_int_buf, _M_int_buf, __inext);
return traits_type::to_int_type(*_M_int_buf);
}
// We need to go around the loop again to get more external characters.
}
}
//----------------------------------------
// Helper functions for output
// This member function is called if there is an error during output.
// It puts the filebuf in error mode, clear the put area buffer, and
// returns eof. Error mode is sticky; it is cleared only by close or
// seek.
template <class _CharT, class _Traits>
__BF_int_type__
basic_filebuf<_CharT, _Traits>::_M_output_error()
{
_M_in_output_mode = false;
_M_in_input_mode = false;
_M_in_error_mode = true;
this->setp(0, 0);
return traits_type::eof();
}
// Write whatever sequence of characters is necessary to get back to
// the initial shift state. This function overwrites the external
// buffer, changes the external file position, and changes the state.
// Precondition: the internal buffer is empty.
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::_M_unshift()
{
if (_M_in_output_mode && !_M_constant_width) {
typename _Codecvt::result __status;
do {
char* __enext = _M_ext_buf;
__status = _M_codecvt->unshift(_M_state,
_M_ext_buf, _M_ext_buf_EOS, __enext);
if (__status == _Codecvt::noconv ||
(__enext == _M_ext_buf && __status == _Codecvt::ok))
return true;
else if (__status == _Codecvt::error)
return false;
else if (!_M_write(_M_ext_buf, __enext - _M_ext_buf))
return false;
} while(__status == _Codecvt::partial);
}
return true;
}
//----------------------------------------
// Helper functions for buffer allocation and deallocation
// This member function is called when we're initializing a filebuf's
// internal and external buffers. The argument is the size of the
// internal buffer; the external buffer is sized using the character
// width in the current encoding. Preconditions: the buffers are currently
// null. __n >= 1. __buf is either a null pointer or a pointer to an
// array show size is at least __n.
// We need __n >= 1 for two different reasons. For input, the base
// class always needs a buffer because of the sementics of underflow().
// For output, we want to have an internal buffer that's larger by one
// element than the buffer that the base class knows about. (See
// basic_filebuf<>::overflow() for the reason.)
template <class _CharT, class _Traits>
bool
basic_filebuf<_CharT, _Traits>::_M_allocate_buffers(_CharT* __buf, streamsize __n)
{
if (__buf == 0) {
_M_int_buf = __STATIC_CAST(_CharT*,malloc(__n * sizeof(_CharT)));
if (! _M_int_buf)
return false;
_M_int_buf_dynamic = true;
}
else {
_M_int_buf = __buf;
_M_int_buf_dynamic = false;
}
size_t __ebufsiz = (max)(__n * (max)(_M_codecvt->encoding(), 1),
streamsize(_M_codecvt->max_length()));
_M_ext_buf = __STATIC_CAST(char*,malloc(__ebufsiz));
if (!_M_ext_buf) {
_M_deallocate_buffers();
return false;
}
_M_int_buf_EOS = _M_int_buf + __n;
_M_ext_buf_EOS = _M_ext_buf + __ebufsiz;
return true;
}
// Abbreviation for the most common case.
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::_M_allocate_buffers()
{
// Choose a buffer that's at least 4096 characters long and that's a
// multiple of the page size.
streamsize __default_bufsiz =
((_M_base.__page_size() + 4095UL) / _M_base.__page_size()) * _M_base.__page_size();
return _M_allocate_buffers(0, __default_bufsiz);
}
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::_M_deallocate_buffers()
{
if (_M_int_buf_dynamic)
free(_M_int_buf);
free(_M_ext_buf);
_M_int_buf = 0;
_M_int_buf_EOS = 0;
_M_ext_buf = 0;
_M_ext_buf_EOS = 0;
}
//----------------------------------------
// Helper functiosn for seek and imbue
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::_M_seek_init(bool __do_unshift) {
// If we're in error mode, leave it.
_M_in_error_mode = false;
// Flush the output buffer if we're in output mode, and (conditionally)
// emit an unshift sequence.
if (_M_in_output_mode) {
bool __ok = !traits_type::eq_int_type(this->overflow(traits_type::eof()),
traits_type::eof());
if (__do_unshift)
__ok = __ok && this->_M_unshift();
if (!__ok) {
_M_in_output_mode = false;
_M_in_error_mode = true;
this->setp(0, 0);
return false;
}
}
// Discard putback characters, if any.
if (_M_in_input_mode && _M_in_putback_mode)
_M_exit_putback_mode();
return true;
}
// Change the filebuf's locale. This member function has no effect
// unless it is called before any I/O is performed on the stream.
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::_M_setup_codecvt(const locale& __loc)
{
_M_codecvt = &use_facet<_Codecvt>(__loc) ;
int __encoding = _M_codecvt->encoding();
_M_width = (max)(__encoding, 1);
_M_max_width = _M_codecvt->max_length();
_M_constant_width = __encoding > 0;
_M_always_noconv = _M_codecvt->always_noconv();
}
_STLP_END_NAMESPACE
# undef __BF_int_type__
# undef __BF_pos_type__
# undef __BF_off_type__
# endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
#endif /* _STLP_FSTREAM_C */
+741
View File
@@ -0,0 +1,741 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// This header defines classes basic_filebuf, basic_ifstream,
// basic_ofstream, and basic_fstream. These classes represent
// streambufs and streams whose sources or destinations are files.
#ifndef _STLP_INTERNAL_FSTREAM_H
#define _STLP_INTERNAL_FSTREAM_H
#if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
#error This header file requires the -LANG:std option
#endif
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
#ifndef _STLP_INTERNAL_ISTREAM_H
#include <stl/_istream.h>
#endif
#ifndef _STLP_INTERNAL_CODECVT_H
#include <stl/_codecvt.h>
#endif
#ifndef _STLP_STDIO_FILE_H
#include <stl/_stdio_file.h>
#endif
#if !defined (_STLP_USE_UNIX_IO) && !defined(_STLP_USE_WIN32_IO) \
&& ! defined (_STLP_USE_UNIX_EMULATION_IO) && !defined (_STLP_USE_STDIO_IO)
# if defined (_STLP_UNIX) || defined (__CYGWIN__) || defined (__amigaos__) || defined (__EMX__)
// open/close/read/write
# define _STLP_USE_UNIX_IO
# elif defined (_STLP_WIN32) && ! defined (__CYGWIN__)
// CreateFile/ReadFile/WriteFile
# define _STLP_USE_WIN32_IO
# elif defined (_STLP_WIN16) || defined (_STLP_WIN32) || defined (_STLP_MAC)
// _open/_read/_write
# define _STLP_USE_UNIX_EMULATION_IO
# else
// fopen/fread/fwrite
# define _STLP_USE_STDIO_IO
# endif /* _STLP_UNIX */
#endif /* mode selection */
#if defined (_STLP_USE_WIN32_IO)
typedef void* _STLP_fd;
#elif defined (_STLP_USE_UNIX_EMULATION_IO) || defined (_STLP_USE_STDIO_IO) || defined (_STLP_USE_UNIX_IO)
typedef int _STLP_fd;
#else
#error "Configure i/o !"
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// Class _Filebuf_base, a private base class to factor out the system-
// dependent code from basic_filebuf<>.
class _STLP_CLASS_DECLSPEC _Filebuf_base {
public: // Opening and closing files.
_Filebuf_base();
bool _M_open(const char*, ios_base::openmode, long __protection);
bool _M_open(const char*, ios_base::openmode);
bool _M_open(int __id, ios_base::openmode = ios_base::__default_mode);
bool _M_close();
public: // Low-level I/O, like Unix read/write
ptrdiff_t _M_read(char* __buf, ptrdiff_t __n);
streamoff _M_seek(streamoff __offset, ios_base::seekdir __dir);
streamoff _M_file_size();
bool _M_write(char* __buf, ptrdiff_t __n);
public: // Memory-mapped I/O.
void* _M_mmap(streamoff __offset, streamoff __len);
void _M_unmap(void* __mmap_base, streamoff __len);
public:
// Returns a value n such that, if pos is the file pointer at the
// beginning of the range [first, last), pos + n is the file pointer at
// the end. On many operating systems n == __last - __first.
// In Unix, writing n characters always bumps the file position by n.
// In Windows text mode, however, it bumps the file position by n + m,
// where m is the number of newlines in the range. That's because an
// internal \n corresponds to an external two-character sequence.
streamoff _M_get_offset(char* __first, char* __last) {
#if defined (_STLP_UNIX) || defined (_STLP_MAC)
return __last - __first;
#else // defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS)
return ( (_M_openmode & ios_base::binary) != 0 )
? (__last - __first)
: count(__first, __last, '\n') + (__last - __first);
#endif
}
// Returns true if we're in binary mode or if we're using an OS or file
// system where there is no distinction between text and binary mode.
bool _M_in_binary_mode() const {
# if defined (_STLP_UNIX) || defined (_STLP_MAC) || defined(__BEOS__) || defined (__amigaos__)
return true;
# elif defined (_STLP_WIN32) || defined (_STLP_WIN16) || defined (_STLP_DOS) || defined (_STLP_VM) || defined (__EMX__)
return (_M_openmode & ios_base::binary) != 0;
# else
# error "Port!"
# endif
}
protected: // Static data members.
static size_t _M_page_size;
protected: // Data members.
_STLP_fd _M_file_id;
# ifdef _STLP_USE_STDIO_IO
// for stdio, the whole FILE* is being kept here
FILE* _M_file;
# endif
# ifdef _STLP_USE_WIN32_IO
void* _M_view_id;
# endif
ios_base::openmode _M_openmode ;
unsigned char _M_is_open ;
unsigned char _M_should_close ;
unsigned char _M_regular_file ;
public :
static size_t _STLP_CALL __page_size() { return _M_page_size; }
int __o_mode() const { return (int)_M_openmode; }
bool __is_open() const { return (_M_is_open !=0 ); }
bool __should_close() const { return (_M_should_close != 0); }
bool __regular_file() const { return (_M_regular_file != 0); }
_STLP_fd __get_fd() const { return _M_file_id; }
};
//----------------------------------------------------------------------
// Class basic_filebuf<>.
// Forward declaration of two helper classes.
template <class _Traits> class _Noconv_input;
_STLP_TEMPLATE_NULL
class _Noconv_input<char_traits<char> >;
template <class _Traits> class _Noconv_output;
_STLP_TEMPLATE_NULL
class _Noconv_output< char_traits<char> >;
// There is a specialized version of underflow, for basic_filebuf<char>,
// in fstream.cxx.
template <class _CharT, class _Traits>
class _Underflow;
_STLP_TEMPLATE_NULL class _Underflow< char, char_traits<char> >;
template <class _CharT, class _Traits>
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
{
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;
typedef typename _Traits::state_type _State_type;
typedef basic_streambuf<_CharT, _Traits> _Base;
typedef basic_filebuf<_CharT, _Traits> _Self;
public: // Constructors, destructor.
basic_filebuf();
~basic_filebuf();
public: // Opening and closing files.
bool is_open() const { return _M_base.__is_open(); }
_Self* open(const char* __s, ios_base::openmode __m) {
return _M_base._M_open(__s, __m) ? this : 0;
}
# ifndef _STLP_NO_EXTENSIONS
// These two version of open() and file descriptor getter are extensions.
_Self* open(const char* __s, ios_base::openmode __m,
long __protection) {
return _M_base._M_open(__s, __m, __protection) ? this : 0;
}
_STLP_fd fd() const { return _M_base.__get_fd(); }
_Self* open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
return this->_M_open(__id, _Init_mode);
}
# endif
_Self* _M_open(int __id, ios_base::openmode _Init_mode = ios_base::__default_mode) {
return _M_base._M_open(__id, _Init_mode) ? this : 0;
}
_Self* close();
protected: // Virtual functions from basic_streambuf.
virtual streamsize showmanyc();
virtual int_type underflow();
virtual int_type pbackfail(int_type = traits_type::eof());
virtual int_type overflow(int_type = traits_type::eof());
virtual basic_streambuf<_CharT, _Traits>* setbuf(char_type*, streamsize);
virtual pos_type seekoff(off_type, ios_base::seekdir,
ios_base::openmode = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type,
ios_base::openmode = ios_base::in | ios_base::out);
virtual int sync();
virtual void imbue(const locale&);
private: // Helper functions.
// Precondition: we are currently in putback input mode. Effect:
// switches back to ordinary input mode.
void _M_exit_putback_mode() {
this->setg(_M_saved_eback, _M_saved_gptr, _M_saved_egptr);
_M_in_putback_mode = false;
}
bool _M_switch_to_input_mode();
void _M_exit_input_mode();
bool _M_switch_to_output_mode();
int_type _M_input_error();
int_type _M_underflow_aux();
// friend class _Noconv_input<_Traits>;
// friend class _Noconv_output<_Traits>;
friend class _Underflow<_CharT, _Traits>;
int_type _M_output_error();
bool _M_unshift();
bool _M_allocate_buffers(_CharT* __buf, streamsize __n);
bool _M_allocate_buffers();
void _M_deallocate_buffers();
pos_type _M_seek_return(off_type __off, _State_type __state) {
if (__off != -1) {
if (_M_in_input_mode)
_M_exit_input_mode();
_M_in_input_mode = false;
_M_in_output_mode = false;
_M_in_putback_mode = false;
_M_in_error_mode = false;
this->setg(0, 0, 0);
this->setp(0, 0);
}
pos_type __result(__off);
__result.state(__state);
return __result;
}
bool _M_seek_init(bool __do_unshift);
void _M_setup_codecvt(const locale&);
private: // Data members used in all modes.
_Filebuf_base _M_base;
private: // Locale-related information.
unsigned char _M_constant_width;
unsigned char _M_always_noconv;
// private: // Mode flags.
unsigned char _M_int_buf_dynamic; // True if internal buffer is heap allocated,
// false if it was supplied by the user.
unsigned char _M_in_input_mode;
unsigned char _M_in_output_mode;
unsigned char _M_in_error_mode;
unsigned char _M_in_putback_mode;
// Internal buffer: characters seen by the filebuf's clients.
_CharT* _M_int_buf;
_CharT* _M_int_buf_EOS;
// External buffer: characters corresponding to the external file.
char* _M_ext_buf;
char* _M_ext_buf_EOS;
// The range [_M_ext_buf, _M_ext_buf_converted) contains the external
// characters corresponding to the sequence in the internal buffer. The
// range [_M_ext_buf_converted, _M_ext_buf_end) contains characters that
// have been read into the external buffer but have not been converted
// to an internal sequence.
char* _M_ext_buf_converted;
char* _M_ext_buf_end;
// State corresponding to beginning of internal buffer.
_State_type _M_state;
private: // Data members used only in input mode.
// Similar to _M_state except that it corresponds to
// the end of the internal buffer instead of the beginning.
_State_type _M_end_state;
// This is a null pointer unless we are in mmap input mode.
void* _M_mmap_base;
streamoff _M_mmap_len;
private: // Data members used only in putback mode.
_CharT* _M_saved_eback;
_CharT* _M_saved_gptr;
_CharT* _M_saved_egptr;
typedef codecvt<_CharT, char, _State_type> _Codecvt;
const _Codecvt* _M_codecvt;
int _M_width; // Width of the encoding (if constant), else 1
int _M_max_width; // Largest possible width of single character.
enum { _S_pback_buf_size = 8 };
_CharT _M_pback_buf[_S_pback_buf_size];
// for _Noconv_output
public:
bool _M_write(char* __buf, ptrdiff_t __n) {return _M_base._M_write(__buf, __n); }
public:
int_type
_M_do_noconv_input() {
_M_ext_buf_converted = _M_ext_buf_end;
this->setg((char_type*)_M_ext_buf, (char_type*)_M_ext_buf, (char_type*)_M_ext_buf_end);
return traits_type::to_int_type(*_M_ext_buf);
}
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<char, char_traits<char> >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_filebuf<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
// public:
// helper class.
template <class _CharT>
struct _Filebuf_Tmp_Buf
{
_CharT* _M_ptr;
_Filebuf_Tmp_Buf(ptrdiff_t __n) : _M_ptr(0) { _M_ptr = new _CharT[__n]; }
~_Filebuf_Tmp_Buf() { delete[] _M_ptr; }
};
//
// This class had to be designed very carefully to work
// with Visual C++.
//
template <class _Traits>
class _Noconv_output {
public:
typedef typename _Traits::char_type char_type;
static bool _STLP_CALL _M_doit(basic_filebuf<char_type, _Traits >*,
char_type*, char_type*)
{
return false;
}
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC _Noconv_output< char_traits<char> > {
public:
static bool _STLP_CALL
_M_doit(basic_filebuf<char, char_traits<char> >* __buf,
char* __first, char* __last)
{
ptrdiff_t __n = __last - __first;
if (__buf->_M_write(__first, __n)) {
return true;
}
else
return false;
}
};
//----------------------------------------------------------------------
// basic_filebuf<> helper functions.
//----------------------------------------
// Helper functions for switching between modes.
//
// This class had to be designed very carefully to work
// with Visual C++.
//
template <class _Traits>
class _Noconv_input {
public:
typedef typename _Traits::int_type int_type;
typedef typename _Traits::char_type char_type;
static inline int_type _STLP_CALL
_M_doit(basic_filebuf<char_type, _Traits>*)
{
return 0;
}
};
_STLP_TEMPLATE_NULL
class _Noconv_input<char_traits<char> > {
public:
static inline int _STLP_CALL
_M_doit(basic_filebuf<char, char_traits<char> >* __buf) {
return __buf->_M_do_noconv_input();
}
};
// underflow() may be called for one of two reasons. (1) We've
// been going through the special putback buffer, and we need to move back
// to the regular internal buffer. (2) We've exhausted the internal buffer,
// and we need to replentish it.
template <class _CharT, class _Traits>
class _Underflow {
public:
typedef typename _Traits::int_type int_type;
typedef _Traits traits_type;
static int_type _STLP_CALL _M_doit(basic_filebuf<_CharT, _Traits>* __this);
};
// Specialization of underflow: if the character type is char, maybe
// we can use mmap instead of read.
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC _Underflow< char, char_traits<char> > {
public:
typedef char_traits<char>::int_type int_type;
typedef char_traits<char> traits_type;
static int _STLP_CALL _M_doit(basic_filebuf<char, traits_type >* __this);
};
// There is a specialized version of underflow, for basic_filebuf<char>,
// in fstream.cxx.
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE _Underflow<_CharT, _Traits>::int_type // _STLP_CALL
_Underflow<_CharT, _Traits>::_M_doit(basic_filebuf<_CharT, _Traits>* __this)
{
if (!__this->_M_in_input_mode) {
if (!__this->_M_switch_to_input_mode())
return traits_type::eof();
}
else if (__this->_M_in_putback_mode) {
__this->_M_exit_putback_mode();
if (__this->gptr() != __this->egptr()) {
int_type __c = traits_type::to_int_type(*__this->gptr());
return __c;
}
}
return __this->_M_underflow_aux();
}
#if defined( _STLP_USE_TEMPLATE_EXPORT ) && ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS _Underflow<wchar_t, char_traits<wchar_t> >;
#endif
//----------------------------------------------------------------------
// Class basic_ifstream<>
template <class _CharT, class _Traits>
class basic_ifstream : public basic_istream<_CharT, _Traits>
{
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;
typedef basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_istream<_CharT, _Traits> _Base;
typedef basic_filebuf<_CharT, _Traits> _Buf;
public: // Constructors, destructor.
basic_ifstream() :
basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
}
explicit basic_ifstream(const char* __s, ios_base::openmode __mod = ios_base::in) :
basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0),
_M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __mod | ios_base::in))
this->setstate(ios_base::failbit);
}
# ifndef _STLP_NO_EXTENSIONS
explicit basic_ifstream(int __id, ios_base::openmode __mod = ios_base::in) :
basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__id, __mod | ios_base::in))
this->setstate(ios_base::failbit);
}
basic_ifstream(const char* __s, ios_base::openmode __m,
long __protection) :
basic_ios<_CharT, _Traits>(), basic_istream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __m | ios_base::in, __protection))
this->setstate(ios_base::failbit);
}
# endif
~basic_ifstream() {}
public: // File and buffer operations.
basic_filebuf<_CharT, _Traits>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
bool is_open() {
return this->rdbuf()->is_open();
}
void open(const char* __s, ios_base::openmode __mod = ios_base::in) {
if (!this->rdbuf()->open(__s, __mod | ios_base::in))
this->setstate(ios_base::failbit);
}
void close() {
if (!this->rdbuf()->close())
this->setstate(ios_base::failbit);
}
private:
basic_filebuf<_CharT, _Traits> _M_buf;
};
//----------------------------------------------------------------------
// Class basic_ofstream<>
template <class _CharT, class _Traits>
class basic_ofstream : public basic_ostream<_CharT, _Traits>
{
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;
typedef basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_ostream<_CharT, _Traits> _Base;
typedef basic_filebuf<_CharT, _Traits> _Buf;
public: // Constructors, destructor.
basic_ofstream() :
basic_ios<_CharT, _Traits>(),
basic_ostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
}
explicit basic_ofstream(const char* __s, ios_base::openmode __mod = ios_base::out)
: basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
_M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __mod | ios_base::out))
this->setstate(ios_base::failbit);
}
# ifndef _STLP_NO_EXTENSIONS
explicit basic_ofstream(int __id, ios_base::openmode __mod = ios_base::out)
: basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0),
_M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__id, __mod | ios_base::out))
this->setstate(ios_base::failbit);
}
basic_ofstream(const char* __s, ios_base::openmode __m, long __protection) :
basic_ios<_CharT, _Traits>(), basic_ostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __m | ios_base::out, __protection))
this->setstate(ios_base::failbit);
}
# endif
~basic_ofstream() {}
public: // File and buffer operations.
basic_filebuf<_CharT, _Traits>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
bool is_open() {
return this->rdbuf()->is_open();
}
void open(const char* __s, ios_base::openmode __mod= ios_base::out) {
if (!this->rdbuf()->open(__s, __mod | ios_base::out))
this->setstate(ios_base::failbit);
}
void close() {
if (!this->rdbuf()->close())
this->setstate(ios_base::failbit);
}
private:
basic_filebuf<_CharT, _Traits> _M_buf;
};
//----------------------------------------------------------------------
// Class basic_fstream<>
template <class _CharT, class _Traits>
class basic_fstream : public basic_iostream<_CharT, _Traits>
{
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;
typedef basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_iostream<_CharT, _Traits> _Base;
typedef basic_filebuf<_CharT, _Traits> _Buf;
public: // Constructors, destructor.
basic_fstream()
: basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
}
explicit basic_fstream(const char* __s,
ios_base::openmode __mod = ios_base::in | ios_base::out) :
basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __mod))
this->setstate(ios_base::failbit);
}
# ifndef _STLP_NO_EXTENSIONS
explicit basic_fstream(int __id,
ios_base::openmode __mod = ios_base::in | ios_base::out) :
basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__id, __mod))
this->setstate(ios_base::failbit);
}
basic_fstream(const char* __s, ios_base::openmode __m, long __protection) :
basic_ios<_CharT, _Traits>(), basic_iostream<_CharT, _Traits>(0), _M_buf() {
this->init(&_M_buf);
if (!_M_buf.open(__s, __m, __protection))
this->setstate(ios_base::failbit);
}
# endif
~basic_fstream() {}
public: // File and buffer operations.
basic_filebuf<_CharT, _Traits>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
bool is_open() {
return this->rdbuf()->is_open();
}
void open(const char* __s,
ios_base::openmode __mod =
ios_base::in | ios_base::out) {
if (!this->rdbuf()->open(__s, __mod))
this->setstate(ios_base::failbit);
}
void close() {
if (!this->rdbuf()->close())
this->setstate(ios_base::failbit);
}
private:
basic_filebuf<_CharT, _Traits> _M_buf;
};
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_fstream.c>
# endif
_STLP_BEGIN_NAMESPACE
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<char, char_traits<char> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<char, char_traits<char> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<char, char_traits<char> >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_ifstream<wchar_t, char_traits<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_ofstream<wchar_t, char_traits<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_fstream<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
_STLP_END_NAMESPACE
#endif /* _STLP_FSTREAM */
// Local Variables:
// mode:C++
// End:
+371
View File
@@ -0,0 +1,371 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_FUNCTION_H
#define _STLP_INTERNAL_FUNCTION_H
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
#include <stl/_function_base.h>
#endif
_STLP_BEGIN_NAMESPACE
# ifndef _STLP_NO_EXTENSIONS
// identity_element (not part of the C++ standard).
template <class _Tp> inline _Tp identity_element(plus<_Tp>) { return _Tp(0); }
template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) { return _Tp(1); }
# endif
# if defined (_STLP_BASE_TYPEDEF_BUG)
// this workaround is needed for SunPro 4.0.1
// suggested by "Martin Abernethy" <gma@paston.co.uk>:
// We have to introduce the XXary_predicate_aux structures in order to
// access the argument and return types of predicate functions supplied
// as type parameters. SUN C++ 4.0.1 compiler gives errors for template type parameters
// of the form 'name1::name2', where name1 is itself a type parameter.
template <class _Pair>
struct __pair_aux : private _Pair
{
typedef typename _Pair::first_type first_type;
typedef typename _Pair::second_type second_type;
};
template <class _Operation>
struct __unary_fun_aux : private _Operation
{
typedef typename _Operation::argument_type argument_type;
typedef typename _Operation::result_type result_type;
};
template <class _Operation>
struct __binary_fun_aux : private _Operation
{
typedef typename _Operation::first_argument_type first_argument_type;
typedef typename _Operation::second_argument_type second_argument_type;
typedef typename _Operation::result_type result_type;
};
# define __UNARY_ARG(__Operation,__type) __unary_fun_aux<__Operation>::__type
# define __BINARY_ARG(__Operation,__type) __binary_fun_aux<__Operation>::__type
# define __PAIR_ARG(__Pair,__type) __pair_aux<__Pair>::__type
# else
# define __UNARY_ARG(__Operation,__type) __Operation::__type
# define __BINARY_ARG(__Operation,__type) __Operation::__type
# define __PAIR_ARG(__Pair,__type) __Pair::__type
# endif
template <class _Predicate>
class unary_negate :
public unary_function<typename __UNARY_ARG(_Predicate,argument_type), bool> {
protected:
_Predicate _M_pred;
public:
explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
bool operator()(const typename _Predicate::argument_type& __x) const {
return !_M_pred(__x);
}
};
template <class _Predicate>
inline unary_negate<_Predicate>
not1(const _Predicate& __pred)
{
return unary_negate<_Predicate>(__pred);
}
template <class _Predicate>
class binary_negate
: public binary_function<typename __BINARY_ARG(_Predicate,first_argument_type),
typename __BINARY_ARG(_Predicate,second_argument_type),
bool> {
protected:
_Predicate _M_pred;
public:
explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
bool operator()(const typename _Predicate::first_argument_type& __x,
const typename _Predicate::second_argument_type& __y) const
{
return !_M_pred(__x, __y);
}
};
template <class _Predicate>
inline binary_negate<_Predicate>
not2(const _Predicate& __pred)
{
return binary_negate<_Predicate>(__pred);
}
template <class _Operation>
class binder1st :
public unary_function<typename __BINARY_ARG(_Operation,second_argument_type),
typename __BINARY_ARG(_Operation,result_type) > {
protected:
_Operation _M_op;
typename _Operation::first_argument_type _M_value;
public:
binder1st(const _Operation& __x,
const typename _Operation::first_argument_type& __y)
: _M_op(__x), _M_value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::second_argument_type& __x) const {
return _M_op(_M_value, __x);
}
typename _Operation::result_type
operator()(typename _Operation::second_argument_type& __x) const {
return _M_op(_M_value, __x);
}
};
template <class _Operation, class _Tp>
inline binder1st<_Operation>
bind1st(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::first_argument_type _Arg1_type;
return binder1st<_Operation>(__fn, _Arg1_type(__x));
}
template <class _Operation>
class binder2nd
: public unary_function<typename __BINARY_ARG(_Operation,first_argument_type),
typename __BINARY_ARG(_Operation,result_type)> {
protected:
_Operation _M_op;
typename _Operation::second_argument_type value;
public:
binder2nd(const _Operation& __x,
const typename _Operation::second_argument_type& __y)
: _M_op(__x), value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::first_argument_type& __x) const {
return _M_op(__x, value);
}
typename _Operation::result_type
operator()(typename _Operation::first_argument_type& __x) const {
return _M_op(__x, value);
}
};
template <class _Operation, class _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__fn, _Arg2_type(__x));
}
# ifndef _STLP_NO_EXTENSIONS
// unary_compose and binary_compose (extensions, not part of the standard).
template <class _Operation1, class _Operation2>
class unary_compose :
public unary_function<typename __UNARY_ARG(_Operation2,argument_type),
typename __UNARY_ARG(_Operation1,result_type)> {
protected:
_Operation1 _M_fn1;
_Operation2 _M_fn2;
public:
unary_compose(const _Operation1& __x, const _Operation2& __y)
: _M_fn1(__x), _M_fn2(__y) {}
typename _Operation1::result_type
operator()(const typename _Operation2::argument_type& __x) const {
return _M_fn1(_M_fn2(__x));
}
typename _Operation1::result_type
operator()(typename _Operation2::argument_type& __x) const {
return _M_fn1(_M_fn2(__x));
}
};
template <class _Operation1, class _Operation2>
inline unary_compose<_Operation1,_Operation2>
compose1(const _Operation1& __fn1, const _Operation2& __fn2)
{
return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
}
template <class _Operation1, class _Operation2, class _Operation3>
class binary_compose :
public unary_function<typename __UNARY_ARG(_Operation2,argument_type),
typename __BINARY_ARG(_Operation1,result_type)> {
protected:
_Operation1 _M_fn1;
_Operation2 _M_fn2;
_Operation3 _M_fn3;
public:
binary_compose(const _Operation1& __x, const _Operation2& __y,
const _Operation3& __z)
: _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
typename _Operation1::result_type
operator()(const typename _Operation2::argument_type& __x) const {
return _M_fn1(_M_fn2(__x), _M_fn3(__x));
}
typename _Operation1::result_type
operator()(typename _Operation2::argument_type& __x) const {
return _M_fn1(_M_fn2(__x), _M_fn3(__x));
}
};
template <class _Operation1, class _Operation2, class _Operation3>
inline binary_compose<_Operation1, _Operation2, _Operation3>
compose2(const _Operation1& __fn1, const _Operation2& __fn2,
const _Operation3& __fn3)
{
return binary_compose<_Operation1,_Operation2,_Operation3>
(__fn1, __fn2, __fn3);
}
# endif /* _STLP_NO_EXTENSIONS */
# ifndef _STLP_NO_EXTENSIONS
// identity is an extension: it is not part of the standard.
template <class _Tp> struct identity : public _Identity<_Tp> {};
// select1st and select2nd are extensions: they are not part of the standard.
template <class _Pair> struct select1st : public _Select1st<_Pair> {};
template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
template <class _Arg1, class _Arg2>
struct project1st : public _Project1st<_Arg1, _Arg2> {};
template <class _Arg1, class _Arg2>
struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
// constant_void_fun, constant_unary_fun, and constant_binary_fun are
// extensions: they are not part of the standard. (The same, of course,
// is true of the helper functions constant0, constant1, and constant2.)
template <class _Result>
struct _Constant_void_fun {
typedef _Result result_type;
result_type _M_val;
_Constant_void_fun(const result_type& __v) : _M_val(__v) {}
const result_type& operator()() const { return _M_val; }
};
template <class _Result>
struct constant_void_fun : public _Constant_void_fun<_Result> {
constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
};
template <class _Result, __DFL_TMPL_PARAM( _Argument , _Result) >
struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
{
constant_unary_fun(const _Result& __v)
: _Constant_unary_fun<_Result, _Argument>(__v) {}
};
template <class _Result, __DFL_TMPL_PARAM( _Arg1 , _Result), __DFL_TMPL_PARAM( _Arg2 , _Arg1) >
struct constant_binary_fun
: public _Constant_binary_fun<_Result, _Arg1, _Arg2>
{
constant_binary_fun(const _Result& __v)
: _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
};
template <class _Result>
inline constant_void_fun<_Result> constant0(const _Result& __val)
{
return constant_void_fun<_Result>(__val);
}
template <class _Result>
inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
{
return constant_unary_fun<_Result,_Result>(__val);
}
template <class _Result>
inline constant_binary_fun<_Result,_Result,_Result>
constant2(const _Result& __val)
{
return constant_binary_fun<_Result,_Result,_Result>(__val);
}
// subtractive_rng is an extension: it is not part of the standard.
// Note: this code assumes that int is 32 bits.
class subtractive_rng : public unary_function<_STLP_UINT32_T, _STLP_UINT32_T> {
private:
_STLP_UINT32_T _M_table[55];
_STLP_UINT32_T _M_index1;
_STLP_UINT32_T _M_index2;
public:
_STLP_UINT32_T operator()(_STLP_UINT32_T __limit) {
_M_index1 = (_M_index1 + 1) % 55;
_M_index2 = (_M_index2 + 1) % 55;
_M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
return _M_table[_M_index1] % __limit;
}
void _M_initialize(_STLP_UINT32_T __seed)
{
_STLP_UINT32_T __k = 1;
_M_table[54] = __seed;
_STLP_UINT32_T __i;
for (__i = 0; __i < 54; __i++) {
_STLP_UINT32_T __ii = (21 * (__i + 1) % 55) - 1;
_M_table[__ii] = __k;
__k = __seed - __k;
__seed = _M_table[__ii];
}
for (int __loop = 0; __loop < 4; __loop++) {
for (__i = 0; __i < 55; __i++)
_M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
}
_M_index1 = 0;
_M_index2 = 31;
}
subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
subtractive_rng() { _M_initialize(161803398ul); }
};
# endif /* _STLP_NO_EXTENSIONS */
_STLP_END_NAMESPACE
#include <stl/_function_adaptors.h>
#endif /* _STLP_INTERNAL_FUNCTION_H */
// Local Variables:
// mode:C++
// End:
+802
View File
@@ -0,0 +1,802 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* Copyright (c) 2000
* Pavel Kuznetsov
*
* Copyright (c) 2001
* Meridian'93
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
// This file has noo macro protection as it is meant to be included several times
// from other header.
// Adaptor function objects: pointers to member functions.
// There are a total of 16 = 2^4 function objects in this family.
// (1) Member functions taking no arguments vs member functions taking
// one argument.
// (2) Call through pointer vs call through reference.
// (3) Member function with void return type vs member function with
// non-void return type.
// (4) Const vs non-const member function.
// Note that choice (3) is nothing more than a workaround: according
// to the draft, compilers should handle void and non-void the same way.
// This feature is not yet widely implemented, though. You can only use
// member functions returning void if your compiler supports partial
// specialization.
// All of this complexity is in the function objects themselves. You can
// ignore it by using the helper function mem_fun and mem_fun_ref,
// which create whichever type of adaptor is appropriate.
_STLP_BEGIN_NAMESPACE
//This implementation will only be used if needed, that is to say when there is the return void bug
//and when there is no partial template specialization
#if defined(_STLP_DONT_RETURN_VOID) && defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) && defined(_STLP_MEMBER_TEMPLATE_CLASSES)
template<class _Result, class _Tp>
class _Mem_fun0_ptr : public unary_function<_Tp*, _Result> {
protected:
typedef _Result (_Tp::*__fun_type) ();
explicit _Mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(_Tp* __p) const { return (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp, class _Arg>
class _Mem_fun1_ptr : public binary_function<_Tp*,_Arg,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) (_Arg);
explicit _Mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp>
class _Const_mem_fun0_ptr : public unary_function<const _Tp*,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) () const;
explicit _Const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(const _Tp* __p) const { return (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp, class _Arg>
class _Const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) (_Arg) const;
explicit _Const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(const _Tp* __p, _Arg __x) const {
return (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp>
class _Mem_fun0_ref : public unary_function<_Tp&,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) ();
explicit _Mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(_Tp& __p) const { return (__p.*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp, class _Arg>
class _Mem_fun1_ref : public binary_function<_Tp&,_Arg,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) (_Arg);
explicit _Mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(_Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp>
class _Const_mem_fun0_ref : public unary_function<const _Tp&,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) () const;
explicit _Const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(const _Tp& __p) const { return (__p.*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Result, class _Tp, class _Arg>
class _Const_mem_fun1_ref : public binary_function<const _Tp&,_Arg,_Result> {
protected:
typedef _Result (_Tp::*__fun_type) (_Arg) const;
explicit _Const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
public:
_Result operator ()(const _Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Result>
struct _Mem_fun_traits {
template<class _Tp>
struct _Args0 {
typedef _Mem_fun0_ptr<_Result,_Tp> _Ptr;
typedef _Const_mem_fun0_ptr<_Result,_Tp> _Ptr_const;
typedef _Mem_fun0_ref<_Result,_Tp> _Ref;
typedef _Const_mem_fun0_ref<_Result,_Tp> _Ref_const;
};
template<class _Tp, class _Arg>
struct _Args1 {
typedef _Mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr;
typedef _Const_mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr_const;
typedef _Mem_fun1_ref<_Result,_Tp,_Arg> _Ref;
typedef _Const_mem_fun1_ref<_Result,_Tp,_Arg> _Ref_const;
};
};
template<class _Arg, class _Result>
class _Ptr_fun1_base : public unary_function<_Arg, _Result> {
protected:
typedef _Result (*__fun_type) (_Arg);
explicit _Ptr_fun1_base(__fun_type __f) : _M_f(__f) {}
public:
_Result operator()(_Arg __x) const { return _M_f(__x); }
private:
__fun_type _M_f;
};
template <class _Arg1, class _Arg2, class _Result>
class _Ptr_fun2_base : public binary_function<_Arg1,_Arg2,_Result> {
protected:
typedef _Result (*__fun_type) (_Arg1, _Arg2);
explicit _Ptr_fun2_base(__fun_type __f) : _M_f(__f) {}
public:
_Result operator()(_Arg1 __x, _Arg2 __y) const { return _M_f(__x, __y); }
private:
__fun_type _M_f;
};
template<class _Result>
struct _Ptr_fun_traits {
template<class _Arg> struct _Args1 {
typedef _Ptr_fun1_base<_Arg,_Result> _Fun;
};
template<class _Arg1, class _Arg2> struct _Args2 {
typedef _Ptr_fun2_base<_Arg1,_Arg2,_Result> _Fun;
};
};
/*Specialization for void return type
*/
template<class _Tp>
class _Void_mem_fun0_ptr : public unary_function<_Tp*,void> {
protected:
typedef void (_Tp::*__fun_type) ();
explicit _Void_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(_Tp* __p) const { (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Tp, class _Arg>
class _Void_mem_fun1_ptr : public binary_function<_Tp*,_Arg,void> {
protected:
typedef void (_Tp::*__fun_type) (_Arg);
explicit _Void_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Tp>
class _Void_const_mem_fun0_ptr : public unary_function<const _Tp*,void> {
protected:
typedef void (_Tp::*__fun_type) () const;
explicit _Void_const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(const _Tp* __p) const { (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Tp, class _Arg>
class _Void_const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,void> {
protected:
typedef void (_Tp::*__fun_type) (_Arg) const;
explicit _Void_const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Tp>
class _Void_mem_fun0_ref : public unary_function<_Tp&,void> {
protected:
typedef void (_Tp::*__fun_type) ();
explicit _Void_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(_Tp& __p) const { (__p.*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Tp, class _Arg>
class _Void_mem_fun1_ref : public binary_function<_Tp&,_Arg,void> {
protected:
typedef void (_Tp::*__fun_type) (_Arg);
explicit _Void_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(_Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template<class _Tp>
class _Void_const_mem_fun0_ref : public unary_function<const _Tp&,void> {
protected:
typedef void (_Tp::*__fun_type) () const;
explicit _Void_const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(const _Tp& __p) const { (__p.*_M_f)(); }
private:
__fun_type _M_f;
};
template<class _Tp, class _Arg>
class _Void_const_mem_fun1_ref : public binary_function<const _Tp&,_Arg,void> {
protected:
typedef void (_Tp::*__fun_type) (_Arg) const;
explicit _Void_const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {}
public:
void operator ()(const _Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); }
private:
__fun_type _M_f;
};
_STLP_TEMPLATE_NULL
struct _Mem_fun_traits<void> {
template<class _Tp> struct _Args0 {
typedef _Void_mem_fun0_ptr<_Tp> _Ptr;
typedef _Void_const_mem_fun0_ptr<_Tp> _Ptr_const;
typedef _Void_mem_fun0_ref<_Tp> _Ref;
typedef _Void_const_mem_fun0_ref<_Tp> _Ref_const;
};
template<class _Tp, class _Arg> struct _Args1 {
typedef _Void_mem_fun1_ptr<_Tp,_Arg> _Ptr;
typedef _Void_const_mem_fun1_ptr<_Tp,_Arg> _Ptr_const;
typedef _Void_mem_fun1_ref<_Tp,_Arg> _Ref;
typedef _Void_const_mem_fun1_ref<_Tp,_Arg> _Ref_const;
};
};
template<class _Arg>
class _Ptr_void_fun1_base : public unary_function<_Arg, void> {
protected:
typedef void (*__fun_type) (_Arg);
explicit _Ptr_void_fun1_base(__fun_type __f) : _M_f(__f) {}
public:
void operator()(_Arg __x) const { _M_f(__x); }
private:
__fun_type _M_f;
};
template <class _Arg1, class _Arg2>
class _Ptr_void_fun2_base : public binary_function<_Arg1,_Arg2,void> {
protected:
typedef void (*__fun_type) (_Arg1, _Arg2);
explicit _Ptr_void_fun2_base(__fun_type __f) : _M_f(__f) {}
public:
void operator()(_Arg1 __x, _Arg2 __y) const { _M_f(__x, __y); }
private:
__fun_type _M_f;
};
_STLP_TEMPLATE_NULL
struct _Ptr_fun_traits<void> {
template<class _Arg> struct _Args1 {
typedef _Ptr_void_fun1_base<_Arg> _Fun;
};
template<class _Arg1, class _Arg2> struct _Args2 {
typedef _Ptr_void_fun2_base<_Arg1,_Arg2> _Fun;
};
};
// pavel: need extra level of inheritance here since MSVC++ does not
// accept traits-based fake partial specialization for template
// arguments other than first
template<class _Result, class _Arg>
class _Ptr_fun1 :
public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun {
protected:
typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun _Base;
explicit _Ptr_fun1(typename _Base::__fun_type __f) : _Base(__f) {}
};
template<class _Result, class _Arg1, class _Arg2>
class _Ptr_fun2 :
public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun {
protected:
typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun _Base;
explicit _Ptr_fun2(typename _Base::__fun_type __f) : _Base(__f) {}
};
#endif /*_STLP_DONT_RETURN_VOID && _STLP_NO_CLASS_PARTIAL_SPECIALIZATION && _STLP_MEMBER_TEMPLATE_CLASSES*/
#if !defined(_STLP_DONT_RETURN_VOID) || !defined(_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) || !defined (_STLP_MEMBER_TEMPLATE_CLASSES)
template <class _Ret, class _Tp>
class mem_fun_t : public unary_function<_Tp*,_Ret> {
typedef _Ret (_Tp::*__fun_type)(void);
public:
explicit mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp>
class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
typedef _Ret (_Tp::*__fun_type)(void) const;
public:
explicit const_mem_fun_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp>
class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
typedef _Ret (_Tp::*__fun_type)(void);
public:
explicit mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp>
class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
typedef _Ret (_Tp::*__fun_type)(void) const;
public:
explicit const_mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
typedef _Ret (_Tp::*__fun_type)(_Arg);
public:
explicit mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
typedef _Ret (_Tp::*__fun_type)(_Arg) const;
public:
explicit const_mem_fun1_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(const _Tp* __p, _Arg __x) const
{ return (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
typedef _Ret (_Tp::*__fun_type)(_Arg);
public:
explicit mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
typedef _Ret (_Tp::*__fun_type)(_Arg) const;
public:
explicit const_mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {}
_Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Arg, class _Result>
class pointer_to_unary_function : public unary_function<_Arg, _Result> {
protected:
_Result (*_M_ptr)(_Arg);
public:
pointer_to_unary_function() {}
explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
_Result operator()(_Arg __x) const { return _M_ptr(__x); }
};
template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
public binary_function<_Arg1,_Arg2,_Result> {
protected:
_Result (*_M_ptr)(_Arg1, _Arg2);
public:
pointer_to_binary_function() {}
explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
: _M_ptr(__x) {}
_Result operator()(_Arg1 __x, _Arg2 __y) const {
return _M_ptr(__x, __y);
}
};
#if defined(_STLP_DONT_RETURN_VOID) && !defined(_STLP_NO_CLASS_PARTIAL_SPECIALIZATION)
//Partial specialization for the void type
template <class _Tp>
class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
typedef void (_Tp::*__fun_type)(void);
public:
explicit mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
void operator()(_Tp* __p) const { (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Tp>
class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
typedef void (_Tp::*__fun_type)(void) const;
public:
explicit const_mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Tp>
class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
typedef void (_Tp::*__fun_type)(void);
public:
explicit mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
void operator()(_Tp& __r) const { (__r.*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Tp>
class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
typedef void (_Tp::*__fun_type)(void) const;
public:
explicit const_mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {}
void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
private:
__fun_type _M_f;
};
template <class _Tp, class _Arg>
class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
typedef void (_Tp::*__fun_type)(_Arg);
public:
explicit mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Tp, class _Arg>
class const_mem_fun1_t<void, _Tp, _Arg>
: public binary_function<const _Tp*,_Arg,void> {
typedef void (_Tp::*__fun_type)(_Arg) const;
public:
explicit const_mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Tp, class _Arg>
class mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp,_Arg,void> {
typedef void (_Tp::*__fun_type)(_Arg);
public:
explicit mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Tp, class _Arg>
class const_mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp,_Arg,void> {
typedef void (_Tp::*__fun_type)(_Arg) const;
public:
explicit const_mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {}
void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
__fun_type _M_f;
};
template <class _Arg>
class pointer_to_unary_function : public unary_function<_Arg, void> {
typedef void (*__fun_type)(_Arg);
__fun_type _M_ptr;
public:
pointer_to_unary_function() {}
explicit pointer_to_unary_function(__fun_type __x) : _M_ptr(__x) {}
void operator()(_Arg __x) const { _M_ptr(__x); }
};
template <class _Arg1, class _Arg2>
class pointer_to_binary_function : public binary_function<_Arg1,_Arg2,void> {
typedef void (*__fun_type)(_Arg1, _Arg2);
__fun_type _M_ptr;
public:
pointer_to_binary_function() {}
explicit pointer_to_binary_function(__fun_type __x) : _M_ptr(__x) {}
void operator()(_Arg1 __x, _Arg2 __y) const { _M_ptr(__x, __y); }
};
#endif /*_STLP_DONT_RETURN_VOID && !_STLP_NO_CLASS_PARTIAL_SPECIALIZATION*/
#else /*!_STLP_DONT_RETURN_VOID || !_STLP_NO_CLASS_PARTIAL_SPECIALIZATION || !_STLP_MEMBER_TEMPLATE_CLASSES*/
//mem_fun_t
template <class _Result, class _Tp>
class mem_fun_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr _Base;
public:
explicit mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//const_mem_fun_t
template <class _Result, class _Tp>
class const_mem_fun_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const _Base;
public:
explicit const_mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//mem_fun_ref_t
template <class _Result, class _Tp>
class mem_fun_ref_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref _Base;
public:
explicit mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//const_mem_fun_ref_t
template <class _Result, class _Tp>
class const_mem_fun_ref_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const _Base;
public:
explicit const_mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//mem_fun1_t
template <class _Result, class _Tp, class _Arg>
class mem_fun1_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr _Base;
public:
explicit mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//const_mem_fun1_t
template <class _Result, class _Tp, class _Arg>
class const_mem_fun1_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const _Base;
public:
explicit const_mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//mem_fun1_ref_t
template <class _Result, class _Tp, class _Arg>
class mem_fun1_ref_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref _Base;
public:
explicit mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
//const_mem_fun1_t
template <class _Result, class _Tp, class _Arg>
class const_mem_fun1_ref_t :
public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const {
typedef typename
_Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const _Base;
public:
explicit const_mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {}
};
template <class _Arg, class _Result>
class pointer_to_unary_function :
public _Ptr_fun1<_Result,_Arg> {
typedef typename
_Ptr_fun1<_Result,_Arg>::__fun_type __fun_type;
public:
explicit pointer_to_unary_function(__fun_type __f)
: _Ptr_fun1<_Result,_Arg>(__f) {}
};
template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
public _Ptr_fun2<_Result,_Arg1,_Arg2> {
typedef typename
_Ptr_fun2<_Result,_Arg1,_Arg2>::__fun_type __fun_type;
public:
explicit pointer_to_binary_function(__fun_type __f)
: _Ptr_fun2<_Result,_Arg1,_Arg2>(__f) {}
};
#endif /*!_STLP_DONT_RETURN_VOID || !_STLP_NO_CLASS_PARTIAL_SPECIALIZATION || !_STLP_MEMBER_TEMPLATE_CLASSES*/
# if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
// Mem_fun adaptor helper functions. There are only two:
// mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref
// are provided for backward compatibility, but they are no longer
// part of the C++ standard.)
template <class _Result, class _Tp>
inline mem_fun_t<_Result,_Tp>
mem_fun(_Result (_Tp::*__f)()) { return mem_fun_t<_Result,_Tp>(__f); }
template <class _Result, class _Tp>
inline const_mem_fun_t<_Result,_Tp>
mem_fun(_Result (_Tp::*__f)() const) { return const_mem_fun_t<_Result,_Tp>(__f); }
template <class _Result, class _Tp>
inline mem_fun_ref_t<_Result,_Tp>
mem_fun_ref(_Result (_Tp::*__f)()) { return mem_fun_ref_t<_Result,_Tp>(__f); }
template <class _Result, class _Tp>
inline const_mem_fun_ref_t<_Result,_Tp>
mem_fun_ref(_Result (_Tp::*__f)() const) { return const_mem_fun_ref_t<_Result,_Tp>(__f); }
template <class _Result, class _Tp, class _Arg>
inline mem_fun1_t<_Result,_Tp,_Arg>
mem_fun(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_t<_Result,_Tp,_Arg>
mem_fun(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
# if !(defined (_STLP_NO_EXTENSIONS) || defined (_STLP_NO_ANACHRONISMS))
// mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
// but they are provided for backward compatibility.
template <class _Result, class _Tp, class _Arg>
inline mem_fun1_t<_Result,_Tp,_Arg>
mem_fun1(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_t<_Result,_Tp,_Arg>
mem_fun1(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun1_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
template <class _Result, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Result,_Tp,_Arg>
mem_fun1_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); }
# endif /* _STLP_NO_EXTENSIONS */
# endif /* _STLP_MEMBER_POINTER_PARAM_BUG */
template <class _Arg, class _Result>
inline pointer_to_unary_function<_Arg, _Result>
ptr_fun(_Result (*__f)(_Arg))
{ return pointer_to_unary_function<_Arg, _Result>(__f); }
template <class _Arg1, class _Arg2, class _Result>
inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
ptr_fun(_Result (*__f)(_Arg1, _Arg2))
{ return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f); }
_STLP_END_NAMESPACE
+226
View File
@@ -0,0 +1,226 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
#define _STLP_INTERNAL_FUNCTION_BASE_H
#ifndef _STLP_CONFIG_H
#include <stl/_config.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _Arg, class _Result>
struct unary_function {
typedef _Arg argument_type;
typedef _Result result_type;
};
template <class _Arg1, class _Arg2, class _Result>
struct binary_function {
typedef _Arg1 first_argument_type;
typedef _Arg2 second_argument_type;
typedef _Result result_type;
};
template <class _Tp>
struct equal_to : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
};
template <class _Tp>
struct not_equal_to : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
};
template <class _Tp>
struct greater : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
};
template <class _Tp>
struct less : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
};
template <class _Tp>
struct greater_equal : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
};
template <class _Tp>
struct less_equal : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
};
template <class _Tp>
less<_Tp> __less(_Tp* ) { return less<_Tp>(); }
template <class _Tp>
equal_to<_Tp> __equal_to(_Tp* ) { return equal_to<_Tp>(); }
template <class _Tp>
struct plus : public binary_function<_Tp,_Tp,_Tp> {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
};
template <class _Tp>
struct minus : public binary_function<_Tp,_Tp,_Tp> {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
};
template <class _Tp>
plus<_Tp> __plus(_Tp* ) { return plus<_Tp>(); }
template <class _Tp>
minus<_Tp> __minus(_Tp* ) { return minus<_Tp>(); }
template <class _Tp>
struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
};
template <class _Tp>
struct divides : public binary_function<_Tp,_Tp,_Tp> {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
};
template <class _Tp>
struct modulus : public binary_function<_Tp,_Tp,_Tp>
{
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
};
template <class _Tp>
struct negate : public unary_function<_Tp,_Tp>
{
_Tp operator()(const _Tp& __x) const { return -__x; }
};
template <class _Tp>
struct logical_and : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
};
template <class _Tp>
struct logical_or : public binary_function<_Tp,_Tp,bool>
{
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
};
template <class _Tp>
struct logical_not : public unary_function<_Tp,bool>
{
bool operator()(const _Tp& __x) const { return !__x; }
};
template <class _Pair>
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
const typename _Pair::first_type& operator()(const _Pair& __x) const {
return __x.first;
}
};
template <class _Pair>
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
{
const typename _Pair::second_type& operator()(const _Pair& __x) const {
return __x.second;
}
};
// project1st and project2nd are extensions: they are not part of the standard
template <class _Arg1, class _Arg2>
struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
_Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
};
template <class _Arg1, class _Arg2>
struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
_Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
};
#ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
// fbp : sort of select1st just for maps
template <class _Pair, class _Whatever>
// JDJ (CW Pro1 doesn't like const when first_type is also const)
struct __Select1st_hint : public unary_function<_Pair, _Whatever> {
const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
};
# define _STLP_SELECT1ST(__x,__y) __Select1st_hint< __x, __y >
# else
# define _STLP_SELECT1ST(__x, __y) _Select1st< __x >
# endif
template <class _Tp>
struct _Identity : public unary_function<_Tp,_Tp> {
const _Tp& operator()(const _Tp& __x) const { return __x; }
};
template <class _Result, class _Argument>
struct _Constant_unary_fun {
typedef _Argument argument_type;
typedef _Result result_type;
result_type _M_val;
_Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
const result_type& operator()(const _Argument&) const { return _M_val; }
};
template <class _Result, class _Arg1, class _Arg2>
struct _Constant_binary_fun {
typedef _Arg1 first_argument_type;
typedef _Arg2 second_argument_type;
typedef _Result result_type;
_Result _M_val;
_Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
const result_type& operator()(const _Arg1&, const _Arg2&) const {
return _M_val;
}
};
// identity_element (not part of the C++ standard).
template <class _Tp> inline _Tp __identity_element(plus<_Tp>) { return _Tp(0); }
template <class _Tp> inline _Tp __identity_element(multiplies<_Tp>) { return _Tp(1); }
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_FUNCTION_BASE_H */
// Local Variables:
// mode:C++
// End:
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_HASH_FUN_H
#define _STLP_HASH_FUN_H
# ifndef _STLP_CSTDDEF
# include <cstddef>
# endif
_STLP_BEGIN_NAMESPACE
template <class _Key> struct hash { };
inline size_t __stl_hash_string(const char* __s)
{
_STLP_FIX_LITERAL_BUG(__s)
unsigned long __h = 0;
for ( ; *__s; ++__s)
__h = 5*__h + *__s;
return size_t(__h);
}
_STLP_TEMPLATE_NULL struct hash<char*>
{
size_t operator()(const char* __s) const { _STLP_FIX_LITERAL_BUG(__s) return __stl_hash_string(__s); }
};
_STLP_TEMPLATE_NULL struct hash<const char*>
{
size_t operator()(const char* __s) const { _STLP_FIX_LITERAL_BUG(__s) return __stl_hash_string(__s); }
};
_STLP_TEMPLATE_NULL struct hash<char> {
size_t operator()(char __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<unsigned char> {
size_t operator()(unsigned char __x) const { return __x; }
};
#ifndef _STLP_NO_SIGNED_BUILTINS
_STLP_TEMPLATE_NULL struct hash<signed char> {
size_t operator()(unsigned char __x) const { return __x; }
};
#endif
_STLP_TEMPLATE_NULL struct hash<short> {
size_t operator()(short __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<unsigned short> {
size_t operator()(unsigned short __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<int> {
size_t operator()(int __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<unsigned int> {
size_t operator()(unsigned int __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<long> {
size_t operator()(long __x) const { return __x; }
};
_STLP_TEMPLATE_NULL struct hash<unsigned long> {
size_t operator()(unsigned long __x) const { return __x; }
};
# if defined (_STLP_LONG_LONG)
_STLP_TEMPLATE_NULL struct hash<_STLP_LONG_LONG> {
size_t operator()(long x) const { return x; }
};
_STLP_TEMPLATE_NULL struct hash<unsigned _STLP_LONG_LONG> {
size_t operator()(unsigned long x) const { return x; }
};
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_HASH_FUN_H */
// Local Variables:
// mode:C++
// End:
+468
View File
@@ -0,0 +1,468 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_HASH_MAP_H
#define _STLP_INTERNAL_HASH_MAP_H
#ifndef _STLP_INTERNAL_HASHTABLE_H
# include <stl/_hashtable.h>
#endif
_STLP_BEGIN_NAMESPACE
# define hash_map __WORKAROUND_RENAME(hash_map)
# define hash_multimap __WORKAROUND_RENAME(hash_multimap)
# define _STLP_KEY_PAIR pair< const _Key, _Tp >
# define _STLP_HASHTABLE hashtable \
< pair < const _Key, _Tp >, _Key, _HashFcn, \
_STLP_SELECT1ST( _STLP_KEY_PAIR, _Key ), _EqualKey, _Alloc >
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
class hash_map
{
private:
typedef _STLP_HASHTABLE _Ht;
typedef hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
public:
typedef typename _Ht::key_type key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef typename _Ht::value_type _value_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename _Ht::iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
private:
_Ht _M_ht;
public:
hash_map() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_map(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_map(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_map(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql)
: _M_ht(__n, __hf, __eql, allocator_type())
{ _M_ht.insert_unique(__f, __l); }
# endif
template <class _InputIterator>
hash_map(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#else
hash_map(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_map(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
public:
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
iterator begin() { return _M_ht.begin(); }
iterator end() { return _M_ht.end(); }
const_iterator begin() const { return _M_ht.begin(); }
const_iterator end() const { return _M_ht.end(); }
public:
pair<iterator,bool> insert(const value_type& __obj)
{ return _M_ht.insert_unique(__obj); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_unique(__f,__l); }
#else
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_unique(__f,__l);
}
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_unique(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
pair<iterator,bool> insert_noresize(const value_type& __obj)
{ return _M_ht.insert_unique_noresize(__obj); }
iterator find(const key_type& __key) { return _M_ht.find(__key); }
const_iterator find(const key_type& __key) const { return _M_ht.find(__key); }
_Tp& operator[](const key_type& __key) {
iterator __it = _M_ht.find(__key);
return (__it == _M_ht.end() ?
_M_ht._M_insert(_value_type(__key, _Tp())).second :
(*__it).second );
}
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& __key)
{ return _M_ht.equal_range(__key); }
pair<const_iterator, const_iterator>
equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
}
};
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_HashFcn,hash<_Key>),
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Key>),
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
class hash_multimap
{
private:
typedef _STLP_HASHTABLE _Ht;
typedef hash_multimap<_Key, _Tp, _HashFcn, _EqualKey, _Alloc> _Self;
public:
typedef typename _Ht::key_type key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef typename _Ht::value_type _value_type;
typedef _value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename _Ht::iterator iterator;
typedef typename _Ht::const_iterator const_iterator;
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
private:
_Ht _M_ht;
public:
hash_multimap() : _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_multimap(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_multimap(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_multimap(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql)
: _M_ht(__n, __hf, __eql, allocator_type())
{ _M_ht.insert_equal(__f, __l); }
# endif
template <class _InputIterator>
hash_multimap(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#else
hash_multimap(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multimap(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
public:
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
iterator begin() { return _M_ht.begin(); }
iterator end() { return _M_ht.end(); }
const_iterator begin() const { return _M_ht.begin(); }
const_iterator end() const { return _M_ht.end(); }
public:
iterator insert(const value_type& __obj)
{ return _M_ht.insert_equal(__obj); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_equal(__f,__l); }
#else
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_equal(__f,__l);
}
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_equal(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
iterator insert_noresize(const value_type& __obj)
{ return _M_ht.insert_equal_noresize(__obj); }
iterator find(const key_type& __key) { return _M_ht.find(__key); }
const_iterator find(const key_type& __key) const
{ return _M_ht.find(__key); }
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& __key)
{ return _M_ht.equal_range(__key); }
pair<const_iterator, const_iterator>
equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
}
};
#define _STLP_TEMPLATE_HEADER template <class _Key, class _Tp, class _HashFcn, class _EqlKey, class _Alloc>
#define _STLP_TEMPLATE_CONTAINER hash_map<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
#include <stl/_relops_hash_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#define _STLP_TEMPLATE_CONTAINER hash_multimap<_Key,_Tp,_HashFcn,_EqlKey,_Alloc>
#include <stl/_relops_hash_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#undef _STLP_TEMPLATE_HEADER
// Specialization of insert_iterator so that it will work for hash_map
// and hash_multimap.
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
class insert_iterator<hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
protected:
typedef hash_map<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(_Container& __x) : container(&__x) {}
insert_iterator(_Container& __x, typename _Container::iterator)
: container(&__x) {}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->insert(__val);
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
template <class _Key, class _Tp, class _HashFn, class _EqKey, class _Alloc>
class insert_iterator<hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> > {
protected:
typedef hash_multimap<_Key, _Tp, _HashFn, _EqKey, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(_Container& __x) : container(&__x) {}
insert_iterator(_Container& __x, typename _Container::iterator)
: container(&__x) {}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->insert(__val);
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
// do a cleanup
# undef hash_map
# undef hash_multimap
# define __hash_map__ __FULL_NAME(hash_map)
# define __hash_multimap__ __FULL_NAME(hash_multimap)
_STLP_END_NAMESPACE
# if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
# include <stl/wrappers/_hash_map.h>
# endif /* WRAPPER */
#endif /* _STLP_INTERNAL_HASH_MAP_H */
// Local Variables:
// mode:C++
// End:
+470
View File
@@ -0,0 +1,470 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_HASH_SET_H
#define _STLP_INTERNAL_HASH_SET_H
#ifndef _STLP_INTERNAL_HASHTABLE_H
# include <stl/_hashtable.h>
#endif
# define hash_set __WORKAROUND_RENAME(hash_set)
# define hash_multiset __WORKAROUND_RENAME(hash_multiset)
_STLP_BEGIN_NAMESPACE
template <class _Value, __DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
class hash_set
{
private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht;
typedef hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
typedef typename _Ht::iterator _ht_iterator;
public:
typedef typename _Ht::key_type key_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
// SunPro bug
typedef typename _Ht::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
private:
_Ht _M_ht;
public:
hash_set()
: _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_set(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_set(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_set(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql)
: _M_ht(__n, __hf, __eql, allocator_type())
{ _M_ht.insert_unique(__f, __l); }
# endif
template <class _InputIterator>
hash_set(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#else
hash_set(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_unique(__f, __l); }
hash_set(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_unique(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
public:
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(_Self& __hs) { _M_ht.swap(__hs._M_ht); }
iterator begin() const { return _M_ht.begin(); }
iterator end() const { return _M_ht.end(); }
public:
pair<iterator, bool> insert(const value_type& __obj)
{
pair<_ht_iterator, bool> __p = _M_ht.insert_unique(__obj);
return pair<iterator,bool>(__REINTERPRET_CAST(const iterator&, __p.first), __p.second);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_unique(__f,__l); }
#else
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_unique(__f,__l);
}
void insert(const_iterator __f, const_iterator __l)
{_M_ht.insert_unique(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
pair<iterator, bool> insert_noresize(const value_type& __obj)
{
pair<_ht_iterator, bool> __p =
_M_ht.insert_unique_noresize(__obj);
return pair<iterator, bool>(__p.first, __p.second);
}
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __key) const { return _M_ht.find(__key); }
# else
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
# endif
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
}
};
template <class _Value, __DFL_TMPL_PARAM(_HashFcn,hash<_Value>),
__DFL_TMPL_PARAM(_EqualKey,equal_to<_Value>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Value) >
class hash_multiset
{
private:
typedef hashtable<_Value, _Value, _HashFcn, _Identity<_Value>,
_EqualKey, _Alloc> _Ht;
typedef hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Self;
public:
typedef typename _Ht::key_type key_type;
typedef typename _Ht::value_type value_type;
typedef typename _Ht::hasher hasher;
typedef typename _Ht::key_equal key_equal;
typedef typename _Ht::size_type size_type;
typedef typename _Ht::difference_type difference_type;
typedef typename _Ht::pointer pointer;
typedef typename _Ht::const_pointer const_pointer;
typedef typename _Ht::reference reference;
typedef typename _Ht::const_reference const_reference;
typedef typename _Ht::const_iterator const_iterator;
// SunPro bug
typedef const_iterator iterator;
typedef typename _Ht::allocator_type allocator_type;
hasher hash_funct() const { return _M_ht.hash_funct(); }
key_equal key_eq() const { return _M_ht.key_eq(); }
allocator_type get_allocator() const { return _M_ht.get_allocator(); }
private:
_Ht _M_ht;
public:
hash_multiset()
: _M_ht(100, hasher(), key_equal(), allocator_type()) {}
explicit hash_multiset(size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type()) {}
hash_multiset(size_type __n, const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type()) {}
hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql)
: _M_ht(__n, __hf, __eql, allocator_type()) {}
hash_multiset(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a)
: _M_ht(__n, __hf, __eql, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql)
: _M_ht(__n, __hf, __eql, allocator_type())
{ _M_ht.insert_equal(__f, __l); }
# endif
template <class _InputIterator>
hash_multiset(_InputIterator __f, _InputIterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#else
hash_multiset(const value_type* __f, const value_type* __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const value_type* __f, const value_type* __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l)
: _M_ht(100, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n)
: _M_ht(__n, hasher(), key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf)
: _M_ht(__n, __hf, key_equal(), allocator_type())
{ _M_ht.insert_equal(__f, __l); }
hash_multiset(const_iterator __f, const_iterator __l, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a = allocator_type())
: _M_ht(__n, __hf, __eql, __a)
{ _M_ht.insert_equal(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
public:
size_type size() const { return _M_ht.size(); }
size_type max_size() const { return _M_ht.max_size(); }
bool empty() const { return _M_ht.empty(); }
void swap(_Self& hs) { _M_ht.swap(hs._M_ht); }
iterator begin() const { return _M_ht.begin(); }
iterator end() const { return _M_ht.end(); }
public:
iterator insert(const value_type& __obj)
{ return _M_ht.insert_equal(__obj); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __f, _InputIterator __l)
{ _M_ht.insert_equal(__f,__l); }
#else
void insert(const value_type* __f, const value_type* __l) {
_M_ht.insert_equal(__f,__l);
}
void insert(const_iterator __f, const_iterator __l)
{ _M_ht.insert_equal(__f, __l); }
#endif /*_STLP_MEMBER_TEMPLATES */
iterator insert_noresize(const value_type& __obj)
{ return _M_ht.insert_equal_noresize(__obj); }
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __key) const { return _M_ht.find(__key); }
# else
iterator find(const key_type& __key) const { return _M_ht.find(__key); }
# endif
size_type count(const key_type& __key) const { return _M_ht.count(__key); }
pair<iterator, iterator> equal_range(const key_type& __key) const
{ return _M_ht.equal_range(__key); }
size_type erase(const key_type& __key) {return _M_ht.erase(__key); }
void erase(iterator __it) { _M_ht.erase(__it); }
void erase(iterator __f, iterator __l) { _M_ht.erase(__f, __l); }
void clear() { _M_ht.clear(); }
public:
void resize(size_type __hint) { _M_ht.resize(__hint); }
size_type bucket_count() const { return _M_ht.bucket_count(); }
size_type max_bucket_count() const { return _M_ht.max_bucket_count(); }
size_type elems_in_bucket(size_type __n) const
{ return _M_ht.elems_in_bucket(__n); }
static bool _STLP_CALL _M_equal (const _Self& __x, const _Self& __y) {
return _Ht::_M_equal(__x._M_ht,__y._M_ht);
}
};
#define _STLP_TEMPLATE_HEADER template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
#define _STLP_TEMPLATE_CONTAINER hash_set<_Value,_HashFcn,_EqualKey,_Alloc>
#include <stl/_relops_hash_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#define _STLP_TEMPLATE_CONTAINER hash_multiset<_Value,_HashFcn,_EqualKey,_Alloc>
#include <stl/_relops_hash_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#undef _STLP_TEMPLATE_HEADER
// Specialization of insert_iterator so that it will work for hash_set
// and hash_multiset.
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class insert_iterator<hash_set<_Value, _HashFcn, _EqualKey, _Alloc> > {
protected:
typedef hash_set<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
_Container* container;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(_Container& __x) : container(&__x) {}
insert_iterator(_Container& __x, typename _Container::iterator)
: container(&__x) {}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->insert(__val);
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
template <class _Value, class _HashFcn, class _EqualKey, class _Alloc>
class insert_iterator<hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> > {
protected:
typedef hash_multiset<_Value, _HashFcn, _EqualKey, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(_Container& __x) : container(&__x) {}
insert_iterator(_Container& __x, typename _Container::iterator)
: container(&__x) {}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->insert(__val);
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
_STLP_END_NAMESPACE
// do a cleanup
# undef hash_set
# undef hash_multiset
// provide a uniform way to access full funclionality
# define __hash_set__ __FULL_NAME(hash_set)
# define __hash_multiset__ __FULL_NAME(hash_multiset)
# if defined ( _STLP_USE_WRAPPER_FOR_ALLOC_PARAM )
# include <stl/wrappers/_hash_set.h>
# endif /* WRAPPER */
#endif /* _STLP_INTERNAL_HASH_SET_H */
// Local Variables:
// mode:C++
// End:
+468
View File
@@ -0,0 +1,468 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_HASHTABLE_C
#define _STLP_HASHTABLE_C
#ifndef _STLP_INTERNAL_HASHTABLE_H
# include <stl/_hashtable.h>
#endif
#ifdef _STLP_DEBUG
# define hashtable __WORKAROUND_DBG_RENAME(hashtable)
#endif
_STLP_BEGIN_NAMESPACE
# define __PRIME_LIST_BODY { \
53ul, 97ul, 193ul, 389ul, 769ul, \
1543ul, 3079ul, 6151ul, 12289ul, 24593ul, \
49157ul, 98317ul, 196613ul, 393241ul, 786433ul, \
1572869ul, 3145739ul, 6291469ul, 12582917ul, 25165843ul, \
50331653ul, 100663319ul, 201326611ul, 402653189ul, 805306457ul,\
1610612741ul, 3221225473ul, 4294967291ul \
}
#if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template <class _Tp>
const size_t _Stl_prime<_Tp>::_M_list[__stl_num_primes] = __PRIME_LIST_BODY;
#else
__DECLARE_INSTANCE(const size_t,
_Stl_prime_type::_M_list[], =__PRIME_LIST_BODY);
#endif /* _STLP_STATIC_TEMPLATE_DATA */
# undef __PRIME_LIST_BODY
// fbp: these defines are for outline methods definitions.
// needed to definitions to be portable. Should not be used in method bodies.
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
# define __size_type__ size_t
# define size_type size_t
# define value_type _Val
# define key_type _Key
# define _Node _Hashtable_node<_Val>
# define __reference__ _Val&
# define __iterator__ _Ht_iterator<_Val, _Nonconst_traits<_Val>, _Key, _HF, _ExK, _EqK, _All>
# define __const_iterator__ _Ht_iterator<_Val, _Const_traits<_Val>, _Key, _HF, _ExK, _EqK, _All>
# else
# define __size_type__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>::size_type
# define __reference__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>::reference
# define __iterator__ _STLP_TYPENAME_ON_RETURN_TYPE hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>::iterator
# endif
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
class _All>
_Hashtable_node<_Val>*
_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_skip_to_next() {
size_t __bucket = _M_ht->_M_bkt_num(_M_cur->_M_val);
size_t __h_sz;
__h_sz = this->_M_ht->bucket_count();
_Node* __i=0;
while (__i==0 && ++__bucket < __h_sz)
__i = (_Node*)_M_ht->_M_buckets[__bucket];
return __i;
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK,
class _All>
__size_type__
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_next_size(size_type __n) const {
const size_type* __first = (const size_type*)_Stl_prime_type::_M_list;
const size_type* __last = (const size_type*)_Stl_prime_type::_M_list + (int)__stl_num_primes;
const size_type* pos = __lower_bound(__first, __last, __n, __less((size_type*)0), (ptrdiff_t*)0);
return (pos == __last ? *(__last - 1) : *pos);
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
bool
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_equal(
const hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht1,
const hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht2)
{
// typedef _Hashtable_node<_Val> _Node;
if (__ht1.bucket_count() != __ht2.bucket_count())
return false;
for (size_t __n = 0; __n < __ht1.bucket_count(); ++__n) {
const _Node* __cur1 = __ht1._M_get_bucket(__n);
const _Node* __cur2 = __ht2._M_get_bucket(__n);
for ( ; __cur1 && __cur2 && __cur1->_M_val == __cur2->_M_val;
__cur1 = __cur1->_M_next, __cur2 = __cur2->_M_next)
{}
if (__cur1 || __cur2)
return false;
}
return true;
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
pair< _Ht_iterator<_Val, _Nonconst_traits<_Val>, _Key, _HF, _ExK, _EqK, _All> , bool>
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::insert_unique_noresize(const value_type& __obj)
{
const size_type __n = _M_bkt_num(__obj);
_Node* __first = (_Node*)_M_buckets[__n];
for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj)))
return pair<iterator, bool>(iterator(__cur, this), false);
_Node* __tmp = _M_new_node(__obj);
__tmp->_M_next = __first;
_M_buckets[__n] = __tmp;
++_M_num_elements._M_data;
return pair<iterator, bool>(iterator(__tmp, this), true);
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
__iterator__
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::insert_equal_noresize(const value_type& __obj)
{
const size_type __n = _M_bkt_num(__obj);
_Node* __first = (_Node*)_M_buckets[__n];
for (_Node* __cur = __first; __cur; __cur = __cur->_M_next)
if (_M_equals(_M_get_key(__cur->_M_val), _M_get_key(__obj))) {
_Node* __tmp = _M_new_node(__obj);
__tmp->_M_next = __cur->_M_next;
__cur->_M_next = __tmp;
++_M_num_elements._M_data;
return iterator(__tmp, this);
}
_Node* __tmp = _M_new_node(__obj);
__tmp->_M_next = __first;
_M_buckets[__n] = __tmp;
++_M_num_elements._M_data;
return iterator(__tmp, this);
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
__reference__
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_insert(const value_type& __obj)
{
resize(_M_num_elements._M_data + 1);
size_type __n = _M_bkt_num(__obj);
_Node* __first = (_Node*)_M_buckets[__n];
_Node* __tmp = _M_new_node(__obj);
__tmp->_M_next = __first;
_M_buckets[__n] = __tmp;
++_M_num_elements._M_data;
return __tmp->_M_val;
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
__reference__
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::find_or_insert(const value_type& __obj)
{
_Node* __first = _M_find(_M_get_key(__obj));
if (__first)
return __first->_M_val;
else
return _M_insert(__obj);
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
pair< _Ht_iterator<_Val, _Nonconst_traits<_Val>, _Key, _HF, _ExK, _EqK, _All>,
_Ht_iterator<_Val, _Nonconst_traits<_Val>, _Key, _HF, _ExK, _EqK, _All> >
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::equal_range(const key_type& __key)
{
typedef pair<iterator, iterator> _Pii;
const size_type __n = _M_bkt_num_key(__key);
for (_Node* __first = (_Node*)_M_buckets[__n]; __first; __first = __first->_M_next)
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
for (_Node* __cur = __first->_M_next; __cur; __cur = __cur->_M_next)
if (!_M_equals(_M_get_key(__cur->_M_val), __key))
return _Pii(iterator(__first, this), iterator(__cur, this));
for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
if (_M_buckets[__m])
return _Pii(iterator(__first, this),
iterator((_Node*)_M_buckets[__m], this));
return _Pii(iterator(__first, this), end());
}
return _Pii(end(), end());
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
pair< _Ht_iterator<_Val, _Const_traits<_Val>, _Key, _HF, _ExK, _EqK, _All>,
_Ht_iterator<_Val, _Const_traits<_Val>, _Key, _HF, _ExK, _EqK, _All> >
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::equal_range(const key_type& __key) const
{
typedef pair<const_iterator, const_iterator> _Pii;
const size_type __n = _M_bkt_num_key(__key);
for (const _Node* __first = (_Node*)_M_buckets[__n] ;
__first;
__first = __first->_M_next) {
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
for (const _Node* __cur = __first->_M_next;
__cur;
__cur = __cur->_M_next)
if (!_M_equals(_M_get_key(__cur->_M_val), __key))
return _Pii(const_iterator(__first, this),
const_iterator(__cur, this));
for (size_type __m = __n + 1; __m < _M_buckets.size(); ++__m)
if (_M_buckets[__m])
return _Pii(const_iterator(__first, this),
const_iterator((_Node*)_M_buckets[__m], this));
return _Pii(const_iterator(__first, this), end());
}
}
return _Pii(end(), end());
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
__size_type__
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::erase(const key_type& __key)
{
const size_type __n = _M_bkt_num_key(__key);
_Node* __first = (_Node*)_M_buckets[__n];
size_type __erased = 0;
if (__first) {
_Node* __cur = __first;
_Node* __next = __cur->_M_next;
while (__next) {
if (_M_equals(_M_get_key(__next->_M_val), __key)) {
__cur->_M_next = __next->_M_next;
_M_delete_node(__next);
__next = __cur->_M_next;
++__erased;
--_M_num_elements._M_data;
}
else {
__cur = __next;
__next = __cur->_M_next;
}
}
if (_M_equals(_M_get_key(__first->_M_val), __key)) {
_M_buckets[__n] = __first->_M_next;
_M_delete_node(__first);
++__erased;
--_M_num_elements._M_data;
}
}
return __erased;
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::erase(const const_iterator& __it)
{
// const iterator& __it = __REINTERPRET_CAST(const iterator&,_c_it);
const _Node* __p = __it._M_cur;
if (__p) {
const size_type __n = _M_bkt_num(__p->_M_val);
_Node* __cur = (_Node*)_M_buckets[__n];
if (__cur == __p) {
_M_buckets[__n] = __cur->_M_next;
_M_delete_node(__cur);
--_M_num_elements._M_data;
}
else {
_Node* __next = __cur->_M_next;
while (__next) {
if (__next == __p) {
__cur->_M_next = __next->_M_next;
_M_delete_node(__next);
--_M_num_elements._M_data;
break;
}
else {
__cur = __next;
__next = __cur->_M_next;
}
}
}
}
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::erase(const_iterator _c_first, const_iterator _c_last)
{
iterator& __first = (iterator&)_c_first;
iterator& __last = (iterator&)_c_last;
size_type __f_bucket = __first._M_cur ?
_M_bkt_num(__first._M_cur->_M_val) : _M_buckets.size();
size_type __l_bucket = __last._M_cur ?
_M_bkt_num(__last._M_cur->_M_val) : _M_buckets.size();
if (__first._M_cur == __last._M_cur)
return;
else if (__f_bucket == __l_bucket)
_M_erase_bucket(__f_bucket, __first._M_cur, __last._M_cur);
else {
_M_erase_bucket(__f_bucket, __first._M_cur, 0);
for (size_type __n = __f_bucket + 1; __n < __l_bucket; ++__n)
_M_erase_bucket(__n, 0);
if (__l_bucket != _M_buckets.size())
_M_erase_bucket(__l_bucket, __last._M_cur);
}
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::resize(size_type __num_elements_hint)
{
const size_type __old_n = _M_buckets.size();
if (__num_elements_hint > __old_n) {
const size_type __n = _M_next_size(__num_elements_hint);
if (__n > __old_n) {
_BucketVector __tmp(__n, (void*)(0),
_M_buckets.get_allocator());
_STLP_TRY {
for (size_type __bucket = 0; __bucket < __old_n; ++__bucket) {
_Node* __first = (_Node*)_M_buckets[__bucket];
while (__first) {
size_type __new_bucket = _M_bkt_num(__first->_M_val, __n);
_M_buckets[__bucket] = __first->_M_next;
__first->_M_next = (_Node*)__tmp[__new_bucket];
__tmp[__new_bucket] = __first;
__first = (_Node*)_M_buckets[__bucket];
}
}
_M_buckets.swap(__tmp);
}
# ifdef _STLP_USE_EXCEPTIONS
catch(...) {
for (size_type __bucket = 0; __bucket < __tmp.size(); ++__bucket) {
while (__tmp[__bucket]) {
_Node* __next = ((_Node*)__tmp[__bucket])->_M_next;
_M_delete_node((_Node*)__tmp[__bucket]);
__tmp[__bucket] = __next;
}
}
throw;
}
# endif /* _STLP_USE_EXCEPTIONS */
}
}
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::_M_erase_bucket(const size_type __n, _Node* __first, _Node* __last)
{
_Node* __cur = (_Node*)_M_buckets[__n];
if (__cur == __first)
_M_erase_bucket(__n, __last);
else {
_Node* __next;
for (__next = __cur->_M_next;
__next != __first;
__cur = __next, __next = __cur->_M_next)
;
while (__next != __last) {
__cur->_M_next = __next->_M_next;
_M_delete_node(__next);
__next = __cur->_M_next;
--_M_num_elements._M_data;
}
}
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::_M_erase_bucket(const size_type __n, _Node* __last)
{
_Node* __cur = (_Node*)_M_buckets[__n];
while (__cur && __cur != __last) {
_Node* __next = __cur->_M_next;
_M_delete_node(__cur);
__cur = __next;
_M_buckets[__n] = __cur;
--_M_num_elements._M_data;
}
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::clear()
{
for (size_type __i = 0; __i < _M_buckets.size(); ++__i) {
_Node* __cur = (_Node*)_M_buckets[__i];
while (__cur != 0) {
_Node* __next = __cur->_M_next;
_M_delete_node(__cur);
__cur = __next;
}
_M_buckets[__i] = 0;
}
_M_num_elements._M_data = 0;
}
template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
void hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
::_M_copy_from(const hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht)
{
_M_buckets.clear();
_M_buckets.reserve(__ht._M_buckets.size());
_M_buckets.insert(_M_buckets.end(), __ht._M_buckets.size(), (void*) 0);
_STLP_TRY {
for (size_type __i = 0; __i < __ht._M_buckets.size(); ++__i) {
const _Node* __cur = (_Node*)__ht._M_buckets[__i];
if (__cur) {
_Node* __xcopy = _M_new_node(__cur->_M_val);
_M_buckets[__i] = __xcopy;
for (_Node* __next = __cur->_M_next;
__next;
__cur = __next, __next = __cur->_M_next) {
__xcopy->_M_next = _M_new_node(__next->_M_val);
__xcopy = __xcopy->_M_next;
}
}
}
_M_num_elements._M_data = __ht._M_num_elements._M_data;
}
_STLP_UNWIND(clear());
}
# undef __iterator__
# undef const_iterator
# undef __size_type__
# undef __reference__
# undef size_type
# undef value_type
# undef key_type
# undef _Node
# undef __stl_num_primes
# undef hashtable
_STLP_END_NAMESPACE
#endif /* _STLP_HASHTABLE_C */
// Local Variables:
// mode:C++
// End:
+613
View File
@@ -0,0 +1,613 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_HASHTABLE_H
#define _STLP_INTERNAL_HASHTABLE_H
# ifndef _STLP_INTERNAL_VECTOR_H
# include <stl/_vector.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_FUNCTION_H
# include <stl/_function_base.h>
# endif
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_HASH_FUN_H
# include <stl/_hash_fun.h>
# endif
// Hashtable class, used to implement the hashed associative containers
// hash_set, hash_map, hash_multiset, and hash_multimap.
#ifdef _STLP_DEBUG
# define hashtable __WORKAROUND_DBG_RENAME(hashtable)
#endif
_STLP_BEGIN_NAMESPACE
template <class _Val>
struct _Hashtable_node
{
typedef _Hashtable_node<_Val> _Self;
_Self* _M_next;
_Val _M_val;
__TRIVIAL_STUFF(_Hashtable_node)
};
// some compilers require the names of template parameters to be the same
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
class hashtable;
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
struct _Hashtable_iterator
{
typedef hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
_Hashtable;
typedef _Hashtable_node<_Val> _Node;
_Node* _M_cur;
_Hashtable* _M_ht;
_Hashtable_iterator(_Node* __n, _Hashtable* __tab)
: _M_cur(__n), _M_ht(__tab) {}
_Hashtable_iterator() {}
_Node* _M_skip_to_next();
};
template <class _Val, class _Traits, class _Key, class _HF,
class _ExK, class _EqK, class _All>
struct _Ht_iterator : public _Hashtable_iterator< _Val, _Key,_HF, _ExK,_EqK,_All>
{
typedef _Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All> _Base;
// typedef _Ht_iterator<_Val, _Nonconst_traits<_Val>,_Key,_HF,_ExK,_EqK,_All> iterator;
// typedef _Ht_iterator<_Val, _Const_traits<_Val>,_Key,_HF,_ExK,_EqK,_All> const_iterator;
typedef _Ht_iterator<_Val, _Traits,_Key,_HF,_ExK,_EqK,_All> _Self;
typedef hashtable<_Val,_Key,_HF,_ExK,_EqK,_All> _Hashtable;
typedef _Hashtable_node<_Val> _Node;
typedef _Val value_type;
typedef forward_iterator_tag iterator_category;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
typedef typename _Traits::reference reference;
typedef typename _Traits::pointer pointer;
_Ht_iterator(const _Node* __n, const _Hashtable* __tab) :
_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>((_Node*)__n, (_Hashtable*)__tab) {}
_Ht_iterator() {}
_Ht_iterator(const _Ht_iterator<_Val, _Nonconst_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>& __it) :
_Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>(__it) {}
reference operator*() const {
return this->_M_cur->_M_val;
}
_STLP_DEFINE_ARROW_OPERATOR
_Self& operator++() {
_Node* __n = this->_M_cur->_M_next;
this->_M_cur = (__n !=0 ? __n : this->_M_skip_to_next());
return *this;
}
inline _Self operator++(int) {
_Self __tmp = *this;
++*this;
return __tmp;
}
};
template <class _Val, class _Traits, class _Traits1, class _Key, class _HF,
class _ExK, class _EqK, class _All>
inline bool
operator==(const _Ht_iterator<_Val, _Traits,_Key,_HF,_ExK,_EqK,_All>& __x,
const _Ht_iterator<_Val, _Traits1,_Key,_HF,_ExK,_EqK,_All>& __y) {
return __x._M_cur == __y._M_cur;
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
inline bool
operator!=(const _Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>& __x,
const _Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>& __y) {
return __x._M_cur != __y._M_cur;
}
#else
# if (defined (__GNUC__) && (__GNUC_MINOR__ < 8))
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
inline bool
operator!=(const _Ht_iterator<_Val, _Const_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>& __x,
const _Ht_iterator<_Val, _Nonconst_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>& __y) {
return __x._M_cur != __y._M_cur;
}
# endif
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
inline bool
operator!=(const _Ht_iterator<_Val, _Nonconst_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>& __x,
const _Ht_iterator<_Val, _Const_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>& __y) {
return __x._M_cur != __y._M_cur;
}
#endif
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Val, class _Traits, class _Key, class _HF, class _ExK, class _EqK, class _All>
inline _Val* value_type(const _Ht_iterator<_Val, _Traits,_Key,_HF,_ExK,_EqK,_All>&) { return (_Val*) 0; }
template <class _Val, class _Traits, class _Key, class _HF, class _ExK, class _EqK, class _All>
inline forward_iterator_tag iterator_category(const _Ht_iterator<_Val, _Traits,_Key,_HF,_ExK,_EqK,_All>&) { return forward_iterator_tag(); }
template <class _Val, class _Traits, class _Key, class _HF, class _ExK, class _EqK, class _All>
inline ptrdiff_t* distance_type(const _Ht_iterator<_Val,_Traits,_Key,_HF,_ExK,_EqK,_All>&) { return (ptrdiff_t*) 0; }
#endif
#define __stl_num_primes 28
template <class _Tp>
class _Stl_prime {
public:
static const size_t _M_list[__stl_num_primes];
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _Stl_prime<bool>;
# endif
typedef _Stl_prime<bool> _Stl_prime_type;
// Hashtables handle allocators a bit differently than other containers
// do. If we're using standard-conforming allocators, then a hashtable
// unconditionally has a member variable to hold its allocator, even if
// it so happens that all instances of the allocator type are identical.
// This is because, for hashtables, this extra storage is negligible.
// Additionally, a base class wouldn't serve any other purposes; it
// wouldn't, for example, simplify the exception-handling code.
template <class _Val, class _Key, class _HF,
class _ExK, class _EqK, class _All>
class hashtable {
typedef hashtable<_Val, _Key, _HF, _ExK, _EqK, _All> _Self;
public:
typedef _Key key_type;
typedef _Val value_type;
typedef _HF hasher;
typedef _EqK key_equal;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef forward_iterator_tag _Iterator_category;
hasher hash_funct() const { return _M_hash; }
key_equal key_eq() const { return _M_equals; }
private:
typedef _Hashtable_node<_Val> _Node;
private:
_STLP_FORCE_ALLOCATORS(_Val, _All)
typedef typename _Alloc_traits<_Node, _All>::allocator_type _M_node_allocator_type;
typedef typename _Alloc_traits<void*, _All>::allocator_type _M_node_ptr_allocator_type;
typedef __vector__<void*, _M_node_ptr_allocator_type> _BucketVector;
public:
typedef typename _Alloc_traits<_Val,_All>::allocator_type allocator_type;
allocator_type get_allocator() const {
return _STLP_CONVERT_ALLOCATOR((const _M_node_allocator_type&)_M_num_elements, _Val);
}
private:
hasher _M_hash;
key_equal _M_equals;
_ExK _M_get_key;
_BucketVector _M_buckets;
_STLP_alloc_proxy<size_type, _Node, _M_node_allocator_type> _M_num_elements;
const _Node* _M_get_bucket(size_t __n) const { return (_Node*)_M_buckets[__n]; }
public:
typedef _Const_traits<_Val> __const_val_traits;
typedef _Nonconst_traits<_Val> __nonconst_val_traits;
typedef _Ht_iterator<_Val, __const_val_traits,_Key,_HF,_ExK,_EqK, _All> const_iterator;
typedef _Ht_iterator<_Val, __nonconst_val_traits,_Key,_HF,_ExK,_EqK,_All> iterator;
friend struct _Hashtable_iterator<_Val,_Key,_HF,_ExK,_EqK,_All>;
friend struct _Ht_iterator<_Val, _Nonconst_traits<_Val>,_Key,_HF,_ExK,_EqK,_All>;
friend struct _Ht_iterator<_Val, _Const_traits<_Val>,_Key,_HF,_ExK,_EqK, _All>;
public:
hashtable(size_type __n,
const _HF& __hf,
const _EqK& __eql,
const _ExK& __ext,
const allocator_type& __a = allocator_type())
:
_M_hash(__hf),
_M_equals(__eql),
_M_get_key(__ext),
_M_buckets(_STLP_CONVERT_ALLOCATOR(__a,void*)),
_M_num_elements(_STLP_CONVERT_ALLOCATOR(__a,_Node), (size_type)0)
{
_M_initialize_buckets(__n);
}
hashtable(size_type __n,
const _HF& __hf,
const _EqK& __eql,
const allocator_type& __a = allocator_type())
:
_M_hash(__hf),
_M_equals(__eql),
_M_get_key(_ExK()),
_M_buckets(_STLP_CONVERT_ALLOCATOR(__a,void*)),
_M_num_elements(_STLP_CONVERT_ALLOCATOR(__a,_Node), (size_type)0)
{
_M_initialize_buckets(__n);
}
hashtable(const _Self& __ht)
:
_M_hash(__ht._M_hash),
_M_equals(__ht._M_equals),
_M_get_key(__ht._M_get_key),
_M_buckets(_STLP_CONVERT_ALLOCATOR(__ht.get_allocator(),void*)),
_M_num_elements((const _M_node_allocator_type&)__ht._M_num_elements, (size_type)0)
{
_M_copy_from(__ht);
}
_Self& operator= (const _Self& __ht)
{
if (&__ht != this) {
clear();
_M_hash = __ht._M_hash;
_M_equals = __ht._M_equals;
_M_get_key = __ht._M_get_key;
_M_copy_from(__ht);
}
return *this;
}
~hashtable() { clear(); }
size_type size() const { return _M_num_elements._M_data; }
size_type max_size() const { return size_type(-1); }
bool empty() const { return size() == 0; }
void swap(_Self& __ht)
{
_STLP_STD::swap(_M_hash, __ht._M_hash);
_STLP_STD::swap(_M_equals, __ht._M_equals);
_STLP_STD::swap(_M_get_key, __ht._M_get_key);
_M_buckets.swap(__ht._M_buckets);
_STLP_STD::swap(_M_num_elements, __ht._M_num_elements);
}
iterator begin()
{
for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
if (_M_buckets[__n])
return iterator((_Node*)_M_buckets[__n], this);
return end();
}
iterator end() { return iterator((_Node*)0, this); }
const_iterator begin() const
{
for (size_type __n = 0; __n < _M_buckets.size(); ++__n)
if (_M_buckets[__n])
return const_iterator((_Node*)_M_buckets[__n], this);
return end();
}
const_iterator end() const { return const_iterator((_Node*)0, this); }
static bool _STLP_CALL _M_equal (const hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>&,
const hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>&);
public:
size_type bucket_count() const { return _M_buckets.size(); }
size_type max_bucket_count() const
{ return _Stl_prime_type::_M_list[(int)__stl_num_primes - 1]; }
size_type elems_in_bucket(size_type __bucket) const
{
size_type __result = 0;
for (_Node* __cur = (_Node*)_M_buckets[__bucket]; __cur; __cur = __cur->_M_next)
__result += 1;
return __result;
}
pair<iterator, bool> insert_unique(const value_type& __obj)
{
resize(_M_num_elements._M_data + 1);
return insert_unique_noresize(__obj);
}
iterator insert_equal(const value_type& __obj)
{
resize(_M_num_elements._M_data + 1);
return insert_equal_noresize(__obj);
}
pair<iterator, bool> insert_unique_noresize(const value_type& __obj);
iterator insert_equal_noresize(const value_type& __obj);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert_unique(_InputIterator __f, _InputIterator __l)
{
insert_unique(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIterator));
}
template <class _InputIterator>
void insert_equal(_InputIterator __f, _InputIterator __l)
{
insert_equal(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIterator));
}
template <class _InputIterator>
void insert_unique(_InputIterator __f, _InputIterator __l,
const input_iterator_tag &)
{
for ( ; __f != __l; ++__f)
insert_unique(*__f);
}
template <class _InputIterator>
void insert_equal(_InputIterator __f, _InputIterator __l,
const input_iterator_tag &)
{
for ( ; __f != __l; ++__f)
insert_equal(*__f);
}
template <class _ForwardIterator>
void insert_unique(_ForwardIterator __f, _ForwardIterator __l,
const forward_iterator_tag &)
{
size_type __n = distance(__f, __l);
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_unique_noresize(*__f);
}
template <class _ForwardIterator>
void insert_equal(_ForwardIterator __f, _ForwardIterator __l,
const forward_iterator_tag &)
{
size_type __n = distance(__f, __l);
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_equal_noresize(*__f);
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert_unique(const value_type* __f, const value_type* __l)
{
size_type __n = __l - __f;
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_unique_noresize(*__f);
}
void insert_equal(const value_type* __f, const value_type* __l)
{
size_type __n = __l - __f;
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_equal_noresize(*__f);
}
void insert_unique(const_iterator __f, const_iterator __l)
{
size_type __n = distance(__f, __l);
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_unique_noresize(*__f);
}
void insert_equal(const_iterator __f, const_iterator __l)
{
size_type __n = distance(__f, __l);
resize(_M_num_elements._M_data + __n);
for ( ; __n > 0; --__n, ++__f)
insert_equal_noresize(*__f);
}
#endif /*_STLP_MEMBER_TEMPLATES */
reference find_or_insert(const value_type& __obj);
private:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC_)))
template <class _KT>
_Node* _M_find(const _KT& __key) const
# else
_Node* _M_find(const key_type& __key) const
# endif
{
size_type __n = _M_hash(__key)% _M_buckets.size();
_Node* __first;
for ( __first = (_Node*)_M_buckets[__n];
__first && !_M_equals(_M_get_key(__first->_M_val), __key);
__first = __first->_M_next)
{}
return __first;
}
public:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))
template <class _KT>
iterator find(const _KT& __key)
# else
iterator find(const key_type& __key)
# endif
{
return iterator(_M_find(__key), this);
}
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__)))
template <class _KT>
const_iterator find(const _KT& __key) const
# else
const_iterator find(const key_type& __key) const
# endif
{
return const_iterator(_M_find(__key), this);
}
size_type count(const key_type& __key) const
{
const size_type __n = _M_bkt_num_key(__key);
size_type __result = 0;
for (const _Node* __cur = (_Node*)_M_buckets[__n]; __cur; __cur = __cur->_M_next)
if (_M_equals(_M_get_key(__cur->_M_val), __key))
++__result;
return __result;
}
pair<iterator, iterator>
equal_range(const key_type& __key);
pair<const_iterator, const_iterator>
equal_range(const key_type& __key) const;
size_type erase(const key_type& __key);
// void erase(const iterator& __it); `
void erase(const const_iterator& __it) ;
// void erase(const const_iterator& __first, const const_iterator __last) {
// erase((const iterator&)__first, (const iterator&)__last);
// }
void erase(const_iterator __first, const_iterator __last);
void resize(size_type __num_elements_hint);
void clear();
public:
// this is for hash_map::operator[]
reference _M_insert(const value_type& __obj);
private:
size_type _M_next_size(size_type __n) const;
void _M_initialize_buckets(size_type __n)
{
const size_type __n_buckets = _M_next_size(__n);
_M_buckets.reserve(__n_buckets);
_M_buckets.insert(_M_buckets.end(), __n_buckets, (void*) 0);
_M_num_elements._M_data = 0;
}
size_type _M_bkt_num_key(const key_type& __key) const
{
return _M_bkt_num_key(__key, _M_buckets.size());
}
size_type _M_bkt_num(const value_type& __obj) const
{
return _M_bkt_num_key(_M_get_key(__obj));
}
size_type _M_bkt_num_key(const key_type& __key, size_t __n) const
{
return _M_hash(__key) % __n;
}
size_type _M_bkt_num(const value_type& __obj, size_t __n) const
{
return _M_bkt_num_key(_M_get_key(__obj), __n);
}
_Node* _M_new_node(const value_type& __obj)
{
_Node* __n = _M_num_elements.allocate(1);
__n->_M_next = 0;
_STLP_TRY {
_Construct(&__n->_M_val, __obj);
// return __n;
}
_STLP_UNWIND(_M_num_elements.deallocate(__n, 1));
return __n;
}
void _M_delete_node(_Node* __n)
{
_STLP_STD::_Destroy(&__n->_M_val);
_M_num_elements.deallocate(__n, 1);
}
void _M_erase_bucket(const size_type __n, _Node* __first, _Node* __last);
void _M_erase_bucket(const size_type __n, _Node* __last);
void _M_copy_from(const _Self& __ht);
};
#define _STLP_TEMPLATE_HEADER template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>
#define _STLP_TEMPLATE_CONTAINER hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>
#include <stl/_relops_hash_cont.h>
#undef _STLP_TEMPLATE_CONTAINER
#undef _STLP_TEMPLATE_HEADER
_STLP_END_NAMESPACE
# undef hashtable
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_hashtable.c>
# endif
# if defined (_STLP_DEBUG)
# include <stl/debug/_hashtable.h>
# endif
#endif /* _STLP_INTERNAL_HASHTABLE_H */
// Local Variables:
// mode:C++
// End:
+242
View File
@@ -0,0 +1,242 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_HEAP_C
#define _STLP_HEAP_C
#ifndef _STLP_INTERNAL_HEAP_H
# include <stl/_heap.h>
#endif
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _RandomAccessIterator, class _Distance, class _Tp>
_STLP_INLINE_LOOP
void
__push_heap(_RandomAccessIterator __first,
_Distance __holeIndex, _Distance __topIndex, _Tp __val)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && *(__first + __parent) < __val) {
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __val;
}
template <class _RandomAccessIterator, class _Distance, class _Tp>
inline void
__push_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Distance*, _Tp*)
{
__push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
_Tp(*(__last - 1)));
}
template <class _RandomAccessIterator>
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
__push_heap_aux(__first, __last,
_STLP_DISTANCE_TYPE(__first, _RandomAccessIterator), _STLP_VALUE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator, class _Distance, class _Tp,
class _Compare>
_STLP_INLINE_LOOP
void
__push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __topIndex, _Tp __val, _Compare __comp)
{
_Distance __parent = (__holeIndex - 1) / 2;
while (__holeIndex > __topIndex && __comp(*(__first + __parent), __val)) {
*(__first + __holeIndex) = *(__first + __parent);
__holeIndex = __parent;
__parent = (__holeIndex - 1) / 2;
}
*(__first + __holeIndex) = __val;
}
template <class _RandomAccessIterator, class _Compare,
class _Distance, class _Tp>
inline void
__push_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp,
_Distance*, _Tp*)
{
__push_heap(__first, _Distance((__last - __first) - 1), _Distance(0),
_Tp(*(__last - 1)), __comp);
}
template <class _RandomAccessIterator, class _Compare>
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp)
{
__push_heap_aux(__first, __last, __comp,
_STLP_DISTANCE_TYPE(__first, _RandomAccessIterator), _STLP_VALUE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator, class _Distance, class _Tp>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __val) {
_Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (__secondChild == __len) {
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
__push_heap(__first, __holeIndex, __topIndex, __val);
}
template <class _RandomAccessIterator, class _Tp>
inline void
__pop_heap_aux(_RandomAccessIterator __first, _RandomAccessIterator __last, _Tp*) {
__pop_heap(__first, __last - 1, __last - 1,
_Tp(*(__last - 1)), _STLP_DISTANCE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator>
void pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last) {
__pop_heap_aux(__first, __last, _STLP_VALUE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator, class _Distance,
class _Tp, class _Compare>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __val, _Compare __comp)
{
_Distance __topIndex = __holeIndex;
_Distance __secondChild = 2 * __holeIndex + 2;
while (__secondChild < __len) {
if (__comp(*(__first + __secondChild), *(__first + (__secondChild - 1))))
__secondChild--;
*(__first + __holeIndex) = *(__first + __secondChild);
__holeIndex = __secondChild;
__secondChild = 2 * (__secondChild + 1);
}
if (__secondChild == __len) {
*(__first + __holeIndex) = *(__first + (__secondChild - 1));
__holeIndex = __secondChild - 1;
}
__push_heap(__first, __holeIndex, __topIndex, __val, __comp);
}
template <class _RandomAccessIterator, class _Tp, class _Compare>
inline void
__pop_heap_aux(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Tp*, _Compare __comp)
{
__pop_heap(__first, __last - 1, __last - 1, _Tp(*(__last - 1)), __comp,
_STLP_DISTANCE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator, class _Compare>
void
pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
__pop_heap_aux(__first, __last, _STLP_VALUE_TYPE(__first, _RandomAccessIterator), __comp);
}
template <class _RandomAccessIterator, class _Tp, class _Distance>
_STLP_INLINE_LOOP
void
__make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Tp*, _Distance*)
{
if (__last - __first < 2) return;
_Distance __len = __last - __first;
_Distance __parent = (__len - 2)/2;
while (true) {
__adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)));
if (__parent == 0) return;
__parent--;
}
}
template <class _RandomAccessIterator>
void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
__make_heap(__first, __last,
_STLP_VALUE_TYPE(__first, _RandomAccessIterator), _STLP_DISTANCE_TYPE(__first, _RandomAccessIterator));
}
template <class _RandomAccessIterator, class _Compare,
class _Tp, class _Distance>
_STLP_INLINE_LOOP
void
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp, _Tp*, _Distance*)
{
if (__last - __first < 2) return;
_Distance __len = __last - __first;
_Distance __parent = (__len - 2)/2;
while (true) {
__adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent)),
__comp);
if (__parent == 0) return;
__parent--;
}
}
template <class _RandomAccessIterator, class _Compare>
void
make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
__make_heap(__first, __last, __comp,
_STLP_VALUE_TYPE(__first, _RandomAccessIterator), _STLP_DISTANCE_TYPE(__first, _RandomAccessIterator));
}
_STLP_END_NAMESPACE
#endif /* _STLP_HEAP_C */
// Local Variables:
// mode:C++
// End:
+129
View File
@@ -0,0 +1,129 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_HEAP_H
#define _STLP_INTERNAL_HEAP_H
#ifndef _STLP_CONFIG_H
#include <stl/_config.h>
#endif
_STLP_BEGIN_NAMESPACE
// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap.
template <class _RandomAccessIterator>
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
template <class _RandomAccessIterator, class _Compare>
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp);
template <class _RandomAccessIterator, class _Distance, class _Tp>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __val);
template <class _RandomAccessIterator, class _Tp, class _Distance>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __val, _Distance*)
{
*__result = *__first;
__adjust_heap(__first, _Distance(0), _Distance(__last - __first), __val);
}
template <class _RandomAccessIterator>
void pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last);
template <class _RandomAccessIterator, class _Distance,
class _Tp, class _Compare>
void
__adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
_Distance __len, _Tp __val, _Compare __comp);
template <class _RandomAccessIterator, class _Tp, class _Compare,
class _Distance>
inline void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last,
_RandomAccessIterator __result, _Tp __val, _Compare __comp,
_Distance*)
{
*__result = *__first;
__adjust_heap(__first, _Distance(0), _Distance(__last - __first),
__val, __comp);
}
template <class _RandomAccessIterator, class _Compare>
void
pop_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp);
template <class _RandomAccessIterator>
void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last);
template <class _RandomAccessIterator, class _Compare>
void
make_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp);
template <class _RandomAccessIterator>
_STLP_INLINE_LOOP
void sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
while (__last - __first > 1)
pop_heap(__first, __last--);
}
template <class _RandomAccessIterator, class _Compare>
_STLP_INLINE_LOOP
void
sort_heap(_RandomAccessIterator __first,
_RandomAccessIterator __last, _Compare __comp)
{
while (__last - __first > 1)
_STLP_STD::pop_heap(__first, __last--, __comp);
}
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_heap.c>
# endif
#endif /* _STLP_INTERNAL_HEAP_H */
// Local Variables:
// mode:C++
// End:
+127
View File
@@ -0,0 +1,127 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_IOS_C
#define _STLP_IOS_C
#ifndef _STLP_INTERNAL_IOS_H
# include <stl/_ios.h>
#endif
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
#ifndef _STLP_INTERNAL_NUMPUNCT_H
# include <stl/_numpunct.h>
#endif
_STLP_BEGIN_NAMESPACE
// basic_ios<>'s non-inline member functions
// Public constructor, taking a streambuf.
template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>
::basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf)
: ios_base(),
_M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
{
init(__streambuf);
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<_CharT, _Traits>* __buf)
{
basic_streambuf<_CharT, _Traits>* __tmp = _M_streambuf;
_M_streambuf = __buf;
this->clear();
return __tmp;
}
template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>&
basic_ios<_CharT, _Traits>::copyfmt(const basic_ios<_CharT, _Traits>& __x)
{
_M_invoke_callbacks(erase_event);
_M_copy_state(__x); // Inherited from ios_base.
_M_fill = __x._M_fill;
_M_tied_ostream = __x._M_tied_ostream;
_M_invoke_callbacks(copyfmt_event);
this->_M_set_exception_mask(__x.exceptions());
return *this;
}
template <class _CharT, class _Traits>
locale basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
{
locale __tmp = ios_base::imbue(__loc);
if (_M_streambuf)
_M_streambuf->pubimbue(__loc);
// no throwing here
this->_M_cached_ctype = __loc._M_get_facet(ctype<char_type>::id) ;
this->_M_cached_numpunct = __loc._M_get_facet(numpunct<char_type>::id) ;
this->_M_cached_grouping = ((numpunct<char_type>*)_M_cached_numpunct)->grouping() ;
return __tmp;
}
// Protected constructor and initialization functions. The default
// constructor creates an uninitialized basic_ios, and init() initializes
// all of the members to the values in Table 89 of the C++ standard.
template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>::basic_ios()
: ios_base(),
_M_fill(_STLP_NULL_CHAR_INIT(_CharT)), _M_streambuf(0), _M_tied_ostream(0)
{}
template <class _CharT, class _Traits>
void
basic_ios<_CharT, _Traits>::init(basic_streambuf<_CharT, _Traits>* __sb)
{
this->rdbuf(__sb);
this->imbue(locale());
this->tie(0);
this->_M_set_exception_mask(ios_base::goodbit);
this->_M_clear_nothrow(__sb != 0 ? ios_base::goodbit : ios_base::badbit);
ios_base::flags(ios_base::skipws | ios_base::dec);
ios_base::width(0);
ios_base::precision(6);
this->fill(widen(' '));
// We don't need to worry about any of the three arrays: they are
// initialized correctly in ios_base's constructor.
}
// This is never called except from within a catch clause.
template <class _CharT, class _Traits>
void basic_ios<_CharT, _Traits>::_M_handle_exception(ios_base::iostate __flag)
{
this->_M_setstate_nothrow(__flag);
if (this->_M_get_exception_mask() & __flag)
_STLP_RETHROW;
}
_STLP_END_NAMESPACE
#endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
#endif /* _STLP_IOS_C */
+199
View File
@@ -0,0 +1,199 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_INTERNAL_IOS_H
#define _STLP_INTERNAL_IOS_H
#ifndef _STLP_IOS_BASE_H
# include <stl/_ios_base.h>
#endif
#ifndef _STLP_INTERNAL_CTYPE_H
# include <stl/_ctype.h>
#endif
#ifndef _STLP_INTERNAL_NUMPUNCT_H
# include <stl/_numpunct.h>
#endif
_STLP_BEGIN_NAMESPACE
// ----------------------------------------------------------------------
// Class basic_ios, a subclass of ios_base. The only important difference
// between the two is that basic_ios is a class template, parameterized
// by the character type. ios_base exists to factor out all of the
// common properties that don't depend on the character type.
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
// The default is declared in header <iosfwd>, and it isn't declared here
// because C++ language rules do not allow it to be declared twice.
template <class _CharT, class _Traits>
class basic_ios : public ios_base {
friend class ios_base;
public: // Synonyms for 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;
public: // Constructor, destructor.
explicit basic_ios(basic_streambuf<_CharT, _Traits>* __streambuf);
virtual ~basic_ios() {}
public: // Members from clause 27.4.4.2
basic_ostream<_CharT, _Traits>* tie() const {
return _M_tied_ostream;
}
basic_ostream<_CharT, _Traits>*
tie(basic_ostream<char_type, traits_type>* __new_tied_ostream) {
basic_ostream<char_type, traits_type>* __tmp = _M_tied_ostream;
_M_tied_ostream = __new_tied_ostream;
return __tmp;
}
basic_streambuf<_CharT, _Traits>* rdbuf() const
{ return _M_streambuf; }
basic_streambuf<_CharT, _Traits>*
rdbuf(basic_streambuf<char_type, traits_type>*);
// Copies __x's state to *this.
basic_ios<_CharT, _Traits>& copyfmt(const basic_ios<_CharT, _Traits>& __x);
char_type fill() const { return _M_fill; }
char_type fill(char_type __fill) {
char_type __tmp(_M_fill);
_M_fill = __fill;
return __tmp;
}
public: // Members from 27.4.4.3. These four functions
// can almost be defined in ios_base.
void clear(iostate __state = goodbit) {
_M_clear_nothrow(this->rdbuf() ? __state : iostate(__state|ios_base::badbit));
_M_check_exception_mask();
}
void setstate(iostate __state) { this->clear(rdstate() | __state); }
iostate exceptions() const { return this->_M_get_exception_mask(); }
void exceptions(iostate __mask) {
this->_M_set_exception_mask(__mask);
this->clear(this->rdstate());
}
public: // Locale-related member functions.
locale imbue(const locale&);
inline char narrow(_CharT, char) const ;
inline _CharT widen(char) const;
// Helper function that makes testing for EOF more convenient.
static bool _STLP_CALL _S_eof(int_type __c) {
const int_type __eof = _Traits::eof();
return _Traits::eq_int_type(__c, __eof);
}
protected:
basic_ios();
void init(basic_streambuf<_CharT, _Traits>* __streambuf);
public:
// Helper function used in istream and ostream. It is called only from
// a catch clause.
void _M_handle_exception(ios_base::iostate __flag);
private: // Data members
char_type _M_fill; // The fill character, used for padding.
basic_streambuf<_CharT, _Traits>* _M_streambuf;
basic_ostream<_CharT, _Traits>* _M_tied_ostream;
};
template <class _CharT, class _Traits>
inline char
basic_ios<_CharT, _Traits>::narrow(_CharT __c, char __default) const
{ return ((const ctype<_CharT>*)this->_M_ctype_facet())->narrow(__c, __default); }
template <class _CharT, class _Traits>
inline _CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
return ((const ctype<_CharT>*)this->_M_ctype_facet())->widen(__c); }
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_ios<char, char_traits<char> >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_ios<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
# if !defined (_STLP_NO_METHOD_SPECIALIZATION)
_STLP_TEMPLATE_NULL
inline char
basic_ios<char, char_traits<char> >::narrow(char __c, char) const
{
return __c;
}
_STLP_TEMPLATE_NULL
inline char
basic_ios<char, char_traits<char> >::widen(char __c) const
{
return __c;
}
# endif /* _STLP_NO_METHOD_SPECIALIZATION */
_STLP_END_NAMESPACE
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_ios.c>
# endif
// The following is needed to ensure that the inlined _Stl_loc_init functions
// that ios_base::_Loc_init::_Loc_init() calls are found eventually.
// Otherwise, undefined externs may be caused.
#if defined(__BORLANDC__) && defined(_RTLDLL)
# ifndef _STLP_INTERNAL_NUM_PUT_H
# include <stl/_num_put.h>
# endif
# ifndef _STLP_INTERNAL_NUM_GET_H
# include <stl/_num_get.h>
# endif
# ifndef _STLP_INTERNAL_MONETARY_H
# include <stl/_monetary.h>
# endif
# ifndef _STLP_INTERNAL_TIME_FACETS_H
# include <stl/_time_facets.h>
# endif
#endif
#endif /* _STLP_IOS */
// Local Variables:
// mode:C++
// End:
+409
View File
@@ -0,0 +1,409 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_IOS_BASE_H
#define _STLP_IOS_BASE_H
#ifndef _STLP_STDEXCEPT
#include <stdexcept>
#endif
#ifndef _STLP_UTILITY
#include <utility>
#endif
#ifndef _STLP_INTERNAL_LOCALE_H
#include <stl/_locale.h>
#endif
#ifndef _STLP_STRING_H
# include <stl/_string.h>
#endif
_STLP_BEGIN_NAMESPACE
// ----------------------------------------------------------------------
// Class ios_base. This is the base class of the ios hierarchy, which
// includes basic_istream and basic_ostream. Classes in the ios
// hierarchy are actually quite simple: they are just glorified
// wrapper classes. They delegate buffering and physical character
// manipulation to the streambuf classes, and they delegate most
// formatting tasks to a locale.
class _STLP_CLASS_DECLSPEC ios_base {
public:
class _STLP_CLASS_DECLSPEC failure : public __Named_exception {
public:
explicit failure(const string&);
virtual ~failure() _STLP_NOTHROW_INHERENTLY;
};
typedef int fmtflags;
typedef int iostate;
typedef int openmode;
typedef int seekdir;
# ifndef _STLP_NO_ANACHRONISMS
typedef fmtflags fmt_flags;
# endif
// Formatting flags.
# ifdef _STLP_STATIC_CONST_INIT_BUG
enum {
# else
// boris : type for all those constants is int
static const int
# endif
left = 0x0001,
right = 0x0002,
internal = 0x0004,
dec = 0x0008,
hex = 0x0010,
oct = 0x0020,
fixed = 0x0040,
scientific = 0x0080,
boolalpha = 0x0100,
showbase = 0x0200,
showpoint = 0x0400,
showpos = 0x0800,
skipws = 0x1000,
unitbuf = 0x2000,
uppercase = 0x4000,
adjustfield = left | right | internal,
basefield = dec | hex | oct,
floatfield = scientific | fixed,
// State flags.
goodbit = 0x00,
badbit = 0x01,
eofbit = 0x02,
failbit = 0x04,
// Openmode flags.
__default_mode = 0x0, /* implementation detail */
app = 0x01,
ate = 0x02,
binary = 0x04,
in = 0x08,
out = 0x10,
trunc = 0x20,
// Seekdir flags
beg = 0x01,
cur = 0x02,
end = 0x04
# ifdef _STLP_STATIC_CONST_INIT_BUG
}
# endif
;
public: // Flag-manipulation functions.
fmtflags flags() const { return _M_fmtflags; }
fmtflags flags(fmtflags __flags) {
fmtflags __tmp = _M_fmtflags;
_M_fmtflags = __flags;
return __tmp;
}
fmtflags setf(fmtflags __flag) {
fmtflags __tmp = _M_fmtflags;
_M_fmtflags |= __flag;
return __tmp;
}
fmtflags setf(fmtflags __flag, fmtflags __mask) {
fmtflags __tmp = _M_fmtflags;
_M_fmtflags &= ~__mask;
_M_fmtflags |= __flag & __mask;
return __tmp;
}
void unsetf(fmtflags __mask) { _M_fmtflags &= ~__mask; }
streamsize precision() const { return _M_precision; }
streamsize precision(streamsize __newprecision) {
streamsize __tmp = _M_precision;
_M_precision = __newprecision;
return __tmp;
}
streamsize width() const { return _M_width; }
streamsize width(streamsize __newwidth) {
streamsize __tmp = _M_width;
_M_width = __newwidth;
return __tmp;
}
public: // Locales
locale imbue(const locale&);
locale getloc() const { return _M_locale; }
public: // Auxiliary storage.
static int _STLP_CALL xalloc();
long& iword(int __index);
void*& pword(int __index);
public: // Destructor.
virtual ~ios_base();
public: // Callbacks.
enum event { erase_event, imbue_event, copyfmt_event };
typedef void (*event_callback)(event, ios_base&, int __index);
void register_callback(event_callback __fn, int __index);
public: // This member function affects only
// the eight predefined ios objects:
// cin, cout, etc.
static bool _STLP_CALL sync_with_stdio(bool __sync = true);
public: // The C++ standard requires only that these
// member functions be defined in basic_ios.
// We define them in the non-template
// base class to avoid code duplication.
operator void*() const { return !fail() ? (void*) __CONST_CAST(ios_base*,this) : (void*) 0; }
bool operator!() const { return fail(); }
iostate rdstate() const { return _M_iostate; }
bool good() const { return _M_iostate == 0; }
bool eof() const { return (_M_iostate & eofbit) != 0; }
bool fail() const { return (_M_iostate & (failbit | badbit)) != 0; }
bool bad() const { return (_M_iostate & badbit) != 0; }
protected: // The functional protected interface.
// Copies the state of __x to *this. This member function makes it
// possible to implement basic_ios::copyfmt without having to expose
// ios_base's private data members. Does not copy _M_exception_mask
// or _M_iostate.
void _M_copy_state(const ios_base& __x);
void _M_setstate_nothrow(iostate __state) { _M_iostate |= __state; }
void _M_clear_nothrow(iostate __state) { _M_iostate = __state; }
iostate _M_get_exception_mask() const { return _M_exception_mask; }
void _M_set_exception_mask(iostate __mask) { _M_exception_mask = __mask; }
void _M_check_exception_mask() {
if (_M_iostate & _M_exception_mask)
_M_throw_failure();
}
void _M_invoke_callbacks(event);
void _M_throw_failure();
ios_base(); // Default constructor.
protected: // Initialization of the I/O system
static void _STLP_CALL _S_initialize();
static void _STLP_CALL _S_uninitialize();
static bool _S_was_synced;
private: // Invalidate the copy constructor and
// assignment operator.
ios_base(const ios_base&);
void operator=(const ios_base&);
private: // Data members.
fmtflags _M_fmtflags; // Flags
iostate _M_iostate;
openmode _M_openmode;
seekdir _M_seekdir;
iostate _M_exception_mask;
streamsize _M_precision;
streamsize _M_width;
locale _M_locale;
pair<event_callback, int>* _M_callbacks;
size_t _M_num_callbacks; // Size of the callback array.
size_t _M_callback_index; // Index of the next available callback;
// initially zero.
long* _M_iwords; // Auxiliary storage. The count is zero
size_t _M_num_iwords; // if and only if the pointer is null.
void** _M_pwords;
size_t _M_num_pwords;
static int _S_index;
protected:
// Cached copies of the curent locale's facets. Set by init() and imbue().
locale::facet* _M_cached_ctype;
locale::facet* _M_cached_numpunct;
string _M_cached_grouping;
public:
// Equivalent to &use_facet< Facet >(getloc()), but faster.
const locale::facet* _M_ctype_facet() const { return _M_cached_ctype; }
const locale::facet* _M_numpunct_facet() const { return _M_cached_numpunct; }
const string& _M_grouping() const { return _M_cached_grouping; }
public:
// ----------------------------------------------------------------------
// Nested initializer class. This is an implementation detail, but it's
// prescribed by the standard. The static initializer object (on
// implementations where such a thing is required) is declared in
// <iostream>
class _STLP_CLASS_DECLSPEC Init {
public:
Init();
~Init();
private:
static long _S_count;
friend class ios_base;
};
// this class is needed to ensure locale initialization w/o <iostream> inclusion
class _STLP_CLASS_DECLSPEC _Loc_init {
public:
_Loc_init();
~_Loc_init();
private:
static long _S_count;
friend class locale;
friend class ios_base;
};
friend class Init;
public:
# ifndef _STLP_NO_ANACHRONISMS
// 31.6 Old iostreams members [depr.ios.members]
typedef iostate io_state;
typedef openmode open_mode;
typedef seekdir seek_dir;
typedef _STLP_STD::streamoff streamoff;
typedef _STLP_STD::streampos streampos;
# endif
};
template <class Facet>
locale::facet* _M_get_facet(ios_base& __i, Facet*)
{
}
// ----------------------------------------------------------------------
// ios_base manipulator functions, from section 27.4.5 of the C++ standard.
// All of them are trivial one-line wrapper functions.
// fmtflag manipulators, section 27.4.5.1
inline ios_base& _STLP_CALL boolalpha(ios_base& __s)
{ __s.setf(ios_base::boolalpha); return __s;}
inline ios_base& _STLP_CALL noboolalpha(ios_base& __s)
{ __s.unsetf(ios_base::boolalpha); return __s;}
inline ios_base& _STLP_CALL showbase(ios_base& __s)
{ __s.setf(ios_base::showbase); return __s;}
inline ios_base& _STLP_CALL noshowbase(ios_base& __s)
{ __s.unsetf(ios_base::showbase); return __s;}
inline ios_base& _STLP_CALL showpoint(ios_base& __s)
{ __s.setf(ios_base::showpoint); return __s;}
inline ios_base& _STLP_CALL noshowpoint(ios_base& __s)
{ __s.unsetf(ios_base::showpoint); return __s;}
inline ios_base& _STLP_CALL showpos(ios_base& __s)
{ __s.setf(ios_base::showpos); return __s;}
inline ios_base& _STLP_CALL noshowpos(ios_base& __s)
{ __s.unsetf(ios_base::showpos); return __s;}
inline ios_base& _STLP_CALL skipws(ios_base& __s)
{ __s.setf(ios_base::skipws); return __s;}
inline ios_base& _STLP_CALL noskipws(ios_base& __s)
{ __s.unsetf(ios_base::skipws); return __s;}
inline ios_base& _STLP_CALL uppercase(ios_base& __s)
{ __s.setf(ios_base::uppercase); return __s;}
inline ios_base& _STLP_CALL nouppercase(ios_base& __s)
{ __s.unsetf(ios_base::uppercase); return __s;}
inline ios_base& _STLP_CALL unitbuf(ios_base& __s)
{ __s.setf(ios_base::unitbuf); return __s;}
inline ios_base& _STLP_CALL nounitbuf(ios_base& __s)
{ __s.unsetf(ios_base::unitbuf); return __s;}
// adjustfield manipulators, section 27.4.5.2
inline ios_base& _STLP_CALL internal(ios_base& __s)
{ __s.setf(ios_base::internal, ios_base::adjustfield); return __s; }
inline ios_base& _STLP_CALL left(ios_base& __s)
{ __s.setf(ios_base::left, ios_base::adjustfield); return __s; }
inline ios_base& _STLP_CALL right(ios_base& __s)
{ __s.setf(ios_base::right, ios_base::adjustfield); return __s; }
// basefield manipulators, section 27.4.5.3
inline ios_base& _STLP_CALL dec(ios_base& __s)
{ __s.setf(ios_base::dec, ios_base::basefield); return __s; }
inline ios_base& _STLP_CALL hex(ios_base& __s)
{ __s.setf(ios_base::hex, ios_base::basefield); return __s; }
inline ios_base& _STLP_CALL oct(ios_base& __s)
{ __s.setf(ios_base::oct, ios_base::basefield); return __s; }
// floatfield manipulators, section 27.4.5.3
inline ios_base& _STLP_CALL fixed(ios_base& __s)
{ __s.setf(ios_base::fixed, ios_base::floatfield); return __s; }
inline ios_base& _STLP_CALL scientific(ios_base& __s)
{ __s.setf(ios_base::scientific, ios_base::floatfield); return __s; }
#if defined(__BORLANDC__) && defined(_RTLDLL)
long ios_base::_Loc_init::_S_count = 0;
void _STLP_CALL _Stl_loc_init_num_put();
void _STLP_CALL _Stl_loc_init_num_get();
void _STLP_CALL _Stl_loc_init_monetary();
void _STLP_CALL _Stl_loc_init_time_facets();
inline ios_base::_Loc_init::_Loc_init() {
if (_S_count++ == 0) {
_Stl_loc_init_num_put();
_Stl_loc_init_num_get();
_Stl_loc_init_monetary();
_Stl_loc_init_time_facets();
locale::_S_initialize();
}
}
inline ios_base::_Loc_init::~_Loc_init() {
if (--_S_count == 0)
locale::_S_uninitialize();
}
#endif /* __BORLANDC__ */
_STLP_END_NAMESPACE
#endif /* _STLP_IOS_BASE */
// Local Variables:
// mode:C++
// End:
+159
View File
@@ -0,0 +1,159 @@
# ifndef _STLP_INTERNAL_IOSFWD
# define _STLP_INTERNAL_IOSFWD
#if defined(__sgi) && !defined(__GNUC__) && !defined(_STANDARD_C_PLUS_PLUS)
#error This header file requires the -LANG:std option
#endif
// This file provides forward declarations of the most important I/O
// classes. Note that almost all of those classes are class templates,
// with default template arguments. According to the C++ standard,
// if a class template is declared more than once in the same scope
// then only one of those declarations may have default arguments.
// <iosfwd> contains the same declarations as other headers, and including
// both <iosfwd> and (say) <iostream> is permitted. This means that only
// one header may contain those default template arguments.
// In this implementation, the declarations in <iosfwd> contain default
// template arguments. All of the other I/O headers include <iosfwd>.
#ifndef _STLP_CHAR_TRAITS_H
# include <stl/char_traits.h>
#endif
_STLP_BEGIN_NAMESPACE
class _STLP_CLASS_DECLSPEC ios_base;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_ios;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_streambuf;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_istream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_ostream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_iostream;
template <class _CharT, __DFL_TMPL_PARAM( _Traits , char_traits<_CharT>),
__DFL_TMPL_PARAM(_Allocator , allocator<_CharT>) >
class basic_stringbuf;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>),
__DFL_TMPL_PARAM(_Allocator , allocator<_CharT>) >
class basic_istringstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>),
__DFL_TMPL_PARAM(_Allocator , allocator<_CharT>) >
class basic_ostringstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>),
__DFL_TMPL_PARAM(_Allocator , allocator<_CharT>) >
class basic_stringstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_filebuf;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_ifstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_ofstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class basic_fstream;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class istreambuf_iterator;
template <class _CharT, __DFL_TMPL_PARAM(_Traits , char_traits<_CharT>) >
class ostreambuf_iterator;
typedef basic_ios<char, char_traits<char> > ios;
# ifndef _STLP_NO_WCHAR_T
typedef basic_ios<wchar_t, char_traits<wchar_t> > wios;
# endif
// Forward declaration of class locale, and of the most important facets.
class locale;
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
template <class _Facet>
struct _Use_facet {
const locale& __loc;
_Use_facet(const locale& __p_loc) : __loc(__p_loc) {}
inline const _Facet& operator *() const;
};
# define use_facet *_Use_facet
# else
template <class _Facet> inline const _Facet& use_facet(const locale&);
# endif
template <class _CharT> class ctype;
template <class _CharT> class ctype_byname;
template <class _CharT> class collate;
template <class _CharT> class collate_byname;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC ctype<char>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC ctype_byname<char>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC collate<char>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC collate_byname<char>;
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC ctype<wchar_t>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC ctype_byname<wchar_t>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC collate<wchar_t>;
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC collate_byname<wchar_t>;
# endif
# if !(defined (__SUNPRO_CC) && __SUNPRO_CC < 0x500 ) && !defined(_STLP_WINCE)
// Typedefs for ordinary (narrow-character) streams.
_STLP_TEMPLATE_NULL class _STLP_CLASS_DECLSPEC basic_streambuf<char, char_traits<char> >;
# endif
typedef basic_istream<char, char_traits<char> > istream;
typedef basic_ostream<char, char_traits<char> > ostream;
typedef basic_iostream<char, char_traits<char> > iostream;
typedef basic_streambuf<char,char_traits<char> > streambuf;
typedef basic_stringbuf<char, char_traits<char>, allocator<char> > stringbuf;
typedef basic_istringstream<char, char_traits<char>, allocator<char> > istringstream;
typedef basic_ostringstream<char, char_traits<char>, allocator<char> > ostringstream;
typedef basic_stringstream<char, char_traits<char>, allocator<char> > stringstream;
typedef basic_filebuf<char, char_traits<char> > filebuf;
typedef basic_ifstream<char, char_traits<char> > ifstream;
typedef basic_ofstream<char, char_traits<char> > ofstream;
typedef basic_fstream<char, char_traits<char> > fstream;
# ifndef _STLP_NO_WCHAR_T
// Typedefs for wide-character streams.
typedef basic_streambuf<wchar_t, char_traits<wchar_t> > wstreambuf;
typedef basic_istream<wchar_t, char_traits<wchar_t> > wistream;
typedef basic_ostream<wchar_t, char_traits<wchar_t> > wostream;
typedef basic_iostream<wchar_t, char_traits<wchar_t> > wiostream;
typedef basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstringbuf;
typedef basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wistringstream;
typedef basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wostringstream;
typedef basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstringstream;
typedef basic_filebuf<wchar_t, char_traits<wchar_t> > wfilebuf;
typedef basic_ifstream<wchar_t, char_traits<wchar_t> > wifstream;
typedef basic_ofstream<wchar_t, char_traits<wchar_t> > wofstream;
typedef basic_fstream<wchar_t, char_traits<wchar_t> > wfstream;
# endif
_STLP_END_NAMESPACE
#endif
// Local Variables:
// mode:C++
// End:
File diff suppressed because it is too large Load Diff
+344
View File
@@ -0,0 +1,344 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_INTERNAL_ISTREAM_H
#define _STLP_INTERNAL_ISTREAM_H
// this block is included by _ostream.h, we include it here to lower #include level
# if defined (_STLP_HAS_WCHAR_T) && !defined (_STLP_CWCHAR_H)
# include <stl/_cwchar.h>
# endif
# ifndef _STLP_INTERNAL_IOS_H
# include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
# endif
#ifndef _STLP_INTERNAL_OSTREAM_H
# include <stl/_ostream.h> // Needed as a base class of basic_iostream.
#endif
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
# include <stl/_istreambuf_iterator.h>
#endif
#include <stl/_ctraits_fns.h> // Helper functions that allow char traits
// to be used as function objects.
_STLP_BEGIN_NAMESPACE
template <class _CharT, class _Traits, class _Number>
ios_base::iostate _STLP_CALL
_M_get_num(basic_istream<_CharT, _Traits>& __that, _Number& __val);
#if defined (_STLP_USE_TEMPLATE_EXPORT)
template <class _CharT, class _Traits>
class _Isentry;
#endif
struct _No_Skip_WS {}; // Dummy class used by sentry.
template <class _CharT, class _Traits>
bool _M_init_skip(basic_istream<_CharT, _Traits>& __is);
template <class _CharT, class _Traits>
bool _M_init_noskip(basic_istream<_CharT, _Traits>& __is);
//----------------------------------------------------------------------
// Class basic_istream, a class that performs formatted input through
// a stream buffer.
// The second template parameter, _Traits, defaults to char_traits<_CharT>.
// The default is declared in header <iosfwd>, and it isn't declared here
// because C++ language rules do not allow it to be declared twice.
template <class _CharT, class _Traits>
class basic_istream : virtual public basic_ios<_CharT, _Traits> {
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;
typedef basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_istream<_CharT, _Traits> _Self;
typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
typedef _Self& (_STLP_CALL *__istream_fn)(_Self&);
public: // Constructor and destructor.
explicit basic_istream(basic_streambuf<_CharT, _Traits>* __buf) :
basic_ios<_CharT, _Traits>(), _M_gcount(0) {
this->init(__buf);
}
~basic_istream() {};
public: // Nested sentry class.
public: // Hooks for manipulators. The arguments are
// function pointers.
_Self& operator>> (__istream_fn __f) { return __f(*this); }
_Self& operator>> (__ios_fn __f) { __f(*this); return *this; }
_Self& operator>> (__ios_base_fn __f) { __f(*this); return *this; }
public: // Formatted input of numbers.
_Self& operator>> (short& __val) {
long __lval;
unsigned short __uval;
_M_get_num(*this, __lval);
__val = __STATIC_CAST(short, __lval);
__uval = __lval;
// check if we lose digits
// if ((__val != __lval) && ((unsigned short)__val != __lval))
if ((__val != __lval) && ((long)__uval != __lval))
this->setstate(ios_base::failbit);
return *this;
}
_Self& operator>> (int& __val) {
long __lval;
unsigned int __uval;
_M_get_num(*this, __lval);
__val = __lval;
__uval = __lval;
// check if we lose digits
// if ((__val != __lval) && ((unsigned int)__val != __lval))
if ((__val != __lval) && ((long)__uval != __lval))
this->setstate(ios_base::failbit);
return *this;
}
_Self& operator>> (unsigned short& __val) { _M_get_num(*this, __val); return *this; }
_Self& operator>> (unsigned int& __val) { _M_get_num(*this, __val); return *this; }
_Self& operator>> (long& __val) { _M_get_num(*this, __val); return *this; }
_Self& operator>> (unsigned long& __val) { _M_get_num(*this, __val); return *this; }
#ifdef _STLP_LONG_LONG
_Self& operator>> (_STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
_Self& operator>> (unsigned _STLP_LONG_LONG& __val) { _M_get_num(*this, __val); return *this; }
#endif
_Self& operator>> (float& __val) { _M_get_num(*this, __val); return *this; }
_Self& operator>> (double& __val) { _M_get_num(*this, __val); return *this; }
# ifndef _STLP_NO_LONG_DOUBLE
_Self& operator>> (long double& __val) { _M_get_num(*this, __val); return *this; }
# endif
# ifndef _STLP_NO_BOOL
_Self& operator>> (bool& __val) { _M_get_num(*this, __val); return *this; }
# endif
_Self& operator>> (void*& __val) { _M_get_num(*this, __val); return *this; }
public: // Copying characters into a streambuf.
_Self& operator>>(basic_streambuf<_CharT, _Traits>*);
public: // Unformatted input.
streamsize gcount() const { return _M_gcount; }
int_type peek();
public: // get() for single characters
int_type get();
_Self& get(char_type& __c);
public: // get() for character arrays.
_Self& get(char_type* __s, streamsize __n, char_type __delim);
_Self& get(char_type* __s, streamsize __n)
{ return get(__s, __n, this->widen('\n')); }
public: // get() for streambufs
_Self& get(basic_streambuf<_CharT, _Traits>& __buf,
char_type __delim);
_Self& get(basic_streambuf<_CharT, _Traits>& __buf)
{ return get(__buf, this->widen('\n')); }
public: // getline()
_Self& getline(char_type* __s, streamsize __n, char_type delim);
_Self& getline(char_type* __s, streamsize __n)
{ return getline(__s, __n, this->widen('\n')); }
public: // read(), readsome(), ignore()
_Self& ignore();
_Self& ignore(streamsize __n);
#if (defined (_STLP_MSVC) && _STLP_MSVC < 1200)
inline
#endif
_Self& ignore(streamsize __n, int_type __delim);
_Self& read(char_type* __s, streamsize __n);
streamsize readsome(char_type* __s, streamsize __n);
public: // putback
_Self& putback(char_type __c);
_Self& unget();
public: // Positioning and buffer control.
int sync();
pos_type tellg();
_Self& seekg(pos_type __pos);
_Self& seekg(off_type, ios_base::seekdir);
public: // Helper functions for non-member extractors.
void _M_formatted_get(_CharT& __c);
void _M_formatted_get(_CharT* __s);
void _M_skip_whitespace(bool __set_failbit);
private: // Number of characters extracted by the
streamsize _M_gcount; // most recent unformatted input function.
public:
#if defined (_STLP_USE_TEMPLATE_EXPORT)
// If we are using DLL specs, we have not to use inner classes
// end class declaration here
typedef _Isentry<_CharT, _Traits> sentry;
};
# define sentry _Isentry
template <class _CharT, class _Traits>
class _Isentry {
typedef _Isentry<_CharT, _Traits> _Self;
# else
class sentry {
typedef sentry _Self;
#endif
private:
const bool _M_ok;
// basic_streambuf<_CharT, _Traits>* _M_buf;
public:
typedef _Traits traits_type;
explicit sentry(basic_istream<_CharT, _Traits>& __is,
bool __noskipws = false) :
_M_ok((__noskipws || !(__is.flags() & ios_base::skipws)) ? _M_init_noskip(__is) : _M_init_skip(__is) )
/* , _M_buf(__is.rdbuf()) */
{}
// Calling this constructor is the same as calling the previous one with
// __noskipws = true, except that it doesn't require a runtime test.
sentry(basic_istream<_CharT, _Traits>& __is, _No_Skip_WS) : /* _M_buf(__is.rdbuf()), */
_M_ok(_M_init_noskip(__is)) {}
~sentry() {}
operator bool() const { return _M_ok; }
private: // Disable assignment and copy constructor.
sentry(const _Self&) : _M_ok(false) {}
void operator=(const _Self&) {}
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
# undef sentry
# else
// close basic_istream class definition here
};
# endif
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<char, char_traits<char> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<char, char_traits<char> >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS _Isentry<wchar_t, char_traits<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_istream<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
// Non-member character and string extractor functions.
template <class _CharT, class _Traits>
inline basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT& __c) {
__in._M_formatted_get(__c);
return __in;
}
template <class _Traits>
inline basic_istream<char, _Traits>& _STLP_CALL
operator>>(basic_istream<char, _Traits>& __in, unsigned char& __c) {
__in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
return __in;
}
template <class _Traits>
inline basic_istream<char, _Traits>& _STLP_CALL
operator>>(basic_istream<char, _Traits>& __in, signed char& __c) {
__in._M_formatted_get(__REINTERPRET_CAST(char&,__c));
return __in;
}
template <class _CharT, class _Traits>
inline basic_istream<_CharT, _Traits>& _STLP_CALL
operator>>(basic_istream<_CharT, _Traits>& __in, _CharT* __s) {
__in._M_formatted_get(__s);
return __in;
}
template <class _Traits>
inline basic_istream<char, _Traits>& _STLP_CALL
operator>>(basic_istream<char, _Traits>& __in, unsigned char* __s) {
__in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
return __in;
}
template <class _Traits>
inline basic_istream<char, _Traits>& _STLP_CALL
operator>>(basic_istream<char, _Traits>& __in, signed char* __s) {
__in._M_formatted_get(__REINTERPRET_CAST(char*,__s));
return __in;
}
//----------------------------------------------------------------------
// istream manipulator.
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>& _STLP_CALL
ws(basic_istream<_CharT, _Traits>& __is);
//----------------------------------------------------------------------
// Class iostream.
template <class _CharT, class _Traits>
class basic_iostream
: public basic_istream<_CharT, _Traits>,
public basic_ostream<_CharT, _Traits>
{
public:
typedef basic_ios<_CharT, _Traits> _Basic_ios;
explicit basic_iostream(basic_streambuf<_CharT, _Traits>* __buf);
virtual ~basic_iostream();
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<char, char_traits<char> >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_iostream<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& __is)
{
return __is.rdbuf();
}
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_istream.c>
# endif
#endif /* _STLP_INTERNAL_ISTREAM_H */
// Local Variables:
// mode:C++
// End:
+167
View File
@@ -0,0 +1,167 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
#define _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
_STLP_BEGIN_NAMESPACE
// defined in _istream.h
template <class _CharT, class _Traits>
extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_istreambuf(basic_istream<_CharT, _Traits>& ) ;
// We do not read any characters until operator* is called. operator* calls sgetc
// unless the iterator is unchanged from the last call in which case a cached value is
// used. Calls to operator++ use sbumpc.
template<class _CharT, class _Traits>
class istreambuf_iterator
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename _Traits::int_type int_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_istream<_CharT, _Traits> istream_type;
typedef input_iterator_tag iterator_category;
typedef _CharT value_type;
typedef typename _Traits::off_type difference_type;
typedef const _CharT* pointer;
typedef const _CharT& reference;
public:
istreambuf_iterator(streambuf_type* __p = 0) { this->_M_init(__p); }
// istreambuf_iterator(basic_istream<_CharT, _Traits>& __is) { this->_M_init(_M_get_istreambuf(__is)); }
inline istreambuf_iterator(basic_istream<_CharT, _Traits>& __is);
char_type operator*() const { this->_M_getc(); return _M_c; }
istreambuf_iterator<_CharT, _Traits>& operator++() { this->_M_bumpc(); return *this; }
istreambuf_iterator<_CharT, _Traits> operator++(int);
bool equal(const istreambuf_iterator<_CharT, _Traits>& __i) const {
if (this->_M_buf)
this->_M_getc();
if (__i._M_buf)
__i._M_getc();
return this->_M_eof == __i._M_eof;
}
private:
void _M_init(streambuf_type* __p) {
_M_buf = __p;
_M_eof = !__p;
// _M_is_initialized = _M_eof;
_M_have_c = false;
}
void _M_getc() const {
if (_M_have_c)
return;
int_type __c = _M_buf->sgetc();
# if !defined (_STLP_NEED_MUTABLE) /* && ! defined (__SUNPRO_CC) */
_M_c = traits_type::to_char_type(__c);
_M_eof = traits_type::eq_int_type(__c, traits_type::eof());
_M_have_c = true;
# else
typedef istreambuf_iterator<_CharT,_Traits> _Self;
_Self* __that = __CONST_CAST(_Self*, this);
__that->_M_c = __STATIC_CAST(_CharT, traits_type::to_char_type(__c));
__that->_M_eof = traits_type::eq_int_type(__c, traits_type::eof());
__that->_M_have_c = true;
# endif
}
void _M_bumpc() {
_M_buf->sbumpc();
_M_have_c = false;
}
private:
streambuf_type* _M_buf;
mutable _CharT _M_c;
mutable unsigned char _M_eof;
mutable unsigned char _M_have_c;
};
template<class _CharT, class _Traits>
inline istreambuf_iterator<_CharT, _Traits>::istreambuf_iterator(basic_istream<_CharT, _Traits>& __is)
{ this->_M_init(_M_get_istreambuf(__is)); }
template<class _CharT, class _Traits>
inline bool _STLP_CALL operator==(const istreambuf_iterator<_CharT, _Traits>& __x,
const istreambuf_iterator<_CharT, _Traits>& __y) {
return __x.equal(__y);
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template<class _CharT, class _Traits>
inline bool _STLP_CALL operator!=(const istreambuf_iterator<_CharT, _Traits>& __x,
const istreambuf_iterator<_CharT, _Traits>& __y) {
return !__x.equal(__y);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<char, char_traits<char> >;
# if defined (INSTANTIATE_WIDE_STREAMS)
_STLP_EXPORT_TEMPLATE_CLASS istreambuf_iterator<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _CharT, class _Traits>
inline input_iterator_tag _STLP_CALL iterator_category(const istreambuf_iterator<_CharT, _Traits>&) { return input_iterator_tag(); }
template <class _CharT, class _Traits>
inline streamoff* _STLP_CALL
distance_type(const istreambuf_iterator<_CharT, _Traits>&) { return (streamoff*)0; }
template <class _CharT, class _Traits>
inline _CharT* _STLP_CALL value_type(const istreambuf_iterator<_CharT, _Traits>&) { return (_CharT*)0; }
# endif
template <class _CharT, class _Traits>
istreambuf_iterator<_CharT, _Traits>
istreambuf_iterator<_CharT, _Traits>::operator++(int) {
istreambuf_iterator<_CharT, _Traits> __tmp = *this;
this->_M_bumpc();
this->_M_have_c = false;
return __tmp;
}
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+269
View File
@@ -0,0 +1,269 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ITERATOR_H
#define _STLP_INTERNAL_ITERATOR_H
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
#if defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
// This is the new version of reverse_iterator, as defined in the
// draft C++ standard. It relies on the iterator_traits template,
// which in turn relies on partial specialization. The class
// reverse_bidirectional_iterator is no longer part of the draft
// standard, but it is retained for backward compatibility.
template <class _Iterator>
class reverse_iterator :
public iterator<typename iterator_traits<_Iterator>::iterator_category,
typename iterator_traits<_Iterator>::value_type,
typename iterator_traits<_Iterator>::difference_type,
typename iterator_traits<_Iterator>::pointer,
typename iterator_traits<_Iterator>::reference>
{
protected:
_Iterator current;
typedef reverse_iterator<_Iterator> _Self;
public:
typedef typename iterator_traits<_Iterator>::iterator_category iterator_category;
typedef typename iterator_traits<_Iterator>::value_type value_type;
typedef typename iterator_traits<_Iterator>::difference_type difference_type;
typedef typename iterator_traits<_Iterator>::pointer pointer;
typedef typename iterator_traits<_Iterator>::reference reference;
typedef _Iterator iterator_type;
public:
reverse_iterator() {}
explicit reverse_iterator(iterator_type __x) : current(__x) {}
reverse_iterator(const _Self& __x) : current(__x.current) {}
_Self& operator = (const _Self& __x) { current = __x.base(); return *this; }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _Iter>
reverse_iterator(const reverse_iterator<_Iter>& __x) : current(__x.base()) {}
template <class _Iter>
_Self& operator = (const reverse_iterator<_Iter>& __x) { current = __x.base(); return *this; }
#endif /* _STLP_MEMBER_TEMPLATES */
iterator_type base() const { return current; }
reference operator*() const {
_Iterator __tmp = current;
return *--__tmp;
}
_STLP_DEFINE_ARROW_OPERATOR
_Self& operator++() {
--current;
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
--current;
return __tmp;
}
_Self& operator--() {
++current;
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
++current;
return __tmp;
}
_Self operator+(difference_type __n) const {
return _Self(current - __n);
}
_Self& operator+=(difference_type __n) {
current -= __n;
return *this;
}
_Self operator-(difference_type __n) const {
return _Self(current + __n);
}
_Self& operator-=(difference_type __n) {
current += __n;
return *this;
}
reference operator[](difference_type __n) const { return *(*this + __n); }
};
template <class _Iterator>
inline bool _STLP_CALL operator==(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return __x.base() == __y.base();
}
template <class _Iterator>
inline bool _STLP_CALL operator<(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return __y.base() < __x.base();
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Iterator>
inline bool _STLP_CALL operator!=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return !(__x == __y);
}
template <class _Iterator>
inline bool _STLP_CALL operator>(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return __y < __x;
}
template <class _Iterator>
inline bool _STLP_CALL operator<=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return !(__y < __x);
}
template <class _Iterator>
inline bool _STLP_CALL operator>=(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return !(__x < __y);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
template <class _Iterator>
# ifdef __SUNPRO_CC
inline ptrdiff_t _STLP_CALL
# else
inline typename reverse_iterator<_Iterator>::difference_type _STLP_CALL
# endif
operator-(const reverse_iterator<_Iterator>& __x,
const reverse_iterator<_Iterator>& __y) {
return __y.base() - __x.base();
}
template <class _Iterator, class _DifferenceType>
inline reverse_iterator<_Iterator> _STLP_CALL
operator+(_DifferenceType n,const reverse_iterator<_Iterator>& x) {
return x.operator+(n);
}
# endif
template <class _Container>
class back_insert_iterator
: public iterator<output_iterator_tag,void,void,void,void>
{
protected:
_Container* container;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
explicit back_insert_iterator(_Container& __x) : container(&__x) {}
back_insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->push_back(__val);
return *this;
}
back_insert_iterator<_Container>& operator*() { return *this; }
back_insert_iterator<_Container>& operator++() { return *this; }
back_insert_iterator<_Container> operator++(int) { return *this; }
};
template <class _Container>
inline back_insert_iterator<_Container> _STLP_CALL back_inserter(_Container& __x) {
return back_insert_iterator<_Container>(__x);
}
template <class _Container>
class front_insert_iterator
: public iterator<output_iterator_tag,void,void,void,void>
{
protected:
_Container* container;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
explicit front_insert_iterator(_Container& __x) : container(&__x) {}
front_insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
container->push_front(__val);
return *this;
}
front_insert_iterator<_Container>& operator*() { return *this; }
front_insert_iterator<_Container>& operator++() { return *this; }
front_insert_iterator<_Container>& operator++(int) { return *this; }
};
template <class _Container>
inline front_insert_iterator<_Container> _STLP_CALL front_inserter(_Container& __x) {
return front_insert_iterator<_Container>(__x);
}
template <class _Container>
class insert_iterator
: public iterator<output_iterator_tag,void,void,void,void>
{
protected:
_Container* container;
typename _Container::iterator iter;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
insert_iterator(_Container& __x, typename _Container::iterator __i)
: container(&__x), iter(__i) {}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
iter = container->insert(iter, __val);
++iter;
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
template <class _Container, class _Iterator>
inline insert_iterator<_Container> _STLP_CALL
inserter(_Container& __x, _Iterator __i)
{
typedef typename _Container::iterator __iter;
return insert_iterator<_Container>(__x, __iter(__i));
}
_STLP_END_NAMESPACE
#if ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
# include <stl/_iterator_old.h>
#endif /* __NO_PARTIAL_SPEC || ANACHRONISMS */
#endif /* _STLP_INTERNAL_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+463
View File
@@ -0,0 +1,463 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
#define _STLP_INTERNAL_ITERATOR_BASE_H
#ifndef _STLP_CSTDDEF
# include <cstddef>
#endif
# if defined (_STLP_IMPORT_VENDOR_CSTD) && ! defined (_STLP_VENDOR_GLOBAL_CSTD)
_STLP_BEGIN_NAMESPACE
using namespace _STLP_VENDOR_CSTD;
_STLP_END_NAMESPACE
#endif /* _STLP_IMPORT_VENDOR_CSTD */
#ifndef __TYPE_TRAITS_H
# include <stl/type_traits.h>
#endif
_STLP_BEGIN_NAMESPACE
struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
template <class _Category, class _Tp, __DFL_TMPL_PARAM(_Distance,ptrdiff_t),
__DFL_TMPL_PARAM(_Pointer,_Tp*), __DFL_TMPL_PARAM(_Reference,_Tp&) >
struct iterator {
typedef _Category iterator_category;
typedef _Tp value_type;
typedef _Distance difference_type;
typedef _Pointer pointer;
typedef _Reference reference;
};
_STLP_TEMPLATE_NULL
struct iterator<output_iterator_tag, void, void, void, void> {
typedef output_iterator_tag iterator_category;
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
#endif
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_category(_It)
# define _STLP_DISTANCE_TYPE(_It, _Tp) distance_type(_It)
# define _STLP_VALUE_TYPE(_It, _Tp) value_type(_It)
# else
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
# define _STLP_VALUE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::value_type*)0
# define _STLP_DISTANCE_TYPE(_It, _Tp) (typename iterator_traits< _Tp >::difference_type*)0
# if defined (__BORLANDC__) || defined (__SUNPRO_CC) || ( defined (__MWERKS__) && (__MWERKS__ <= 0x2303)) || ( defined (__sgi) && defined (_COMPILER_VERSION)) || defined (__DMC__)
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) iterator_traits< _Tp >::iterator_category()
# else
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) typename iterator_traits< _Tp >::iterator_category()
# endif
# else
# define _STLP_ITERATOR_CATEGORY(_It, _Tp) __iterator_category(_It, _IsPtrType<_Tp>::_Ret())
# define _STLP_DISTANCE_TYPE(_It, _Tp) (ptrdiff_t*)0
# define _STLP_VALUE_TYPE(_It, _Tp) __value_type(_It, _IsPtrType<_Tp>::_Ret() )
# endif
# endif
template <class _Iterator>
struct iterator_traits {
typedef typename _Iterator::iterator_category iterator_category;
typedef typename _Iterator::value_type value_type;
typedef typename _Iterator::difference_type difference_type;
typedef typename _Iterator::pointer pointer;
typedef typename _Iterator::reference reference;
};
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && ! defined (__SUNPRO_CC)
# define _STLP_DIFFERENCE_TYPE(_Iterator) typename iterator_traits<_Iterator>::difference_type
# else
# define _STLP_DIFFERENCE_TYPE(_Iterator) ptrdiff_t
# endif
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
// fbp : this order keeps gcc happy
template <class _Tp>
struct iterator_traits<const _Tp*> {
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
};
template <class _Tp>
struct iterator_traits<_Tp*> {
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef _Tp& reference;
};
# if defined (__BORLANDC__)
template <class _Tp>
struct iterator_traits<_Tp* const> {
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
};
# endif
# endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) \
|| (defined (_STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && ! defined (_STLP_NO_ARROW_OPERATOR))
# define _STLP_POINTERS_SPECIALIZE( _TpP )
# define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { return &(operator*()); }
# else
# include <stl/_ptrs_specialize.h>
# endif
# ifndef _STLP_USE_OLD_HP_ITERATOR_QUERIES
// The overloaded functions iterator_category, distance_type, and
// value_type are not part of the C++ standard. (They have been
// replaced by struct iterator_traits.) They are included for
// backward compatibility with the HP STL.
// We introduce internal names for these functions.
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Iter>
inline typename iterator_traits<_Iter>::iterator_category __iterator_category(const _Iter&) {
typedef typename iterator_traits<_Iter>::iterator_category _Category;
return _Category();
}
template <class _Iter>
inline typename iterator_traits<_Iter>::difference_type* __distance_type(const _Iter&) {
typedef typename iterator_traits<_Iter>::difference_type _diff_type;
return __STATIC_CAST(_diff_type*,0);
}
template <class _Iter>
inline typename iterator_traits<_Iter>::value_type* __value_type(const _Iter&) {
typedef typename iterator_traits<_Iter>::value_type _value_type;
return __STATIC_CAST(_value_type*,0);
}
# else
template <class _Iter>
inline random_access_iterator_tag
__iterator_category(const _Iter&, const __true_type&) {
return random_access_iterator_tag();
}
template <class _Iter>
inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::iterator_category
__iterator_category(const _Iter&, const __false_type&) {
typedef typename iterator_traits<_Iter>::iterator_category _Category;
return _Category();
}
template <class _Iter>
inline ptrdiff_t* _STLP_CALL __distance_type(const _Iter&) { return (ptrdiff_t*)(0); }
template <class _Iter>
inline _STLP_TYPENAME_ON_RETURN_TYPE iterator_traits<_Iter>::value_type*
__value_type(const _Iter&, const __false_type&) {
typedef typename iterator_traits<_Iter>::value_type _value_type;
return __STATIC_CAST(_value_type*,0);
}
template <class _Tp>
inline _Tp*
__value_type(const _Tp*, const __true_type&) {
return __STATIC_CAST(_Tp*, 0);
}
# endif
#else /* old queries */
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
inline _Category _STLP_CALL iterator_category(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return _Category(); }
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
inline _Tp* _STLP_CALL value_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Tp*)(0); }
template <class _Category, class _Tp, class _Distance, class _Pointer, class _Reference>
inline _Distance* _STLP_CALL distance_type(const iterator<_Category,_Tp,_Distance,_Pointer,_Reference>&) { return (_Distance*)(0); }
template <class _Tp>
inline random_access_iterator_tag _STLP_CALL iterator_category(const _Tp*) { return random_access_iterator_tag(); }
template <class _Tp>
inline _Tp* _STLP_CALL value_type(const _Tp*) { return (_Tp*)(0); }
template <class _Tp>
inline ptrdiff_t* _STLP_CALL distance_type(const _Tp*) { return (ptrdiff_t*)(0); }
#endif /* _STLP_USE_OLD_HP_ITERATOR_QUERIES */
# if ! defined (_STLP_NO_ANACHRONISMS)
// The base classes input_iterator, output_iterator, forward_iterator,
// bidirectional_iterator, and random_access_iterator are not part of
// the C++ standard. (They have been replaced by struct iterator.)
// They are included for backward compatibility with the HP STL.
template <class _Tp, class _Distance> struct input_iterator :
public iterator <input_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
struct output_iterator : public iterator <output_iterator_tag, void, void, void, void> {};
template <class _Tp, class _Distance> struct forward_iterator :
public iterator<forward_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
template <class _Tp, class _Distance> struct bidirectional_iterator :
public iterator<bidirectional_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
template <class _Tp, class _Distance> struct random_access_iterator :
public iterator<random_access_iterator_tag, _Tp, _Distance, _Tp*, _Tp&> {};
# if defined (_STLP_BASE_MATCH_BUG) && defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
template <class _Tp, class _Distance>
inline input_iterator_tag _STLP_CALL
iterator_category(const input_iterator<_Tp, _Distance>&) { return input_iterator_tag(); }
inline output_iterator_tag _STLP_CALL
iterator_category(const output_iterator&) { return output_iterator_tag(); }
template <class _Tp, class _Distance>
inline forward_iterator_tag _STLP_CALL
iterator_category(const forward_iterator<_Tp, _Distance>&) { return forward_iterator_tag(); }
template <class _Tp, class _Distance>
inline bidirectional_iterator_tag _STLP_CALL
iterator_category(const bidirectional_iterator<_Tp, _Distance>&) { return bidirectional_iterator_tag(); }
template <class _Tp, class _Distance>
inline random_access_iterator_tag _STLP_CALL
iterator_category(const random_access_iterator<_Tp, _Distance>&) { return random_access_iterator_tag(); }
template <class _Tp, class _Distance>
inline _Tp* _STLP_CALL value_type(const input_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
template <class _Tp, class _Distance>
inline _Tp* _STLP_CALL value_type(const forward_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
template <class _Tp, class _Distance>
inline _Tp* _STLP_CALL value_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
template <class _Tp, class _Distance>
inline _Tp* _STLP_CALL value_type(const random_access_iterator<_Tp, _Distance>&) { return (_Tp*)(0); }
template <class _Tp, class _Distance>
inline _Distance* _STLP_CALL distance_type(const input_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
template <class _Tp, class _Distance>
inline _Distance* _STLP_CALL distance_type(const forward_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
template <class _Tp, class _Distance>
inline _Distance* _STLP_CALL distance_type(const bidirectional_iterator<_Tp, _Distance>&) { return (_Distance*)(0);}
template <class _Tp, class _Distance>
inline _Distance* _STLP_CALL distance_type(const random_access_iterator<_Tp, _Distance>&) { return (_Distance*)(0); }
# endif /* BASE_MATCH */
#endif /* _STLP_NO_ANACHRONISMS */
template <class _InputIterator, class _Distance>
inline void _STLP_CALL __distance(const _InputIterator& __first, const _InputIterator& __last,
_Distance& __n, const input_iterator_tag &) {
_InputIterator __it(__first);
while (__it != __last) { ++__it; ++__n; }
}
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
template <class _ForwardIterator, class _Distance>
inline void _STLP_CALL __distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
_Distance& __n, const forward_iterator_tag &) {
_ForwardIterator __it(__first);
while (__it != __last) { ++__first; ++__n; }
}
template <class _BidirectionalIterator, class _Distance>
_STLP_INLINE_LOOP void _STLP_CALL __distance(const _BidirectionalIterator& __first,
const _BidirectionalIterator& __last,
_Distance& __n, const bidirectional_iterator_tag &) {
_BidirectionalIterator __it(__first);
while (__it != __last) { ++__it; ++__n; }
}
# endif
template <class _RandomAccessIterator, class _Distance>
inline void _STLP_CALL __distance(const _RandomAccessIterator& __first,
const _RandomAccessIterator& __last,
_Distance& __n, const random_access_iterator_tag &) {
__n += __last - __first;
}
#ifndef _STLP_NO_ANACHRONISMS
template <class _InputIterator, class _Distance>
inline void _STLP_CALL distance(const _InputIterator& __first,
const _InputIterator& __last, _Distance& __n) {
__distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
#endif
template <class _InputIterator>
inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
__distance(const _InputIterator& __first, const _InputIterator& __last, const input_iterator_tag &) {
_STLP_DIFFERENCE_TYPE(_InputIterator) __n = 0;
_InputIterator __it(__first);
while (__it != __last) {
++__it; ++__n;
}
return __n;
}
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
template <class _ForwardIterator>
inline _STLP_DIFFERENCE_TYPE(_ForwardIterator) _STLP_CALL
__distance(const _ForwardIterator& __first, const _ForwardIterator& __last,
const forward_iterator_tag &)
{
_STLP_DIFFERENCE_TYPE(_ForwardIterator) __n = 0;
_ForwardIterator __it(__first);
while (__it != __last) {
++__it; ++__n;
}
return __n;
}
template <class _BidirectionalIterator>
_STLP_INLINE_LOOP _STLP_DIFFERENCE_TYPE(_BidirectionalIterator) _STLP_CALL
__distance(const _BidirectionalIterator& __first,
const _BidirectionalIterator& __last,
const bidirectional_iterator_tag &) {
_STLP_DIFFERENCE_TYPE(_BidirectionalIterator) __n = 0;
_BidirectionalIterator __it(__first);
while (__it != __last) {
++__it; ++__n;
}
return __n;
}
# endif
template <class _RandomAccessIterator>
inline _STLP_DIFFERENCE_TYPE(_RandomAccessIterator) _STLP_CALL
__distance(const _RandomAccessIterator& __first, const _RandomAccessIterator& __last,
const random_access_iterator_tag &) {
return __last - __first;
}
template <class _InputIterator>
inline _STLP_DIFFERENCE_TYPE(_InputIterator) _STLP_CALL
distance(const _InputIterator& __first, const _InputIterator& __last) {
return __distance(__first, __last, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
// fbp: those are being used for iterator/const_iterator definitions everywhere
template <class _Tp>
struct _Nonconst_traits;
template <class _Tp>
struct _Const_traits {
typedef _Tp value_type;
typedef const _Tp& reference;
typedef const _Tp* pointer;
typedef _Nonconst_traits<_Tp> _Non_const_traits;
};
template <class _Tp>
struct _Nonconst_traits {
typedef _Tp value_type;
typedef _Tp& reference;
typedef _Tp* pointer;
typedef _Nonconst_traits<_Tp> _Non_const_traits;
};
# if defined (_STLP_BASE_TYPEDEF_BUG)
// this workaround is needed for SunPro 4.0.1
template <class _Traits>
struct __cnst_traits_aux : private _Traits
{
typedef typename _Traits::value_type value_type;
};
# define __TRAITS_VALUE_TYPE(_Traits) __cnst_traits_aux<_Traits>::value_type
# else
# define __TRAITS_VALUE_TYPE(_Traits) _Traits::value_type
# endif
# if defined (_STLP_MSVC)
// MSVC specific
template <class _InputIterator, class _Dist>
inline void _STLP_CALL _Distance(_InputIterator __first,
_InputIterator __last, _Dist& __n) {
__distance(__first, __last, __n, _STLP_ITERATOR_CATEGORY(__first, _InputIterator));
}
# endif
template <class _InputIter, class _Distance>
_STLP_INLINE_LOOP void _STLP_CALL __advance(_InputIter& __i, _Distance __n, const input_iterator_tag &) {
while (__n--) ++__i;
}
// fbp : added output iterator tag variant
template <class _InputIter, class _Distance>
_STLP_INLINE_LOOP void _STLP_CALL __advance(_InputIter& __i, _Distance __n, const output_iterator_tag &) {
while (__n--) ++__i;
}
# if defined (_STLP_NONTEMPL_BASE_MATCH_BUG)
template <class _ForwardIterator, class _Distance>
_STLP_INLINE_LOOP void _STLP_CALL __advance(_ForwardIterator& i, _Distance n, const forward_iterator_tag &) {
while (n--) ++i;
}
# endif
template <class _BidirectionalIterator, class _Distance>
_STLP_INLINE_LOOP void _STLP_CALL __advance(_BidirectionalIterator& __i, _Distance __n,
const bidirectional_iterator_tag &) {
if (__n > 0)
while (__n--) ++__i;
else
while (__n++) --__i;
}
template <class _RandomAccessIterator, class _Distance>
inline void _STLP_CALL __advance(_RandomAccessIterator& __i, _Distance __n,
const random_access_iterator_tag &) {
__i += __n;
}
template <class _InputIterator, class _Distance>
inline void _STLP_CALL advance(_InputIterator& __i, _Distance __n) {
__advance(__i, __n, _STLP_ITERATOR_CATEGORY(__i, _InputIterator));
}
_STLP_END_NAMESPACE
# if defined (_STLP_DEBUG) && ! defined (_STLP_DEBUG_H)
# include <stl/debug/_debug.h>
# endif
#endif /* _STLP_INTERNAL_ITERATOR_BASE_H */
// Local Variables:
// mode:C++
// End:
+351
View File
@@ -0,0 +1,351 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_ITERATOR_OLD_H
#define _STLP_INTERNAL_ITERATOR_OLD_H
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const back_insert_iterator<_Container>&) { return output_iterator_tag(); }
template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const front_insert_iterator<_Container>&) { return output_iterator_tag(); }
template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const insert_iterator<_Container>&) { return output_iterator_tag(); }
# endif
# if defined (_STLP_MSVC50_COMPATIBILITY)
# define __Reference _Reference, class _Pointer
# define Reference__ _Reference, _Pointer
template <class _BidirectionalIterator, class _Tp,
__DFL_TMPL_PARAM(_Reference, _Tp& ),
__DFL_TMPL_PARAM(_Pointer, _Tp*),
__DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
# else
# define __Reference _Reference
# define Reference__ _Reference
template <class _BidirectionalIterator, class _Tp, __DFL_TMPL_PARAM(_Reference, _Tp& ),
__DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
# endif
class reverse_bidirectional_iterator {
typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
Reference__, _Distance> _Self;
// friend inline bool operator== _STLP_NULL_TMPL_ARGS (const _Self& x, const _Self& y);
protected:
_BidirectionalIterator current;
public:
typedef bidirectional_iterator_tag iterator_category;
typedef _Tp value_type;
typedef _Distance difference_type;
# if defined (_STLP_MSVC50_COMPATIBILITY)
typedef _Pointer pointer;
# else
typedef _Tp* pointer;
# endif
typedef _Reference reference;
reverse_bidirectional_iterator() {}
explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
: current(__x) {}
_BidirectionalIterator base() const { return current; }
_Reference operator*() const {
_BidirectionalIterator __tmp = current;
return *--__tmp;
}
# if !(defined _STLP_NO_ARROW_OPERATOR)
_STLP_DEFINE_ARROW_OPERATOR
# endif
_Self& operator++() {
--current;
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
--current;
return __tmp;
}
_Self& operator--() {
++current;
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
++current;
return __tmp;
}
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _BidirectionalIterator, class _Tp, class __Reference,
class _Distance>
inline bidirectional_iterator_tag _STLP_CALL
iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return bidirectional_iterator_tag(); }
template <class _BidirectionalIterator, class _Tp, class __Reference,
class _Distance>
inline _Tp* _STLP_CALL
value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return (_Tp*) 0; }
template <class _BidirectionalIterator, class _Tp, class __Reference,
class _Distance>
inline _Distance* _STLP_CALL
distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return (_Distance*) 0; }
#endif
template <class _BidirectionalIterator, class _Tp, class __Reference,
class _Distance>
inline bool _STLP_CALL operator==(
const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
Reference__, _Distance>& __y)
{
return __x.base() == __y.base();
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _BiIter, class _Tp, class __Reference, class _Distance>
inline bool _STLP_CALL operator!=(
const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __x,
const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __y)
{
return !(__x == __y);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
#if ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
// This is the old version of reverse_iterator, as found in the original
// HP STL. It does not use partial specialization.
template <class _RandomAccessIterator,
# if defined (__MSL__) && (__MSL__ >= 0x2405) \
|| defined(__MRC__) || (defined(__SC__) && !defined(__DMC__)) //*ty 03/22/2001 - give the default to the secont param under MPW.
// I believe giving the default will cause any harm even though the 2nd type parameter
// still have to be provided for T* type iterators.
__DFL_TMPL_PARAM(_Tp,iterator_traits<_RandomAccessIterator>::value_type),
# else
class _Tp,
#endif
__DFL_TMPL_PARAM(_Reference,_Tp&),
# if defined (_STLP_MSVC50_COMPATIBILITY)
__DFL_TMPL_PARAM(_Pointer, _Tp*),
# endif
__DFL_TYPE_PARAM(_Distance,ptrdiff_t)>
class reverse_iterator {
typedef reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>
_Self;
protected:
_RandomAccessIterator __current;
public:
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef _Distance difference_type;
# if defined (_STLP_MSVC50_COMPATIBILITY)
typedef _Pointer pointer;
# else
typedef _Tp* pointer;
# endif
typedef _Reference reference;
reverse_iterator() {}
reverse_iterator(const _Self& __x) : __current(__x.base()) {}
explicit reverse_iterator(_RandomAccessIterator __x) : __current(__x) {}
_Self& operator=(const _Self& __x) {__current = __x.base(); return *this; }
_RandomAccessIterator base() const { return __current; }
_Reference operator*() const { return *(__current - (difference_type)1); }
# if !(defined _STLP_NO_ARROW_OPERATOR)
_STLP_DEFINE_ARROW_OPERATOR
# endif
_Self& operator++() {
--__current;
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
--__current;
return __tmp;
}
_Self& operator--() {
++__current;
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
++__current;
return __tmp;
}
_Self operator+(_Distance __n) const {
return _Self(__current - __n);
}
_Self& operator+=(_Distance __n) {
__current -= __n;
return *this;
}
_Self operator-(_Distance __n) const {
return _Self(__current + __n);
}
_Self& operator-=(_Distance __n) {
__current += __n;
return *this;
}
_Reference operator[](_Distance __n) const { return *(*this + __n); }
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline random_access_iterator_tag _STLP_CALL
iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return random_access_iterator_tag(); }
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline _Tp* _STLP_CALL value_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return (_Tp*) 0; }
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline _Distance* _STLP_CALL
distance_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return (_Distance*) 0; }
#endif
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y)
{
return __x.base() == __y.base();
}
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y)
{
return __y.base() < __x.base();
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y) {
return !(__x == __y);
}
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y) {
return __y < __x;
}
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y) {
return !(__y < __x);
}
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline bool _STLP_CALL
operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y) {
return !(__x < __y);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline _Distance _STLP_CALL
operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __y)
{
return __y.base() - __x.base();
}
template <class _RandomAccessIterator, class _Tp,
class __Reference, class _Distance>
inline reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance> _STLP_CALL
operator+(_Distance __n,
const reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>& __x)
{
return reverse_iterator<_RandomAccessIterator, _Tp,
Reference__, _Distance>(__x.base() - __n);
}
#endif /* ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) */
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+293
View File
@@ -0,0 +1,293 @@
/*
* Copyright (c) 1998,1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
# if !defined (_STLP_LIMITS_C)
# define _STLP_LIMITS_C
#ifndef _STLP_INTERNAL_LIMITS_H
# include <stl/_limits.h>
#endif
//==========================================================
// numeric_limits static members
//==========================================================
_STLP_BEGIN_NAMESPACE
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
# define __declare_numeric_base_member(__type, __mem, _Init) \
template <class __number> \
const __type _Numeric_limits_base<__number>:: __mem
__declare_numeric_base_member(bool, is_specialized, false);
__declare_numeric_base_member(int, digits, 0);
__declare_numeric_base_member(int, digits10, 0);
__declare_numeric_base_member(bool, is_signed, false);
__declare_numeric_base_member(bool, is_integer, false);
__declare_numeric_base_member(bool, is_exact, false);
__declare_numeric_base_member(int, radix, 0);
__declare_numeric_base_member(int, min_exponent, 0);
__declare_numeric_base_member(int, max_exponent, 0);
__declare_numeric_base_member(int, min_exponent10, 0);
__declare_numeric_base_member(int, max_exponent10, 0);
__declare_numeric_base_member(bool, has_infinity, false);
__declare_numeric_base_member(bool, has_quiet_NaN, false);
__declare_numeric_base_member(bool, has_signaling_NaN, false);
__declare_numeric_base_member(float_denorm_style, has_denorm, denorm_absent);
__declare_numeric_base_member(bool, has_denorm_loss, false);
__declare_numeric_base_member(bool, is_iec559, false);
__declare_numeric_base_member(bool, is_bounded, false);
__declare_numeric_base_member(bool, is_modulo, false);
__declare_numeric_base_member(bool, traps, false);
__declare_numeric_base_member(bool, tinyness_before, false);
__declare_numeric_base_member(float_round_style, round_style, round_toward_zero);
# undef __declare_numeric_base_member
# define __declare_integer_limits_member(__type, __mem, _Init) \
template <class _Int, _STLP_LIMITS_MIN_TYPE __imin, _STLP_LIMITS_MAX_TYPE __imax, int __idigits, bool __ismod> \
const __type _Integer_limits<_Int, __imin, __imax, __idigits, __ismod>:: __mem
__declare_integer_limits_member(bool, is_specialized, true);
__declare_integer_limits_member(int, digits, (__idigits < 0) ? \
((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1)) \
: (__idigits) );
__declare_integer_limits_member(int, digits10, (int)(301UL * digits) /1000);
__declare_integer_limits_member(bool, is_signed, __imin != 0);
__declare_integer_limits_member(bool, is_integer, true);
__declare_integer_limits_member(bool, is_exact, true);
__declare_integer_limits_member(int, radix, 2);
__declare_integer_limits_member(bool, is_bounded, true);
__declare_integer_limits_member(bool, is_modulo, true);
# define __declare_float_limits_member(__type, __mem, _Init) \
template <class __number, \
int __Digits, int __Digits10, \
int __MinExp, int __MaxExp, \
int __MinExp10, int __MaxExp10, \
bool __IsIEC559, \
float_round_style __RoundStyle> \
const __type _Floating_limits< __number, __Digits, __Digits10, \
__MinExp, __MaxExp, __MinExp10, __MaxExp10, \
__IsIEC559, __RoundStyle>::\
__mem
__declare_float_limits_member(bool, is_specialized, true);
__declare_float_limits_member(int, digits, __Digits);
__declare_float_limits_member(int, digits10, __Digits10);
__declare_float_limits_member(bool, is_signed, true);
__declare_float_limits_member(int, radix, FLT_RADIX);
__declare_float_limits_member(int, min_exponent, __MinExp);
__declare_float_limits_member(int, max_exponent, __MaxExp);
__declare_float_limits_member(int, min_exponent10, __MinExp10);
__declare_float_limits_member(int, max_exponent10, __MaxExp10);
__declare_float_limits_member(bool, has_infinity, true);
__declare_float_limits_member(bool, has_quiet_NaN, true);
__declare_float_limits_member(bool, has_signaling_NaN, true);
__declare_float_limits_member(float_denorm_style, has_denorm, denorm_indeterminate);
__declare_float_limits_member(bool, has_denorm_loss, false);
__declare_float_limits_member(bool, is_iec559, __IsIEC559);
__declare_float_limits_member(bool, is_bounded, true);
__declare_float_limits_member(bool, traps, true);
__declare_float_limits_member(bool, tinyness_before, false);
__declare_float_limits_member(float_round_style, round_style, __RoundStyle);
# endif /* _STLP_STATIC_CONST_INIT_BUG */
# ifdef _STLP_EXPOSE_GLOBALS_IMPLEMENTATION
# if defined(_STLP_BIG_ENDIAN)
# if defined(__OS400__)
# define _STLP_FLOAT_INF_REP { 0x7f80, 0 }
# define _STLP_FLOAT_QNAN_REP { 0xffc0, 0 }
# define _STLP_FLOAT_SNAN_REP { 0xff80, 0 }
# define _STLP_DOUBLE_INF_REP { 0x7ff0, 0, 0, 0 }
# define _STLP_DOUBLE_QNAN_REP { 0xfff8, 0, 0, 0 }
# define _STLP_DOUBLE_SNAN_REP { 0xfff0, 0, 0, 0 }
# define _STLP_LDOUBLE_INF_REP { 0x7ff0, 0, 0, 0, 0, 0, 0, 0 }
# define _STLP_LDOUBLE_QNAN_REP { 0xfff8, 0, 0, 0, 0, 0, 0, 0 }
# define _STLP_LDOUBLE_SNAN_REP { 0xfff0, 0, 0, 0, 0, 0, 0, 0 }
# else
# define _STLP_FLOAT_INF_REP { 0x7f80, 0 }
# define _STLP_FLOAT_SNAN_REP { 0x7f81, 0 }
# define _STLP_FLOAT_QNAN_REP { 0x7fc1, 0 }
# define _STLP_DOUBLE_INF_REP { 0x7ff0, 0, 0, 0 }
# define _STLP_DOUBLE_QNAN_REP { 0x7ff1, 0, 0, 0 }
# define _STLP_DOUBLE_SNAN_REP { 0x7ff9, 0, 0, 0 }
# define _STLP_LDOUBLE_INF_REP { 0x7ff0, 0, 0, 0, 0, 0, 0, 0 }
# define _STLP_LDOUBLE_SNAN_REP { 0x7ff1, 0, 0, 0, 0, 0, 0, 0 }
# define _STLP_LDOUBLE_QNAN_REP { 0x7ff9, 0, 0, 0, 0, 0, 0, 0 }
# endif
# elif defined (_STLP_LITTLE_ENDIAN)
# if 0 /* defined(_STLP_MSVC) || defined(__linux__) */
// some IA-32 platform ??
# define _STLP_FLOAT_INF_REP { 0, 0x7f80 }
# define _STLP_FLOAT_QNAN_REP { 0, 0xffc0 }
# define _STLP_FLOAT_SNAN_REP { 0, 0xff80 }
# define _STLP_DOUBLE_INF_REP { 0, 0, 0, 0x7ff0 }
# define _STLP_DOUBLE_QNAN_REP { 0, 0, 0, 0xfff8 }
# define _STLP_DOUBLE_SNAN_REP { 0, 0, 0, 0xfff0 }
# define _STLP_LDOUBLE_INF_REP { 0, 0, 0, 0x7FF0, 0 } // ????
# define _STLP_LDOUBLE_QNAN_REP { 0, 0, 0, 0xFFF8, 0 } // ????
# define _STLP_LDOUBLE_SNAN_REP { 0, 0, 0, 0xFFF0, 0 } // ????
# elif defined(__DECCXX)
# define _STLP_FLOAT_INF_REP { 0, 0x7f80 }
# define _STLP_FLOAT_QNAN_REP { 0, 0xffc0 }
# define _STLP_FLOAT_SNAN_REP { 0x5555, 0x7f85 }
# define _STLP_DOUBLE_INF_REP { 0, 0, 0, 0x7ff0 }
# define _STLP_DOUBLE_QNAN_REP { 0, 0, 0, 0xfff8 }
# define _STLP_DOUBLE_SNAN_REP { 0x5555, 0x5555, 0x5555, 0x7ff5 }
# define _STLP_LDOUBLE_INF_REP { 0, 0, 0, 0, 0, 0, 0, 0x7fff }
# define _STLP_LDOUBLE_QNAN_REP { 0, 0, 0, 0, 0, 0, 0x8000, 0xffff }
# define _STLP_LDOUBLE_SNAN_REP { 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x5555, 0x7fff}
# else
# define _STLP_FLOAT_INF_REP { 0, 0x7f80 }
# define _STLP_FLOAT_QNAN_REP { 0, 0x7fa0 }
# define _STLP_FLOAT_SNAN_REP { 0, 0x7fc0 }
# define _STLP_DOUBLE_INF_REP { 0, 0, 0, 0x7ff0 }
# define _STLP_DOUBLE_QNAN_REP { 0, 0, 0, 0x7ff4 }
# define _STLP_DOUBLE_SNAN_REP { 0, 0, 0, 0x7ff8 }
# if defined (_STLP_MSVC) || defined (__ICL) || defined (__BORLANDC__)
# define _STLP_LDOUBLE_INF_REP { 0, 0, 0, 0x7FF0, 0 } // ????
# define _STLP_LDOUBLE_QNAN_REP { 0, 0, 0, 0xFFF8, 0 } // ????
# define _STLP_LDOUBLE_SNAN_REP { 0, 0, 0, 0xFFF8, 0 }
# else
# define _STLP_LDOUBLE_INF_REP { 0, 0, 0, 0x8000, 0x7fff }
# define _STLP_LDOUBLE_QNAN_REP { 0, 0, 0, 0xa000, 0x7fff }
# define _STLP_LDOUBLE_SNAN_REP { 0, 0, 0, 0xc000, 0x7fff }
# endif
# endif
#else
/* This is an architecture we don't know how to handle. Return some
obviously wrong values. */
# define _STLP_FLOAT_INF_REP { 0, 0 }
# define _STLP_FLOAT_QNAN_REP { 0, 0 }
# define _STLP_FLOAT_SNAN_REP { 0, 0 }
# define _STLP_DOUBLE_INF_REP { 0, 0 }
# define _STLP_DOUBLE_QNAN_REP { 0, 0 }
# define _STLP_DOUBLE_SNAN_REP { 0, 0 }
# define _STLP_LDOUBLE_INF_REP { 0 }
# define _STLP_LDOUBLE_QNAN_REP { 0 }
# define _STLP_LDOUBLE_SNAN_REP { 0 }
#endif
# if 0
# if defined(_STLP_BIG_ENDIAN)
# elif defined (_STLP_LITTLE_ENDIAN)
#else
/* This is an architecture we don't know how to handle. Return some
obviously wrong values. */
# define _STLP_FLOAT_INF_REP { 0, 0 }
# define _STLP_FLOAT_QNAN_REP { 0, 0 }
# define _STLP_FLOAT_SNAN_REP { 0, 0 }
# define _STLP_DOUBLE_INF_REP { 0, 0 }
# define _STLP_DOUBLE_QNAN_REP { 0, 0 }
# define _STLP_DOUBLE_SNAN_REP { 0, 0 }
# define _STLP_LDOUBLE_INF_REP { 0 }
# define _STLP_LDOUBLE_QNAN_REP { 0 }
# define _STLP_LDOUBLE_SNAN_REP { 0 }
#endif
# endif
#if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
# ifndef _STLP_NO_LONG_DOUBLE
template <class __dummy>
const _L_rep _LimG<__dummy>::_L_inf = {_STLP_LDOUBLE_INF_REP};
template <class __dummy>
const _L_rep _LimG<__dummy>::_L_qNaN = {_STLP_LDOUBLE_QNAN_REP};
template <class __dummy>
const _L_rep _LimG<__dummy>::_L_sNaN = {_STLP_LDOUBLE_SNAN_REP};
# endif
template <class __dummy>
const _D_rep _LimG<__dummy>::_D_inf = {_STLP_DOUBLE_INF_REP};
template <class __dummy>
const _D_rep _LimG<__dummy>::_D_qNaN = {_STLP_DOUBLE_QNAN_REP};
template <class __dummy>
const _D_rep _LimG<__dummy>::_D_sNaN = {_STLP_DOUBLE_SNAN_REP};
template <class __dummy>
const _F_rep _LimG<__dummy>::_F_inf = {_STLP_FLOAT_INF_REP};
template <class __dummy>
const _F_rep _LimG<__dummy>::_F_qNaN = {_STLP_FLOAT_QNAN_REP};
template <class __dummy>
const _F_rep _LimG<__dummy>::_F_sNaN = {_STLP_FLOAT_SNAN_REP};
#else
__DECLARE_INSTANCE( const _F_rep,
_LimG<bool>::_F_inf, = _STLP_FLOAT_INF_REP);
__DECLARE_INSTANCE( const _F_rep,
_LimG<bool>::_F_qNaN, = _STLP_FLOAT_QNAN_REP);
__DECLARE_INSTANCE( const _F_rep,
_LimG<bool>::_F_sNaN, = _STLP_FLOAT_SNAN_REP);
__DECLARE_INSTANCE( const _D_rep,
_LimG<bool>::_D_inf, = _STLP_DOUBLE_INF_REP);
__DECLARE_INSTANCE( const _D_rep,
_LimG<bool>::_D_qNaN, = _STLP_DOUBLE_QNAN_REP);
__DECLARE_INSTANCE( const _D_rep,
_LimG<bool>::_D_sNaN, = _STLP_DOUBLE_SNAN_REP);
# ifndef _STLP_NO_LONG_DOUBLE
__DECLARE_INSTANCE( const _L_rep,
_LimG<bool>::_L_inf, = _STLP_LDOUBLE_INF_REP);
__DECLARE_INSTANCE( const _L_rep,
_LimG<bool>::_L_qNaN, = _STLP_LDOUBLE_QNAN_REP);
__DECLARE_INSTANCE( const _L_rep,
_LimG<bool>::_L_sNaN, = _STLP_LDOUBLE_SNAN_REP);
# endif
#endif /* STATIC_DATA */
# endif /* _STLP_EXPOSE_GLOBALS_IMPLEMENTATION */
# undef __declare_integer_limits_member
# undef __declare_float_limits_member
# undef __HACK_ILIMITS
# undef __HACK_NOTHING
# undef __declare_int_members
# undef __declare_float_members
# undef _STLP_LIMITS_MIN_TYPE
# undef _STLP_LIMITS_MAX_TYPE
# undef _STLP_FLOAT_INF_REP
# undef _STLP_FLOAT_QNAN_REP
# undef _STLP_FLOAT_SNAN_REP
# undef _STLP_DOUBLE_INF_REP
# undef _STLP_DOUBLE_QNAN_REP
# undef _STLP_DOUBLE_SNAN_REP
# undef _STLP_LDOUBLE_INF_REP
# undef _STLP_LDOUBLE_QNAN_REP
# undef _STLP_LDOUBLE_SNAN_REP
_STLP_END_NAMESPACE
#endif /* _STLP_LIMITS_C_INCLUDED */
+557
View File
@@ -0,0 +1,557 @@
/*
* Copyright (c) 1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This may be not portable code. Parts of numeric_limits<> are
* inherently machine-dependent. At present this file is suitable
* for the MIPS, SPARC, Alpha and ia32 architectures.
*/
#ifndef _STLP_INTERNAL_LIMITS_H
# define _STLP_INTERNAL_LIMITS_H
#ifndef _STLP_CLIMITS
# include <climits>
#endif
#ifndef _STLP_CFLOAT
# include <cfloat>
#endif
#if !defined (_STLP_NO_WCHAR_T) && !defined (_STLP_CWCHAR_H)
# include <stl/_cwchar.h>
#endif
_STLP_BEGIN_NAMESPACE
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_denorm_style {
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
// Base class for all specializations of numeric_limits.
template <class __number>
class _Numeric_limits_base {
public:
static __number (_STLP_CALL min)() _STLP_NOTHROW { return __number(); }
static __number (_STLP_CALL max)() _STLP_NOTHROW { return __number(); }
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
enum {
# else
static const int
# endif
digits = 0,
digits10 = 0,
radix = 0,
min_exponent = 0,
min_exponent10 = 0,
max_exponent = 0,
max_exponent10 = 0
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
,
has_denorm = denorm_absent,
round_style = round_toward_zero,
# else
;
static const float_denorm_style has_denorm = denorm_absent;
static const float_round_style round_style = round_toward_zero;
static const bool
# endif
is_specialized = false,
is_signed = false,
is_integer = false,
is_exact = false,
has_infinity = false,
has_quiet_NaN = false,
has_signaling_NaN = false,
has_denorm_loss = false,
is_iec559 = false,
is_bounded = false,
is_modulo = false,
traps = false,
tinyness_before = false
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
static __number _STLP_CALL epsilon() _STLP_NOTHROW { return __number(); }
static __number _STLP_CALL round_error() _STLP_NOTHROW { return __number(); }
static __number _STLP_CALL infinity() _STLP_NOTHROW { return __number(); }
static __number _STLP_CALL quiet_NaN() _STLP_NOTHROW { return __number(); }
static __number _STLP_CALL signaling_NaN() _STLP_NOTHROW { return __number(); }
static __number _STLP_CALL denorm_min() _STLP_NOTHROW { return __number(); }
};
// Base class for integers.
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
# ifdef _STLP_LONG_LONG
# define _STLP_LIMITS_MIN_TYPE _STLP_LONG_LONG
# define _STLP_LIMITS_MAX_TYPE unsigned _STLP_LONG_LONG
# else
# define _STLP_LIMITS_MIN_TYPE long
# define _STLP_LIMITS_MAX_TYPE unsigned long
# endif
# else
# define _STLP_LIMITS_MIN_TYPE _Int
# define _STLP_LIMITS_MAX_TYPE _Int
# endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
template <class _Int,
_STLP_LIMITS_MIN_TYPE __imin,
_STLP_LIMITS_MAX_TYPE __imax,
int __idigits, bool __ismod>
class _Integer_limits : public _Numeric_limits_base<_Int>
{
public:
static _Int (_STLP_CALL min) () _STLP_NOTHROW { return (_Int)__imin; }
static _Int (_STLP_CALL max) () _STLP_NOTHROW { return (_Int)__imax; }
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
enum {
# else
static const int
# endif
digits = (__idigits < 0) ?
((int)((sizeof(_Int) * (CHAR_BIT))) - ((__imin == 0) ? 0 : 1))
: (__idigits),
digits10 = (digits * 301UL) / 1000,
radix = 2
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
;
static const bool
# else
,
# endif
is_specialized = true,
is_signed = (__imin != 0),
is_integer = true,
is_exact = true,
is_bounded = true,
is_modulo = __ismod
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
};
// Base class for floating-point numbers.
template <class __number,
int __Digits, int __Digits10,
int __MinExp, int __MaxExp,
int __MinExp10, int __MaxExp10,
bool __IsIEC559,
float_round_style __RoundStyle>
class _Floating_limits : public _Numeric_limits_base<__number>
{
public:
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
enum {
# else
static const int
# endif
digits = __Digits,
digits10 = __Digits10,
radix = ( FLT_RADIX /* 2 */ ),
min_exponent = __MinExp,
max_exponent = __MaxExp,
min_exponent10 = __MinExp10,
max_exponent10 = __MaxExp10
# if defined (_STLP_STATIC_CONST_INIT_BUG)
,
has_denorm = denorm_indeterminate,
round_style = __RoundStyle,
# else
;
static const float_denorm_style has_denorm = denorm_indeterminate;
static const float_round_style round_style = __RoundStyle;
static const bool
# endif
is_specialized = true,
is_signed = true,
#if (!defined(_CRAY) || !defined(_CRAYIEEE))
has_infinity = true,
has_quiet_NaN = true,
has_signaling_NaN= true,
#else
has_infinity = false,
has_quiet_NaN = false,
has_signaling_NaN= false,
#endif
has_denorm_loss = false,
is_iec559 = __IsIEC559,
is_bounded = true,
traps = true,
tinyness_before= false
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
};
// Class numeric_limits
// The unspecialized class.
template<class _Tp>
class numeric_limits : public _Numeric_limits_base<_Tp> {};
// Specializations for all built-in integral types.
#ifndef _STLP_NO_BOOL
_STLP_TEMPLATE_NULL
class numeric_limits<bool>
: public _Integer_limits<bool, false, true, 1, false>
{};
#endif /* _STLP_NO_BOOL */
_STLP_TEMPLATE_NULL
class numeric_limits<char>
: public _Integer_limits<char, CHAR_MIN, CHAR_MAX, -1, true>
{};
# ifndef _STLP_NO_SIGNED_BUILTINS
_STLP_TEMPLATE_NULL
class numeric_limits<signed char>
: public _Integer_limits<signed char, SCHAR_MIN, SCHAR_MAX, -1, true>
{};
# endif
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned char>
: public _Integer_limits<unsigned char, 0, UCHAR_MAX, -1, true>
{};
#if !(defined ( _STLP_NO_WCHAR_T ) || defined (_STLP_WCHAR_T_IS_USHORT))
_STLP_TEMPLATE_NULL
class numeric_limits<wchar_t>
: public _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
{};
#endif
_STLP_TEMPLATE_NULL
class numeric_limits<short>
: public _Integer_limits<short, SHRT_MIN, SHRT_MAX, -1, true>
{};
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned short>
: public _Integer_limits<unsigned short, 0, USHRT_MAX, -1, true>
{};
# if defined (__xlC__) && (__xlC__ == 0x500)
# undef INT_MIN
# define INT_MIN -2147483648
# endif
_STLP_TEMPLATE_NULL
class numeric_limits<int>
: public _Integer_limits<int, INT_MIN, INT_MAX, -1, true>
{};
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned int>
: public _Integer_limits<unsigned int, 0, UINT_MAX, -1, true>
{};
_STLP_TEMPLATE_NULL
class numeric_limits<long>
: public _Integer_limits<long, LONG_MIN, LONG_MAX, -1, true>
{};
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned long>
: public _Integer_limits<unsigned long, 0, ULONG_MAX, -1, true>
{};
#ifdef _STLP_LONG_LONG
# if defined (_STLP_MSVC) || defined (__BORLANDC__)
# define LONGLONG_MAX 0x7fffffffffffffffi64
# define LONGLONG_MIN (-LONGLONG_MAX-1i64)
# define ULONGLONG_MAX 0xffffffffffffffffUi64
# else
# ifndef LONGLONG_MAX
# define LONGLONG_MAX 0x7fffffffffffffffLL
# endif
# ifndef LONGLONG_MIN
# define LONGLONG_MIN (-LONGLONG_MAX-1LL)
# endif
# ifndef ULONGLONG_MAX
# define ULONGLONG_MAX 0xffffffffffffffffULL
# endif
# endif
#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ <= 96)
_STLP_TEMPLATE_NULL
class numeric_limits<_STLP_LONG_LONG>
: public _Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
{};
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned _STLP_LONG_LONG>
: public _Integer_limits<unsigned _STLP_LONG_LONG, 0, ULONGLONG_MAX, -1, true>
{};
#else /* gcc 2.97 (after 2000-11-01), 2.98, 3.0 */
/*
newest gcc has new mangling scheme, that has problem
with generating name [instantiated] of template specialization like
_Integer_limits<_STLP_LONG_LONG, LONGLONG_MIN, LONGLONG_MAX, -1, true>
~~~~~~~~~~~~ ~~~~~~~~~~~~
Below is code that solve this problem.
- ptr
*/
_STLP_TEMPLATE_NULL
class numeric_limits<_STLP_LONG_LONG>
: public _Numeric_limits_base<_STLP_LONG_LONG>
{
public:
static _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return LONGLONG_MIN; }
static _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return LONGLONG_MAX; }
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
enum {
# else
static const int
# endif
digits = ((int)((sizeof(_STLP_LONG_LONG) * (CHAR_BIT))) - 1),
digits10 = (digits * 301UL) / 1000,
radix = 2
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
;
static const bool
# else
,
# endif
is_specialized = true,
is_signed = true,
is_integer = true,
is_exact = true,
is_bounded = true,
is_modulo = true
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
};
_STLP_TEMPLATE_NULL
class numeric_limits<unsigned _STLP_LONG_LONG>
: public _Numeric_limits_base<unsigned _STLP_LONG_LONG>
{
public:
static unsigned _STLP_LONG_LONG (_STLP_CALL min) () _STLP_NOTHROW { return 0ULL; }
static unsigned _STLP_LONG_LONG (_STLP_CALL max) () _STLP_NOTHROW { return ULONGLONG_MAX; }
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
enum {
# else
static const int
# endif
digits = ((int)((sizeof(unsigned _STLP_LONG_LONG) * (CHAR_BIT)))),
digits10 = (digits * 301UL) / 1000,
radix = 2
# if ! defined ( _STLP_STATIC_CONST_INIT_BUG)
;
static const bool
# else
,
# endif
is_specialized = true,
is_signed = false,
is_integer = true,
is_exact = true,
is_bounded = true,
is_modulo = true
# if defined ( _STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
};
# endif /* __GNUC__ > 2000-11-01 */
#endif /* _STLP_LONG_LONG */
// Specializations for all built-in floating-point types.
union _F_rep
{
unsigned short rep[2];
float val;
};
union _D_rep
{
unsigned short rep[4];
double val;
};
# ifndef _STLP_NO_LONG_DOUBLE
union _L_rep
{
unsigned short rep[8];
long double val;
};
# endif
template <class __dummy>
class _LimG
{
public:
static const _F_rep _F_inf;
static const _F_rep _F_qNaN;
static const _F_rep _F_sNaN;
static const _D_rep _D_inf;
static const _D_rep _D_qNaN;
static const _D_rep _D_sNaN;
# ifndef _STLP_NO_LONG_DOUBLE
static const _L_rep _L_inf;
static const _L_rep _L_qNaN;
static const _L_rep _L_sNaN;
# endif
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _LimG<bool>;
# endif
_STLP_TEMPLATE_NULL class numeric_limits<float>
: public _Floating_limits<float,
FLT_MANT_DIG, // Binary digits of precision
FLT_DIG, // Decimal digits of precision
FLT_MIN_EXP, // Minimum exponent
FLT_MAX_EXP, // Maximum exponent
FLT_MIN_10_EXP, // Minimum base 10 exponent
FLT_MAX_10_EXP, // Maximum base 10 exponent
true, // conforms to iec559
round_to_nearest>
{
public:
static float (_STLP_CALL min) () _STLP_NOTHROW { return FLT_MIN; }
static float _STLP_CALL denorm_min() _STLP_NOTHROW { return FLT_MIN; }
static float (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return FLT_MAX; }
static float _STLP_CALL epsilon() _STLP_NOTHROW { return FLT_EPSILON; }
static float _STLP_CALL round_error() _STLP_NOTHROW { return 0.5f; } // Units: ulps.
static float _STLP_CALL infinity() { return _LimG<bool>::_F_inf.val; }
static float _STLP_CALL quiet_NaN() { return _LimG<bool>::_F_qNaN.val; }
static float _STLP_CALL signaling_NaN() { return _LimG<bool>::_F_sNaN.val; }
};
_STLP_TEMPLATE_NULL class numeric_limits<double>
: public _Floating_limits<double,
DBL_MANT_DIG, // Binary digits of precision
DBL_DIG, // Decimal digits of precision
DBL_MIN_EXP, // Minimum exponent
DBL_MAX_EXP, // Maximum exponent
DBL_MIN_10_EXP, // Minimum base 10 exponent
DBL_MAX_10_EXP, // Maximum base 10 exponent
true, // conforms to iec559
round_to_nearest>
{
public:
static double (_STLP_CALL min)() _STLP_NOTHROW { return DBL_MIN; }
static double _STLP_CALL denorm_min() _STLP_NOTHROW { return DBL_MIN; }
static double (_STLP_CALL max)() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return DBL_MAX; }
static double _STLP_CALL epsilon() _STLP_NOTHROW { return DBL_EPSILON; }
static double _STLP_CALL round_error() _STLP_NOTHROW { return 0.5; } // Units: ulps.
static double _STLP_CALL infinity() { return _LimG<bool>::_D_inf.val; }
static double _STLP_CALL quiet_NaN(){ return _LimG<bool>::_D_qNaN.val; }
static double _STLP_CALL signaling_NaN() { return _LimG<bool>::_D_sNaN.val; }
};
# ifndef _STLP_NO_LONG_DOUBLE
_STLP_TEMPLATE_NULL
class numeric_limits<long double>
: public _Floating_limits<long double,
LDBL_MANT_DIG, // Binary digits of precision
LDBL_DIG, // Decimal digits of precision
LDBL_MIN_EXP, // Minimum exponent
LDBL_MAX_EXP, // Maximum exponent
LDBL_MIN_10_EXP,// Minimum base 10 exponent
LDBL_MAX_10_EXP,// Maximum base 10 exponent
false, // Doesn't conform to iec559
round_to_nearest>
{
public:
static long double (_STLP_CALL min) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
static long double _STLP_CALL denorm_min() _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MIN; }
static long double (_STLP_CALL max) () _STLP_NOTHROW { _STLP_USING_VENDOR_CSTD return LDBL_MAX; }
static long double _STLP_CALL epsilon() _STLP_NOTHROW { return LDBL_EPSILON; }
static long double _STLP_CALL round_error() _STLP_NOTHROW { return 4; } // Units: ulps.
static long double _STLP_CALL infinity() { return _LimG<bool>::_L_inf.val; }
static long double _STLP_CALL quiet_NaN() { return _LimG<bool>::_L_qNaN.val; }
static long double _STLP_CALL signaling_NaN() { return _LimG<bool>::_L_sNaN.val; }
};
# endif
// We write special values (Inf and NaN) as bit patterns and
// cast the the appropriate floating-point types.
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_limits.c>
# endif
#endif
// Local Variables:
// mode:C++
// End:
+210
View File
@@ -0,0 +1,210 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_LIST_C
#define _STLP_LIST_C
#ifndef _STLP_INTERNAL_LIST_H
# include <stl/_list.h>
#endif
#if defined (__WATCOMC__)
#include <vector>
#endif
# undef list
# define list __WORKAROUND_DBG_RENAME(list)
_STLP_BEGIN_NAMESPACE
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
template <class _Dummy>
void _STLP_CALL
_List_global<_Dummy>::_Transfer(_List_node_base* __position,
_List_node_base* __first, _List_node_base* __last) {
if (__position != __last) {
// Remove [first, last) from its old position.
((_Node*) (__last->_M_prev))->_M_next = __position;
((_Node*) (__first->_M_prev))->_M_next = __last;
((_Node*) (__position->_M_prev))->_M_next = __first;
// Splice [first, last) into its new position.
_Node* __tmp = (_Node*) (__position->_M_prev);
__position->_M_prev = __last->_M_prev;
__last->_M_prev = __first->_M_prev;
__first->_M_prev = __tmp;
}
}
#endif /* defined (__BUILDING_STLPORT) || ! defined (_STLP_OWN_IOSTREAMS) */
template <class _Tp, class _Alloc>
void
_List_base<_Tp,_Alloc>::clear()
{
_List_node<_Tp>* __cur = (_List_node<_Tp>*) this->_M_node._M_data->_M_next;
while (__cur != this->_M_node._M_data) {
_List_node<_Tp>* __tmp = __cur;
__cur = (_List_node<_Tp>*) __cur->_M_next;
_STLP_STD::_Destroy(&__tmp->_M_data);
this->_M_node.deallocate(__tmp, 1);
}
this->_M_node._M_data->_M_next = this->_M_node._M_data;
this->_M_node._M_data->_M_prev = this->_M_node._M_data;
}
# if defined (_STLP_NESTED_TYPE_PARAM_BUG)
# define size_type size_t
# endif
template <class _Tp, class _Alloc>
void list<_Tp, _Alloc>::resize(size_type __new_size, _Tp __x)
{
iterator __i = begin();
size_type __len = 0;
for ( ; __i != end() && __len < __new_size; ++__i, ++__len);
if (__len == __new_size)
erase(__i, end());
else // __i == end()
insert(end(), __new_size - __len, __x);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list<_Tp, _Alloc>& __x)
{
if (this != &__x) {
iterator __first1 = begin();
iterator __last1 = end();
const_iterator __first2 = __x.begin();
const_iterator __last2 = __x.end();
while (__first1 != __last1 && __first2 != __last2)
*__first1++ = *__first2++;
if (__first2 == __last2)
erase(__first1, __last1);
else
insert(__last1, __first2, __last2);
}
return *this;
}
template <class _Tp, class _Alloc>
void list<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
iterator __i = begin();
for ( ; __i != end() && __n > 0; ++__i, --__n)
*__i = __val;
if (__n > 0)
insert(end(), __n, __val);
else
erase(__i, end());
}
template <class _Tp, class _Alloc, class _Predicate>
void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred) {
typename list<_Tp, _Alloc>::iterator __first = __that.begin();
typename list<_Tp, _Alloc>::iterator __last = __that.end();
while (__first != __last) {
typename list<_Tp, _Alloc>::iterator __next = __first;
++__next;
if (__pred(*__first)) __that.erase(__first);
__first = __next;
}
}
template <class _Tp, class _Alloc, class _BinaryPredicate>
void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred) {
typename list<_Tp, _Alloc>::iterator __first = __that.begin();
typename list<_Tp, _Alloc>::iterator __last = __that.end();
if (__first == __last) return;
typename list<_Tp, _Alloc>::iterator __next = __first;
while (++__next != __last) {
if (__binary_pred(*__first, *__next))
__that.erase(__next);
else
__first = __next;
__next = __first;
}
}
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
_StrictWeakOrdering __comp) {
typedef typename list<_Tp, _Alloc>::iterator _Literator;
_Literator __first1 = __that.begin();
_Literator __last1 = __that.end();
_Literator __first2 = __x.begin();
_Literator __last2 = __x.end();
while (__first1 != __last1 && __first2 != __last2)
if (__comp(*__first2, *__first1)) {
_Literator __next = __first2;
_List_global_inst::_Transfer(__first1._M_node, __first2._M_node, (++__next)._M_node);
__first2 = __next;
}
else
++__first1;
if (__first2 != __last2) _List_global_inst::_Transfer(__last1._M_node, __first2._M_node, __last2._M_node);
}
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp) {
// Do nothing if the list has length 0 or 1.
if (__that._M_node._M_data->_M_next != __that._M_node._M_data &&
(__that._M_node._M_data->_M_next)->_M_next != __that._M_node._M_data) {
list<_Tp, _Alloc> __carry;
#if !defined (__WATCOMC__)
list<_Tp, _Alloc> __counter[64];
#else
__vector__<list<_Tp, _Alloc>, _Alloc> __counter(64);
#endif //*TY 05/25/2000 -
int __fill = 0;
while (!__that.empty()) {
__carry.splice(__carry.begin(), __that, __that.begin());
int __i = 0;
while(__i < __fill && !__counter[__i].empty()) {
_S_merge(__counter[__i], __carry, __comp);
__carry.swap(__counter[__i++]);
}
__carry.swap(__counter[__i]);
if (__i == __fill) ++__fill;
}
for (int __i = 1; __i < __fill; ++__i)
_S_merge(__counter[__i], __counter[__i-1], __comp);
__that.swap(__counter[__fill-1]);
}
}
# undef list
# undef size_type
_STLP_END_NAMESPACE
#endif /* _STLP_LIST_C */
// Local Variables:
// mode:C++
// End:
+575
View File
@@ -0,0 +1,575 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_LIST_H
#define _STLP_INTERNAL_LIST_H
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_INTERNAL_ALLOC_H
# include <stl/_alloc.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_CONSTRUCT_H
# include <stl/_construct.h>
# endif
# ifndef _STLP_INTERNAL_FUNCTION_BASE_H
# include <stl/_function_base.h>
# endif
_STLP_BEGIN_NAMESPACE
# undef list
# define list __WORKAROUND_DBG_RENAME(list)
struct _List_node_base {
_List_node_base* _M_next;
_List_node_base* _M_prev;
};
template <class _Dummy>
class _List_global {
public:
typedef _List_node_base _Node;
static void _STLP_CALL _Transfer(_List_node_base* __position,
_List_node_base* __first, _List_node_base* __last);
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _List_global<bool>;
# endif
typedef _List_global<bool> _List_global_inst;
template <class _Tp>
struct _List_node : public _List_node_base {
_Tp _M_data;
__TRIVIAL_STUFF(_List_node)
#ifdef __DMC__
// for some reason, Digital Mars C++ needs a constructor...
private:
_List_node();
#endif
};
struct _List_iterator_base {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef bidirectional_iterator_tag iterator_category;
_List_node_base* _M_node;
_List_iterator_base(_List_node_base* __x) : _M_node(__x) {}
_List_iterator_base() {}
void _M_incr() { _M_node = _M_node->_M_next; }
void _M_decr() { _M_node = _M_node->_M_prev; }
bool operator==(const _List_iterator_base& __y ) const {
return _M_node == __y._M_node;
}
bool operator!=(const _List_iterator_base& __y ) const {
return _M_node != __y._M_node;
}
};
template<class _Tp, class _Traits>
struct _List_iterator : public _List_iterator_base {
typedef _Tp value_type;
typedef typename _Traits::pointer pointer;
typedef typename _Traits::reference reference;
typedef _List_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
typedef _List_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
typedef _List_iterator<_Tp, _Traits> _Self;
typedef bidirectional_iterator_tag iterator_category;
typedef _List_node<_Tp> _Node;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
_List_iterator(_Node* __x) : _List_iterator_base(__x) {}
_List_iterator() {}
_List_iterator(const iterator& __x) : _List_iterator_base(__x._M_node) {}
reference operator*() const { return ((_Node*)_M_node)->_M_data; }
_STLP_DEFINE_ARROW_OPERATOR
_Self& operator++() {
this->_M_incr();
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
this->_M_incr();
return __tmp;
}
_Self& operator--() {
this->_M_decr();
return *this;
}
_Self operator--(int) {
_Self __tmp = *this;
this->_M_decr();
return __tmp;
}
};
#ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Tp, class _Traits>
inline _Tp* value_type(const _List_iterator<_Tp, _Traits>&) { return 0; }
inline bidirectional_iterator_tag iterator_category(const _List_iterator_base&) { return bidirectional_iterator_tag();}
inline ptrdiff_t* distance_type(const _List_iterator_base&) { return 0; }
#endif
// Base class that encapsulates details of allocators and helps
// to simplify EH
template <class _Tp, class _Alloc>
class _List_base
{
protected:
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef _List_node<_Tp> _Node;
typedef typename _Alloc_traits<_Node, _Alloc>::allocator_type
_Node_allocator_type;
public:
typedef typename _Alloc_traits<_Tp, _Alloc>::allocator_type
allocator_type;
allocator_type get_allocator() const {
return _STLP_CONVERT_ALLOCATOR((const _Node_allocator_type&)_M_node, _Tp);
}
_List_base(const allocator_type& __a) : _M_node(_STLP_CONVERT_ALLOCATOR(__a, _Node), (_Node*)0) {
_Node* __n = _M_node.allocate(1);
__n->_M_next = __n;
__n->_M_prev = __n;
_M_node._M_data = __n;
}
~_List_base() {
clear();
_M_node.deallocate(_M_node._M_data, 1);
}
void clear();
public:
_STLP_alloc_proxy<_Node*, _Node, _Node_allocator_type> _M_node;
};
template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
class list;
// helper functions to reduce code duplication
template <class _Tp, class _Alloc, class _Predicate>
void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred);
template <class _Tp, class _Alloc, class _BinaryPredicate>
void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred);
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
_StrictWeakOrdering __comp);
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp);
template <class _Tp, class _Alloc>
class list : public _List_base<_Tp, _Alloc> {
typedef _List_base<_Tp, _Alloc> _Base;
typedef list<_Tp, _Alloc> _Self;
public:
typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef _List_node<_Tp> _Node;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Base::allocator_type allocator_type;
typedef bidirectional_iterator_tag _Iterator_category;
public:
typedef _List_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
typedef _List_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
_STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
protected:
_Node* _M_create_node(const _Tp& __x)
{
_Node* __p = this->_M_node.allocate(1);
_STLP_TRY {
_STLP_STD::_Construct(&__p->_M_data, __x);
}
_STLP_UNWIND(this->_M_node.deallocate(__p, 1));
return __p;
}
_Node* _M_create_node()
{
_Node* __p = this->_M_node.allocate(1);
_STLP_TRY {
_STLP_STD::_Construct(&__p->_M_data);
}
_STLP_UNWIND(this->_M_node.deallocate(__p, 1));
return __p;
}
public:
# if !(defined(__MRC__)||(defined(__SC__) && !defined(__DMC__)))
explicit
# endif
list(const allocator_type& __a = allocator_type()) :
_List_base<_Tp, _Alloc>(__a) {}
iterator begin() { return iterator((_Node*)(this->_M_node._M_data->_M_next)); }
const_iterator begin() const { return const_iterator((_Node*)(this->_M_node._M_data->_M_next)); }
iterator end() { return this->_M_node._M_data; }
const_iterator end() const { return this->_M_node._M_data; }
reverse_iterator rbegin()
{ return reverse_iterator(end()); }
const_reverse_iterator rbegin() const
{ return const_reverse_iterator(end()); }
reverse_iterator rend()
{ return reverse_iterator(begin()); }
const_reverse_iterator rend() const
{ return const_reverse_iterator(begin()); }
bool empty() const { return this->_M_node._M_data->_M_next == this->_M_node._M_data; }
size_type size() const {
size_type __result = distance(begin(), end());
return __result;
}
size_type max_size() const { return size_type(-1); }
reference front() { return *begin(); }
const_reference front() const { return *begin(); }
reference back() { return *(--end()); }
const_reference back() const { return *(--end()); }
void swap(list<_Tp, _Alloc>& __x) {
_STLP_STD::swap(this->_M_node, __x._M_node);
}
iterator insert(iterator __position, const _Tp& __x) {
_Node* __tmp = _M_create_node(__x);
_List_node_base* __n = __position._M_node;
_List_node_base* __p = __n->_M_prev;
__tmp->_M_next = __n;
__tmp->_M_prev = __p;
__p->_M_next = __tmp;
__n->_M_prev = __tmp;
return __tmp;
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_insert_dispatch(__pos, __first, __last, _Integral());
}
// Check whether it's an integral type. If so, it's not an iterator.
template<class _Integer>
void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
const __true_type&) {
_M_fill_insert(__pos, (size_type) __n, (_Tp) __x);
}
template <class _InputIter>
void
_M_insert_dispatch(iterator __position,
_InputIter __first, _InputIter __last,
const __false_type&)
#else /* _STLP_MEMBER_TEMPLATES */
void insert(iterator __position, const _Tp* __first, const _Tp* __last) {
for ( ; __first != __last; ++__first)
insert(__position, *__first);
}
void insert(iterator __position, const_iterator __first, const_iterator __last)
#endif /* _STLP_MEMBER_TEMPLATES */
{
for ( ; __first != __last; ++__first)
insert(__position, *__first);
}
void insert(iterator __pos, size_type __n, const _Tp& __x) { _M_fill_insert(__pos, __n, __x); }
void _M_fill_insert(iterator __pos, size_type __n, const _Tp& __x) {
for ( ; __n > 0; --__n)
insert(__pos, __x);
}
void push_front(const _Tp& __x) { insert(begin(), __x); }
void push_back(const _Tp& __x) { insert(end(), __x); }
# ifndef _STLP_NO_ANACHRONISMS
iterator insert(iterator __position) { return insert(__position, _Tp()); }
void push_front() {insert(begin());}
void push_back() {insert(end());}
# endif
iterator erase(iterator __position) {
_List_node_base* __next_node = __position._M_node->_M_next;
_List_node_base* __prev_node = __position._M_node->_M_prev;
_Node* __n = (_Node*) __position._M_node;
__prev_node->_M_next = __next_node;
__next_node->_M_prev = __prev_node;
_STLP_STD::_Destroy(&__n->_M_data);
this->_M_node.deallocate(__n, 1);
return iterator((_Node*)__next_node);
}
iterator erase(iterator __first, iterator __last) {
while (__first != __last)
erase(__first++);
return __last;
}
void resize(size_type __new_size, _Tp __x);
void resize(size_type __new_size) { this->resize(__new_size, _Tp()); }
void pop_front() { erase(begin()); }
void pop_back() {
iterator __tmp = end();
erase(--__tmp);
}
list(size_type __n, const _Tp& __val,
const allocator_type& __a = allocator_type())
: _List_base<_Tp, _Alloc>(__a)
{ this->insert(begin(), __n, __val); }
explicit list(size_type __n)
: _List_base<_Tp, _Alloc>(allocator_type())
{ this->insert(begin(), __n, _Tp()); }
#ifdef _STLP_MEMBER_TEMPLATES
// We don't need any dispatching tricks here, because insert does all of
// that anyway.
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
list(_InputIterator __first, _InputIterator __last)
: _List_base<_Tp, _Alloc>(allocator_type())
{ insert(begin(), __first, __last); }
# endif
template <class _InputIterator>
list(_InputIterator __first, _InputIterator __last,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _List_base<_Tp, _Alloc>(__a)
{ insert(begin(), __first, __last); }
#else /* _STLP_MEMBER_TEMPLATES */
list(const _Tp* __first, const _Tp* __last,
const allocator_type& __a = allocator_type())
: _List_base<_Tp, _Alloc>(__a)
{ insert(begin(), __first, __last); }
list(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type())
: _List_base<_Tp, _Alloc>(__a)
{ insert(begin(), __first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
list(const list<_Tp, _Alloc>& __x) : _List_base<_Tp, _Alloc>(__x.get_allocator())
{ insert(begin(), __x.begin(), __x.end()); }
~list() { }
list<_Tp, _Alloc>& operator=(const list<_Tp, _Alloc>& __x);
public:
// assign(), a generalized assignment member function. Two
// versions: one that takes a count, and one that takes a range.
// The range version is a member template, so we dispatch on whether
// or not the type is an integer.
void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
void _M_fill_assign(size_type __n, const _Tp& __val);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
{ assign((size_type) __n, (_Tp) __val); }
template <class _InputIterator>
void _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
const __false_type&) {
iterator __first1 = begin();
iterator __last1 = end();
for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
*__first1 = *__first2;
if (__first2 == __last2)
erase(__first1, __last1);
else
insert(__last1, __first2, __last2);
}
#endif /* _STLP_MEMBER_TEMPLATES */
public:
void splice(iterator __position, _Self& __x) {
if (!__x.empty())
_List_global_inst::_Transfer(__position._M_node, __x.begin()._M_node, __x.end()._M_node);
}
void splice(iterator __position, _Self&, iterator __i) {
iterator __j = __i;
++__j;
if (__position == __i || __position == __j) return;
_List_global_inst::_Transfer(__position._M_node, __i._M_node, __j._M_node);
}
void splice(iterator __position, _Self&, iterator __first, iterator __last) {
if (__first != __last)
_List_global_inst::_Transfer(__position._M_node, __first._M_node, __last._M_node);
}
void remove(const _Tp& __val) {
iterator __first = begin();
iterator __last = end();
while (__first != __last) {
iterator __next = __first;
++__next;
if (__val == *__first) erase(__first);
__first = __next;
}
}
void unique() {
_S_unique(*this, equal_to<_Tp>());
}
void merge(_Self& __x) {
_S_merge(*this, __x, less<_Tp>());
}
void reverse() {
_List_node_base* __p = this->_M_node._M_data;
_List_node_base* __tmp = __p;
do {
_STLP_STD::swap(__tmp->_M_next, __tmp->_M_prev);
__tmp = __tmp->_M_prev; // Old next node is now prev.
} while (__tmp != __p);
}
void sort() {
_S_sort(*this, less<_Tp>());
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _Predicate> void remove_if(_Predicate __pred) {
_S_remove_if(*this, __pred);
}
template <class _BinaryPredicate>
void unique(_BinaryPredicate __binary_pred) {
_S_unique(*this, __binary_pred);
}
template <class _StrictWeakOrdering>
void merge(list<_Tp, _Alloc>& __x,
_StrictWeakOrdering __comp) {
_S_merge(*this, __x, __comp);
}
template <class _StrictWeakOrdering>
void sort(_StrictWeakOrdering __comp) {
_S_sort(*this, __comp);
}
#endif /* _STLP_MEMBER_TEMPLATES */
};
template <class _Tp, class _Alloc>
_STLP_INLINE_LOOP bool _STLP_CALL
operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y)
{
typedef typename list<_Tp,_Alloc>::const_iterator const_iterator;
const_iterator __end1 = __x.end();
const_iterator __end2 = __y.end();
const_iterator __i1 = __x.begin();
const_iterator __i2 = __y.begin();
while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
++__i1;
++__i2;
}
return __i1 == __end1 && __i2 == __end2;
}
# define _STLP_EQUAL_OPERATOR_SPECIALIZED
# define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
# define _STLP_TEMPLATE_CONTAINER list<_Tp, _Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
# undef _STLP_EQUAL_OPERATOR_SPECIALIZED
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_list.c>
# endif
// do a cleanup
# undef list
# define __list__ __FULL_NAME(list)
#if defined (_STLP_DEBUG)
# include <stl/debug/_list.h>
#endif
#if defined (_STLP_USE_WRAPPER_FOR_ALLOC_PARAM)
# include <stl/wrappers/_list.h>
#endif
#endif /* _STLP_INTERNAL_LIST_H */
// Local Variables:
// mode:C++
// End:
+233
View File
@@ -0,0 +1,233 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_LOCALE_H
#define _STLP_INTERNAL_LOCALE_H
#ifndef _STLP_CSTDLIB
# include <cstdlib>
#endif
#ifndef _STLP_CWCHAR_H
# include <stl/_cwchar.h>
#endif
#ifndef _STLP_INTERNAL_THREADS_H
# include <stl/_threads.h>
#endif
#ifndef _STLP_STRING_FWD_H
# include <stl/_string_fwd.h>
#endif
_STLP_BEGIN_NAMESPACE
class _STLP_CLASS_DECLSPEC _Locale_impl; // Forward declaration of opaque type.
class _STLP_CLASS_DECLSPEC _Locale; // Forward declaration of opaque type.
class _STLP_CLASS_DECLSPEC locale;
class _STLP_CLASS_DECLSPEC ios_base;
template <class _CharT>
bool
__locale_do_operator_call (const locale* __that,
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __x,
const basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >& __y);
# define _BaseFacet locale::facet
class _STLP_CLASS_DECLSPEC locale {
public:
// types:
class _STLP_DECLSPEC facet : private _Refcount_Base {
protected:
explicit facet(size_t __no_del = 0) : _Refcount_Base(1), _M_delete(__no_del == 0) {}
virtual ~facet();
friend class locale;
friend class _Locale_impl;
friend class _Locale;
private: // Invalidate assignment and copying.
facet(const facet& __f) : _Refcount_Base(1), _M_delete(__f._M_delete == 0) {};
void operator=(const facet&);
private: // Data members.
const bool _M_delete;
};
#if defined(__MVS__) || defined(__OS400__)
struct
#else
class
#endif
_STLP_DECLSPEC id {
friend class locale;
friend class _Locale_impl;
public:
size_t _M_index;
static size_t _S_max;
};
typedef int category;
# if defined (_STLP_STATIC_CONST_INIT_BUG)
enum _Category {
# else
static const category
# endif
none = 0x000,
collate = 0x010,
ctype = 0x020,
monetary = 0x040,
numeric = 0x100,
time = 0x200,
messages = 0x400,
all = collate | ctype | monetary | numeric | time | messages
# if defined (_STLP_STATIC_CONST_INIT_BUG)
}
# endif
;
// construct/copy/destroy:
locale();
locale(const locale&) _STLP_NOTHROW;
explicit locale(const char *);
locale(const locale&, const char*, category);
// those are for internal use
locale(_Locale_impl*);
locale(_Locale_impl*, bool);
public:
# if defined ( _STLP_MEMBER_TEMPLATES ) /* && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) */
template <class _Facet>
locale(const locale& __loc, _Facet* __f) : _M_impl(0)
{
// _M_impl = this->_S_copy_impl(__loc._M_impl, __f != 0);
new(this) locale(__loc._M_impl, __f != 0);
if (__f != 0)
this->_M_insert(__f, _Facet::id);
}
# endif
locale(const locale&, const locale&, category);
~locale() _STLP_NOTHROW;
const locale& operator=(const locale&) _STLP_NOTHROW;
# if !(defined (_STLP_NO_MEMBER_TEMPLATES) || defined (_STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS))
template <class _Facet> locale combine(const locale& __loc) {
locale __result(__loc._M_impl, true);
if (facet* __f = __loc._M_get_facet(_Facet::id)) {
__result._M_insert(__f, _Facet::id);
__f->_M_incr();
}
else
_M_throw_runtime_error();
return __result;
}
# endif
// locale operations:
string name() const;
bool operator==(const locale&) const;
bool operator!=(const locale&) const;
# if ! defined ( _STLP_MEMBER_TEMPLATES ) || defined (_STLP_INLINE_MEMBER_TEMPLATES) || (defined(__MWERKS__) && __MWERKS__ <= 0x2301)
bool operator()(const string& __x, const string& __y) const;
# ifndef _STLP_NO_WCHAR_T
bool operator()(const wstring& __x, const wstring& __y) const;
# endif
# else
template <class _CharT, class _Traits, class _Alloc>
bool operator()(const basic_string<_CharT, _Traits, _Alloc>& __x,
const basic_string<_CharT, _Traits, _Alloc>& __y) const {
return __locale_do_operator_call(this, __x, __y);
}
# endif
// global locale objects:
static locale _STLP_CALL global(const locale&);
static const locale& _STLP_CALL classic();
public: // Helper functions for locale globals.
facet* _M_get_facet(const id&) const;
// same, but throws
facet* _M_use_facet(const id&) const;
static void _STLP_CALL _M_throw_runtime_error(const char* = 0);
static void _STLP_CALL _S_initialize();
static void _STLP_CALL _S_uninitialize();
private: // More helper functions.
// static _Locale_impl* _STLP_CALL _S_copy_impl(_Locale_impl*, bool);
void _M_insert(facet* __f, id& __id);
// friends:
friend class _Locale_impl;
friend class _Locale;
friend class ios_base;
private: // Data members
_Locale_impl* _M_impl;
};
//----------------------------------------------------------------------
// locale globals
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
template <class _Facet>
inline const _Facet&
_Use_facet<_Facet>::operator *() const
# else
template <class _Facet> inline const _Facet& use_facet(const locale& __loc)
# endif
{
return *__STATIC_CAST(const _Facet*,__loc._M_use_facet(_Facet::id));
}
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
template <class _Facet>
struct has_facet {
const locale& __loc;
has_facet(const locale& __p_loc) : __loc(__p_loc) {}
operator bool() const _STLP_NOTHROW
# else
template <class _Facet> inline bool has_facet(const locale& __loc) _STLP_NOTHROW
# endif
{
return (__loc._M_get_facet(_Facet::id) != 0);
}
# ifdef _STLP_NO_EXPLICIT_FUNCTION_TMPL_ARGS
// close class definition
};
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_LOCALE_H */
// Local Variables:
// mode:C++
// End:
+424
View File
@@ -0,0 +1,424 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_MAP_H
#define _STLP_INTERNAL_MAP_H
#ifndef _STLP_INTERNAL_TREE_H
# include <stl/_tree.h>
#endif
#define map __WORKAROUND_RENAME(map)
#define multimap __WORKAROUND_RENAME(multimap)
_STLP_BEGIN_NAMESPACE
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_Compare, less<_Key> ),
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
class map {
public:
// typedefs:
typedef _Key key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
class value_compare
: public binary_function<value_type, value_type, bool> {
friend class map<_Key,_Tp,_Compare,_Alloc>;
protected :
_Compare _M_comp;
value_compare(_Compare __c) : _M_comp(__c) {}
public:
bool operator()(const value_type& __x, const value_type& __y) const {
return _M_comp(__x.first, __y.first);
}
};
private:
# ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
typedef _Rb_tree<key_type, value_type,
_Select1st_hint<value_type, _Key>, key_compare, _Alloc> _Rep_type;
# else
typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
# endif
_Rep_type _M_t; // red-black tree representing map
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
map() : _M_t(_Compare(), allocator_type()) {}
explicit map(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
map(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
template <class _InputIterator>
map(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
map(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
# endif
#else
map(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
map(const value_type* __first,
const value_type* __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
map(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
map(const_iterator __first, const_iterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
map(const map<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
map<_Key,_Tp,_Compare,_Alloc>&
operator=(const map<_Key, _Tp, _Compare, _Alloc>& __x)
{
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() { return _M_t.begin(); }
const_iterator begin() const { return _M_t.begin(); }
iterator end() { return _M_t.end(); }
const_iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() { return _M_t.rbegin(); }
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() { return _M_t.rend(); }
const_reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
_Tp& operator[](const key_type& __k) {
iterator __i = lower_bound(__k);
// __i->first is greater than or equivalent to __k.
if (__i == end() || key_comp()(__k, (*__i).first))
__i = insert(__i, value_type(__k, _STLP_DEFAULT_CONSTRUCTED(_Tp)));
return (*__i).second;
}
void swap(map<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
pair<iterator,bool> insert(const value_type& __x)
{ return _M_t.insert_unique(__x); }
iterator insert(iterator position, const value_type& __x)
{ return _M_t.insert_unique(position, __x); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
#else
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_unique(__first, __last);
}
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_unique(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator erase(iterator __position)
{
iterator next = __position;
next++;
_M_t.erase(__position);
return next;
}
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
void erase(iterator __first, iterator __last)
{ _M_t.erase(__first, __last); }
void clear() { _M_t.clear(); }
// map operations:
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const {
return _M_t.find(__x) == _M_t.end() ? 0 : 1;
}
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x);
}
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
template <class _Key, class _Tp, __DFL_TMPL_PARAM(_Compare, less<_Key> ),
_STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(const _Key, _Tp) >
class multimap {
public:
// typedefs:
typedef _Key key_type;
typedef _Tp data_type;
typedef _Tp mapped_type;
typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
class value_compare : public binary_function<value_type, value_type, bool> {
friend class multimap<_Key,_Tp,_Compare,_Alloc>;
protected:
_Compare _M_comp;
value_compare(_Compare __c) : _M_comp(__c) {}
public:
bool operator()(const value_type& __x, const value_type& __y) const {
return _M_comp(__x.first, __y.first);
}
};
private:
# ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
typedef _Rb_tree<key_type, value_type,
_Select1st_hint<value_type, _Key>, key_compare, _Alloc> _Rep_type;
# else
typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type;
# endif
_Rep_type _M_t; // red-black tree representing multimap
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation
multimap() : _M_t(_Compare(), allocator_type()) { }
explicit multimap(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
multimap(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
multimap(_InputIterator __first, _InputIterator __last,
const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
# endif
template <class _InputIterator>
multimap(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#else
multimap(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multimap(const value_type* __first, const value_type* __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
multimap(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multimap(const_iterator __first, const_iterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
multimap(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) : _M_t(__x._M_t) { }
multimap<_Key,_Tp,_Compare,_Alloc>&
operator=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return value_compare(_M_t.key_comp()); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() { return _M_t.begin(); }
const_iterator begin() const { return _M_t.begin(); }
iterator end() { return _M_t.end(); }
const_iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() { return _M_t.rbegin(); }
const_reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() { return _M_t.rend(); }
const_reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
iterator insert(const value_type& __x) { return _M_t.insert_equal(__x); }
iterator insert(iterator __position, const value_type& __x) {
return _M_t.insert_equal(__position, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
#else
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_equal(__first, __last);
}
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_equal(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator erase(iterator __position)
{
iterator next = __position;
next++;
_M_t.erase(__position);
return next;
}
size_type erase(const key_type& __x) { return _M_t.erase(__x); }
void erase(iterator __first, iterator __last)
{ _M_t.erase(__first, __last); }
void clear() { _M_t.clear(); }
// multimap operations:
iterator find(const key_type& __x) { return _M_t.find(__x); }
const_iterator find(const key_type& __x) const { return _M_t.find(__x); }
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) {return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) {return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) {
return _M_t.equal_range(__x);
}
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
# define _STLP_TEMPLATE_HEADER template <class _Key, class _Tp, class _Compare, class _Alloc>
# define _STLP_TEMPLATE_CONTAINER map<_Key,_Tp,_Compare,_Alloc>
// fbp : if this template header gets protected against your will, report it !
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# define _STLP_TEMPLATE_CONTAINER multimap<_Key,_Tp,_Compare,_Alloc>
// fbp : if this template header gets protected against your will, report it !
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
_STLP_END_NAMESPACE
// do a cleanup
# undef map
# undef multimap
// provide a way to access full funclionality
# define __map__ __FULL_NAME(map)
# define __multimap__ __FULL_NAME(multimap)
# ifdef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
# include <stl/wrappers/_map.h>
# endif
#endif /* _STLP_INTERNAL_MAP_H */
// Local Variables:
// mode:C++
// End:
+168
View File
@@ -0,0 +1,168 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_MESSAGES_H
#define _STLP_INTERNAL_MESSAGES_H
#ifndef _STLP_IOS_BASE_H
# include <stl/_ios_base.h>
#endif
# ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
# endif
#ifndef _STLP_STRING_H
# include <stl/_string.h>
#endif
_STLP_BEGIN_NAMESPACE
// messages facets
class messages_base {
public:
typedef int catalog;
};
template <class _CharT> class messages {};
class _Messages;
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC messages<char> : public locale::facet, public messages_base
{
friend class _Locale;
public:
typedef messages_base::catalog catalog;
typedef char char_type;
typedef string string_type;
explicit messages(size_t __refs = 0);
catalog open(const string& __fn, const locale& __loc) const
{ return do_open(__fn, __loc); }
string_type get(catalog __c, int __set, int __msgid,
const string_type& __dfault) const
{ return do_get(__c, __set, __msgid, __dfault); }
inline void close(catalog __c) const
{ do_close(__c); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
messages(_Messages*);
protected:
messages(size_t, _Locale_messages*);
~messages();
virtual catalog do_open(const string& __fn, const locale& __loc) const;
virtual string_type do_get(catalog __c, int __set, int __msgid,
const string_type& __dfault) const;
virtual void do_close(catalog __c) const;
void _M_initialize(const char* __name);
private:
_Messages* _M_impl;
};
# if !defined (_STLP_NO_WCHAR_T)
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC messages<wchar_t> : public locale::facet, public messages_base
{
friend class _Locale;
public:
typedef messages_base::catalog catalog;
typedef wchar_t char_type;
typedef wstring string_type;
explicit messages(size_t __refs = 0);
inline catalog open(const string& __fn, const locale& __loc) const
{ return do_open(__fn, __loc); }
inline string_type get(catalog __c, int __set, int __msgid,
const string_type& __dfault) const
{ return do_get(__c, __set, __msgid, __dfault); }
inline void close(catalog __c) const
{ do_close(__c); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
messages(_Messages*);
protected:
messages(size_t, _Locale_messages*);
~messages();
virtual catalog do_open(const string& __fn, const locale& __loc) const;
virtual string_type do_get(catalog __c, int __set, int __msgid,
const string_type& __dfault) const;
virtual void do_close(catalog __c) const;
void _M_initialize(const char* __name);
private:
_Messages* _M_impl;
};
# endif /* WCHAR_T */
template <class _CharT> class messages_byname {};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC messages_byname<char> : public messages<char> {
public:
typedef messages_base::catalog catalog;
typedef string string_type;
explicit messages_byname(const char* __name, size_t __refs = 0);
protected:
~messages_byname();
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC messages_byname<wchar_t> : public messages<wchar_t> {
public:
typedef messages_base::catalog catalog;
typedef wstring string_type;
explicit messages_byname(const char* __name, size_t __refs = 0);
protected:
~messages_byname();
};
# endif /* WCHAR_T */
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_MESSAGES_H */
// Local Variables:
// mode:C++
// End:
+527
View File
@@ -0,0 +1,527 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_MONETARY_C
#define _STLP_MONETARY_C
# ifndef _STLP_INTERNAL_MONETARY_H
# include <stl/_monetary.h>
# endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
#ifndef _STLP_INTERNAL_IOS_H
# include <stl/_ios.h>
#endif
#ifndef _STLP_INTERNAL_NUM_PUT_H
# include <stl/_num_put.h>
#endif
#ifndef _STLP_INTERNAL_NUM_GET_H
# include <stl/_num_get.h>
#endif
_STLP_BEGIN_NAMESPACE
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template <class _CharT, class _InputIterator>
locale::id money_get<_CharT, _InputIterator>::id;
template <class _CharT, class _OutputIterator>
locale::id money_put<_CharT, _OutputIterator>::id;
# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
typedef money_get<char, const char*> money_get_char;
typedef money_put<char, char*> money_put_char;
typedef money_get<char, istreambuf_iterator<char, char_traits<char> > > money_get_char_2;
typedef money_put<char, ostreambuf_iterator<char, char_traits<char> > > money_put_char_2;
__DECLARE_INSTANCE(locale::id, money_get_char::id, );
__DECLARE_INSTANCE(locale::id, money_put_char::id, );
__DECLARE_INSTANCE(locale::id, money_get_char_2::id, );
__DECLARE_INSTANCE(locale::id, money_put_char_2::id, );
# ifndef _STLP_NO_WCHAR_T
typedef money_get<wchar_t, const wchar_t*> money_get_wchar_t;
typedef money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_get_wchar_t_2;
typedef money_put<wchar_t, wchar_t*> money_put_wchar_t;
typedef money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > money_put_wchar_t_2;
__DECLARE_INSTANCE(locale::id, money_get_wchar_t::id, );
__DECLARE_INSTANCE(locale::id, money_put_wchar_t::id, );
__DECLARE_INSTANCE(locale::id, money_get_wchar_t_2::id, );
__DECLARE_INSTANCE(locale::id, money_put_wchar_t_2::id, );
# endif
# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
// money_get facets
// helper functions for do_get
template <class _InIt1, class _InIt2>
pair<_InIt1, bool> __get_string(_InIt1 __first, _InIt1 __last,
_InIt2 __str_first, _InIt2 __str_last) {
pair<_InIt1, _InIt2> __pr = mismatch(__first, __last, __str_first);
return make_pair(__pr.first, __pr.second == __str_last);
}
template <class _InIt, class _OuIt, class _CharT>
bool
__get_monetary_value(_InIt& __first, _InIt __last, _OuIt __out,
const ctype<_CharT>& _c_type,
_CharT __point,
int __frac_digits,
_CharT __sep,
const string& __grouping,
bool& __syntax_ok)
{
if (__first == __last || !_c_type.is(ctype_base::digit, *__first))
return false;
char __group_sizes[128];
char* __group_sizes_end = __grouping.size() == 0 ? 0 : __group_sizes;
char __current_group_size = 0;
while (__first != __last) {
if (_c_type.is(ctype_base::digit, *__first)) {
++__current_group_size;
*__out++ = *__first++;
}
else if (__group_sizes_end) {
if (*__first == __sep) {
*__group_sizes_end++ = __current_group_size;
__current_group_size = 0;
++__first;
}
else break;
}
else
break;
}
if (__grouping.size() == 0)
__syntax_ok = true;
else {
if (__group_sizes_end != __group_sizes)
*__group_sizes_end++ = __current_group_size;
__syntax_ok = __valid_grouping(__group_sizes, __group_sizes_end,
__grouping.data(), __grouping.data()+ __grouping.size());
if (__first == __last || *__first != __point) {
for (int __digits = 0; __digits != __frac_digits; ++__digits)
*__out++ = _CharT('0');
return true; // OK not to have decimal point
}
}
++__first;
size_t __digits = 0;
while (__first != __last && _c_type.is(ctype_base::digit, *__first)) {
*__out++ = *__first++;
++__digits;
}
__syntax_ok = __syntax_ok && (__digits == __frac_digits);
return true;
}
# ifndef _STLP_NO_LONG_DOUBLE
//===== methods ======
template <class _CharT, class _InputIter>
_InputIter
money_get<_CharT, _InputIter>::do_get(_InputIter __s, _InputIter __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
long double& __units) const {
string_type __buf;
__s = do_get(__s, __end, __intl, __str, __err, __buf);
if (__err == ios_base::goodbit || __err == ios_base::eofbit) {
__buf.push_back(0);
typename string_type::iterator __b = __buf.begin(), __e = __buf.end();
// Can't use atold, since it might be wchar_t. Don't get confused by name below :
// it's perfectly capable of reading long double.
__get_decimal_integer(__b, __e, __units);
}
if (__s == __end)
__err |= ios_base::eofbit;
return __s;
}
# endif
template <class _CharT, class _InputIter>
_InputIter
money_get<_CharT, _InputIter>::do_get(iter_type __s,
iter_type __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
string_type& __digits) const {
if (__s == __end) {
__err |= ios_base::eofbit;
return __s;
}
typedef moneypunct<_CharT, false> _Punct;
typedef moneypunct<_CharT, true> _Punct_intl;
typedef ctype<_CharT> _Ctype;
locale __loc = __str.getloc();
const _Punct& __punct = use_facet<_Punct>(__loc) ;
const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
const _Ctype& __c_type = use_facet<_Ctype>(__loc) ;
money_base::pattern __format = __intl ? __punct_intl.neg_format()
: __punct.neg_format();
string_type __ns = __intl ? __punct_intl.negative_sign()
: __punct.negative_sign();
string_type __ps = __intl ? __punct_intl.positive_sign()
: __punct.positive_sign();
int __i;
bool __is_positive = true;
bool __symbol_required = (__str.flags() & ios_base::showbase) !=0;
string_type __buf;
back_insert_iterator<string_type> __out(__buf);
// pair<iter_type, bool> __result;
for (__i = 0; __i < 4; ++__i) {
switch (__format.field[__i]) {
case (char) money_base::none:
if (__i == 3) {
if (__c_type.is(ctype_base::space, *__s)) {
__err = ios_base::failbit;
return __s;
}
break;
}
while (__s != __end && __c_type.is(ctype_base::space, *__s))
++__s;
break;
case (char) money_base::space:
if (!__c_type.is(ctype_base::space, *__s)) {
__err = ios_base::failbit;
return __s;
}
++__s;
while (__s != __end && __c_type.is(ctype_base::space, *__s))
++__s;
break;
case money_base::symbol: {
string_type __curs = __intl ? __punct_intl.curr_symbol()
: __punct.curr_symbol();
pair<iter_type, bool>
__result = __get_string(__s, __end, __curs.begin(), __curs.end());
if (!__result.second && __symbol_required)
__err = ios_base::failbit;
__s = __result.first;
break;
}
case money_base::sign: {
if (__s == __end) {
if (__ps.size() == 0)
break;
if (__ns.size() == 0) {
__is_positive = false;
break;
}
__err = ios_base::failbit;
return __s;
}
else {
if (__ps.size() == 0) {
if (__ns.size() == 0)
break;
if (*__s == ++__ns[0]) {
++__s;
__is_positive = false;
break;
}
__err = ios_base::failbit;
// return __s;
}
else {
if (*__s == __ps[0]) {
++__s;
break;
}
if (__ns.size() == 0)
break;
if (*__s == __ns[0]) {
++__s;
__is_positive = false;
break;
}
__err = ios_base::failbit;
// return __s;
}
}
return __s;
// break;
}
case money_base::value: {
_CharT __point = __intl ? __punct_intl.decimal_point()
: __punct.decimal_point();
int __frac_digits = __intl ? __punct_intl.frac_digits()
: __punct.frac_digits();
string __grouping = __intl ? __punct_intl.grouping()
: __punct.grouping();
bool __syntax_ok = true;
bool __result;
_CharT __sep = __grouping.size() == 0 ? _CharT() :
__intl ? __punct_intl.thousands_sep() : __punct.thousands_sep();
__result = __get_monetary_value(__s, __end, __out, __c_type,
__point, __frac_digits,
__sep,
__grouping, __syntax_ok);
if (!__syntax_ok)
__err |= ios_base::failbit;
if (!__result) {
__err = ios_base::failbit;
return __s;
}
break;
} // Close money_base::value case
} // Close switch statement
} // Close for loop
if (__is_positive) {
if (__ps.size() > 1) {
pair<_InputIter, bool>
__result = __get_string(__s, __end, __ps.begin() + 1, __ps.end());
__s = __result.first;
if (!__result.second)
__err |= ios::failbit;
}
if (!(__err & ios_base::failbit))
__digits = __buf;
}
else {
if (__ns.size() > 1) {
pair<_InputIter, bool>
__result = __get_string(__s, __end, __ns.begin() + 1, __ns.end());
__s = __result.first;
if (!__result.second)
__err |= ios::failbit;
}
if (!(__err & ios::failbit)) {
__buf.insert(__buf.begin(),__c_type.widen('-'));
__digits = __buf;
}
}
if (__s == __end)
__err |= ios::eofbit;
return __s;
}
// money_put facets
template <class _CharT, class _OutputIter>
_OutputIter
money_put<_CharT, _OutputIter>
::do_put(_OutputIter __s, bool __intl, ios_base& __str,
char_type __fill,
const string_type& __digits) const {
typedef ctype<_CharT> _Ctype;
typedef moneypunct<_CharT, false> _Punct;
typedef moneypunct<_CharT, true> _Punct_intl;
locale __loc = __str.getloc();
const _Ctype& __c_type = use_facet<_Ctype>(__loc) ;
const _Punct& __punct = use_facet<_Punct>(__loc) ;
const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
// some special characters
char_type __minus = __c_type.widen('-');
char_type __plus = __c_type.widen('+');
char_type __space = __c_type.widen(' ');
char_type __zero = __c_type.widen('0');
char_type __point = __intl ? __c_type.widen(__punct_intl.decimal_point())
: __c_type.widen(__punct.decimal_point());
char_type __sep = __intl ? __punct_intl.thousands_sep()
: __punct .thousands_sep();
string __grouping = __intl ? __punct_intl.grouping()
: __punct .grouping();
int __frac_digits = __intl ? __punct_intl.frac_digits()
: __punct.frac_digits();
string_type __curr_sym = __intl ? __punct_intl.curr_symbol()
: __punct.curr_symbol();
// if there are no digits we are going to return __s. If there
// are digits, but not enough to fill the frac_digits, we are
// going to add zeros. I don't know whether this is right or
// not.
if (__digits.size() == 0)
return __s;
typename string_type::const_iterator __digits_first = __digits.begin();
typename string_type::const_iterator __digits_last = __digits.end();
bool __is_negative = *__digits_first == __minus;
if (__is_negative)
++__digits_first;
string_type __sign = __intl ?
__is_negative ? __punct_intl.negative_sign()
: __punct_intl.positive_sign()
:
__is_negative ? __punct.negative_sign()
: __punct.positive_sign();
typename string_type::const_iterator __cp = __digits_first;
while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
++__cp;
if (__cp == __digits_first)
return __s;
__digits_last = __cp;
// If grouping is required, we make a copy of __digits and
// insert the grouping.
// To handle the fractional digits, we augment the first group
// by frac_digits. If there is only one group, we need first
// to duplicate it.
string_type __new_digits(__digits_first, __digits_last);
if (__grouping.size() != 0) {
if (__grouping.size() == 1)
__grouping.push_back(__grouping[0]);
__grouping[0] += __frac_digits;
_CharT* __data_ptr = __CONST_CAST(_CharT*,__new_digits.data());
_CharT* __data_end = __data_ptr + __new_digits.size();
ptrdiff_t __value_length = __insert_grouping(__data_ptr,
__data_end,
__grouping,
__sep,
__plus, __minus, 0);
__digits_first = __new_digits.begin();
__digits_last = __digits_first + __value_length;
}
// Determine the amount of padding required, if any.
size_t __width = __str.width();
#if defined(_STLP_DEBUG) && (defined(__HP_aCC) || (__HP_aCC <= 1))
size_t __value_length = operator -(__digits_last, __digits_first);
#else
size_t __value_length = __digits_last - __digits_first;
#endif
size_t __length = __value_length;
__length += __sign.size();
if (__frac_digits != 0)
++__length;
bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
if (__generate_curr)
__length += __curr_sym.size();
money_base::pattern __format =
__intl ? (__is_negative ? __punct_intl.neg_format()
: __punct_intl.pos_format())
: (__is_negative ? __punct.neg_format()
: __punct.pos_format());
{
for (int __i = 0; __i < 4; ++__i)
if (__format.field[__i] == (char) money_base::space)
++__length;
}
size_t __fill_amt = __length < __width ? __width - __length : 0;
ios_base::fmtflags __fill_pos = __str.flags() & ios_base::adjustfield;
if (__fill_amt != 0 &&
!(__fill_pos & (ios_base::left | ios_base::internal)))
__s = fill_n(__s, __fill_amt, __fill);
for (int __i = 0; __i < 4; ++__i) {
char __ffield = __format.field[__i];
if (__ffield == money_base::none) {
if (__fill_amt != 0 && __fill_pos == ios_base::internal)
__s = fill_n(__s, __fill_amt, __fill);
}
else if (__ffield == money_base::space) {
*__s++ = __space;
if (__fill_amt != 0 && __fill_pos == ios_base::internal)
__s = fill_n(__s, __fill_amt, __fill);
}
else if (__ffield == money_base::symbol) {
if (__generate_curr)
__s = copy(__curr_sym.begin(), __curr_sym.end(), __s);
}
else if (__ffield == money_base::sign) {
if (__sign.size() != 0)
*__s++ = __sign[0];
}
else if (__ffield == money_base::value) {
if (__frac_digits == 0)
__s = copy(__digits_first, __digits_last, __s);
else {
if ((int)__value_length <= __frac_digits) {
*__s++ = __point;
__s = copy(__digits_first, __digits_last, __s);
__s = fill_n(__s, __frac_digits - __value_length, __zero);
}
else {
__s = copy(__digits_first, __digits_last - __frac_digits, __s);
if (__frac_digits != 0) {
*__s++ = __point;
__s = copy(__digits_last - __frac_digits, __digits_last, __s);
}
}
}
}
} // Close for loop
// Ouput rest of sign if necessary.
if (__sign.size() > 1)
__s = copy(__sign.begin() + 1, __sign.end(), __s);
if (!(__fill_pos & (ios_base::right | ios_base::internal)))
__s = fill_n(__s, __fill_amt, __fill);
return __s;
}
_STLP_END_NAMESPACE
# endif /* EXPOSE */
#endif /* _STLP_MONETARY_C */
+463
View File
@@ -0,0 +1,463 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_MONETARY_H
#define _STLP_INTERNAL_MONETARY_H
#ifndef _STLP_INTERNAL_CTYPE_H
# include <stl/_ctype.h>
#endif
#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
# include <stl/_ostreambuf_iterator.h>
#endif
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
# include <stl/_istreambuf_iterator.h>
#endif
_STLP_BEGIN_NAMESPACE
class money_base {
public:
enum part {none, space, symbol, sign, value};
struct pattern {
char field[4];
};
};
// moneypunct facets: forward declaration
template <class _charT, __DFL_NON_TYPE_PARAM(bool, _International, false) > class moneypunct {};
// money_get facets
template <class _CharT, __DFL_TMPL_PARAM(_InputIter , istreambuf_iterator<_CharT>) >
class money_get : public locale::facet
{
friend class _Locale;
public:
typedef _CharT char_type;
typedef _InputIter iter_type;
typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type;
money_get(size_t __refs = 0) : _BaseFacet(__refs) {}
# ifndef _STLP_NO_LONG_DOUBLE
iter_type get(iter_type __s, iter_type __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
long double& __units) const
{ return do_get(__s, __end, __intl, __str, __err, __units); }
# endif
iter_type get(iter_type __s, iter_type __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
string_type& __digits) const
{ return do_get(__s, __end, __intl, __str, __err, __digits); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~money_get() {}
# ifndef _STLP_NO_LONG_DOUBLE
virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
long double& __units) const;
# endif
virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl,
ios_base& __str, ios_base::iostate& __err,
string_type& __digits) const;
};
// moneypunct facets: definition of specializations
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct<char, true> : public locale::facet, public money_base
{
public:
typedef char char_type;
typedef string string_type;
explicit moneypunct _STLP_PSPEC2(char, true) (size_t __refs = 0);
char decimal_point() const { return do_decimal_point(); }
char thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
string_type curr_symbol() const { return do_curr_symbol(); }
string_type positive_sign() const { return do_positive_sign(); }
string_type negative_sign() const { return do_negative_sign(); }
int frac_digits() const { return do_frac_digits(); }
pattern pos_format() const { return do_pos_format(); }
pattern neg_format() const { return do_neg_format(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# if defined (_STLP_STATIC_CONST_INIT_BUG)
enum _IntlVal { intl = 1 } ;
# else
static const bool intl = true;
# endif
protected:
pattern _M_pos_format;
pattern _M_neg_format;
~moneypunct _STLP_PSPEC2(char, true) ();
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
virtual string do_curr_symbol() const;
virtual string do_positive_sign() const;
virtual string do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
friend class _Locale;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct<char, false> : public locale::facet, public money_base
{
public:
typedef char char_type;
typedef string string_type;
explicit moneypunct _STLP_PSPEC2(char, false) (size_t __refs = 0);
char decimal_point() const { return do_decimal_point(); }
char thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
string_type curr_symbol() const { return do_curr_symbol(); }
string_type positive_sign() const { return do_positive_sign(); }
string_type negative_sign() const { return do_negative_sign(); }
int frac_digits() const { return do_frac_digits(); }
pattern pos_format() const { return do_pos_format(); }
pattern neg_format() const { return do_neg_format(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# if defined (_STLP_STATIC_CONST_INIT_BUG)
enum _IntlVal { intl = 0 } ;
# else
static const bool intl = false;
# endif
protected:
pattern _M_pos_format;
pattern _M_neg_format;
~moneypunct _STLP_PSPEC2(char, false) ();
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
virtual string do_curr_symbol() const;
virtual string do_positive_sign() const;
virtual string do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
friend class _Locale;
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, true> : public locale::facet, public money_base
{
friend class _Locale;
public:
typedef wchar_t char_type;
typedef wstring string_type;
explicit moneypunct _STLP_PSPEC2(wchar_t, true) (size_t __refs = 0);
wchar_t decimal_point() const { return do_decimal_point(); }
wchar_t thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
string_type curr_symbol() const { return do_curr_symbol(); }
string_type positive_sign() const { return do_positive_sign(); }
string_type negative_sign() const { return do_negative_sign(); }
int frac_digits() const { return do_frac_digits(); }
pattern pos_format() const { return do_pos_format(); }
pattern neg_format() const { return do_neg_format(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# if defined (_STLP_STATIC_CONST_INIT_BUG)
enum _IntlVal { intl = 1 } ;
# else
static const bool intl = true;
# endif
protected:
pattern _M_pos_format;
pattern _M_neg_format;
~moneypunct _STLP_PSPEC2(wchar_t, true) ();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct<wchar_t, false> : public locale::facet, public money_base
{
friend class _Locale;
public:
typedef wchar_t char_type;
typedef wstring string_type;
explicit moneypunct _STLP_PSPEC2(wchar_t, false) (size_t __refs = 0);
wchar_t decimal_point() const { return do_decimal_point(); }
wchar_t thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
string_type curr_symbol() const { return do_curr_symbol(); }
string_type positive_sign() const { return do_positive_sign(); }
string_type negative_sign() const { return do_negative_sign(); }
int frac_digits() const { return do_frac_digits(); }
pattern pos_format() const { return do_pos_format(); }
pattern neg_format() const { return do_neg_format(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# if defined (_STLP_STATIC_CONST_INIT_BUG)
enum _IntlVal { intl = 0 } ;
# else
static const bool intl = false;
# endif
protected:
pattern _M_pos_format;
pattern _M_neg_format;
~moneypunct _STLP_PSPEC2(wchar_t, false) ();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
virtual pattern do_pos_format() const;
virtual pattern do_neg_format() const;
};
# endif
template <class _charT, __DFL_NON_TYPE_PARAM(bool , _International , false) > class moneypunct_byname {};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct_byname<char, true> : public moneypunct<char, true>
{
public:
typedef money_base::pattern pattern;
typedef char char_type;
typedef string string_type;
explicit moneypunct_byname _STLP_PSPEC2(char, true) (const char * __name, size_t __refs = 0);
protected:
_Locale_monetary* _M_monetary;
~moneypunct_byname _STLP_PSPEC2(char, true) ();
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct_byname<char, false> : public moneypunct<char, false>
{
public:
typedef money_base::pattern pattern;
typedef char char_type;
typedef string string_type;
explicit moneypunct_byname _STLP_PSPEC2(char, false) (const char * __name, size_t __refs = 0);
protected:
_Locale_monetary* _M_monetary;
~moneypunct_byname _STLP_PSPEC2(char, false) ();
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, true> : public moneypunct<wchar_t, true>
{
public:
typedef money_base::pattern pattern;
typedef wchar_t char_type;
typedef wstring string_type;
explicit moneypunct_byname _STLP_PSPEC2(wchar_t, true) (const char * __name, size_t __refs = 0);
protected:
_Locale_monetary* _M_monetary;
~moneypunct_byname _STLP_PSPEC2(wchar_t, true) ();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC moneypunct_byname<wchar_t, false> : public moneypunct<wchar_t, false>
{
public:
typedef money_base::pattern pattern;
typedef wchar_t char_type;
typedef wstring string_type;
explicit moneypunct_byname _STLP_PSPEC2(wchar_t, false) (const char * __name, size_t __refs = 0);
protected:
_Locale_monetary* _M_monetary;
~moneypunct_byname _STLP_PSPEC2(wchar_t, false) ();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_curr_symbol() const;
virtual string_type do_positive_sign() const;
virtual string_type do_negative_sign() const;
virtual int do_frac_digits() const;
};
# endif
//===== methods ======
// money_put facets
template <class _CharT, __DFL_TMPL_PARAM( _OutputIter , ostreambuf_iterator<_CharT>) >
class money_put : public locale::facet {
friend class _Locale;
public:
typedef _CharT char_type;
typedef _OutputIter iter_type;
typedef basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > string_type;
money_put(size_t __refs = 0) : _BaseFacet(__refs) {}
# ifndef _STLP_NO_LONG_DOUBLE
iter_type put(iter_type __s, bool __intl, ios_base& __str,
char_type __fill, long double __units) const
{ return do_put(__s, __intl, __str, __fill, __units); }
# endif
iter_type put(iter_type __s, bool __intl, ios_base& __str,
char_type __fill,
const string_type& __digits) const
{ return do_put(__s, __intl, __str, __fill, __digits); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~money_put() {}
# ifndef _STLP_NO_LONG_DOUBLE
virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str,
char_type __fill, long double /* __units */ ) const {
locale __loc = __str.getloc();
_CharT __buf[64];
return do_put(__s, __intl, __str, __fill, __buf + 0);
}
# endif
virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __str,
char_type __fill,
const string_type& __digits) const;
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS money_get<char, istreambuf_iterator<char, char_traits<char> > >;
_STLP_EXPORT_TEMPLATE_CLASS money_put<char, ostreambuf_iterator<char, char_traits<char> > >;
// _STLP_EXPORT_TEMPLATE_CLASS money_get<char, const char* >;
// _STLP_EXPORT_TEMPLATE_CLASS money_put<char, char* >;
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
_STLP_EXPORT_TEMPLATE_CLASS money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// _STLP_EXPORT_TEMPLATE_CLASS money_get<wchar_t, const wchar_t* >;
// _STLP_EXPORT_TEMPLATE_CLASS money_put<wchar_t, wchar_t* >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
# if defined (__BORLANDC__) && defined (_RTLDLL)
inline void _Stl_loc_init_monetary() {
money_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 8;
money_get<char, const char*>::id._M_index = 9;
money_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 10;
money_put<char, char*>::id._M_index = 11;
# ifndef _STLP_NO_WCHAR_T
money_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 27;
money_get<wchar_t, const wchar_t*>::id._M_index = 28;
money_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 29;
money_put<wchar_t, wchar_t*>::id._M_index = 30;
# endif
}
#endif
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_monetary.c>
# endif
#endif /* _STLP_INTERNAL_MONETARY_H */
// Local Variables:
// mode:C++
// End:
+93
View File
@@ -0,0 +1,93 @@
#ifndef _STLP_NEW_H_HEADER
# define _STLP_NEW_H_HEADER
# ifdef _STLP_NO_BAD_ALLOC
# ifndef _STLP_NEW_DONT_THROW
# define _STLP_NEW_DONT_THROW 1
# endif /* _STLP_NEW_DONT_THROW */
# include <exception>
_STLP_BEGIN_NAMESPACE
struct nothrow_t {};
# ifdef _STLP_OWN_IOSTREAMS
extern _STLP_DECLSPEC const nothrow_t nothrow;
# else
# define nothrow nothrow_t()
# endif
class bad_alloc : public _STLP_EXCEPTION_BASE {
public:
bad_alloc () _STLP_NOTHROW_INHERENTLY { }
bad_alloc(const bad_alloc&) _STLP_NOTHROW_INHERENTLY { }
bad_alloc& operator=(const bad_alloc&) _STLP_NOTHROW_INHERENTLY {return *this;}
~bad_alloc () _STLP_NOTHROW_INHERENTLY { }
const char* what() const _STLP_NOTHROW_INHERENTLY { return "bad alloc"; }
};
_STLP_END_NAMESPACE
#endif /* _STLP_NO_BAD_ALLOC */
#ifdef _STLP_WINCE
_STLP_BEGIN_NAMESPACE
inline void* _STLP_CALL __stl_new(size_t __n) {
return ::malloc(__n);
}
inline void _STLP_CALL __stl_delete(void* __p) {
free(__p);
}
_STLP_END_NAMESPACE
#else /* _STLP_WINCE */
#include <new>
# ifndef _STLP_NO_BAD_ALLOC
# ifdef _STLP_USE_OWN_NAMESPACE
_STLP_BEGIN_NAMESPACE
using _STLP_VENDOR_EXCEPT_STD::bad_alloc;
using _STLP_VENDOR_EXCEPT_STD::nothrow_t;
using _STLP_VENDOR_EXCEPT_STD::nothrow;
# if defined (_STLP_GLOBAL_NEW_HANDLER)
using ::new_handler;
using ::set_new_handler;
# else
using _STLP_VENDOR_EXCEPT_STD::new_handler;
using _STLP_VENDOR_EXCEPT_STD::set_new_handler;
# endif
_STLP_END_NAMESPACE
# endif /* _STLP_OWN_NAMESPACE */
# endif /* _STLP_NO_BAD_ALLOC */
# if defined (_STLP_NO_NEW_NEW_HEADER) || defined (_STLP_NEW_DONT_THROW) && ! defined (_STLP_CHECK_NULL_ALLOC)
# define _STLP_CHECK_NULL_ALLOC(__x) void* __y = __x;if (__y == 0){_STLP_THROW(bad_alloc());}return __y
# else
# define _STLP_CHECK_NULL_ALLOC(__x) return __x
# endif
_STLP_BEGIN_NAMESPACE
#if (( defined(__IBMCPP__)|| defined(__OS400__) || defined (__xlC__) || defined (qTidyHeap)) && defined(__DEBUG_ALLOC__) )
inline void* _STLP_CALL __stl_new(size_t __n) { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n, __FILE__, __LINE__)); }
inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p, __FILE__, __LINE__); }
#else
inline void* _STLP_CALL __stl_new(size_t __n) { _STLP_CHECK_NULL_ALLOC(::operator _STLP_NEW(__n)); }
inline void _STLP_CALL __stl_delete(void* __p) { ::operator delete(__p); }
#endif
_STLP_END_NAMESPACE
# endif /* _STLP_WINCE */
#endif /* _STLP_NEW_H_HEADER */
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2000
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_NULL_STREAM_H
# define _STLP_NULL_STREAM_H
_STLP_BEGIN_NAMESPACE
struct __null_stream
{
void flush() { }
};
template <class _Tp>
__null_stream& operator <<(__null_stream& __x, const _Tp& )
{
return __x;
}
template <class _Tp>
__null_stream& operator >>(const _Tp&, __null_stream& __x )
{
return __x;
}
extern __null_stream cin, cout, cerr, endl, ws, hex, dec;
_STLP_END_NAMESPACE
# endif
+671
View File
@@ -0,0 +1,671 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_NUM_GET_C
#define _STLP_NUM_GET_C
#ifndef _STLP_INTERNAL_NUM_GET_H
# include <stl/_num_get.h>
#endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
#ifndef _STLP_LIMITS_H
# include <stl/_limits.h>
#endif
_STLP_BEGIN_NAMESPACE
extern const unsigned char __digit_val_table[];
template < class _InputIter, class _Integer, class _CharT>
_InputIter _STLP_CALL
_M_do_get_integer(_InputIter&, _InputIter&, ios_base&, ios_base::iostate&, _Integer&, _CharT*);
// _M_do_get_integer and its helper functions.
inline bool _STLP_CALL __get_fdigit(char& __c, const char*)
{ return __c >= '0' && __c <= '9'; }
inline bool _STLP_CALL __get_fdigit_or_sep(char& __c, char __sep, const char *)
{
if (__c == __sep) {
__c = ',' ;
return true ;
} else
return ( __c >= '0' && __c <= '9');
}
inline int _STLP_CALL
__get_digit_from_table(unsigned __index)
{
return (__index > 127 ? 0xFF : __digit_val_table[__index]);
}
extern const char __narrow_atoms[];
template <class _InputIter, class _CharT>
int
_M_get_base_or_zero(_InputIter& __in, _InputIter& __end, ios_base& __str, _CharT*)
{
_CharT __atoms[5];
const ctype<_CharT>& __c_type = use_facet< ctype<_CharT> >(__str.getloc());
// const ctype<_CharT>& __c_type = *(const ctype<_CharT>*)__str._M_ctype_facet();
__c_type.widen(__narrow_atoms, __narrow_atoms + 5, __atoms);
bool __negative = false;
_CharT __c = *__in;
if (__c == __atoms[1] /* __xminus_char */ ) {
__negative = true;
++__in;
}
else if (__c == __atoms[0] /* __xplus_char */ )
++__in;
int __base;
int __valid_zero = 0;
ios_base::fmtflags __basefield = __str.flags() & ios_base::basefield;
switch (__basefield) {
case ios_base::oct:
__base = 8;
break;
case ios_base::dec:
__base = 10;
break;
case ios_base::hex:
__base = 16;
if (__in != __end && *__in == __atoms[2] /* __zero_char */ ) {
++__in;
if (__in != __end &&
(*__in == __atoms[3] /* __x_char */ || *__in == __atoms[4] /* __X_char */ ))
++__in;
else
__valid_zero = 1; // That zero is valid by itself.
}
break;
default:
if (__in != __end && *__in == __atoms[2] /* __zero_char */ ) {
++__in;
if (__in != __end &&
(*__in == __atoms[3] /* __x_char */ || *__in == __atoms[4] /* __X_char */ )) {
++__in;
__base = 16;
}
else
{
__base = 8;
__valid_zero = 1; // That zero is still valid by itself.
}
}
else
__base = 10;
break;
}
return (__base << 2) | ((int)__negative << 1) | __valid_zero;
}
template <class _InputIter, class _Integer>
bool _STLP_CALL
__get_integer(_InputIter& __first, _InputIter& __last,
int __base, _Integer& __val,
int __got, bool __is_negative, char __separator, const string& __grouping, const __true_type&)
{
bool __ovflow = false;
_Integer __result = 0;
bool __is_group = !__grouping.empty();
char __group_sizes[64];
int __current_group_size = 0;
char* __group_sizes_end = __group_sizes;
_Integer __over_base = (numeric_limits<_Integer>::min)() / __STATIC_CAST(_Integer, __base);
for ( ; __first != __last ; ++__first) {
const char __c = *__first;
if (__is_group && __c == __separator) {
*__group_sizes_end++ = __current_group_size;
__current_group_size = 0;
continue;
}
int __n = __get_digit_from_table(__c);
if (__n >= __base)
break;
++__got;
++__current_group_size;
if (__result < __over_base)
__ovflow = true; // don't need to keep accumulating
else {
_Integer __next = __STATIC_CAST(_Integer, __base * __result - __n);
if (__result != 0)
__ovflow = __ovflow || __next >= __result;
__result = __next;
}
}
if (__is_group && __group_sizes_end != __group_sizes) {
*__group_sizes_end++ = __current_group_size;
}
// fbp : added to not modify value if nothing was read
if (__got > 0) {
__val = __ovflow
? __is_negative ? (numeric_limits<_Integer>::min)()
: (numeric_limits<_Integer>::max)()
: (__is_negative ? __result : __STATIC_CAST(_Integer, -__result));
}
// overflow is being treated as failure
return ((__got > 0) && !__ovflow) && (__is_group == 0 || __valid_grouping(__group_sizes, __group_sizes_end,
__grouping.data(), __grouping.data()+ __grouping.size())) ;
}
template <class _InputIter, class _Integer>
bool _STLP_CALL
__get_integer(_InputIter& __first, _InputIter& __last,
int __base, _Integer& __val,
int __got, bool __is_negative, char __separator, const string& __grouping, const __false_type&)
{
bool __ovflow = false;
_Integer __result = 0;
bool __is_group = !__grouping.empty();
char __group_sizes[64];
int __current_group_size = 0;
char* __group_sizes_end = __group_sizes;
_Integer __over_base = (numeric_limits<_Integer>::max)() / __STATIC_CAST(_Integer, __base);
for ( ; __first != __last ; ++__first) {
const char __c = *__first;
if (__is_group && __c == __separator) {
*__group_sizes_end++ = __current_group_size;
__current_group_size = 0;
continue;
}
int __n = __get_digit_from_table(__c);
if (__n >= __base)
break;
++__got;
++__current_group_size;
if (__result > __over_base)
__ovflow = true; //don't need to keep accumulating
else {
_Integer __next = __STATIC_CAST(_Integer, __base * __result + __n);
if (__result != 0)
__ovflow = __ovflow || __next <= __result;
__result = __next;
}
}
if (__is_group && __group_sizes_end != __group_sizes) {
*__group_sizes_end++ = __current_group_size;
}
// fbp : added to not modify value if nothing was read
if (__got > 0) {
__val = __ovflow
? (numeric_limits<_Integer>::max)()
: (__is_negative ? __STATIC_CAST(_Integer, -__result) : __result);
}
// overflow is being treated as failure
return ((__got > 0) && !__ovflow) &&
(__is_group == 0 || __valid_grouping(__group_sizes, __group_sizes_end,
__grouping.data(), __grouping.data()+ __grouping.size())) ;
}
template <class _InputIter, class _Integer>
bool _STLP_CALL
__get_decimal_integer(_InputIter& __first, _InputIter& __last, _Integer& __val)
{
string __grp;
return __get_integer(__first, __last, 10, __val, 0, false, ' ', __grp, __false_type());
}
template <class _InputIter, class _Integer, class _CharT>
_InputIter _STLP_CALL
_M_do_get_integer(_InputIter& __in, _InputIter& __end, ios_base& __str,
ios_base::iostate& __err, _Integer& __val, _CharT* __pc)
{
#if defined(__HP_aCC) && (__HP_aCC == 1)
bool _IsSigned = !((_Integer)(-1) > 0);
#else
typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
#endif
const numpunct<_CharT>& __numpunct = *(const numpunct<_CharT>*)__str._M_numpunct_facet();
const string& __grouping = __str._M_grouping(); // cached copy
const int __base_or_zero = _M_get_base_or_zero(__in, __end, __str, __pc);
int __got = __base_or_zero & 1;
bool __result;
if (__in == __end) { // We may have already read a 0. If so,
if (__got > 0) { // the result is 0 even if we're at eof.
__val = 0;
__result = true;
}
else
__result = false;
} else {
const bool __negative = __base_or_zero & 2;
const int __base = __base_or_zero >> 2;
#if defined(__HP_aCC) && (__HP_aCC == 1)
if (_IsSigned)
__result = __get_integer(__in, __end, __base, __val, __got, __negative, __numpunct.thousands_sep(), __grouping, __true_type() );
else
__result = __get_integer(__in, __end, __base, __val, __got, __negative, __numpunct.thousands_sep(), __grouping, __false_type() );
#else
__result = __get_integer(__in, __end, __base, __val, __got, __negative, __numpunct.thousands_sep(), __grouping, _IsSigned());
# endif
}
__err = __STATIC_CAST(ios_base::iostate, __result ? ios_base::goodbit : ios_base::failbit);
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
// _M_read_float and its helper functions.
template <class _InputIter, class _CharT>
_InputIter _STLP_CALL
__copy_sign(_InputIter __first, _InputIter __last, string& __v,
_CharT __xplus, _CharT __xminus) {
if (__first != __last) {
_CharT __c = *__first;
if (__c == __xplus)
++__first;
else if (__c == __xminus) {
__v.push_back('-');
++__first;
}
}
return __first;
}
template <class _InputIter, class _CharT>
bool _STLP_CALL
__copy_digits(_InputIter& __first, _InputIter& __last,
string& __v, const _CharT* __digits)
{
bool __ok = false;
for ( ; __first != __last; ++__first) {
_CharT __c = *__first;
if (__get_fdigit(__c, __digits)) {
__v.push_back((char)__c);
__ok = true;
}
else
break;
}
return __ok;
}
template <class _InputIter, class _CharT>
bool _STLP_CALL
__copy_grouped_digits(_InputIter& __first, _InputIter& __last,
string& __v, const _CharT * __digits,
_CharT __sep, const string& __grouping,
bool& __grouping_ok)
{
bool __ok = false;
char __group_sizes[64];
char*__group_sizes_end = __group_sizes;
char __current_group_size = 0;
for ( ; __first != __last; ++__first) {
_CharT __c = *__first;
bool __tmp = __get_fdigit_or_sep(__c, __sep, __digits);
if (__tmp) {
if (__c == ',') {
*__group_sizes_end++ = __current_group_size;
__current_group_size = 0;
}
else {
__ok = true;
__v.push_back((char)__c);
++__current_group_size;
}
}
else
break;
}
if (__group_sizes_end != __group_sizes)
*__group_sizes_end++ = __current_group_size;
__grouping_ok = __valid_grouping(__group_sizes, __group_sizes_end, __grouping.data(), __grouping.data() + __grouping.size());
return __ok;
}
template <class _InputIter, class _CharT>
bool _STLP_CALL
_M_read_float(string& __buf, _InputIter& __in, _InputIter& __end, ios_base& __s, _CharT*)
{
// Create a string, copying characters of the form
// [+-]? [0-9]* .? [0-9]* ([eE] [+-]? [0-9]+)?
bool __digits_before_dot /* = false */;
bool __digits_after_dot = false;
bool __ok;
bool __grouping_ok = true;
const ctype<_CharT>& __ct = use_facet< ctype<_CharT> >(__s.getloc());
// const ctype<_CharT>& __ct = *(const ctype<_CharT>*)__s._M_ctype_facet();
const numpunct<_CharT>& __numpunct = *(const numpunct<_CharT>*)__s._M_numpunct_facet();
const string& __grouping = __s._M_grouping(); // cached copy
_CharT __dot = __numpunct.decimal_point();
_CharT __sep = __numpunct.thousands_sep();
_CharT __digits[10];
_CharT __xplus;
_CharT __xminus;
_CharT __pow_e;
_CharT __pow_E;
_Initialize_get_float(__ct, __xplus, __xminus, __pow_e, __pow_E, __digits);
// Get an optional sign
__in = __copy_sign(__in, __end, __buf, __xplus, __xminus);
// Get an optional string of digits.
if (__grouping.size() != 0)
__digits_before_dot = __copy_grouped_digits(__in, __end, __buf, __digits,
__sep, __grouping, __grouping_ok);
else
__digits_before_dot = __copy_digits(__in, __end, __buf, __digits);
// Get an optional decimal point, and an optional string of digits.
if (__in != __end && *__in == __dot) {
__buf.push_back('.');
++__in;
__digits_after_dot = __copy_digits(__in, __end, __buf, __digits);
}
// There have to be some digits, somewhere.
__ok = __digits_before_dot || __digits_after_dot;
// Get an optional exponent.
if (__ok && __in != __end && (*__in == __pow_e || *__in == __pow_E)) {
__buf.push_back('e');
++__in;
__in = __copy_sign(__in, __end, __buf, __xplus, __xminus);
__ok = __copy_digits(__in, __end, __buf, __digits);
// If we have an exponent then the sign
// is optional but the digits aren't.
}
return __ok;
}
//
// num_get<>, num_put<>
//
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template <class _CharT, class _InputIterator>
locale::id num_get<_CharT, _InputIterator>::id;
# else
typedef num_get<char, const char*> num_get_char;
typedef num_get<char, istreambuf_iterator<char, char_traits<char> > > num_get_char_2;
__DECLARE_INSTANCE(locale::id, num_get_char::id, );
__DECLARE_INSTANCE(locale::id, num_get_char_2::id, );
# ifndef _STLP_NO_WCHAR_T
typedef num_get<wchar_t, const wchar_t*> num_get_wchar_t;
typedef num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_get_wchar_t_2;
__DECLARE_INSTANCE(locale::id, num_get_wchar_t::id, );
__DECLARE_INSTANCE(locale::id, num_get_wchar_t_2::id, );
# endif
# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
# ifndef _STLP_NO_BOOL
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end,
ios_base& __s,
ios_base::iostate& __err, bool& __x) const
{
if (__s.flags() & ios_base::boolalpha) {
locale __loc = __s.getloc();
const _Numpunct& __np = *(const _Numpunct*)__s._M_numpunct_facet();
// const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc) ;
// const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__loc) ;
const basic_string<_CharT> __truename = __np.truename();
const basic_string<_CharT> __falsename = __np.falsename();
bool __true_ok = true;
bool __false_ok = true;
size_t __n = 0;
for ( ; __in != __end; ++__in) {
_CharT __c = *__in;
__true_ok = __true_ok && (__c == __truename[__n]);
__false_ok = __false_ok && (__c == __falsename[__n]);
++__n;
if ((!__true_ok && !__false_ok) ||
(__true_ok && __n >= __truename.size()) ||
(__false_ok && __n >= __falsename.size())) {
++__in;
break;
}
}
if (__true_ok && __n < __truename.size()) __true_ok = false;
if (__false_ok && __n < __falsename.size()) __false_ok = false;
if (__true_ok || __false_ok) {
__err = ios_base::goodbit;
__x = __true_ok;
}
else
__err = ios_base::failbit;
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
else {
long __lx;
_InputIter __tmp = this->do_get(__in, __end, __s, __err, __lx);
if (!(__err & ios_base::failbit)) {
if (__lx == 0)
__x = false;
else if (__lx == 1)
__x = true;
else
__err |= ios_base::failbit;
}
return __tmp;
}
}
# endif /* _STLP_NO_BOOL */
# ifdef _STLP_FIX_LIBRARY_ISSUES
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, short& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, int& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
# endif
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, long& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
unsigned short& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
unsigned int& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
unsigned long& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
float& __val) const {
string __buf ;
bool __ok = _M_read_float(__buf, __in, __end, __str, (_CharT*)0 );
__string_to_float(__buf, __val);
__err = __STATIC_CAST(ios_base::iostate, __ok ? ios_base::goodbit : ios_base::failbit);
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
double& __val) const {
string __buf ;
bool __ok = _M_read_float(__buf, __in, __end, __str, (_CharT*)0 );
__string_to_float(__buf, __val);
__err = __STATIC_CAST(ios_base::iostate, __ok ? ios_base::goodbit : ios_base::failbit);
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
#ifndef _STLP_NO_LONG_DOUBLE
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
long double& __val) const {
string __buf ;
bool __ok = _M_read_float(__buf, __in, __end, __str, (_CharT*)0 );
__string_to_float(__buf, __val);
__err = __STATIC_CAST(ios_base::iostate, __ok ? ios_base::goodbit : ios_base::failbit);
if (__in == __end)
__err |= ios_base::eofbit;
return __in;
}
#endif /* _STLP_NO_LONG_DOUBLE */
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
void*& __p) const {
# if defined(_STLP_LONG_LONG)&&!defined(__MRC__) //*ty 12/07/2001 - MrCpp can not cast from long long to void*
unsigned _STLP_LONG_LONG __val;
# else
unsigned long __val;
# endif
iter_type __tmp = _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
if (!(__err & ios_base::failbit))
__p = __REINTERPRET_CAST(void*,__val);
return __tmp;
}
#ifdef _STLP_LONG_LONG
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
_STLP_LONG_LONG& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
template <class _CharT, class _InputIter>
_InputIter
num_get<_CharT, _InputIter>::do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
unsigned _STLP_LONG_LONG& __val) const {
return _M_do_get_integer(__in, __end, __str, __err, __val, (_CharT*)0 );
}
#endif /* _STLP_LONG_LONG */
_STLP_END_NAMESPACE
# endif /* _STLP_EXPOSE_STREAM_IMPLEMENTATION */
#endif /* _STLP_NUMERIC_FACETS_C */
// Local Variables:
// mode:C++
// End:
+259
View File
@@ -0,0 +1,259 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_NUM_GET_H
#define _STLP_INTERNAL_NUM_GET_H
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
# include <stl/_istreambuf_iterator.h>
#endif
# ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
# endif
#ifndef _STLP_INTERNAL_NUMPUNCT_H
# include <stl/_numpunct.h>
#endif
#ifndef _STLP_INTERNAL_CTYPE_H
# include <stl/_ctype.h>
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// num_get facets
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
template <class _CharT, class _InputIter>
# else
template <class _CharT, class _InputIter = istreambuf_iterator<_CharT> >
# endif
class num_get: public locale::facet
{
friend class _Locale;
public:
typedef _CharT char_type;
typedef _InputIter iter_type;
explicit num_get(size_t __refs = 0): locale::facet(__refs) {}
# ifndef _STLP_NO_BOOL
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, bool& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
# endif
# ifdef _STLP_FIX_LIBRARY_ISSUES
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, short& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, int& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
# endif
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, long& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned short& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned int& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned long& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
#ifdef _STLP_LONG_LONG
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, _STLP_LONG_LONG& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned _STLP_LONG_LONG& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
#endif /* _STLP_LONG_LONG */
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, float& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, double& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
# ifndef _STLP_NO_LONG_DOUBLE
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, long double& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
# endif
_InputIter get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, void*& __val) const {
return do_get(__in, __end, __str, __err, __val);
}
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~num_get() {}
typedef string string_type;
typedef ctype<_CharT> _Ctype;
typedef numpunct<_CharT> _Numpunct;
# ifndef _STLP_NO_BOOL
virtual _InputIter do_get(_InputIter __in, _InputIter __end,
ios_base& __str, ios_base::iostate& __err, bool& __val) const;
# endif
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, long& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned short& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned int& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned long& __val) const;
# ifdef _STLP_FIX_LIBRARY_ISSUES
// issue 118 : those are actually not supposed to be here
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, short& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, int& __val) const;
# endif
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, float& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, double& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err,
void*& __p) const;
#ifndef _STLP_NO_LONG_DOUBLE
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, long double& __val) const;
#endif /* _STLP_NO_LONG_DOUBLE */
#ifdef _STLP_LONG_LONG
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, _STLP_LONG_LONG& __val) const;
virtual _InputIter do_get(_InputIter __in, _InputIter __end, ios_base& __str,
ios_base::iostate& __err, unsigned _STLP_LONG_LONG& __val) const;
#endif /* _STLP_LONG_LONG */
};
# ifdef _STLP_USE_TEMPLATE_EXPORT
_STLP_EXPORT_TEMPLATE_CLASS num_get<char, istreambuf_iterator<char, char_traits<char> > >;
// _STLP_EXPORT_TEMPLATE_CLASS num_get<char, const char*>;
# ifndef _STLP_NO_WCHAR_T
_STLP_EXPORT_TEMPLATE_CLASS num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// _STLP_EXPORT_TEMPLATE_CLASS num_get<wchar_t, const wchar_t*>;
# endif /* _STLP_NO_WCHAR_T */
# endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
extern bool _STLP_CALL __valid_grouping(const char*, const char*, const char*, const char*);
template <class _InputIter, class _Integer>
bool _STLP_CALL
__get_decimal_integer(_InputIter& __first, _InputIter& __last, _Integer& __val);
inline bool _STLP_CALL __get_fdigit(char& __c, const char*);
inline bool _STLP_CALL __get_fdigit_or_sep(char& __c, char __sep, const char *);
# ifndef _STLP_NO_WCHAR_T
bool _STLP_CALL __get_fdigit(wchar_t&, const wchar_t*);
bool _STLP_CALL __get_fdigit_or_sep(wchar_t&, wchar_t, const wchar_t*);
# endif
inline void _STLP_CALL
_Initialize_get_float(const ctype<char>&,
char& Plus, char& Minus,
char& pow_e, char& pow_E,
char*)
{
Plus = '+';
Minus = '-';
pow_e = 'e';
pow_E = 'E';
}
# ifndef _STLP_NO_WCHAR_T
void _STLP_CALL _Initialize_get_float(const ctype<wchar_t>&,
wchar_t&, wchar_t&, wchar_t&, wchar_t&, wchar_t*);
# endif
void _STLP_CALL __string_to_float(const string&, float&);
void _STLP_CALL __string_to_float(const string&, double&);
# ifndef _STLP_NO_LONG_DOUBLE
void _STLP_CALL __string_to_float(const string&, long double&);
# endif
# endif
# if defined (__BORLANDC__) && defined (_RTLDLL)
inline void _Stl_loc_init_num_get() {
num_get<char, istreambuf_iterator<char, char_traits<char> > >::id._M_index = 12;
num_get<char, const char*>::id._M_index = 13;
# ifndef _STLP_NO_WCHAR_T
num_get<wchar_t, istreambuf_iterator<wchar_t, char_traits<wchar_t> > >::id._M_index = 31;
num_get<wchar_t, const wchar_t*>::id._M_index = 32;
# endif
}
# endif
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && ! defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_num_get.c>
# endif
#endif /* _STLP_INTERNAL_NUM_GET_H */
// Local Variables:
// mode:C++
// End:
+553
View File
@@ -0,0 +1,553 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_NUM_PUT_C
#define _STLP_NUM_PUT_C
#ifndef _STLP_INTERNAL_NUM_PUT_H
# include <stl/_num_put.h>
#endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
#ifndef _STLP_LIMITS_H
# include <stl/_limits.h>
#endif
_STLP_BEGIN_NAMESPACE
// _M_do_put_float and its helper functions. Strategy: write the output
// to a buffer of char, transform the buffer to _CharT, and then copy
// it to the output.
template <class _CharT, class _OutputIter,class _Float>
_OutputIter _STLP_CALL
_M_do_put_float(_OutputIter __s, ios_base& __f, _CharT __fill,_Float __x);
//----------------------------------------------------------------------
// num_put facet
template <class _CharT, class _OutputIter>
_OutputIter _STLP_CALL
__copy_float_and_fill(const _CharT* __first, const _CharT* __last,
_OutputIter __out,
ios_base::fmtflags __flags,
streamsize __width, _CharT __fill,
_CharT __xplus, _CharT __xminus) {
if (__width <= __last - __first)
return copy(__first, __last, __out);
else {
streamsize __pad = __width - (__last - __first);
ios_base::fmtflags __dir = __flags & ios_base::adjustfield;
if (__dir == ios_base::left) {
__out = copy(__first, __last, __out);
return fill_n(__out, __pad, __fill);
}
else if (__dir == ios_base::internal && __first != __last &&
(*__first == __xplus || *__first == __xminus)) {
*__out++ = *__first++;
__out = fill_n(__out, __pad, __fill);
return copy(__first, __last, __out);
}
else {
__out = fill_n(__out, __pad, __fill);
return copy(__first, __last, __out);
}
}
}
#ifndef _STLP_NO_WCHAR_T
// Helper routine for wchar_t
template <class _OutputIter>
_OutputIter _STLP_CALL
__put_float(char* __ibuf, char* __iend, _OutputIter __out,
ios_base& __f, wchar_t __fill,
wchar_t __decimal_point,
wchar_t __sep, const string& __grouping)
{
const ctype<wchar_t>& __ct = *(ctype<wchar_t>*)__f._M_ctype_facet() ;
wchar_t __wbuf[128];
wchar_t* __eend = __convert_float_buffer(__ibuf, __iend, __wbuf,
__ct, __decimal_point);
if (!__grouping.empty()) {
// In order to do separator-insertion only to the left of the
// decimal point, we adjust the size of the first (right-most)
// group. We need to be careful if there is only one entry in
// grouping: in this case we need to duplicate the first entry.
string __new_grouping = __grouping;
wchar_t* __decimal_pos = find(__wbuf, __eend, __decimal_point);
if (__grouping.size() == 1)
__new_grouping.push_back(__grouping[0]);
// dwa 1/24/00 - try as I might, there doesn't seem to be a way
// to suppress the warning
__new_grouping[0] += __STATIC_CAST(char, __eend - __decimal_pos);
ptrdiff_t __len = __insert_grouping(__wbuf, __eend, __new_grouping,
__sep,
__ct.widen('+'), __ct.widen('-'),
0);
__eend = __wbuf + __len;
}
return __copy_float_and_fill(__wbuf, __eend, __out,
__f.flags(), __f.width(0), __fill,
__ct.widen('+'), __ct.widen('-'));
}
# endif /* WCHAR_T */
// Helper routine for char
template <class _OutputIter>
_OutputIter _STLP_CALL
__put_float(char* __ibuf, char* __iend, _OutputIter __out,
ios_base& __f, char __fill,
char __decimal_point,
char __sep, const string& __grouping)
{
__adjust_float_buffer(__ibuf, __iend, __decimal_point);
if (!__grouping.empty()) {
string __new_grouping = __grouping;
const char * __decimal_pos = find(__ibuf, __iend, __decimal_point);
if (__grouping.size() == 1)
__new_grouping.push_back(__grouping[0]);
__new_grouping[0] += __STATIC_CAST(char, (__iend - __decimal_pos));
ptrdiff_t __len = __insert_grouping(__ibuf, __iend, __new_grouping,
__sep, '+', '-', 0);
__iend = __ibuf + __len;
}
return __copy_float_and_fill(__ibuf, __iend, __out,
__f.flags(), __f.width(0), __fill, '+', '-');
}
template <class _CharT, class _OutputIter, class _Float>
_OutputIter _STLP_CALL
_M_do_put_float(_OutputIter __s, ios_base& __f,
_CharT __fill, _Float __x)
{
string __buf;
__buf.reserve(128);
__write_float(__buf, __f.flags(), (int)__f.precision(), __x);
const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
return __put_float(__CONST_CAST(char*, __buf.c_str()),
__CONST_CAST(char*, __buf.c_str()) + __buf.size(),
__s, __f, __fill,
__np.decimal_point(),
__np.thousands_sep(), __f._M_grouping());
}
// _M_do_put_integer and its helper functions.
template <class _CharT, class _OutputIter>
_OutputIter _STLP_CALL
__copy_integer_and_fill(const _CharT* __buf, ptrdiff_t __len,
_OutputIter __out,
ios_base::fmtflags __flg, streamsize __wid, _CharT __fill,
_CharT __xplus, _CharT __xminus)
{
if (__len >= __wid)
return copy(__buf, __buf + __len, __out);
else {
ptrdiff_t __pad = __wid - __len;
ios_base::fmtflags __dir = __flg & ios_base::adjustfield;
if (__dir == ios_base::left) {
__out = copy(__buf, __buf + __len, __out);
return fill_n(__out, __pad, __fill);
}
else if (__dir == ios_base::internal && __len != 0 &&
(__buf[0] == __xplus || __buf[0] == __xminus)) {
*__out++ = __buf[0];
__out = fill_n(__out, __pad, __fill);
return copy(__buf + 1, __buf + __len, __out);
}
else if (__dir == ios_base::internal && __len >= 2 &&
(__flg & ios_base::showbase) &&
(__flg & ios_base::basefield) == ios_base::hex) {
*__out++ = __buf[0];
*__out++ = __buf[1];
__out = fill_n(__out, __pad, __fill);
return copy(__buf + 2, __buf + __len, __out);
}
else {
__out = fill_n(__out, __pad, __fill);
return copy(__buf, __buf + __len, __out);
}
}
}
#ifndef _STLP_NO_WCHAR_T
// Helper function for wchar_t
template <class _OutputIter>
_OutputIter _STLP_CALL
__put_integer(char* __buf, char* __iend, _OutputIter __s,
ios_base& __f,
ios_base::fmtflags __flags, wchar_t __fill)
{
locale __loc = __f.getloc();
// const ctype<wchar_t>& __ct = use_facet<ctype<wchar_t> >(__loc);
const ctype<wchar_t>& __ct = *(const ctype<wchar_t>*)__f._M_ctype_facet();
wchar_t __xplus = __ct.widen('+');
wchar_t __xminus = __ct.widen('-');
wchar_t __wbuf[64];
__ct.widen(__buf, __iend, __wbuf);
ptrdiff_t __len = __iend - __buf;
wchar_t* __eend = __wbuf + __len;
// const numpunct<wchar_t>& __np = use_facet<numpunct<wchar_t> >(__loc);
// const string& __grouping = __np.grouping();
const numpunct<wchar_t>& __np = *(const numpunct<wchar_t>*)__f._M_numpunct_facet();
const string& __grouping = __f._M_grouping();
if (!__grouping.empty()) {
int __basechars;
if (__flags & ios_base::showbase)
switch (__flags & ios_base::basefield) {
case ios_base::hex: __basechars = 2; break;
case ios_base::oct: __basechars = 1; break;
default: __basechars = 0;
}
else
__basechars = 0;
__len = __insert_grouping(__wbuf, __eend, __grouping, __np.thousands_sep(),
__xplus, __xminus, __basechars);
}
return __copy_integer_and_fill((wchar_t*)__wbuf, __len, __s,
__flags, __f.width(0), __fill, __xplus, __xminus);
}
#endif
// Helper function for char
template <class _OutputIter>
_OutputIter _STLP_CALL
__put_integer(char* __buf, char* __iend, _OutputIter __s,
ios_base& __f, ios_base::fmtflags __flags, char __fill)
{
ptrdiff_t __len = __iend - __buf;
char __grpbuf[64];
// const numpunct<char>& __np = use_facet<numpunct<char> >(__f.getloc());
// const string& __grouping = __np.grouping();
const numpunct<char>& __np = *(const numpunct<char>*)__f._M_numpunct_facet();
const string& __grouping = __f._M_grouping();
if (!__grouping.empty()) {
int __basechars;
if (__flags & ios_base::showbase)
switch (__flags & ios_base::basefield) {
case ios_base::hex: __basechars = 2; break;
case ios_base::oct: __basechars = 1; break;
default: __basechars = 0;
}
else
__basechars = 0;
// make sure there is room at the end of the buffer
// we pass to __insert_grouping
copy(__buf, __iend, (char *) __grpbuf);
__buf = __grpbuf;
__iend = __grpbuf + __len;
__len = __insert_grouping(__buf, __iend, __grouping, __np.thousands_sep(),
'+', '-', __basechars);
}
return __copy_integer_and_fill(__buf, __len, __s, __flags, __f.width(0), __fill, '+', '-');
}
#ifdef _STLP_LONG_LONG
typedef _STLP_LONG_LONG __max_int_t;
typedef unsigned _STLP_LONG_LONG __umax_int_t;
#else
typedef long __max_int_t;
typedef unsigned long __umax_int_t;
#endif
extern const char __hex_char_table_lo[];
extern const char __hex_char_table_hi[];
template <class _Integer>
inline char* _STLP_CALL
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __true_type& /* is_signed */)
{
const bool __negative = __x < 0 ;
__max_int_t __temp = __x;
__umax_int_t __utemp = __negative?-__temp:__temp;
for (; __utemp != 0; __utemp /= 10)
*--__ptr = (int)(__utemp % 10) + '0';
// put sign if needed or requested
if (__negative)
*--__ptr = '-';
else if (__flags & ios_base::showpos)
*--__ptr = '+';
return __ptr;
}
template <class _Integer>
inline char* _STLP_CALL
__write_decimal_backward(char* __ptr, _Integer __x, ios_base::fmtflags __flags, const __false_type& /* is_signed */)
{
for (; __x != 0; __x /= 10)
*--__ptr = (int)(__x % 10) + '0';
// put sign if requested
if (__flags & ios_base::showpos)
*--__ptr = '+';
return __ptr;
}
template <class _Integer>
char* _STLP_CALL
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x)
{
char* __ptr = __buf;
__umax_int_t __temp;
if (__x == 0) {
*--__ptr = '0';
if ((__flags & ios_base::showpos) && ( (__flags & (ios_base::hex | ios_base::oct)) == 0 ))
*--__ptr = '+';
}
else {
switch (__flags & ios_base::basefield) {
case ios_base::oct:
__temp = __x;
// if the size of integer is less than 8, clear upper part
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
__temp &= 0xFFFFFFFF;
for (; __temp != 0; __temp >>=3)
*--__ptr = (((unsigned)__temp)& 0x7) + '0';
// put leading '0' is showbase is set
if (__flags & ios_base::showbase)
*--__ptr = '0';
break;
case ios_base::hex:
{
const char* __table_ptr = (__flags & ios_base::uppercase) ?
__hex_char_table_hi : __hex_char_table_lo;
__temp = __x;
// if the size of integer is less than 8, clear upper part
if ( sizeof(__x) < 8 && sizeof(__umax_int_t) >= 8 )
__temp &= 0xFFFFFFFF;
for (; __temp != 0; __temp >>=4)
*--__ptr = __table_ptr[((unsigned)__temp & 0xF)];
if (__flags & ios_base::showbase) {
*--__ptr = __table_ptr[16];
*--__ptr = '0';
}
}
break;
default:
{
#if defined(__HP_aCC) && (__HP_aCC == 1)
bool _IsSigned = !((_Integer)-1 > 0);
if (_IsSigned)
__ptr = __write_decimal_backward(__ptr, __x, __flags, __true_type() );
else
__ptr = __write_decimal_backward(__ptr, __x, __flags, __false_type() );
#else
typedef typename __bool2type<numeric_limits<_Integer>::is_signed>::_Ret _IsSigned;
__ptr = __write_decimal_backward(__ptr, __x, __flags, _IsSigned());
# endif
}
break;
}
}
// return pointer to beginning of the string
return __ptr;
}
//
// num_put<>
//
# if ( _STLP_STATIC_TEMPLATE_DATA > 0 )
template <class _CharT, class _OutputIterator>
locale::id num_put<_CharT, _OutputIterator>::id;
# else /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
typedef num_put<char, const char*> num_put_char;
typedef num_put<char, char*> num_put_char_2;
typedef num_put<char, ostreambuf_iterator<char, char_traits<char> > > num_put_char_3;
__DECLARE_INSTANCE(locale::id, num_put_char::id, );
__DECLARE_INSTANCE(locale::id, num_put_char_2::id, );
__DECLARE_INSTANCE(locale::id, num_put_char_3::id, );
# ifndef _STLP_NO_WCHAR_T
typedef num_put<wchar_t, const wchar_t*> num_put_wchar_t;
typedef num_put<wchar_t, wchar_t*> num_put_wchar_t_2;
typedef num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > num_put_wchar_t_3;
__DECLARE_INSTANCE(locale::id, num_put_wchar_t::id, );
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_2::id, );
__DECLARE_INSTANCE(locale::id, num_put_wchar_t_3::id, );
# endif
# endif /* ( _STLP_STATIC_TEMPLATE_DATA > 0 ) */
// issue 118
# ifndef _STLP_NO_BOOL
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f,
char_type __fill, bool __val) const {
if (!(__f.flags() & ios_base::boolalpha))
return this->do_put(__s, __f, __fill, __STATIC_CAST(long,__val));
locale __loc = __f.getloc();
// typedef numpunct<_CharT> _Punct;
// const _Punct& __np = use_facet<_Punct>(__loc);
const numpunct<_CharT>& __np = *(const numpunct<_CharT>*)__f._M_numpunct_facet();
basic_string<_CharT> __str = __val ? __np.truename() : __np.falsename();
// Reuse __copy_integer_and_fill. Since internal padding makes no
// sense for bool, though, make sure we use something else instead.
// The last two argument to __copy_integer_and_fill are dummies.
ios_base::fmtflags __flags = __f.flags();
if ((__flags & ios_base::adjustfield) == ios_base::internal)
__flags = (__flags & ~ios_base::adjustfield) | ios_base::right;
return __copy_integer_and_fill(__str.c_str(), __str.size(), __s,
__flags, __f.width(0), __fill,
(_CharT) 0, (_CharT) 0);
}
# endif
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
long __val) const {
char __buf[64]; // Large enough for a base 8 64-bit integer,
// plus any necessary grouping.
ios_base::fmtflags __flags = __f.flags();
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
}
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
unsigned long __val) const {
char __buf[64]; // Large enough for a base 8 64-bit integer,
// plus any necessary grouping.
ios_base::fmtflags __flags = __f.flags();
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
}
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
double __val) const {
return _M_do_put_float(__s, __f, __fill, __val);
}
#ifndef _STLP_NO_LONG_DOUBLE
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
long double __val) const {
return _M_do_put_float(__s, __f, __fill, __val);
}
#endif
#ifdef _STLP_LONG_LONG
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
_STLP_LONG_LONG __val) const {
char __buf[64]; // Large enough for a base 8 64-bit integer,
// plus any necessary grouping.
ios_base::fmtflags __flags = __f.flags();
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
}
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
unsigned _STLP_LONG_LONG __val) const {
char __buf[64]; // Large enough for a base 8 64-bit integer,
// plus any necessary grouping.
ios_base::fmtflags __flags = __f.flags();
char* __ibeg = __write_integer_backward((char*)__buf+64, __flags, __val);
return __put_integer(__ibeg, (char*)__buf+64, __s, __f, __flags, __fill);
}
#endif /* _STLP_LONG_LONG */
// lib.facet.num.put.virtuals "12 For conversion from void* the specifier is %p."
template <class _CharT, class _OutputIter>
_OutputIter
num_put<_CharT, _OutputIter>::do_put(_OutputIter __s, ios_base& __f, _CharT /*__fill*/,
const void* __val) const {
const ctype<_CharT>& __c_type = *(const ctype<_CharT>*)__f._M_ctype_facet();
ios_base::fmtflags __save_flags = __f.flags();
__f.setf(ios_base::hex, ios_base::basefield);
__f.setf(ios_base::showbase);
__f.setf(ios_base::internal, ios_base::adjustfield);
__f.width((sizeof(void*) * 2) + 2); // digits in pointer type plus '0x' prefix
# if defined(_STLP_LONG_LONG) && !defined(__MRC__) //*ty 11/24/2001 - MrCpp can not cast from void* to long long
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned _STLP_LONG_LONG,__val));
# else
_OutputIter result = this->do_put(__s, __f, __c_type.widen('0'), __REINTERPRET_CAST(unsigned long,__val));
# endif
__f.flags(__save_flags);
return result;
}
_STLP_END_NAMESPACE
# endif /* _STLP_EXPOSE_STREAM_IMPLEMENTATION */
#endif /* _STLP_NUM_PUT_C */
// Local Variables:
// mode:C++
// End:
+186
View File
@@ -0,0 +1,186 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_NUM_PUT_H
#define _STLP_INTERNAL_NUM_PUT_H
#ifndef _STLP_INTERNAL_NUMPUNCT_H
# include <stl/_numpunct.h>
#endif
#ifndef _STLP_INTERNAL_CTYPE_H
# include <stl/_ctype.h>
#endif
#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
# include <stl/_ostreambuf_iterator.h>
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// num_put facet
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
template <class _CharT, class _OutputIter>
# else
template <class _CharT, class _OutputIter = ostreambuf_iterator<_CharT, char_traits<_CharT> > >
# endif
class num_put: public locale::facet
{
friend class _Locale;
public:
typedef _CharT char_type;
typedef _OutputIter iter_type;
explicit num_put(size_t __refs = 0) : _BaseFacet(__refs) {}
# ifndef _STLP_NO_BOOL
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
bool __val) const {
return do_put(__s, __f, __fill, __val);
}
# endif
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
long __val) const {
return do_put(__s, __f, __fill, __val);
}
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
unsigned long __val) const {
return do_put(__s, __f, __fill, __val);
}
#ifdef _STLP_LONG_LONG
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
_STLP_LONG_LONG __val) const {
return do_put(__s, __f, __fill, __val);
}
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
unsigned _STLP_LONG_LONG __val) const {
return do_put(__s, __f, __fill, __val);
}
#endif
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
double __val) const {
return do_put(__s, __f, __fill, (double)__val);
}
#ifndef _STLP_NO_LONG_DOUBLE
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
long double __val) const {
return do_put(__s, __f, __fill, __val);
}
# endif
iter_type put(iter_type __s, ios_base& __f, char_type __fill,
const void * __val) const {
return do_put(__s, __f, __fill, __val);
}
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
~num_put() {}
# ifndef _STLP_NO_BOOL
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, bool __val) const;
# endif
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, long __val) const;
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, unsigned long __val) const;
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, double __val) const;
#ifndef _STLP_NO_LONG_DOUBLE
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, long double __val) const;
#endif
#ifdef _STLP_LONG_LONG
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, _STLP_LONG_LONG __val) const;
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill,
unsigned _STLP_LONG_LONG __val) const ;
#endif /* _STLP_LONG_LONG */
virtual _OutputIter do_put(_OutputIter __s, ios_base& __f, _CharT __fill, const void* __val) const;
};
# ifdef _STLP_USE_TEMPLATE_EXPORT
_STLP_EXPORT_TEMPLATE_CLASS num_put<char, ostreambuf_iterator<char, char_traits<char> > >;
// _STLP_EXPORT_TEMPLATE_CLASS num_put<char, char*>;
# ifndef _STLP_NO_WCHAR_T
_STLP_EXPORT_TEMPLATE_CLASS num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > >;
// _STLP_EXPORT_TEMPLATE_CLASS num_put<wchar_t, wchar_t*>;
# endif /* _STLP_NO_WCHAR_T */
# endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
template <class _Integer>
char* _STLP_CALL
__write_integer_backward(char* __buf, ios_base::fmtflags __flags, _Integer __x);
void _STLP_CALL __string_to_float(const string&, float&);
void _STLP_CALL __string_to_float(const string&, double&);
extern void _STLP_CALL __write_float(string&, ios_base::fmtflags, int, double);
# ifndef _STLP_NO_LONG_DOUBLE
void _STLP_CALL __string_to_float(const string&, long double&);
extern void _STLP_CALL __write_float(string&, ios_base::fmtflags, int, long double);
# endif
#ifndef _STLP_NO_WCHAR_T
extern wchar_t* _STLP_CALL __convert_float_buffer(const char*, const char*, wchar_t*, const ctype<wchar_t>&, wchar_t);
#endif
extern void _STLP_CALL __adjust_float_buffer(char*, char*, char);
extern char* _STLP_CALL
__write_integer(char* buf, ios_base::fmtflags flags, long x);
extern ptrdiff_t _STLP_CALL __insert_grouping(char* first, char* last, const string&, char, char, char, int);
# ifndef _STLP_NO_WCHAR_T
extern ptrdiff_t _STLP_CALL __insert_grouping(wchar_t*, wchar_t*, const string&, wchar_t, wchar_t, wchar_t, int);
# endif
# endif
# if defined (__BORLANDC__) && defined (_RTLDLL)
inline void _Stl_loc_init_num_put() {
num_put<char, ostreambuf_iterator<char, char_traits<char> > >::id._M_index = 14;
num_put<char, char*>::id._M_index = 15;
# ifndef _STLP_NO_WCHAR_T
num_put<wchar_t, ostreambuf_iterator<wchar_t, char_traits<wchar_t> > > ::id._M_index = 33;
num_put<wchar_t, wchar_t*>::id._M_index = 34;
# endif
}
# endif
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && ! defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_num_put.c>
# endif
#endif /* _STLP_INTERNAL_NUMERIC_FACETS_H */
// Local Variables:
// mode:C++
// End:
+104
View File
@@ -0,0 +1,104 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_NUMERIC_C
#define _STLP_NUMERIC_C
#ifndef _STLP_INTERNAL_NUMERIC_H
# include <stl/_numeric.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*, _BinaryOperation __binary_op)
{
_STLP_DEBUG_CHECK(__check_range(__first, __last))
if (__first == __last) return __result;
*__result = *__first;
_Tp __val = *__first;
while (++__first != __last) {
__val = __binary_op(__val, *__first);
*++__result = __val;
}
return ++__result;
}
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*,
_BinaryOperation __binary_op) {
_STLP_DEBUG_CHECK(__check_range(__first, __last))
if (__first == __last) return __result;
*__result = *__first;
_Tp __val = *__first;
while (++__first != __last) {
_Tp __tmp = *__first;
*++__result = __binary_op(__tmp, __val);
__val = __tmp;
}
return ++__result;
}
template <class _Tp, class _Integer, class _MonoidOperation>
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr)
{
_STLP_MPWFIX_TRY
if (__n == 0)
return __identity_element(__opr);
else {
while ((__n & 1) == 0) {
__n >>= 1;
__x = __opr(__x, __x);
}
_Tp __result = __x;
_STLP_MPWFIX_TRY
__n >>= 1;
while (__n != 0) {
__x = __opr(__x, __x);
if ((__n & 1) != 0)
__result = __opr(__result, __x);
__n >>= 1;
}
return __result;
_STLP_MPWFIX_CATCH
}
_STLP_MPWFIX_CATCH_ACTION(__x = _Tp())
}
_STLP_END_NAMESPACE
#endif /* _STLP_NUMERIC_C */
// Local Variables:
// mode:C++
// End:
+186
View File
@@ -0,0 +1,186 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_NUMERIC_H
#define _STLP_INTERNAL_NUMERIC_H
#ifndef _STLP_INTERNAL_FUNCTION_H
# include <stl/_function_base.h>
#endif
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _InputIterator, class _Tp>
_STLP_INLINE_LOOP
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init)
{
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
_Init = _Init + *__first;
return _Init;
}
template <class _InputIterator, class _Tp, class _BinaryOperation>
_STLP_INLINE_LOOP
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp _Init,
_BinaryOperation __binary_op)
{
_STLP_DEBUG_CHECK(__check_range(__first, __last))
for ( ; __first != __last; ++__first)
_Init = __binary_op(_Init, *__first);
return _Init;
}
template <class _InputIterator1, class _InputIterator2, class _Tp>
_STLP_INLINE_LOOP
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp _Init)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2)
_Init = _Init + (*__first1 * *__first2);
return _Init;
}
template <class _InputIterator1, class _InputIterator2, class _Tp,
class _BinaryOperation1, class _BinaryOperation2>
_STLP_INLINE_LOOP
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp _Init,
_BinaryOperation1 __binary_op1,
_BinaryOperation2 __binary_op2)
{
_STLP_DEBUG_CHECK(__check_range(__first1, __last1))
for ( ; __first1 != __last1; ++__first1, ++__first2)
_Init = __binary_op1(_Init, __binary_op2(*__first1, *__first2));
return _Init;
}
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*, _BinaryOperation __binary_op);
template <class _InputIterator, class _OutputIterator>
inline _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result) {
return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator),
__plus(_STLP_VALUE_TYPE(__first, _InputIterator)));
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
inline _OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op) {
return __partial_sum(__first, __last, __result, _STLP_VALUE_TYPE(__first, _InputIterator),
__binary_op);
}
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOperation>
_OutputIterator
__adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp*,
_BinaryOperation __binary_op);
template <class _InputIterator, class _OutputIterator>
inline _OutputIterator
adjacent_difference(_InputIterator __first,
_InputIterator __last, _OutputIterator __result) {
return __adjacent_difference(__first, __last, __result,
_STLP_VALUE_TYPE(__first, _InputIterator),
__minus(_STLP_VALUE_TYPE(__first, _InputIterator)));
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOperation __binary_op) {
return __adjacent_difference(__first, __last, __result,
_STLP_VALUE_TYPE(__first, _InputIterator),
__binary_op);
}
template <class _Tp, class _Integer, class _MonoidOperation>
_Tp __power(_Tp __x, _Integer __n, _MonoidOperation __opr);
# ifndef _STLP_NO_EXTENSIONS
// Returns __x ** __n, where __n >= 0. _Note that "multiplication"
// is required to be associative, but not necessarily commutative.
template <class _Tp, class _Integer>
inline _Tp __power(_Tp __x, _Integer __n)
{
return __power(__x, __n, multiplies<_Tp>());
}
// Alias for the internal name __power. Note that power is an extension,
// not part of the C++ standard.
template <class _Tp, class _Integer, class _MonoidOperation>
inline _Tp power(_Tp __x, _Integer __n, _MonoidOperation __opr) {
return __power(__x, __n, __opr);
}
template <class _Tp, class _Integer>
inline _Tp power(_Tp __x, _Integer __n) {
return __power(__x, __n, multiplies<_Tp>());
}
// iota is not part of the C++ standard. It is an extension.
template <class _ForwardIterator, class _Tp>
_STLP_INLINE_LOOP
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __val)
{
_STLP_DEBUG_CHECK(__check_range(__first, __last))
while (__first != __last)
*__first++ = __val++;
}
# endif
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_numeric.c>
# endif
#endif /* _STLP_INTERNAL_NUMERIC_H */
// Local Variables:
// mode:C++
// End:
+170
View File
@@ -0,0 +1,170 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_NUMPUNCT_H
#define _STLP_INTERNAL_NUMPUNCT_H
#ifndef _STLP_IOS_BASE_H
# include <stl/_ios_base.h>
#endif
# ifndef _STLP_C_LOCALE_H
# include <stl/c_locale.h>
# endif
#ifndef _STLP_STRING_H
# include <stl/_string.h>
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// numpunct facets
template <class _CharT> class numpunct {};
template <class _CharT> class numpunct_byname {};
template <class _Ch, class _InIt> class num_get;
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC numpunct<char> : public locale::facet
{
friend class _Locale;
# ifndef _STLP_NO_FRIEND_TEMPLATES
template <class _Ch, class _InIt> friend class num_get;
# endif
public:
typedef char char_type;
typedef string string_type;
explicit numpunct(size_t __refs = 0) : _BaseFacet(__refs) {}
char decimal_point() const { return do_decimal_point(); }
char thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
string truename() const { return do_truename(); }
string falsename() const { return do_falsename(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
# ifndef _STLP_NO_FRIEND_TEMPLATES
protected:
# endif
~numpunct();
_STLP_STATIC_MEMBER_DECLSPEC static string _M_truename;
_STLP_STATIC_MEMBER_DECLSPEC static string _M_falsename;
_STLP_STATIC_MEMBER_DECLSPEC static string _M_grouping;
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
virtual string do_truename() const;
virtual string do_falsename() const;
};
# if ! defined (_STLP_NO_WCHAR_T)
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC numpunct<wchar_t> : public locale::facet
{
friend class _Locale;
public:
typedef wchar_t char_type;
typedef wstring string_type;
explicit numpunct(size_t __refs = 0) : _BaseFacet(__refs) {}
wchar_t decimal_point() const { return do_decimal_point(); }
wchar_t thousands_sep() const { return do_thousands_sep(); }
string grouping() const { return do_grouping(); }
wstring truename() const { return do_truename(); }
wstring falsename() const { return do_falsename(); }
_STLP_STATIC_MEMBER_DECLSPEC static locale::id id;
protected:
_STLP_STATIC_MEMBER_DECLSPEC static wstring _M_truename;
_STLP_STATIC_MEMBER_DECLSPEC static wstring _M_falsename;
_STLP_STATIC_MEMBER_DECLSPEC static string _M_grouping;
~numpunct();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
virtual wstring do_truename() const;
virtual wstring do_falsename() const;
};
# endif /* WCHAR_T */
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC numpunct_byname<char> : public numpunct<char> {
public:
typedef char char_type;
typedef string string_type;
explicit numpunct_byname(const char* __name, size_t __refs = 0);
protected:
~numpunct_byname();
virtual char do_decimal_point() const;
virtual char do_thousands_sep() const;
virtual string do_grouping() const;
private:
_Locale_numeric* _M_numeric;
};
# ifndef _STLP_NO_WCHAR_T
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC numpunct_byname<wchar_t>: public numpunct<wchar_t> {
public:
typedef wchar_t char_type;
typedef wstring string_type;
explicit numpunct_byname(const char* __name, size_t __refs = 0);
protected:
~numpunct_byname();
virtual wchar_t do_decimal_point() const;
virtual wchar_t do_thousands_sep() const;
virtual string do_grouping() const;
private:
_Locale_numeric* _M_numeric;
};
# endif /* WCHAR_T */
_STLP_END_NAMESPACE
#endif /* _STLP_NUMPUNCT_H */
// Local Variables:
// mode:C++
// End:
+382
View File
@@ -0,0 +1,382 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_OSTREAM_C
#define _STLP_OSTREAM_C
#ifndef _STLP_INTERNAL_OSTREAM_H
# include <stl/_ostream.h>
#endif
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
#if !defined (_STLP_INTERNAL_NUM_PUT_H)
# include <stl/_num_put.h> // For basic_streambuf and iterators
#endif
_STLP_BEGIN_NAMESPACE
// Helper functions for istream<>::sentry constructor.
template <class _CharT, class _Traits>
bool
_M_init(basic_ostream<_CharT, _Traits>& __str) {
if (__str.good()) {
// boris : check if this is needed !
if (!__str.rdbuf())
__str.setstate(ios_base::badbit);
if (__str.tie())
__str.tie()->flush();
return __str.good();
} else
return false;
}
//----------------------------------------------------------------------
// Definitions of non-inline member functions.
// Constructor, destructor
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>
::basic_ostream(basic_streambuf<_CharT, _Traits>* __buf)
: basic_ios<_CharT, _Traits>()
{
this->init(__buf);
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>::~basic_ostream()
{}
// Output directly from a streambuf.
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<_CharT, _Traits>* __from)
{
sentry __sentry(*this);
if (__sentry) {
if (__from) {
bool __any_inserted = __from->gptr() != __from->egptr()
? this->_M_copy_buffered(__from, this->rdbuf())
: this->_M_copy_unbuffered(__from, this->rdbuf());
if (!__any_inserted)
this->setstate(ios_base::failbit);
}
else
this->setstate(ios_base::badbit);
}
return *this;
}
// Helper functions for the streambuf version of operator<<. The
// exception-handling code is complicated because exceptions thrown
// while extracting characters are treated differently than exceptions
// thrown while inserting characters.
template <class _CharT, class _Traits>
bool basic_ostream<_CharT, _Traits>
::_M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
basic_streambuf<_CharT, _Traits>* __to)
{
bool __any_inserted = false;
while (__from->egptr() != __from->gptr()) {
const ptrdiff_t __avail = __from->egptr() - __from->gptr();
streamsize __nwritten;
_STLP_TRY {
__nwritten = __to->sputn(__from->gptr(), __avail);
__from->gbump((int)__nwritten);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
return __any_inserted;
}
if (__nwritten == __avail) {
_STLP_TRY {
if (this->_S_eof(__from->sgetc()))
return true;
else
__any_inserted = true;
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::failbit);
return false;
}
}
else if (__nwritten != 0)
return true;
else
return __any_inserted;
}
// No characters are in the buffer, but we aren't at EOF. Switch to
// unbuffered mode.
return __any_inserted || this->_M_copy_unbuffered(__from, __to);
}
template <class _CharT, class _Traits>
bool basic_ostream<_CharT, _Traits>
::_M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
basic_streambuf<_CharT, _Traits>* __to)
{
bool __any_inserted = false;
while (true) {
int_type __c;
_STLP_TRY {
__c = __from->sbumpc();
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::failbit);
return __any_inserted;
}
if (this->_S_eof(__c))
return __any_inserted;
else {
int_type __tmp;
_STLP_TRY {
__tmp = __to->sputc(__c);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
return __any_inserted;
}
if (this->_S_eof(__tmp)) {
_STLP_TRY {
/* __tmp = */ __from->sputbackc(__c);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
return __any_inserted;
}
}
else
__any_inserted = true;
}
}
}
// Helper function for numeric output.
template <class _CharT, class _Traits, class _Number>
basic_ostream<_CharT, _Traits>& _STLP_CALL
_M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x)
{
typedef typename basic_ostream<_CharT, _Traits>::sentry _Sentry;
_Sentry __sentry(__os);
bool __failed = true;
if (__sentry) {
_STLP_TRY {
typedef num_put<_CharT, ostreambuf_iterator<_CharT, _Traits> > _NumPut;
__failed = (use_facet<_NumPut>(__os.getloc())).put(
ostreambuf_iterator<_CharT, _Traits>(__os.rdbuf()),
__os, __os.fill(),
__x).failed();
}
_STLP_CATCH_ALL {
__os._M_handle_exception(ios_base::badbit);
}
}
if (__failed)
__os.setstate(ios_base::badbit);
return __os;
}
# if defined (_STLP_USE_TEMPLATE_EXPORT) && defined (__BUILDING_STLPORT)
_STLP_EXPORT_TEMPLATE _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
_M_put_num(basic_ostream<char, char_traits<char> >&, unsigned long);
_STLP_EXPORT_TEMPLATE _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
_M_put_num(basic_ostream<char, char_traits<char> >&, long);
# if defined (_STLP_LONG_LONG)
_STLP_EXPORT_TEMPLATE _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
_M_put_num(basic_ostream<char, char_traits<char> >&, unsigned _STLP_LONG_LONG);
_STLP_EXPORT_TEMPLATE _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL
_M_put_num(basic_ostream<char, char_traits<char> >&, _STLP_LONG_LONG );
# endif
# endif
template <class _CharT, class _Traits>
void basic_ostream<_CharT, _Traits>::_M_put_char(_CharT __c)
{
sentry __sentry(*this);
if (__sentry) {
bool __failed = true;
_STLP_TRY {
streamsize __npad = this->width() > 0 ? this->width() - 1 : 0;
// if (__npad <= 1)
if (__npad == 0)
__failed = this->_S_eof(this->rdbuf()->sputc(__c));
else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
__failed = this->_S_eof(this->rdbuf()->sputc(__c));
__failed = __failed ||
this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
}
else {
__failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
__failed = __failed || this->_S_eof(this->rdbuf()->sputc(__c));
}
this->width(0);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
}
if (__failed)
this->setstate(ios_base::badbit);
}
}
template <class _CharT, class _Traits>
void basic_ostream<_CharT, _Traits>::_M_put_nowiden(const _CharT* __s)
{
sentry __sentry(*this);
if (__sentry) {
bool __failed = true;
streamsize __n = _Traits::length(__s);
streamsize __npad = this->width() > __n ? this->width() - __n : 0;
_STLP_TRY {
if (__npad == 0)
__failed = this->rdbuf()->sputn(__s, __n) != __n;
else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
__failed = this->rdbuf()->sputn(__s, __n) != __n;
__failed = __failed ||
this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
}
else {
__failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
__failed = __failed || this->rdbuf()->sputn(__s, __n) != __n;
}
this->width(0);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
}
if (__failed)
this->setstate(ios_base::failbit);
}
}
template <class _CharT, class _Traits>
void basic_ostream<_CharT, _Traits>::_M_put_widen(const char* __s)
{
sentry __sentry(*this);
if (__sentry) {
bool __failed = true;
streamsize __n = char_traits<char>::length(__s);
streamsize __npad = this->width() > __n ? this->width() - __n : 0;
_STLP_TRY {
if (__npad == 0)
__failed = !this->_M_put_widen_aux(__s, __n);
else if ((this->flags() & ios_base::adjustfield) == ios_base::left) {
__failed = !this->_M_put_widen_aux(__s, __n);
__failed = __failed ||
this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
}
else {
__failed = this->rdbuf()->_M_sputnc(this->fill(), __npad) != __npad;
__failed = __failed || !this->_M_put_widen_aux(__s, __n);
}
this->width(0);
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
}
if (__failed)
this->setstate(ios_base::failbit);
}
}
template <class _CharT, class _Traits>
bool basic_ostream<_CharT, _Traits>::_M_put_widen_aux(const char* __s,
streamsize __n)
{
basic_streambuf<_CharT, _Traits>* __buf = this->rdbuf();
for ( ; __n > 0 ; --__n)
if (this->_S_eof(__buf->sputc(this->widen(*__s++))))
return false;
return true;
}
// Unformatted output of a single character.
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::put(char_type __c)
{
sentry __sentry(*this);
bool __failed = true;
if (__sentry) {
_STLP_TRY {
__failed = this->_S_eof(this->rdbuf()->sputc(__c));
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
}
}
if (__failed)
this->setstate(ios_base::badbit);
return *this;
}
// Unformatted output of a single character.
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
{
sentry __sentry(*this);
bool __failed = true;
if (__sentry) {
_STLP_TRY {
__failed = this->rdbuf()->sputn(__s, __n) != __n;
}
_STLP_CATCH_ALL {
this->_M_handle_exception(ios_base::badbit);
}
}
if (__failed)
this->setstate(ios_base::badbit);
return *this;
}
_STLP_END_NAMESPACE
#endif /* defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) */
#endif /* _STLP_OSTREAM_C */
+356
View File
@@ -0,0 +1,356 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_INTERNAL_OSTREAM_H
#define _STLP_INTERNAL_OSTREAM_H
#ifndef _STLP_INTERNAL_IOS_H
# include <stl/_ios.h> // For basic_ios<>. Includes <iosfwd>.
#endif
#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
# include <stl/_ostreambuf_iterator.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _CharT, class _Traits, class _Number>
basic_ostream<_CharT, _Traits>& _STLP_CALL
_M_put_num(basic_ostream<_CharT, _Traits>& __os, _Number __x);
# if defined (_STLP_USE_TEMPLATE_EXPORT)
template <class _CharT, class _Traits>
class _Osentry;
# endif
template <class _CharT, class _Traits>
bool
_M_init(basic_ostream<_CharT, _Traits>& __str);
//----------------------------------------------------------------------
// class basic_ostream<>
template <class _CharT, class _Traits>
class basic_ostream : virtual public basic_ios<_CharT, _Traits>
{
typedef basic_ostream<_CharT, _Traits> _Self;
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;
typedef basic_ios<_CharT, _Traits> _Basic_ios;
public: // Constructor and destructor.
explicit basic_ostream(basic_streambuf<_CharT, _Traits>* __buf);
~basic_ostream();
public: // Hooks for manipulators.
typedef basic_ios<_CharT, _Traits>& (_STLP_CALL *__ios_fn)(basic_ios<_CharT, _Traits>&);
typedef ios_base& (_STLP_CALL *__ios_base_fn)(ios_base&);
typedef _Self& (_STLP_CALL *__ostream_fn)(_Self&);
_Self& operator<< (__ostream_fn __f) { return __f(*this); }
_Self & operator<< (__ios_base_fn __f) { __f(*this); return *this; }
_Self& operator<< (__ios_fn __ff) { __ff(*this); return *this; }
private:
bool _M_copy_buffered(basic_streambuf<_CharT, _Traits>* __from,
basic_streambuf<_CharT, _Traits>* __to);
bool _M_copy_unbuffered(basic_streambuf<_CharT, _Traits>* __from,
basic_streambuf<_CharT, _Traits>* __to);
public:
void _M_put_char(_CharT __c);
void _M_put_nowiden(const _CharT* __s);
void _M_put_widen(const char* __s);
bool _M_put_widen_aux(const char* __s, streamsize __n);
public: // Unformatted output.
_Self& put(char_type __c);
_Self& write(const char_type* __s, streamsize __n);
public: // Formatted output.
// Formatted output from a streambuf.
_Self& operator<<(basic_streambuf<_CharT, _Traits>* __buf);
# ifndef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
// this is needed for compiling with option char = unsigned
_Self& operator<<(unsigned char __x) { _M_put_char(__x); return *this; }
# endif
_Self& operator<<(short __x) { return _M_put_num(*this, __STATIC_CAST(long,__x)); }
_Self& operator<<(unsigned short __x) { return _M_put_num(*this, __STATIC_CAST(unsigned long,__x)); }
_Self& operator<<(int __x) { return _M_put_num(*this, __STATIC_CAST(long,__x)); }
_Self& operator<<(unsigned int __x) { return _M_put_num(*this, __STATIC_CAST(unsigned long,__x)); }
_Self& operator<<(long __x) { return _M_put_num(*this, __x); }
_Self& operator<<(unsigned long __x) { return _M_put_num(*this, __x); }
#ifdef _STLP_LONG_LONG
_Self& operator<< (_STLP_LONG_LONG __x) { return _M_put_num(*this, __x); }
_Self& operator<< (unsigned _STLP_LONG_LONG __x) { return _M_put_num(*this, __x); }
#endif
_Self& operator<<(float __x)
{ return _M_put_num(*this, __STATIC_CAST(double,__x)); }
_Self& operator<<(double __x) { return _M_put_num(*this, __x); }
# ifndef _STLP_NO_LONG_DOUBLE
_Self& operator<<(long double __x) { return _M_put_num(*this, __x); }
# endif
_Self& operator<<(const void* __x) { return _M_put_num(*this, __x); }
# ifndef _STLP_NO_BOOL
_Self& operator<<(bool __x) { return _M_put_num(*this, __x); }
# endif
public: // Buffer positioning and manipulation.
_Self& flush() {
if (this->rdbuf())
if (this->rdbuf()->pubsync() == -1)
this->setstate(ios_base::badbit);
return *this;
}
pos_type tellp() {
return this->rdbuf() && !this->fail()
? this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out)
: pos_type(-1);
}
_Self& seekp(pos_type __pos) {
if (this->rdbuf() && !this->fail())
this->rdbuf()->pubseekpos(__pos, ios_base::out);
return *this;
}
_Self& seekp(off_type __off, ios_base::seekdir __dir) {
if (this->rdbuf() && !this->fail())
this->rdbuf()->pubseekoff(__off, __dir, ios_base::out);
return *this;
}
#if defined (_STLP_USE_TEMPLATE_EXPORT)
// If we are using DLL specs, we have not to use inner classes
// end class declaration here
typedef _Osentry<_CharT, _Traits> sentry;
};
# define sentry _Osentry
template <class _CharT, class _Traits>
class _Osentry {
typedef _Osentry<_CharT, _Traits> _Self;
# else
class sentry {
typedef sentry _Self;
# endif
private:
basic_ostream<_CharT, _Traits>& _M_str;
// basic_streambuf<_CharT, _Traits>* _M_buf;
bool _M_ok;
public:
explicit sentry(basic_ostream<_CharT, _Traits>& __str)
: _M_str(__str), /* _M_buf(__str.rdbuf()), */ _M_ok(_M_init(__str))
{
}
~sentry() {
if (_M_str.flags() & ios_base::unitbuf)
# ifndef _STLP_INCOMPLETE_EXCEPTION_HEADER
if (!_STLP_VENDOR_EXCEPT_STD::uncaught_exception())
# endif
_M_str.flush();
}
operator bool() const { return _M_ok; }
private: // Disable assignment and copy constructor.
sentry(const _Self& __s) : _M_str (__s._M_str) {};
void operator=(const _Self&) {};
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
# undef sentry
# else
// close basic_ostream class definition here
};
# endif
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_ostream<char, char_traits<char> >;
_STLP_EXPORT_TEMPLATE_CLASS _Osentry<char, char_traits<char> >;
# if !defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_ostream<wchar_t, char_traits<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS _Osentry<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
template <class _CharT, class _Traits>
inline basic_streambuf<_CharT, _Traits>* _STLP_CALL
_M_get_ostreambuf(basic_ostream<_CharT, _Traits>& __St)
{
return __St.rdbuf();
}
// Non-member functions.
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c) {
__os._M_put_char(__c);
return __os;
}
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __s) {
__os._M_put_nowiden(__s);
return __os;
}
# ifdef _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER
// some specializations
inline basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __os, char __c) {
__os._M_put_char(__c);
return __os;
}
inline basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __os, signed char __c) {
__os._M_put_char(__c);
return __os;
}
inline basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __os, unsigned char __c) {
__os._M_put_char(__c);
return __os;
}
inline basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __os, const char* __s) {
__os._M_put_nowiden(__s);
return __os;
}
inline basic_ostream<char, char_traits<char> >& _STLP_CALL
operator<<(basic_ostream<char, char_traits<char> >& __os, const signed char* __s) {
__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
return __os;
}
inline basic_ostream<char, char_traits<char> >&
operator<<(basic_ostream<char, char_traits<char> >& __os, const unsigned char* __s) {
__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
return __os;
}
# else
// also for compilers who might use that
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, char __c) {
__os._M_put_char(__os.widen(__c));
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>& _STLP_CALL
operator<<(basic_ostream<char, _Traits>& __os, char __c) {
__os._M_put_char(__c);
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>& _STLP_CALL
operator<<(basic_ostream<char, _Traits>& __os, signed char __c) {
__os._M_put_char(__c);
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>& _STLP_CALL
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c) {
__os._M_put_char(__c);
return __os;
}
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __s) {
__os._M_put_widen(__s);
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>& _STLP_CALL
operator<<(basic_ostream<char, _Traits>& __os, const char* __s) {
__os._M_put_nowiden(__s);
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>& _STLP_CALL
operator<<(basic_ostream<char, _Traits>& __os, const signed char* __s) {
__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
return __os;
}
template <class _Traits>
inline basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __s) {
__os._M_put_nowiden(__REINTERPRET_CAST(const char*,__s));
return __os;
}
# endif /* _STLP_NO_FUNCTION_TMPL_PARTIAL_ORDER */
//----------------------------------------------------------------------
// basic_ostream manipulators.
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
endl(basic_ostream<_CharT, _Traits>& __os) {
__os.put(__os.widen('\n'));
__os.flush();
return __os;
}
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
ends(basic_ostream<_CharT, _Traits>& __os) {
__os.put(_STLP_DEFAULT_CONSTRUCTED(_CharT));
return __os;
}
template <class _CharT, class _Traits>
inline basic_ostream<_CharT, _Traits>& _STLP_CALL
flush(basic_ostream<_CharT, _Traits>& __os) {
__os.flush();
return __os;
}
_STLP_END_NAMESPACE
# undef _STLP_MANIP_INLINE
#if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_ostream.c>
# endif
#endif /* _STLP_INTERNAL_OSTREAM_H */
// Local Variables:
// mode:C++
// End:
@@ -0,0 +1,97 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
#define _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _CharT, class _Traits>
extern basic_streambuf<_CharT, _Traits>* _STLP_CALL _M_get_ostreambuf(basic_ostream<_CharT, _Traits>& ) ;
// The default template argument is declared in iosfwd
template<class _CharT, class _Traits>
class ostreambuf_iterator
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename _Traits::int_type int_type;
typedef basic_streambuf<_CharT, _Traits> streambuf_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
public:
ostreambuf_iterator(streambuf_type* __buf) _STLP_NOTHROW : _M_buf(__buf), _M_ok(__buf!=0) {}
// ostreambuf_iterator(ostream_type& __o) _STLP_NOTHROW : _M_buf(_M_get_ostreambuf(__o)), _M_ok(_M_buf != 0) {}
inline ostreambuf_iterator(ostream_type& __o) _STLP_NOTHROW;
ostreambuf_iterator<_CharT, _Traits>& operator=(char_type __c) {
_M_ok = _M_ok && !traits_type::eq_int_type(_M_buf->sputc(__c),
traits_type::eof());
return *this;
}
ostreambuf_iterator<_CharT, _Traits>& operator*() { return *this; }
ostreambuf_iterator<_CharT, _Traits>& operator++() { return *this; }
ostreambuf_iterator<_CharT, _Traits>& operator++(int) { return *this; }
bool failed() const { return !_M_ok; }
private:
streambuf_type* _M_buf;
bool _M_ok;
};
template <class _CharT, class _Traits>
inline ostreambuf_iterator<_CharT, _Traits>::ostreambuf_iterator(basic_ostream<_CharT, _Traits>& __o) _STLP_NOTHROW : _M_buf(_M_get_ostreambuf(__o)), _M_ok(_M_buf != 0) {}
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS ostreambuf_iterator<char, char_traits<char> >;
# if defined (INSTANTIATE_WIDE_STREAMS)
_STLP_EXPORT_TEMPLATE_CLASS ostreambuf_iterator<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _CharT, class _Traits>
inline output_iterator_tag _STLP_CALL
iterator_category(const ostreambuf_iterator<_CharT, _Traits>&) { return output_iterator_tag(); }
# endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+161
View File
@@ -0,0 +1,161 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_PAIR_H
#define _STLP_INTERNAL_PAIR_H
_STLP_BEGIN_NAMESPACE
template <class _T1, class _T2>
struct pair {
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
# if defined (_STLP_CONST_CONSTRUCTOR_BUG)
pair() {}
# else
pair() : first(_T1()), second(_T2()) {}
# endif
pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
#if defined (_STLP_MEMBER_TEMPLATES) && !(defined (_STLP_MSVC) && (_STLP_MSVC < 1200))
template <class _U1, class _U2>
pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
pair(const pair<_T1,_T2>& __o) : first(__o.first), second(__o.second) {}
#endif
__TRIVIAL_DESTRUCTOR(pair)
};
template <class _T1, class _T2>
inline bool _STLP_CALL operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{
return __x.first == __y.first && __x.second == __y.second;
}
template <class _T1, class _T2>
inline bool _STLP_CALL operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{
return __x.first < __y.first ||
(!(__y.first < __x.first) && __x.second < __y.second);
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template <class _T1, class _T2>
inline bool _STLP_CALL operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
return !(__x == __y);
}
template <class _T1, class _T2>
inline bool _STLP_CALL operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
return __y < __x;
}
template <class _T1, class _T2>
inline bool _STLP_CALL operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
return !(__y < __x);
}
template <class _T1, class _T2>
inline bool _STLP_CALL operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) {
return !(__x < __y);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
#if defined(_STLP_FUNCTION_TMPL_PARTIAL_ORDER) && ! defined (_STLP_NO_EXTENSIONS) && ! defined (__BORLANDC__) && ! defined (__DMC__)
template <class _T1, class _T2, int _Sz>
inline pair<_T1, _T2 const*> make_pair(_T1 const& __x,
_T2 const (&__y)[_Sz])
{
return pair<_T1, _T2 const*>(__x, static_cast<_T2 const*>(__y));
}
template <class _T1, class _T2, int _Sz>
inline pair<_T1 const*, _T2> make_pair(_T1 const (&__x)[_Sz],
_T2 const& __y)
{
return pair<_T1 const*, _T2>(static_cast<_T1 const*>(__x), __y);
}
template <class _T1, class _T2, int _Sz1, int _Sz2>
inline pair<_T1 const*, _T2 const*> make_pair(_T1 const (&__x)[_Sz1],
_T2 const (&__y)[_Sz2])
{
return pair<_T1 const*, _T2 const*>(static_cast<_T1 const*>(__x),
static_cast<_T2 const*>(__y));
}
#endif
template <class _T1, class _T2>
inline pair<_T1, _T2> _STLP_CALL make_pair(const _T1& __x, const _T2& __y)
{
return pair<_T1, _T2>(__x, __y);
}
_STLP_END_NAMESPACE
# if defined (_STLP_USE_NAMESPACES) || ! defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
_STLP_BEGIN_RELOPS_NAMESPACE
template <class _Tp>
inline bool _STLP_CALL operator!=(const _Tp& __x, const _Tp& __y) {
return !(__x == __y);
}
template <class _Tp>
inline bool _STLP_CALL operator>(const _Tp& __x, const _Tp& __y) {
return __y < __x;
}
template <class _Tp>
inline bool _STLP_CALL operator<=(const _Tp& __x, const _Tp& __y) {
return !(__y < __x);
}
template <class _Tp>
inline bool _STLP_CALL operator>=(const _Tp& __x, const _Tp& __y) {
return !(__x < __y);
}
_STLP_END_RELOPS_NAMESPACE
# endif
#endif /* _STLP_INTERNAL_PAIR_H */
// Local Variables:
// mode:C++
// End:
+17
View File
@@ -0,0 +1,17 @@
/* NOTE : this header has no guards and is MEANT for multiple inclusion !
* If you are using "header protection" option with your compiler,
* please also find #pragma which disables it and put it here, to
* allow reentrancy of this header.
*/
/* We undef "std" on entry , as STLport headers may include native ones. */
# undef std
# ifndef _STLP_CONFIG_H
# include <stl/_config.h>
# endif
/* If the platform provides any specific prolog actions,
* like #pragmas, do include platform-specific prolog file */
# if defined (_STLP_HAS_SPECIFIC_PROLOG_EPILOG)
# include <config/_prolog.h>
# endif
+262
View File
@@ -0,0 +1,262 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_PTHREAD_ALLOC_C
#define _STLP_PTHREAD_ALLOC_C
#ifdef __WATCOMC__
#pragma warning 13 9
#pragma warning 367 9
#pragma warning 368 9
#endif
#ifndef _STLP_PTHREAD_ALLOC_H
# include <stl/_pthread_alloc.h>
#endif
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
# include <cerrno>
_STLP_BEGIN_NAMESPACE
template <size_t _Max_size>
void _Pthread_alloc<_Max_size>::_S_destructor(void * __instance)
{
_M_lock __lock_instance; // Need to acquire lock here.
_Pthread_alloc_per_thread_state<_Max_size>* __s =
(_Pthread_alloc_per_thread_state<_Max_size> *)__instance;
__s -> __next = _S_free_per_thread_states;
_S_free_per_thread_states = __s;
}
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc<_Max_size>::_S_new_per_thread_state()
{
/* lock already held here. */
if (0 != _S_free_per_thread_states) {
_Pthread_alloc_per_thread_state<_Max_size> *__result =
_S_free_per_thread_states;
_S_free_per_thread_states = _S_free_per_thread_states -> __next;
return __result;
} else {
return _STLP_NEW _Pthread_alloc_per_thread_state<_Max_size>;
}
}
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> *
_Pthread_alloc<_Max_size>::_S_get_per_thread_state()
{
int __ret_code;
__state_type* __result;
if (_S_key_initialized && (__result = (__state_type*) pthread_getspecific(_S_key)))
return __result;
/*REFERENCED*/
_M_lock __lock_instance; // Need to acquire lock here.
if (!_S_key_initialized) {
if (pthread_key_create(&_S_key, _S_destructor)) {
__THROW_BAD_ALLOC; // failed
}
_S_key_initialized = true;
}
__result = _S_new_per_thread_state();
__ret_code = pthread_setspecific(_S_key, __result);
if (__ret_code) {
if (__ret_code == ENOMEM) {
__THROW_BAD_ALLOC;
} else {
// EINVAL
_STLP_ABORT();
}
}
return __result;
}
/* We allocate memory in large chunks in order to avoid fragmenting */
/* the malloc heap too much. */
/* We assume that size is properly aligned. */
template <size_t _Max_size>
char *_Pthread_alloc<_Max_size>
::_S_chunk_alloc(size_t __p_size, size_t &__nobjs)
{
{
char * __result;
size_t __total_bytes;
size_t __bytes_left;
/*REFERENCED*/
_M_lock __lock_instance; // Acquire lock for this routine
__total_bytes = __p_size * __nobjs;
__bytes_left = _S_end_free - _S_start_free;
if (__bytes_left >= __total_bytes) {
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else if (__bytes_left >= __p_size) {
__nobjs = __bytes_left/__p_size;
__total_bytes = __p_size * __nobjs;
__result = _S_start_free;
_S_start_free += __total_bytes;
return(__result);
} else {
size_t __bytes_to_get =
2 * __total_bytes + _S_round_up(_S_heap_size >> 4);
// Try to make use of the left-over piece.
if (__bytes_left > 0) {
_Pthread_alloc_per_thread_state<_Max_size>* __a =
(_Pthread_alloc_per_thread_state<_Max_size>*)
pthread_getspecific(_S_key);
__obj * volatile * __my_free_list =
__a->__free_list + _S_freelist_index(__bytes_left);
((__obj *)_S_start_free) -> __free_list_link = *__my_free_list;
*__my_free_list = (__obj *)_S_start_free;
}
# ifdef _SGI_SOURCE
// Try to get memory that's aligned on something like a
// cache line boundary, so as to avoid parceling out
// parts of the same line to different threads and thus
// possibly different processors.
{
const int __cache_line_size = 128; // probable upper bound
__bytes_to_get &= ~(__cache_line_size-1);
_S_start_free = (char *)memalign(__cache_line_size, __bytes_to_get);
if (0 == _S_start_free) {
_S_start_free = (char *)__malloc_alloc<0>::allocate(__bytes_to_get);
}
}
# else /* !SGI_SOURCE */
_S_start_free = (char *)__malloc_alloc<0>::allocate(__bytes_to_get);
# endif
_S_heap_size += __bytes_to_get;
_S_end_free = _S_start_free + __bytes_to_get;
}
}
// lock is released here
return(_S_chunk_alloc(__p_size, __nobjs));
}
/* Returns an object of size n, and optionally adds to size n free list.*/
/* We assume that n is properly aligned. */
/* We hold the allocation lock. */
template <size_t _Max_size>
void *_Pthread_alloc_per_thread_state<_Max_size>
::_M_refill(size_t __n)
{
size_t __nobjs = 128;
char * __chunk =
_Pthread_alloc<_Max_size>::_S_chunk_alloc(__n, __nobjs);
__obj * volatile * __my_free_list;
__obj * __result;
__obj * __current_obj, * __next_obj;
int __i;
if (1 == __nobjs) {
return(__chunk);
}
__my_free_list = __free_list
+ _Pthread_alloc<_Max_size>::_S_freelist_index(__n);
/* Build free list in chunk */
__result = (__obj *)__chunk;
*__my_free_list = __next_obj = (__obj *)(__chunk + __n);
for (__i = 1; ; __i++) {
__current_obj = __next_obj;
__next_obj = (__obj *)((char *)__next_obj + __n);
if (__nobjs - 1 == __i) {
__current_obj -> __free_list_link = 0;
break;
} else {
__current_obj -> __free_list_link = __next_obj;
}
}
return(__result);
}
template <size_t _Max_size>
void *_Pthread_alloc<_Max_size>
::reallocate(void *__p, size_t __old_sz, size_t __new_sz)
{
void * __result;
size_t __copy_sz;
if (__old_sz > _Max_size
&& __new_sz > _Max_size) {
return(realloc(__p, __new_sz));
}
if (_S_round_up(__old_sz) == _S_round_up(__new_sz)) return(__p);
__result = allocate(__new_sz);
__copy_sz = __new_sz > __old_sz? __old_sz : __new_sz;
memcpy(__result, __p, __copy_sz);
deallocate(__p, __old_sz);
return(__result);
}
#if defined (_STLP_STATIC_TEMPLATE_DATA) && (_STLP_STATIC_TEMPLATE_DATA > 0)
template <size_t _Max_size>
_Pthread_alloc_per_thread_state<_Max_size> * _Pthread_alloc<_Max_size>::_S_free_per_thread_states = 0;
template <size_t _Max_size>
pthread_key_t _Pthread_alloc<_Max_size>::_S_key =0;
template <size_t _Max_size>
bool _Pthread_alloc<_Max_size>::_S_key_initialized = false;
template <size_t _Max_size>
_STLP_mutex_base _Pthread_alloc<_Max_size>::_S_chunk_allocator_lock _STLP_MUTEX_INITIALIZER;
template <size_t _Max_size>
char *_Pthread_alloc<_Max_size>::_S_start_free = 0;
template <size_t _Max_size>
char *_Pthread_alloc<_Max_size>::_S_end_free = 0;
template <size_t _Max_size>
size_t _Pthread_alloc<_Max_size>::_S_heap_size = 0;
# else
__DECLARE_INSTANCE(template <size_t _Max_size> _Pthread_alloc_per_thread_state<_Max_size> *, _Pthread_alloc<_Max_size>::_S_free_per_thread_states, = 0);
__DECLARE_INSTANCE(template <size_t _Max_size> pthread_key_t, _Pthread_alloc<_Max_size>::_S_key, = 0);
__DECLARE_INSTANCE(template <size_t _Max_size> bool, _Pthread_alloc<_Max_size>::_S_key_initialized, = false);
__DECLARE_INSTANCE(template <size_t _Max_size> char *, _Pthread_alloc<_Max_size>::_S_start_free, = 0);
__DECLARE_INSTANCE(template <size_t _Max_size> char *, _Pthread_alloc<_Max_size>::_S_end_free, = 0);
__DECLARE_INSTANCE(template <size_t _Max_size> size_t, _Pthread_alloc<_Max_size>::_S_heap_size, = 0);
# endif
_STLP_END_NAMESPACE
# endif /* _STLP_EXPOSE_GLOBALS_IMPLEMENTATION */
#endif /* _STLP_PTHREAD_ALLOC_C */
// Local Variables:
// mode:C++
// End:
+489
View File
@@ -0,0 +1,489 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_PTHREAD_ALLOC_H
#define _STLP_PTHREAD_ALLOC_H
// Pthread-specific node allocator.
// This is similar to the default allocator, except that free-list
// information is kept separately for each thread, avoiding locking.
// This should be reasonably fast even in the presence of threads.
// The down side is that storage may not be well-utilized.
// It is not an error to allocate memory in thread A and deallocate
// it in thread B. But this effectively transfers ownership of the memory,
// so that it can only be reallocated by thread B. Thus this can effectively
// result in a storage leak if it's done on a regular basis.
// It can also result in frequent sharing of
// cache lines among processors, with potentially serious performance
// consequences.
#include <pthread.h>
#ifndef _STLP_INTERNAL_ALLOC_H
#include <stl/_alloc.h>
#endif
#ifndef __RESTRICT
# define __RESTRICT
#endif
_STLP_BEGIN_NAMESPACE
#define _STLP_DATA_ALIGNMENT 8
union _Pthread_alloc_obj {
union _Pthread_alloc_obj * __free_list_link;
char __client_data[_STLP_DATA_ALIGNMENT]; /* The client sees this. */
};
// Pthread allocators don't appear to the client to have meaningful
// instances. We do in fact need to associate some state with each
// thread. That state is represented by
// _Pthread_alloc_per_thread_state<_Max_size>.
template<size_t _Max_size>
struct _Pthread_alloc_per_thread_state {
typedef _Pthread_alloc_obj __obj;
enum { _S_NFREELISTS = _Max_size/_STLP_DATA_ALIGNMENT };
// Free list link for list of available per thread structures.
// When one of these becomes available for reuse due to thread
// termination, any objects in its free list remain associated
// with it. The whole structure may then be used by a newly
// created thread.
_Pthread_alloc_per_thread_state() : __next(0)
{
memset((void *)__free_list, 0, (size_t)_S_NFREELISTS * sizeof(__obj *));
}
// Returns an object of size __n, and possibly adds to size n free list.
void *_M_refill(size_t __n);
_Pthread_alloc_obj* volatile __free_list[_S_NFREELISTS];
_Pthread_alloc_per_thread_state<_Max_size> * __next;
// this data member is only to be used by per_thread_allocator, which returns memory to the originating thread.
_STLP_mutex _M_lock;
};
// Pthread-specific allocator.
// The argument specifies the largest object size allocated from per-thread
// free lists. Larger objects are allocated using malloc_alloc.
// Max_size must be a power of 2.
template < __DFL_NON_TYPE_PARAM(size_t, _Max_size, _MAX_BYTES) >
class _Pthread_alloc {
public: // but only for internal use:
typedef _Pthread_alloc_obj __obj;
typedef _Pthread_alloc_per_thread_state<_Max_size> __state_type;
typedef char value_type;
// Allocates a chunk for nobjs of size size. nobjs may be reduced
// if it is inconvenient to allocate the requested number.
static char *_S_chunk_alloc(size_t __size, size_t &__nobjs);
enum {_S_ALIGN = _STLP_DATA_ALIGNMENT};
static size_t _S_round_up(size_t __bytes) {
return (((__bytes) + (int)_S_ALIGN-1) & ~((int)_S_ALIGN - 1));
}
static size_t _S_freelist_index(size_t __bytes) {
return (((__bytes) + (int)_S_ALIGN-1)/(int)_S_ALIGN - 1);
}
private:
// Chunk allocation state. And other shared state.
// Protected by _S_chunk_allocator_lock.
static _STLP_mutex_base _S_chunk_allocator_lock;
static char *_S_start_free;
static char *_S_end_free;
static size_t _S_heap_size;
static _Pthread_alloc_per_thread_state<_Max_size>* _S_free_per_thread_states;
static pthread_key_t _S_key;
static bool _S_key_initialized;
// Pthread key under which per thread state is stored.
// Allocator instances that are currently unclaimed by any thread.
static void _S_destructor(void *instance);
// Function to be called on thread exit to reclaim per thread
// state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_new_per_thread_state();
public:
// Return a recycled or new per thread state.
static _Pthread_alloc_per_thread_state<_Max_size> *_S_get_per_thread_state();
private:
// ensure that the current thread has an associated
// per thread state.
class _M_lock;
friend class _M_lock;
class _M_lock {
public:
_M_lock () { _S_chunk_allocator_lock._M_acquire_lock(); }
~_M_lock () { _S_chunk_allocator_lock._M_release_lock(); }
};
public:
/* n must be > 0 */
static void * allocate(size_t __n)
{
__obj * volatile * __my_free_list;
__obj * __RESTRICT __result;
__state_type* __a;
if (__n > _Max_size) {
return(__malloc_alloc<0>::allocate(__n));
}
__a = _S_get_per_thread_state();
__my_free_list = __a -> __free_list + _S_freelist_index(__n);
__result = *__my_free_list;
if (__result == 0) {
void *__r = __a -> _M_refill(_S_round_up(__n));
return __r;
}
*__my_free_list = __result -> __free_list_link;
return (__result);
};
/* p may not be 0 */
static void deallocate(void *__p, size_t __n)
{
__obj *__q = (__obj *)__p;
__obj * volatile * __my_free_list;
__state_type* __a;
if (__n > _Max_size) {
__malloc_alloc<0>::deallocate(__p, __n);
return;
}
__a = _S_get_per_thread_state();
__my_free_list = __a->__free_list + _S_freelist_index(__n);
__q -> __free_list_link = *__my_free_list;
*__my_free_list = __q;
}
// boris : versions for per_thread_allocator
/* n must be > 0 */
static void * allocate(size_t __n, __state_type* __a)
{
__obj * volatile * __my_free_list;
__obj * __RESTRICT __result;
if (__n > _Max_size) {
return(__malloc_alloc<0>::allocate(__n));
}
// boris : here, we have to lock per thread state, as we may be getting memory from
// different thread pool.
_STLP_mutex_lock __lock(__a->_M_lock);
__my_free_list = __a -> __free_list + _S_freelist_index(__n);
__result = *__my_free_list;
if (__result == 0) {
void *__r = __a -> _M_refill(_S_round_up(__n));
return __r;
}
*__my_free_list = __result -> __free_list_link;
return (__result);
};
/* p may not be 0 */
static void deallocate(void *__p, size_t __n, __state_type* __a)
{
__obj *__q = (__obj *)__p;
__obj * volatile * __my_free_list;
if (__n > _Max_size) {
__malloc_alloc<0>::deallocate(__p, __n);
return;
}
// boris : here, we have to lock per thread state, as we may be returning memory from
// different thread.
_STLP_mutex_lock __lock(__a->_M_lock);
__my_free_list = __a->__free_list + _S_freelist_index(__n);
__q -> __free_list_link = *__my_free_list;
*__my_free_list = __q;
}
static void * reallocate(void *__p, size_t __old_sz, size_t __new_sz);
} ;
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _Pthread_alloc<_MAX_BYTES>;
# endif
typedef _Pthread_alloc<_MAX_BYTES> __pthread_alloc;
typedef __pthread_alloc pthread_alloc;
template <class _Tp>
class pthread_allocator {
typedef pthread_alloc _S_Alloc; // The underlying allocator.
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _NewType> struct rebind {
typedef pthread_allocator<_NewType> other;
};
#endif
pthread_allocator() _STLP_NOTHROW {}
pthread_allocator(const pthread_allocator<_Tp>& a) _STLP_NOTHROW {}
#if defined (_STLP_MEMBER_TEMPLATES) /* && defined (_STLP_FUNCTION_PARTIAL_ORDER) */
template <class _OtherType> pthread_allocator(const pthread_allocator<_OtherType>&)
_STLP_NOTHROW {}
#endif
~pthread_allocator() _STLP_NOTHROW {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// __n is permitted to be 0. The C++ standard says nothing about what
// the return value is when __n == 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0 ? __STATIC_CAST(_Tp*,_S_Alloc::allocate(__n * sizeof(_Tp)))
: 0;
}
// p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ _S_Alloc::deallocate(__p, __n * sizeof(_Tp)); }
size_type max_size() const _STLP_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { _STLP_PLACEMENT_NEW (__p) _Tp(__val); }
void destroy(pointer _p) { _p->~_Tp(); }
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC pthread_allocator<void> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _NewType> struct rebind {
typedef pthread_allocator<_NewType> other;
};
#endif
};
template <class _T1, class _T2>
inline bool operator==(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>& a2)
{
return true;
}
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
template <class _T1, class _T2>
inline bool operator!=(const pthread_allocator<_T1>&,
const pthread_allocator<_T2>&)
{
return false;
}
#endif
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
# ifdef _STLP_USE_RAW_SGI_ALLOCATORS
template <class _Tp, size_t _Max_size>
struct _Alloc_traits<_Tp, _Pthread_alloc<_Max_size> >
{
typedef __allocator<_Tp, _Pthread_alloc<_Max_size> >
allocator_type;
};
# endif
template <class _Tp, class _Atype>
struct _Alloc_traits<_Tp, pthread_allocator<_Atype> >
{
typedef pthread_allocator<_Tp> allocator_type;
};
#endif
#if !defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
template <class _Tp1, class _Tp2>
inline pthread_allocator<_Tp2>&
__stl_alloc_rebind(pthread_allocator<_Tp1>& __x, const _Tp2*) {
return (pthread_allocator<_Tp2>&)__x;
}
template <class _Tp1, class _Tp2>
inline pthread_allocator<_Tp2>
__stl_alloc_create(pthread_allocator<_Tp1>&, const _Tp2*) {
return pthread_allocator<_Tp2>();
}
#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
//
// per_thread_allocator<> : this allocator always return memory to the same thread
// it was allocated from.
//
template <class _Tp>
class per_thread_allocator {
typedef pthread_alloc _S_Alloc; // The underlying allocator.
typedef pthread_alloc::__state_type __state_type;
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _NewType> struct rebind {
typedef per_thread_allocator<_NewType> other;
};
#endif
per_thread_allocator() _STLP_NOTHROW {
_M_state = _S_Alloc::_S_get_per_thread_state();
}
per_thread_allocator(const per_thread_allocator<_Tp>& __a) _STLP_NOTHROW : _M_state(__a._M_state){}
#if defined (_STLP_MEMBER_TEMPLATES) /* && defined (_STLP_FUNCTION_PARTIAL_ORDER) */
template <class _OtherType> per_thread_allocator(const per_thread_allocator<_OtherType>& __a)
_STLP_NOTHROW : _M_state(__a._M_state) {}
#endif
~per_thread_allocator() _STLP_NOTHROW {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// __n is permitted to be 0. The C++ standard says nothing about what
// the return value is when __n == 0.
_Tp* allocate(size_type __n, const void* = 0) {
return __n != 0 ? __STATIC_CAST(_Tp*,_S_Alloc::allocate(__n * sizeof(_Tp), _M_state)): 0;
}
// p is not permitted to be a null pointer.
void deallocate(pointer __p, size_type __n)
{ _S_Alloc::deallocate(__p, __n * sizeof(_Tp), _M_state); }
size_type max_size() const _STLP_NOTHROW
{ return size_t(-1) / sizeof(_Tp); }
void construct(pointer __p, const _Tp& __val) { _STLP_PLACEMENT_NEW (__p) _Tp(__val); }
void destroy(pointer _p) { _p->~_Tp(); }
// state is being kept here
__state_type* _M_state;
};
_STLP_TEMPLATE_NULL
class _STLP_CLASS_DECLSPEC per_thread_allocator<void> {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
#ifdef _STLP_MEMBER_TEMPLATE_CLASSES
template <class _NewType> struct rebind {
typedef per_thread_allocator<_NewType> other;
};
#endif
};
template <class _T1, class _T2>
inline bool operator==(const per_thread_allocator<_T1>& __a1,
const per_thread_allocator<_T2>& __a2)
{
return __a1._M_state == __a2._M_state;
}
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
template <class _T1, class _T2>
inline bool operator!=(const per_thread_allocator<_T1>& __a1,
const per_thread_allocator<_T2>& __a2)
{
return __a1._M_state != __a2._M_state;
}
#endif
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Tp, class _Atype>
struct _Alloc_traits<_Tp, per_thread_allocator<_Atype> >
{
typedef per_thread_allocator<_Tp> allocator_type;
};
#endif
#if !defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
template <class _Tp1, class _Tp2>
inline per_thread_allocator<_Tp2>&
__stl_alloc_rebind(per_thread_allocator<_Tp1>& __x, const _Tp2*) {
return (per_thread_allocator<_Tp2>&)__x;
}
template <class _Tp1, class _Tp2>
inline per_thread_allocator<_Tp2>
__stl_alloc_create(per_thread_allocator<_Tp1>&, const _Tp2*) {
return per_thread_allocator<_Tp2>();
}
#endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_pthread_alloc.c>
# endif
#endif /* _STLP_PTHREAD_ALLOC */
// Local Variables:
// mode:C++
// End:
+72
View File
@@ -0,0 +1,72 @@
#ifndef _STLP_PTRS_SPECIALIZE_H
# define _STLP_PTRS_SPECIALIZE_H
// the following is a workaround for arrow operator problems
# if defined ( _STLP_NO_ARROW_OPERATOR )
// User wants to disable proxy -> operators
# define _STLP_DEFINE_ARROW_OPERATOR
# define _STLP_ARROW_SPECIALIZE_WITH_PTRS(_Tp)
# else
// Compiler can handle generic -> operator.
# define _STLP_ARROW_SPECIALIZE_WITH_PTRS(_Tp)
# ifdef __BORLANDC__
# define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { return &(*(*this)); }
# elif defined ( _STLP_WINCE ) || defined(__WATCOMC__)
# define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { reference x = operator*(); return &x; }
# else
# define _STLP_DEFINE_ARROW_OPERATOR pointer operator->() const { return &(operator*()); }
# endif
# endif /* _STLP_NO_ARROW_OPERATOR */
// Important pointers specializations
# ifdef _STLP_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS
# define _STLP_TYPE_TRAITS_POD_SPECIALIZE_V(_Type)
# define _STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type)
# else
# define _STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type) _STLP_TEMPLATE_NULL struct __type_traits<_Type> : __type_traits_aux<true> {};
# define _STLP_TYPE_TRAITS_POD_SPECIALIZE_V(_Type) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type*) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(const _Type*) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type**) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type* const *) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(const _Type**) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(_Type***) \
_STLP_TYPE_TRAITS_POD_SPECIALIZE(const _Type***)
# endif
# define _STLP_POINTERS_SPECIALIZE(_Type) _STLP_TYPE_TRAITS_POD_SPECIALIZE_V(_Type) _STLP_ARROW_SPECIALIZE_WITH_PTRS(_Type)
# if !defined ( _STLP_NO_BOOL )
_STLP_POINTERS_SPECIALIZE( bool )
# endif
_STLP_TYPE_TRAITS_POD_SPECIALIZE_V(void)
# ifndef _STLP_NO_SIGNED_BUILTINS
_STLP_POINTERS_SPECIALIZE( signed char )
# endif
_STLP_POINTERS_SPECIALIZE( char )
_STLP_POINTERS_SPECIALIZE( unsigned char )
_STLP_POINTERS_SPECIALIZE( short )
_STLP_POINTERS_SPECIALIZE( unsigned short )
_STLP_POINTERS_SPECIALIZE( int )
_STLP_POINTERS_SPECIALIZE( unsigned int )
_STLP_POINTERS_SPECIALIZE( long )
_STLP_POINTERS_SPECIALIZE( unsigned long )
_STLP_POINTERS_SPECIALIZE( float )
_STLP_POINTERS_SPECIALIZE( double )
# if !defined ( _STLP_NO_LONG_DOUBLE )
_STLP_POINTERS_SPECIALIZE( long double )
# endif
# if defined ( _STLP_LONG_LONG)
_STLP_POINTERS_SPECIALIZE( _STLP_LONG_LONG )
_STLP_POINTERS_SPECIALIZE( unsigned _STLP_LONG_LONG )
# endif
#if defined ( _STLP_HAS_WCHAR_T ) && ! defined (_STLP_WCHAR_T_IS_USHORT)
_STLP_POINTERS_SPECIALIZE( wchar_t )
# endif
# undef _STLP_ARROW_SPECIALIZE
# undef _STLP_ARROW_SPECIALIZE_WITH_PTRS
# undef _STLP_TYPE_TRAITS_POD_SPECIALIZE_V
#endif
+212
View File
@@ -0,0 +1,212 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_QUEUE_H
#define _STLP_INTERNAL_QUEUE_H
#ifndef _STLP_INTERNAL_DEQUE_H
# include <stl/_deque.h>
#endif
#ifndef _STLP_INTERNAL_VECTOR_H
# include <stl/_vector.h>
#endif
#ifndef _STLP_INTERNAL_HEAP_H
# include <stl/_heap.h>
#endif
#ifndef _STLP_INTERNAL_FUNCTION_H
# include <stl/_function.h>
#endif
#if defined(__SC__) && !defined(__DMC__) //*ty 12/07/2001 - since "comp" is a built-in type and reserved under SCpp
#define comp _Comp
#endif
_STLP_BEGIN_NAMESPACE
# if ! defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
template <class _Tp, class _Sequence = deque<_Tp> >
# elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
# define _STLP_QUEUE_ARGS _Tp
template <class _Tp>
# else
template <class _Tp, class _Sequence>
# endif
class queue {
# if defined ( _STLP_QUEUE_ARGS )
typedef deque<_Tp> _Sequence;
# endif
public:
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
_Sequence c;
public:
queue() : c() {}
explicit queue(const _Sequence& __c) : c(__c) {}
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference front() { return c.front(); }
const_reference front() const { return c.front(); }
reference back() { return c.back(); }
const_reference back() const { return c.back(); }
void push(const value_type& __x) { c.push_back(__x); }
void pop() { c.pop_front(); }
const _Sequence& _Get_c() const { return c; }
};
# ifndef _STLP_QUEUE_ARGS
# define _STLP_QUEUE_ARGS _Tp, _Sequence
# define _STLP_QUEUE_HEADER_ARGS class _Tp, class _Sequence
# else
# define _STLP_QUEUE_HEADER_ARGS class _Tp
# endif
template < _STLP_QUEUE_HEADER_ARGS >
inline bool _STLP_CALL
operator==(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y)
{
return __x._Get_c() == __y._Get_c();
}
template < _STLP_QUEUE_HEADER_ARGS >
inline bool _STLP_CALL
operator<(const queue<_STLP_QUEUE_ARGS >& __x, const queue<_STLP_QUEUE_ARGS >& __y)
{
return __x._Get_c() < __y._Get_c();
}
_STLP_RELOPS_OPERATORS( template < _STLP_QUEUE_HEADER_ARGS >, queue<_STLP_QUEUE_ARGS > )
# if !(defined ( _STLP_LIMITED_DEFAULT_TEMPLATES ) || defined ( _STLP_TEMPLATE_PARAM_SUBTYPE_BUG ))
template <class _Tp, class _Sequence = vector<_Tp>,
class _Compare = less<_STLP_HEADER_TYPENAME _Sequence::value_type> >
# elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
template <class _Tp>
# else
template <class _Tp, class _Sequence, class _Compare>
# endif
class priority_queue {
# ifdef _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS
typedef vector<_Tp> _Sequence;
typedef less< typename vector<_Tp>::value_type> _Compare;
# endif
public:
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
_Sequence c;
_Compare comp;
public:
priority_queue() : c() {}
explicit priority_queue(const _Compare& __x) : c(), comp(__x) {}
priority_queue(const _Compare& __x, const _Sequence& __s)
: c(__s), comp(__x)
{ make_heap(c.begin(), c.end(), comp); }
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last)
: c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
template <class _InputIterator>
priority_queue(_InputIterator __first,
_InputIterator __last, const _Compare& __x)
: c(__first, __last), comp(__x)
{ make_heap(c.begin(), c.end(), comp); }
template <class _InputIterator>
priority_queue(_InputIterator __first, _InputIterator __last,
const _Compare& __x, const _Sequence& __s)
: c(__s), comp(__x)
{
c.insert(c.end(), __first, __last);
make_heap(c.begin(), c.end(), comp);
}
#else /* _STLP_MEMBER_TEMPLATES */
priority_queue(const value_type* __first, const value_type* __last)
: c(__first, __last) { make_heap(c.begin(), c.end(), comp); }
priority_queue(const value_type* __first, const value_type* __last,
const _Compare& __x)
: c(__first, __last), comp(__x)
{ make_heap(c.begin(), c.end(), comp); }
priority_queue(const value_type* __first, const value_type* __last,
const _Compare& __x, const _Sequence& __c)
: c(__c), comp(__x)
{
c.insert(c.end(), __first, __last);
make_heap(c.begin(), c.end(), comp);
}
#endif /* _STLP_MEMBER_TEMPLATES */
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
const_reference top() const { return c.front(); }
void push(const value_type& __x) {
_STLP_TRY {
c.push_back(__x);
push_heap(c.begin(), c.end(), comp);
}
_STLP_UNWIND(c.clear());
}
void pop() {
_STLP_TRY {
pop_heap(c.begin(), c.end(), comp);
c.pop_back();
}
_STLP_UNWIND(c.clear());
}
};
_STLP_END_NAMESPACE
# undef _STLP_QUEUE_ARGS
# undef _STLP_QUEUE_HEADER_ARGS
#endif /* _STLP_INTERNAL_QUEUE_H */
// Local Variables:
// mode:C++
// End:
+97
View File
@@ -0,0 +1,97 @@
/*
* Copyright (c) 1999
* Silicon Graphics
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
#ifndef _STLP_RANGE_ERRORS_H
#define _STLP_RANGE_ERRORS_H
// A few places in the STL throw range errors, using standard exception
// classes defined in <stdexcept>. This header file provides functions
// to throw those exception objects.
// _STLP_DONT_THROW_RANGE_ERRORS is a hook so that users can disable
// this exception throwing.
#if defined(_STLP_CAN_THROW_RANGE_ERRORS) && defined(_STLP_USE_EXCEPTIONS) \
&& !defined(_STLP_DONT_THROW_RANGE_ERRORS)
# define _STLP_THROW_RANGE_ERRORS
#endif
// For the STLport iostreams, only declaration here, definition is in the lib
#if defined ( _STLP_OWN_IOSTREAMS ) && ! defined (_STLP_EXTERN_RANGE_ERRORS)
# define _STLP_EXTERN_RANGE_ERRORS
# endif
#if defined (_STLP_EXTERN_RANGE_ERRORS)
_STLP_BEGIN_NAMESPACE
void _STLP_DECLSPEC _STLP_CALL __stl_throw_range_error(const char* __msg);
void _STLP_DECLSPEC _STLP_CALL __stl_throw_out_of_range(const char* __msg);
void _STLP_DECLSPEC _STLP_CALL __stl_throw_length_error(const char* __msg);
void _STLP_DECLSPEC _STLP_CALL __stl_throw_invalid_argument(const char* __msg);
void _STLP_DECLSPEC _STLP_CALL __stl_throw_overflow_error(const char* __msg);
_STLP_END_NAMESPACE
#else
#if defined(_STLP_THROW_RANGE_ERRORS)
# ifndef _STLP_STDEXCEPT
# include <stdexcept>
# endif
# ifndef _STLP_STRING
# include <string>
# endif
# define _STLP_THROW_MSG(ex,msg) throw ex(string(msg))
#else
# if defined (_STLP_WINCE)
# define _STLP_THROW_MSG(ex,msg) TerminateProcess(GetCurrentProcess(), 0)
# else
# include <cstdlib>
# include <cstdio>
# define _STLP_THROW_MSG(ex,msg) puts(msg),_STLP_ABORT()
# endif
#endif
// For wrapper mode and throwing range errors, include the
// stdexcept header and throw the appropriate exceptions directly.
_STLP_BEGIN_NAMESPACE
inline void _STLP_DECLSPEC _STLP_CALL __stl_throw_range_error(const char* __msg) {
_STLP_THROW_MSG(range_error, __msg);
}
inline void _STLP_DECLSPEC _STLP_CALL __stl_throw_out_of_range(const char* __msg) {
_STLP_THROW_MSG(out_of_range, __msg);
}
inline void _STLP_DECLSPEC _STLP_CALL __stl_throw_length_error(const char* __msg) {
_STLP_THROW_MSG(length_error, __msg);
}
inline void _STLP_DECLSPEC _STLP_CALL __stl_throw_invalid_argument(const char* __msg) {
_STLP_THROW_MSG(invalid_argument, __msg);
}
inline void _STLP_DECLSPEC _STLP_CALL __stl_throw_overflow_error(const char* __msg) {
_STLP_THROW_MSG(overflow_error, __msg);
}
_STLP_END_NAMESPACE
# undef _STLP_THROW_MSG
# endif /* EXTERN_RANGE_ERRORS */
#endif /* _STLP_RANGE_ERRORS_H */
// Local Variables:
// mode:C++
// End:
+82
View File
@@ -0,0 +1,82 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_RAW_STORAGE_ITERATOR_H
#define _STLP_INTERNAL_RAW_STORAGE_ITERATOR_H
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
_STLP_BEGIN_NAMESPACE
template <class _ForwardIterator, class _Tp>
class raw_storage_iterator
# ifdef _STLP_HAS_VOID_SPECIALIZATION
: public iterator<output_iterator_tag,void,void,void,void>
# endif
{
protected:
_ForwardIterator _M_iter;
public:
typedef output_iterator_tag iterator_category;
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
# endif
explicit raw_storage_iterator(_ForwardIterator __x) : _M_iter(__x) {}
raw_storage_iterator<_ForwardIterator, _Tp>& operator*() { return *this; }
raw_storage_iterator<_ForwardIterator, _Tp>& operator=(const _Tp& __element) {
_Construct(&*_M_iter, __element);
return *this;
}
raw_storage_iterator<_ForwardIterator, _Tp>& operator++() {
++_M_iter;
return *this;
}
raw_storage_iterator<_ForwardIterator, _Tp> operator++(int) {
raw_storage_iterator<_ForwardIterator, _Tp> __tmp = *this;
++_M_iter;
return __tmp;
}
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _ForwardIterator, class _Tp>
inline output_iterator_tag iterator_category(const raw_storage_iterator<_ForwardIterator, _Tp>&) { return output_iterator_tag(); }
#endif
_STLP_END_NAMESPACE
#endif /* _STLP_INTERNAL_RAW_STORAGE_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+33
View File
@@ -0,0 +1,33 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
* Copyright (c) 1996,1997
* Silicon Graphics
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
// Local Variables:
// mode:C++
// End:
+29
View File
@@ -0,0 +1,29 @@
// This is an implementation file which
// is intended to be included multiple times with different _STLP_ASSOCIATIVE_CONTAINER
// setting
#ifndef _STLP_EQUAL_OPERATOR_SPECIALIZED
_STLP_TEMPLATE_HEADER
inline bool _STLP_CALL operator==(const _STLP_TEMPLATE_CONTAINER& __x,
const _STLP_TEMPLATE_CONTAINER& __y) {
return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin());
}
#endif /* _STLP_EQUAL_OPERATOR_SPECIALIZED */
_STLP_TEMPLATE_HEADER
inline bool _STLP_CALL operator<(const _STLP_TEMPLATE_CONTAINER& __x,
const _STLP_TEMPLATE_CONTAINER& __y) {
return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
_STLP_RELOPS_OPERATORS( _STLP_TEMPLATE_HEADER , _STLP_TEMPLATE_CONTAINER )
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
_STLP_TEMPLATE_HEADER
inline void _STLP_CALL swap(_STLP_TEMPLATE_CONTAINER& __x,
_STLP_TEMPLATE_CONTAINER& __y) {
__x.swap(__y);
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
+32
View File
@@ -0,0 +1,32 @@
// This is an implementation file which
// is intended to be included multiple times with different _STLP_ASSOCIATIVE_CONTAINER
// setting
_STLP_TEMPLATE_HEADER
inline bool _STLP_CALL
operator==(const _STLP_TEMPLATE_CONTAINER& __hm1, const _STLP_TEMPLATE_CONTAINER& __hm2)
{
return _STLP_TEMPLATE_CONTAINER::_M_equal(__hm1, __hm2);
}
#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
_STLP_TEMPLATE_HEADER
inline bool _STLP_CALL
operator!=(const _STLP_TEMPLATE_CONTAINER& __hm1, const _STLP_TEMPLATE_CONTAINER& __hm2) {
return !(__hm1 == __hm2);
}
#endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
#ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
_STLP_TEMPLATE_HEADER
inline void _STLP_CALL
swap(_STLP_TEMPLATE_CONTAINER& __hm1, _STLP_TEMPLATE_CONTAINER& __hm2)
{
__hm1.swap(__hm2);
}
#endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
+1
View File
@@ -0,0 +1 @@
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+378
View File
@@ -0,0 +1,378 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_SET_H
#define _STLP_INTERNAL_SET_H
#ifndef _STLP_INTERNAL_TREE_H
#include <stl/_tree.h>
#endif
#define set __WORKAROUND_RENAME(set)
#define multiset __WORKAROUND_RENAME(multiset)
_STLP_BEGIN_NAMESPACE
template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
class set {
public:
// typedefs:
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
private:
_Rep_type _M_t; // red-black tree representing set
public:
// allocation/deallocation
set() : _M_t(_Compare(), allocator_type()) {}
explicit set(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
# endif
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#else
set(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const value_type* __first,
const value_type* __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
{
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
pair<iterator,bool> insert(const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
pair<_Rep_iterator, bool> __p = _M_t.insert_unique(__x);
return pair<iterator, bool>(__REINTERPRET_CAST(const iterator&,__p.first), __p.second);
}
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_unique((_Rep_iterator&)__position, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
#else
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_unique(__first, __last);
}
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_unique(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
iterator next = __position;
next++;
_M_t.erase((_Rep_iterator&)__position);
return next;
}
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { _M_t.clear(); }
// set operations:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __x) const { return _M_t.find(__x); }
# else
iterator find(const key_type& __x) const { return _M_t.find(__x); }
# endif
size_type count(const key_type& __x) const {
return _M_t.find(__x) == _M_t.end() ? 0 : 1 ;
}
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
class multiset {
public:
// typedefs:
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
private:
_Rep_type _M_t; // red-black tree representing multiset
public:
// allocation/deallocation
multiset() : _M_t(_Compare(), allocator_type()) {}
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
# endif
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#else
multiset(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const value_type* __first, const value_type* __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
multiset<_Key,_Compare,_Alloc>&
operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
iterator insert(const value_type& __x) {
return _M_t.insert_equal(__x);
}
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_equal((_Rep_iterator&)__position, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
#else
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_equal(__first, __last);
}
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_equal(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
iterator next = __position;
next++;
_M_t.erase((_Rep_iterator&)__position);
return next;
}
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { _M_t.clear(); }
// multiset operations:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __x) const { return _M_t.find(__x); }
# else
iterator find(const key_type& __x) const { return _M_t.find(__x); }
# endif
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
# define _STLP_TEMPLATE_HEADER template <class _Key, class _Compare, class _Alloc>
# define _STLP_TEMPLATE_CONTAINER set<_Key,_Compare,_Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# define _STLP_TEMPLATE_CONTAINER multiset<_Key,_Compare,_Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
_STLP_END_NAMESPACE
// do a cleanup
# undef set
# undef multiset
// provide a way to access full funclionality
# define __set__ __FULL_NAME(set)
# define __multiset__ __FULL_NAME(multiset)
# ifdef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
# include <stl/wrappers/_set.h>
# endif
#endif /* _STLP_INTERNAL_SET_H */
// Local Variables:
// mode:C++
// End:
+375
View File
@@ -0,0 +1,375 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_SET_H
#define _STLP_INTERNAL_SET_H
#ifndef _STLP_INTERNAL_TREE_H
#include <stl/_tree.h>
#endif
#define set __WORKAROUND_RENAME(set)
#define multiset __WORKAROUND_RENAME(multiset)
_STLP_BEGIN_NAMESPACE
template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
class set {
public:
// typedefs:
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
private:
_Rep_type _M_t; // red-black tree representing set
public:
// allocation/deallocation
set() : _M_t(_Compare(), allocator_type()) {}
explicit set(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_unique(__first, __last); }
# endif
template <class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#else
set(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const value_type* __first,
const value_type* __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); }
set(const_iterator __first, const_iterator __last, const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_unique(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x)
{
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
pair<iterator,bool> insert(const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
pair<_Rep_iterator, bool> __p = _M_t.insert_unique(__x);
return pair<iterator, bool>(__REINTERPRET_CAST(const iterator&,__p.first), __p.second);
}
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_unique((_Rep_iterator&)__position, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_unique(__first, __last);
}
#else
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_unique(__first, __last);
}
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_unique(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
iterator next = __position;
next++;
_M_t.erase((_Rep_iterator&)__position);
return next;
}
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { _M_t.clear(); }
// set operations:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __x) const { return _M_t.find(__x); }
# else
iterator find(const key_type& __x) const { return _M_t.find(__x); }
# endif
size_type count(const key_type& __x) const {
return _M_t.find(__x) == _M_t.end() ? 0 : 1 ;
}
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
template <class _Key, __DFL_TMPL_PARAM(_Compare,less<_Key>),
_STLP_DEFAULT_ALLOCATOR_SELECT(_Key) >
class multiset {
public:
// typedefs:
typedef _Key key_type;
typedef _Key value_type;
typedef _Compare key_compare;
typedef _Compare value_compare;
private:
typedef _Rb_tree<key_type, value_type,
_Identity<value_type>, key_compare, _Alloc> _Rep_type;
public:
typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::allocator_type allocator_type;
private:
_Rep_type _M_t; // red-black tree representing multiset
public:
// allocation/deallocation
multiset() : _M_t(_Compare(), allocator_type()) {}
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp)
: _M_t(__comp, allocator_type()) { _M_t.insert_equal(__first, __last); }
# endif
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#else
multiset(const value_type* __first, const value_type* __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const value_type* __first, const value_type* __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
multiset(const_iterator __first, const_iterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
multiset<_Key,_Compare,_Alloc>&
operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
key_compare key_comp() const { return _M_t.key_comp(); }
value_compare value_comp() const { return _M_t.key_comp(); }
allocator_type get_allocator() const { return _M_t.get_allocator(); }
iterator begin() const { return _M_t.begin(); }
iterator end() const { return _M_t.end(); }
reverse_iterator rbegin() const { return _M_t.rbegin(); }
reverse_iterator rend() const { return _M_t.rend(); }
bool empty() const { return _M_t.empty(); }
size_type size() const { return _M_t.size(); }
size_type max_size() const { return _M_t.max_size(); }
void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); }
// insert/erase
iterator insert(const value_type& __x) {
return _M_t.insert_equal(__x);
}
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_equal((_Rep_iterator&)__position, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) {
_M_t.insert_equal(__first, __last);
}
#else
void insert(const value_type* __first, const value_type* __last) {
_M_t.insert_equal(__first, __last);
}
void insert(const_iterator __first, const_iterator __last) {
_M_t.insert_equal(__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
void erase(iterator __position) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
size_type erase(const key_type& __x) {
return _M_t.erase(__x);
}
void erase(iterator __first, iterator __last) {
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
void clear() { _M_t.clear(); }
// multiset operations:
# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS )
template <class _KT>
iterator find(const _KT& __x) const { return _M_t.find(__x); }
# else
iterator find(const key_type& __x) const { return _M_t.find(__x); }
# endif
size_type count(const key_type& __x) const { return _M_t.count(__x); }
iterator lower_bound(const key_type& __x) const {
return _M_t.lower_bound(__x);
}
iterator upper_bound(const key_type& __x) const {
return _M_t.upper_bound(__x);
}
pair<iterator,iterator> equal_range(const key_type& __x) const {
return _M_t.equal_range(__x);
}
};
# define _STLP_TEMPLATE_HEADER template <class _Key, class _Compare, class _Alloc>
# define _STLP_TEMPLATE_CONTAINER set<_Key,_Compare,_Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# define _STLP_TEMPLATE_CONTAINER multiset<_Key,_Compare,_Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
_STLP_END_NAMESPACE
// do a cleanup
# undef set
# undef multiset
// provide a way to access full funclionality
# define __set__ __FULL_NAME(set)
# define __multiset__ __FULL_NAME(multiset)
# ifdef _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
# include <stl/wrappers/_set.h>
# endif
#endif /* _STLP_INTERNAL_SET_H */
// Local Variables:
// mode:C++
// End:
+194
View File
@@ -0,0 +1,194 @@
//
// This file defines site configuration.
//
//
/*
* _STLP_NO_THREADS: if defined, STLport don't use any
* multithreading support. Synonym is _NOTHREADS
*/
//#define _NOTHREADS
//#define _STLP_NO_THREADS
/* _PTHREADS: if defined, use Posix threads for multithreading support. */
// #define _PTHREADS
// compatibility section
# if defined (_STLP_NO_IOSTREAMS) || defined (_STLP_NO_NEW_IOSTREAMS) && ! defined ( _STLP_NO_OWN_IOSTREAMS )
# define _STLP_NO_OWN_IOSTREAMS
# endif
# if !defined (_STLP_NO_OWN_IOSTREAMS) && ! defined (_STLP_OWN_IOSTREAMS)
# define _STLP_OWN_IOSTREAMS
# endif
# if (defined (_STLP_NOTHREADS) || defined (_STLP_NO_THREADS) || defined (NOTHREADS))
# if ! defined (_NOTHREADS)
# define _NOTHREADS
# endif
# if ! defined (_STLP_NO_THREADS)
# define _STLP_NO_THREADS
# endif
# endif
/*
* Turn _STLP_USE_DYNAMIC_LIB to enforce use of .dll version of STLport library.
* NOTE : please do that only if you know what you are doing !
* Changing default will require you to change makefile in "src" accordingly
* and to rebuild STLPort library !
* On UNIX, this has no effect.
*
*/
// # define _STLP_USE_DYNAMIC_LIB
/*
* Turn _STLP_USE_STATIC_LIB to enforce use of static version of STLport library.
* NOTE : please do that only if you know what you are doing !
* Changing default will require you to change makefile in "src" accordingly
* and to rebuild STLPort library !
* On UNIX, this has no effect.
*
*/
// # define _STLP_USE_STATIC_LIB
/*
* Edit relative path below (or put full path) to get native
* compiler vendor's headers included. Default is "../include"
* Hint : never install STLport in the directory that ends with "include"
*/
// # undef _STLP_NATIVE_INCLUDE_PATH
// # define _STLP_NATIVE_INCLUDE_PATH ../include
// same for C library headers like <cstring>
// # undef _STLP_NATIVE_CPP_C_INCLUDE_PATH
// # define _STLP_NATIVE_CPP_C_INCLUDE_PATH ../include
// same for C headers like <string.h>
// # undef _STLP_NATIVE_C_INCLUDE_PATH
// # define _STLP_NATIVE_C_INCLUDE_PATH ../include
/*
* _STLP_USE_OWN_NAMESPACE/_STLP_NO_OWN_NAMESPACE
* If defined, STLport uses _STL:: namespace, else std::
* The reason you have to use separate namespace in wrapper mode is that new-style IO
* compiled library may have its own idea about STL stuff (string, vector, etc.),
* so redefining them in the same namespace would break ODR and may cause
* undefined behaviour. Rule of thumb is - if new-style iostreams are
* available, there WILL be a conflict. Otherwise you should be OK.
* In STLport iostreams mode, there is no need for this flag other than to facilitate
* link with third-part libraries compiled with different standard library implementation.
*/
// # define _STLP_USE_OWN_NAMESPACE 1
// # define _STLP_NO_OWN_NAMESPACE 1
/*
* Uncomment _STLP_USE_NEWALLOC to force allocator<T> to use plain "new"
* instead of STLport optimized node allocator engine.
*/
// #define _STLP_USE_NEWALLOC 1
/*
* Uncomment _STLP_USE_MALLOC to force allocator<T> to use plain "malloc"
* instead of STLport optimized node allocator engine.
*/
// #define _STLP_USE_MALLOC 1
/*
* Set _STLP_DEBUG_ALLOC to use allocators that perform memory debugging,
* such as padding/checking for memory consistency
*/
// #define _STLP_DEBUG_ALLOC 1
/*
* Uncomment this to force all debug diagnostic to be directed through a
* user-defined global function:
* void __stl_debug_message(const char * format_str, ...)
* instead of predefined STLport routine.
* This allows you to take control of debug message output.
* Default routine calls fprintf(stderr,...)
* Note : If you set this macro, you must supply __stl_debug_message
* function definition somewhere.
*/
//#define _STLP_DEBUG_MESSAGE 1
/*
* Uncomment this to force all failed assertions to be executed through
* user-defined global function:
* void __stl_debug_terminate(void). This allows
* you to take control of assertion behaviour for debugging purposes.
* Default routine throws unique exception if _STLP_USE_EXCEPTIONS is set,
* calls _STLP_ABORT() otherwise.
* Note : If you set this macro, you must supply __stl_debug_terminate
* function definition somewhere.
*/
//#define _STLP_DEBUG_TERMINATE 1
/*
* Comment this out to enable throwing exceptions from default __stl_debug_terminate()
* instead of calling _STLP_ABORT().
*/
#define _STLP_NO_DEBUG_EXCEPTIONS 1
/*
* Uncomment that to disable exception handling code
*/
// #define _STLP_NO_EXCEPTIONS 1
/*
* _STLP_NO_NAMESPACES: if defined, don't put the library in namespace
* stlport:: or std::, even if the compiler supports namespaces
*/
// #define _STLP_NO_NAMESPACES 1
//==========================================================
// Compatibility section
//==========================================================
/*
* Use abbreviated class names for linker benefit (don't affect interface).
* This option is obsolete, but should work in this release.
*
*/
// # define _STLP_USE_ABBREVS
/*
* This definition precludes STLport reverse_iterator to be compatible with
* other parts of MSVC library. (With partial specialization, it just
* has no effect).
* Use it _ONLY_ if you use SGI-style reverse_iterator<> template explicitly
*/
// # define _STLP_NO_MSVC50_COMPATIBILITY 1
/*
* _STLP_USE_RAW_SGI_ALLOCATORS is a hook so that users can disable use of
* allocator<T> as default parameter for containers, and use SGI
* raw allocators as default ones, without having to edit library headers.
* Use of this macro is strongly discouraged.
*/
// #define _STLP_USE_RAW_SGI_ALLOCATORS 1
/*
* Use obsolete overloaded template functions iterator_category(), value_type(), distance_type()
* for querying iterator properties. Please note those names are non-standard and are not guaranteed
* to be used by every implementation. However, this setting is on by default when partial specialization
* is not implemented in the compiler and cannot be sumulated (only if _STLP_NO_ANACHRONISMS is not set).
* Use of those interfaces for user-defined iterators is strongly discouraged:
* please use public inheritance from iterator<> template to achieve desired effect.
* Second form is to disable old-style queries in any case.
*/
// # define _STLP_USE_OLD_HP_ITERATOR_QUERIES
// # define _STLP_NO_OLD_HP_ITERATOR_QUERIES
//==========================================================================
// This section contains swithes which should be off by default,
// but so few compilers would have it undefined, so that we set them here,
// with the option to be turned off later in compiler-specific file
# define _STLP_INCOMPLETE_EXCEPTION_HEADER
+179
View File
@@ -0,0 +1,179 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_SLIST_C
#define _STLP_SLIST_C
#ifndef _STLP_INTERNAL_SLIST_H
# include <stl/_slist.h>
#endif
# undef slist
# define slist __WORKAROUND_DBG_RENAME(slist)
# if defined (_STLP_NESTED_TYPE_PARAM_BUG)
# define size_type size_t
# endif
_STLP_BEGIN_NAMESPACE
template <class _Tp, class _Alloc>
_Slist_node_base*
_Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
_Slist_node_base* __last_node) {
_Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
while (__cur != __last_node) {
_Slist_node<_Tp>* __tmp = __cur;
__cur = (_Slist_node<_Tp>*) __cur->_M_next;
_STLP_STD::_Destroy(&__tmp->_M_data);
_M_head.deallocate(__tmp,1);
}
__before_first->_M_next = __last_node;
return __last_node;
}
template <class _Tp, class _Alloc>
slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
{
if (&__x != this) {
_Node_base* __p1 = &this->_M_head._M_data;
_Node* __n1 = (_Node*) this->_M_head._M_data._M_next;
const _Node* __n2 = (const _Node*) __x._M_head._M_data._M_next;
while (__n1 && __n2) {
__n1->_M_data = __n2->_M_data;
__p1 = __n1;
__n1 = (_Node*) __n1->_M_next;
__n2 = (const _Node*) __n2->_M_next;
}
if (__n2 == 0)
this->_M_erase_after(__p1, 0);
else
_M_insert_after_range(__p1, const_iterator((_Node*)__n2),
const_iterator(0));
}
return *this;
}
template <class _Tp, class _Alloc>
void slist<_Tp, _Alloc>::_M_fill_assign(size_type __n, const _Tp& __val) {
_Node_base* __prev = &this->_M_head._M_data;
_Node* __node = (_Node*) this->_M_head._M_data._M_next;
for ( ; __node != 0 && __n > 0 ; --__n) {
__node->_M_data = __val;
__prev = __node;
__node = (_Node*) __node->_M_next;
}
if (__n > 0)
_M_insert_after_fill(__prev, __n, __val);
else
this->_M_erase_after(__prev, 0);
}
template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
{
_Node_base* __cur = &this->_M_head._M_data;
while (__cur->_M_next != 0 && __len > 0) {
--__len;
__cur = __cur->_M_next;
}
if (__cur->_M_next)
this->_M_erase_after(__cur, 0);
else
_M_insert_after_fill(__cur, __len, __x);
}
template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::remove(const _Tp& __val)
{
_Node_base* __cur = &this->_M_head._M_data;
while (__cur && __cur->_M_next) {
if (((_Node*) __cur->_M_next)->_M_data == __val)
this->_M_erase_after(__cur);
else
__cur = __cur->_M_next;
}
}
template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::unique()
{
_Node_base* __cur = this->_M_head._M_data._M_next;
if (__cur) {
while (__cur->_M_next) {
if (((_Node*)__cur)->_M_data ==
((_Node*)(__cur->_M_next))->_M_data)
this->_M_erase_after(__cur);
else
__cur = __cur->_M_next;
}
}
}
template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
{
_Node_base* __n1 = &this->_M_head._M_data;
while (__n1->_M_next && __x._M_head._M_data._M_next) {
if (((_Node*) __x._M_head._M_data._M_next)->_M_data <
((_Node*) __n1->_M_next)->_M_data)
_Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
__n1 = __n1->_M_next;
}
if (__x._M_head._M_data._M_next) {
__n1->_M_next = __x._M_head._M_data._M_next;
__x._M_head._M_data._M_next = 0;
}
}
template <class _Tp, class _Alloc>
void slist<_Tp,_Alloc>::sort()
{
if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
_Self __carry;
_Self __counter[64];
int __fill = 0;
while (!empty()) {
_Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
int __i = 0;
while (__i < __fill && !__counter[__i].empty()) {
__counter[__i].merge(__carry);
__carry.swap(__counter[__i]);
++__i;
}
__carry.swap(__counter[__i]);
if (__i == __fill)
++__fill;
}
for (int __i = 1; __i < __fill; ++__i)
__counter[__i].merge(__counter[__i-1]);
this->swap(__counter[__fill-1]);
}
}
# undef slist
# undef size_type
_STLP_END_NAMESPACE
#endif /* _STLP_SLIST_C */
// Local Variables:
// mode:C++
// End:
+741
View File
@@ -0,0 +1,741 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_SLIST_H
#define _STLP_INTERNAL_SLIST_H
# ifndef _STLP_INTERNAL_ALGOBASE_H
# include <stl/_algobase.h>
# endif
# ifndef _STLP_INTERNAL_ALLOC_H
# include <stl/_alloc.h>
# endif
# ifndef _STLP_INTERNAL_ITERATOR_H
# include <stl/_iterator.h>
# endif
# ifndef _STLP_INTERNAL_CONSTRUCT_H
# include <stl/_construct.h>
# endif
# ifndef _STLP_INTERNAL_SLIST_BASE_H
# include <stl/_slist_base.h>
# endif
# undef slist
# define slist __WORKAROUND_DBG_RENAME(slist)
_STLP_BEGIN_NAMESPACE
template <class _Tp>
struct _Slist_node : public _Slist_node_base
{
_Tp _M_data;
__TRIVIAL_STUFF(_Slist_node)
};
struct _Slist_iterator_base {
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef forward_iterator_tag iterator_category;
_Slist_node_base* _M_node;
_Slist_iterator_base(_Slist_node_base* __x) : _M_node(__x) {}
void _M_incr() {
// _STLP_VERBOSE_ASSERT(_M_node != 0, _StlMsg_INVALID_ADVANCE)
_M_node = _M_node->_M_next;
}
bool operator==(const _Slist_iterator_base& __y ) const {
return _M_node == __y._M_node;
}
bool operator!=(const _Slist_iterator_base& __y ) const {
return _M_node != __y._M_node;
}
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
inline ptrdiff_t* _STLP_CALL distance_type(const _Slist_iterator_base&) { return 0; }
inline forward_iterator_tag _STLP_CALL iterator_category(const _Slist_iterator_base&) { return forward_iterator_tag(); }
#endif
template <class _Tp, class _Traits>
struct _Slist_iterator : public _Slist_iterator_base
{
typedef _Tp value_type;
typedef typename _Traits::pointer pointer;
typedef typename _Traits::reference reference;
typedef forward_iterator_tag iterator_category;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Slist_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
typedef _Slist_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
typedef _Slist_iterator<_Tp, _Traits> _Self;
typedef _Slist_node<value_type> _Node;
_Slist_iterator(_Node* __x) : _Slist_iterator_base(__x) {}
_Slist_iterator() : _Slist_iterator_base(0) {}
_Slist_iterator(const iterator& __x) : _Slist_iterator_base(__x._M_node) {}
reference operator*() const { return ((_Node*) _M_node)->_M_data; }
_STLP_DEFINE_ARROW_OPERATOR
_Self& operator++()
{
_M_incr();
return *this;
}
_Self operator++(int)
{
_Self __tmp = *this;
_M_incr();
return __tmp;
}
};
#ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Tp, class _Traits>
inline _Tp* _STLP_CALL value_type(const _Slist_iterator<_Tp, _Traits>&) { return (_Tp*)0; }
#endif /* OLD_QUERIES */
// Base class that encapsulates details of allocators and simplifies EH
template <class _Tp, class _Alloc>
struct _Slist_base {
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
typedef _Slist_node<_Tp> _Node;
_Slist_base(const allocator_type& __a) :
_M_head(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Slist_node_base() ) {
_M_head._M_data._M_next = 0;
}
~_Slist_base() { _M_erase_after(&_M_head._M_data, 0); }
protected:
typedef typename _Alloc_traits<_Node,_Alloc>::allocator_type _M_node_allocator_type;
_Slist_node_base* _M_erase_after(_Slist_node_base* __pos)
{
_Node* __next = (_Node*) (__pos->_M_next);
_Slist_node_base* __next_next = __next->_M_next;
__pos->_M_next = __next_next;
_STLP_STD::_Destroy(&__next->_M_data);
_M_head.deallocate(__next,1);
return __next_next;
}
_Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*);
public:
allocator_type get_allocator() const {
return _STLP_CONVERT_ALLOCATOR((const _M_node_allocator_type&)_M_head, _Tp);
}
_STLP_alloc_proxy<_Slist_node_base, _Node, _M_node_allocator_type> _M_head;
};
template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
class slist : protected _Slist_base<_Tp,_Alloc>
{
private:
typedef _Slist_base<_Tp,_Alloc> _Base;
typedef slist<_Tp,_Alloc> _Self;
public:
typedef _Tp value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef forward_iterator_tag _Iterator_category;
typedef _Slist_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
typedef _Slist_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
typedef typename _Base::allocator_type allocator_type;
private:
typedef _Slist_node<_Tp> _Node;
typedef _Slist_node_base _Node_base;
typedef _Slist_iterator_base _Iterator_base;
_Node* _M_create_node(const value_type& __x) {
_Node* __node = this->_M_head.allocate(1);
_STLP_TRY {
_Construct(&__node->_M_data, __x);
__node->_M_next = 0;
}
_STLP_UNWIND(this->_M_head.deallocate(__node, 1));
return __node;
}
_Node* _M_create_node() {
_Node* __node = this->_M_head.allocate(1);
_STLP_TRY {
_Construct(&__node->_M_data);
__node->_M_next = 0;
}
_STLP_UNWIND(this->_M_head.deallocate(__node, 1));
return __node;
}
public:
allocator_type get_allocator() const { return _Base::get_allocator(); }
explicit slist(const allocator_type& __a = allocator_type()) : _Slist_base<_Tp,_Alloc>(__a) {}
slist(size_type __n, const value_type& __x,
const allocator_type& __a = allocator_type()) : _Slist_base<_Tp,_Alloc>(__a)
{ _M_insert_after_fill(&this->_M_head._M_data, __n, __x); }
explicit slist(size_type __n) : _Slist_base<_Tp,_Alloc>(allocator_type())
{ _M_insert_after_fill(&this->_M_head._M_data, __n, value_type()); }
#ifdef _STLP_MEMBER_TEMPLATES
// We don't need any dispatching tricks here, because _M_insert_after_range
// already does them.
template <class _InputIterator>
slist(_InputIterator __first, _InputIterator __last,
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL) :
_Slist_base<_Tp,_Alloc>(__a)
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
# ifdef _STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS
// VC++ needs this crazyness
template <class _InputIterator>
slist(_InputIterator __first, _InputIterator __last) :
_Slist_base<_Tp,_Alloc>(allocator_type())
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
# endif
#else /* _STLP_MEMBER_TEMPLATES */
slist(const_iterator __first, const_iterator __last,
const allocator_type& __a = allocator_type() ) :
_Slist_base<_Tp,_Alloc>(__a)
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
slist(const value_type* __first, const value_type* __last,
const allocator_type& __a = allocator_type()) :
_Slist_base<_Tp,_Alloc>(__a)
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
#endif /* _STLP_MEMBER_TEMPLATES */
slist(const _Self& __x) : _Slist_base<_Tp,_Alloc>(__x.get_allocator())
{ _M_insert_after_range(&this->_M_head._M_data, __x.begin(), __x.end()); }
_Self& operator= (const _Self& __x);
~slist() {}
public:
// assign(), a generalized assignment member function. Two
// versions: one that takes a count, and one that takes a range.
// The range version is a member template, so we dispatch on whether
// or not the type is an integer.
void assign(size_type __n, const _Tp& __val)
{ _M_fill_assign(__n, __val); }
void _M_fill_assign(size_type __n, const _Tp& __val);
#ifdef _STLP_MEMBER_TEMPLATES
template <class _InputIterator>
void assign(_InputIterator __first, _InputIterator __last) {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
template <class _Integer>
void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
{ _M_fill_assign((size_type) __n, (_Tp) __val); }
template <class _InputIter>
void
_M_assign_dispatch(_InputIter __first, _InputIter __last,
const __false_type&) {
_Node_base* __prev = &this->_M_head._M_data;
_Node* __node = (_Node*) this->_M_head._M_data._M_next;
while (__node != 0 && __first != __last) {
__node->_M_data = *__first;
__prev = __node;
__node = (_Node*) __node->_M_next;
++__first;
}
if (__first != __last)
_M_insert_after_range(__prev, __first, __last);
else
this->_M_erase_after(__prev, 0);
}
#endif /* _STLP_MEMBER_TEMPLATES */
public:
// Experimental new feature: before_begin() returns a
// non-dereferenceable iterator that, when incremented, yields
// begin(). This iterator may be used as the argument to
// insert_after, erase_after, etc. Note that even for an empty
// slist, before_begin() is not the same iterator as end(). It
// is always necessary to increment before_begin() at least once to
// obtain end().
iterator before_begin() { return iterator((_Node*) &this->_M_head._M_data); }
const_iterator before_begin() const
{ return const_iterator((_Node*) &this->_M_head._M_data); }
iterator begin() { return iterator((_Node*)this->_M_head._M_data._M_next); }
const_iterator begin() const
{ return const_iterator((_Node*)this->_M_head._M_data._M_next);}
iterator end() { return iterator(0); }
const_iterator end() const { return const_iterator(0); }
size_type size() const { return _Sl_global_inst::size(this->_M_head._M_data._M_next); }
size_type max_size() const { return size_type(-1); }
bool empty() const { return this->_M_head._M_data._M_next == 0; }
void swap(_Self& __x) {
_STLP_STD::swap(this->_M_head, __x._M_head);
}
public:
reference front() { return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
const_reference front() const
{ return ((_Node*) this->_M_head._M_data._M_next)->_M_data; }
void push_front(const value_type& __x) {
__slist_make_link(&this->_M_head._M_data, _M_create_node(__x));
}
# ifndef _STLP_NO_ANACHRONISMS
void push_front() { __slist_make_link(&this->_M_head._M_data, _M_create_node());}
# endif
void pop_front() {
_Node* __node = (_Node*) this->_M_head._M_data._M_next;
this->_M_head._M_data._M_next = __node->_M_next;
_STLP_STD::_Destroy(&__node->_M_data);
this->_M_head.deallocate(__node, 1);
}
iterator previous(const_iterator __pos) {
return iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
}
const_iterator previous(const_iterator __pos) const {
return const_iterator((_Node*) _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
}
private:
_Node* _M_insert_after(_Node_base* __pos, const value_type& __x) {
return (_Node*) (__slist_make_link(__pos, _M_create_node(__x)));
}
_Node* _M_insert_after(_Node_base* __pos) {
return (_Node*) (__slist_make_link(__pos, _M_create_node()));
}
void _M_insert_after_fill(_Node_base* __pos,
size_type __n, const value_type& __x) {
for (size_type __i = 0; __i < __n; ++__i)
__pos = __slist_make_link(__pos, _M_create_node(__x));
}
#ifdef _STLP_MEMBER_TEMPLATES
// Check whether it's an integral type. If so, it's not an iterator.
template <class _InIter>
void _M_insert_after_range(_Node_base* __pos,
_InIter __first, _InIter __last) {
typedef typename _Is_integer<_InIter>::_Integral _Integral;
_M_insert_after_range(__pos, __first, __last, _Integral());
}
template <class _Integer>
void _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
const __true_type&) {
_M_insert_after_fill(__pos, __n, __x);
}
template <class _InIter>
void _M_insert_after_range(_Node_base* __pos,
_InIter __first, _InIter __last,
const __false_type&) {
while (__first != __last) {
__pos = __slist_make_link(__pos, _M_create_node(*__first));
++__first;
}
}
#else /* _STLP_MEMBER_TEMPLATES */
void _M_insert_after_range(_Node_base* __pos,
const_iterator __first, const_iterator __last) {
while (__first != __last) {
__pos = __slist_make_link(__pos, _M_create_node(*__first));
++__first;
}
}
void _M_insert_after_range(_Node_base* __pos,
const value_type* __first,
const value_type* __last) {
while (__first != __last) {
__pos = __slist_make_link(__pos, _M_create_node(*__first));
++__first;
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
public:
iterator insert_after(iterator __pos, const value_type& __x) {
return iterator(_M_insert_after(__pos._M_node, __x));
}
iterator insert_after(iterator __pos) {
return insert_after(__pos, value_type());
}
void insert_after(iterator __pos, size_type __n, const value_type& __x) {
_M_insert_after_fill(__pos._M_node, __n, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
// We don't need any dispatching tricks here, because _M_insert_after_range
// already does them.
template <class _InIter>
void insert_after(iterator __pos, _InIter __first, _InIter __last) {
_M_insert_after_range(__pos._M_node, __first, __last);
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert_after(iterator __pos,
const_iterator __first, const_iterator __last) {
_M_insert_after_range(__pos._M_node, __first, __last);
}
void insert_after(iterator __pos,
const value_type* __first, const value_type* __last) {
_M_insert_after_range(__pos._M_node, __first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
iterator insert(iterator __pos, const value_type& __x) {
return iterator(_M_insert_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
__x));
}
iterator insert(iterator __pos) {
return iterator(_M_insert_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
value_type()));
}
void insert(iterator __pos, size_type __n, const value_type& __x) {
_M_insert_after_fill(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __n, __x);
}
#ifdef _STLP_MEMBER_TEMPLATES
// We don't need any dispatching tricks here, because _M_insert_after_range
// already does them.
template <class _InIter>
void insert(iterator __pos, _InIter __first, _InIter __last) {
_M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
__first, __last);
}
#else /* _STLP_MEMBER_TEMPLATES */
void insert(iterator __pos, const_iterator __first, const_iterator __last) {
_M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
__first, __last);
}
void insert(iterator __pos, const value_type* __first,
const value_type* __last) {
_M_insert_after_range(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
__first, __last);
}
#endif /* _STLP_MEMBER_TEMPLATES */
public:
iterator erase_after(iterator __pos) {
return iterator((_Node*) this->_M_erase_after(__pos._M_node));
}
iterator erase_after(iterator __before_first, iterator __last) {
return iterator((_Node*) this->_M_erase_after(__before_first._M_node,
__last._M_node));
}
iterator erase(iterator __pos) {
return iterator((_Node*) this->_M_erase_after(_Sl_global_inst::__previous(&this->_M_head._M_data,
__pos._M_node)));
}
iterator erase(iterator __first, iterator __last) {
return iterator((_Node*) this->_M_erase_after(
_Sl_global_inst::__previous(&this->_M_head._M_data, __first._M_node), __last._M_node));
}
void resize(size_type new_size, const _Tp& __x);
void resize(size_type new_size) { resize(new_size, _Tp()); }
void clear() {
this->_M_erase_after(&this->_M_head._M_data, 0);
}
public:
// Moves the range [__before_first + 1, __before_last + 1) to *this,
// inserting it immediately after __pos. This is constant time.
void splice_after(iterator __pos,
iterator __before_first, iterator __before_last)
{
if (__before_first != __before_last) {
_Sl_global_inst::__splice_after(__pos._M_node, __before_first._M_node,
__before_last._M_node);
}
}
// Moves the element that follows __prev to *this, inserting it immediately
// after __pos. This is constant time.
void splice_after(iterator __pos, iterator __prev)
{
_Sl_global_inst::__splice_after(__pos._M_node,
__prev._M_node, __prev._M_node->_M_next);
}
// Removes all of the elements from the list __x to *this, inserting
// them immediately after __pos. __x must not be *this. Complexity:
// linear in __x.size().
void splice_after(iterator __pos, _Self& __x)
{
_Sl_global_inst::__splice_after(__pos._M_node, &__x._M_head._M_data);
}
// Linear in distance(begin(), __pos), and linear in __x.size().
void splice(iterator __pos, _Self& __x) {
if (__x._M_head._M_data._M_next)
_Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
&__x._M_head._M_data, _Sl_global_inst::__previous(&__x._M_head._M_data, 0));
}
// Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
void splice(iterator __pos, _Self& __x, iterator __i) {
_Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
_Sl_global_inst::__previous(&__x._M_head._M_data, __i._M_node),
__i._M_node);
}
// Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
// and in distance(__first, __last).
void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
{
if (__first != __last)
_Sl_global_inst::__splice_after(_Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
_Sl_global_inst::__previous(&__x._M_head._M_data, __first._M_node),
_Sl_global_inst::__previous(__first._M_node, __last._M_node));
}
public:
void reverse() {
if (this->_M_head._M_data._M_next)
this->_M_head._M_data._M_next = _Sl_global_inst::__reverse(this->_M_head._M_data._M_next);
}
void remove(const _Tp& __val);
void unique();
void merge(_Self& __x);
void sort();
#ifdef _STLP_MEMBER_TEMPLATES
template <class _Predicate>
void remove_if(_Predicate __pred) {
_Node_base* __cur = &this->_M_head._M_data;
while (__cur->_M_next) {
if (__pred(((_Node*) __cur->_M_next)->_M_data))
this->_M_erase_after(__cur);
else
__cur = __cur->_M_next;
}
}
template <class _BinaryPredicate>
void unique(_BinaryPredicate __pred) {
_Node* __cur = (_Node*) this->_M_head._M_data._M_next;
if (__cur) {
while (__cur->_M_next) {
if (__pred(((_Node*)__cur)->_M_data,
((_Node*)(__cur->_M_next))->_M_data))
this->_M_erase_after(__cur);
else
__cur = (_Node*) __cur->_M_next;
}
}
}
template <class _StrictWeakOrdering>
void merge(slist<_Tp,_Alloc>& __x,
_StrictWeakOrdering __comp) {
_Node_base* __n1 = &this->_M_head._M_data;
while (__n1->_M_next && __x._M_head._M_data._M_next) {
if (__comp(((_Node*) __x._M_head._M_data._M_next)->_M_data,
((_Node*) __n1->_M_next)->_M_data))
_Sl_global_inst::__splice_after(__n1, &__x._M_head._M_data, __x._M_head._M_data._M_next);
__n1 = __n1->_M_next;
}
if (__x._M_head._M_data._M_next) {
__n1->_M_next = __x._M_head._M_data._M_next;
__x._M_head._M_data._M_next = 0;
}
}
template <class _StrictWeakOrdering>
void sort(_StrictWeakOrdering __comp) {
if (this->_M_head._M_data._M_next && this->_M_head._M_data._M_next->_M_next) {
slist __carry;
slist __counter[64];
int __fill = 0;
while (!empty()) {
_Sl_global_inst::__splice_after(&__carry._M_head._M_data, &this->_M_head._M_data, this->_M_head._M_data._M_next);
int __i = 0;
while (__i < __fill && !__counter[__i].empty()) {
__counter[__i].merge(__carry, __comp);
__carry.swap(__counter[__i]);
++__i;
}
__carry.swap(__counter[__i]);
if (__i == __fill)
++__fill;
}
for (int __i = 1; __i < __fill; ++__i)
__counter[__i].merge(__counter[__i-1], __comp);
this->swap(__counter[__fill-1]);
}
}
#endif /* _STLP_MEMBER_TEMPLATES */
};
template <class _Tp, class _Alloc>
inline bool _STLP_CALL
operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
{
typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator;
const_iterator __end1 = _SL1.end();
const_iterator __end2 = _SL2.end();
const_iterator __i1 = _SL1.begin();
const_iterator __i2 = _SL2.begin();
while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
++__i1;
++__i2;
}
return __i1 == __end1 && __i2 == __end2;
}
# define _STLP_EQUAL_OPERATOR_SPECIALIZED
# define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
# define _STLP_TEMPLATE_CONTAINER slist<_Tp, _Alloc>
# include <stl/_relops_cont.h>
# undef _STLP_TEMPLATE_CONTAINER
# undef _STLP_TEMPLATE_HEADER
# undef _STLP_EQUAL_OPERATOR_SPECIALIZED
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_slist.c>
# endif
# undef slist
# define __slist__ __FULL_NAME(slist)
#if defined (_STLP_DEBUG) && !defined (_STLP_INTERNAL_DBG_SLIST_H)
# include <stl/debug/_slist.h>
#endif
_STLP_BEGIN_NAMESPACE
// Specialization of insert_iterator so that insertions will be constant
// time rather than linear time.
#ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
template <class _Tp, class _Alloc>
class insert_iterator<slist<_Tp, _Alloc> > {
protected:
typedef slist<_Tp, _Alloc> _Container;
_Container* container;
typename _Container::iterator iter;
public:
typedef _Container container_type;
typedef output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
insert_iterator(_Container& __x, typename _Container::iterator __i)
: container(&__x) {
if (__i == __x.begin())
iter = __x.before_begin();
else
iter = __x.previous(__i);
}
insert_iterator<_Container>&
operator=(const typename _Container::value_type& __val) {
iter = container->insert_after(iter, __val);
return *this;
}
insert_iterator<_Container>& operator*() { return *this; }
insert_iterator<_Container>& operator++() { return *this; }
insert_iterator<_Container>& operator++(int) { return *this; }
};
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
_STLP_END_NAMESPACE
# if defined ( _STLP_USE_WRAPPER_FOR_ALLOC_PARAM )
# include <stl/wrappers/_slist.h>
# endif
#endif /* _STLP_INTERNAL_SLIST_H */
// Local Variables:
// mode:C++
// End:
+109
View File
@@ -0,0 +1,109 @@
/*
*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_SLIST_BASE_C
#define _STLP_SLIST_BASE_C
#ifndef _STLP_INTERNAL_SLIST_BASE_H
# include <stl/_slist_base.h>
#endif
_STLP_BEGIN_NAMESPACE
# if defined (_STLP_EXPOSE_GLOBALS_IMPLEMENTATION)
template <class _Dummy>
_Slist_node_base* _STLP_CALL
_Sl_global<_Dummy>::__previous(_Slist_node_base* __head,
const _Slist_node_base* __node)
{
while (__head && __head->_M_next != __node)
__head = __head->_M_next;
return __head;
}
template <class _Dummy>
void _STLP_CALL
_Sl_global<_Dummy>::__splice_after(_Slist_node_base* __pos, _Slist_node_base* __head)
{
_Slist_node_base* __before_last = __previous(__head, 0);
if (__before_last != __head) {
_Slist_node_base* __after = __pos->_M_next;
__pos->_M_next = __head->_M_next;
__head->_M_next = 0;
__before_last->_M_next = __after;
}
}
template <class _Dummy>
void _STLP_CALL
_Sl_global<_Dummy>::__splice_after(_Slist_node_base* __pos,
_Slist_node_base* __before_first,
_Slist_node_base* __before_last)
{
if (__pos != __before_first && __pos != __before_last) {
_Slist_node_base* __first = __before_first->_M_next;
_Slist_node_base* __after = __pos->_M_next;
__before_first->_M_next = __before_last->_M_next;
__pos->_M_next = __first;
__before_last->_M_next = __after;
}
}
template <class _Dummy>
_Slist_node_base* _STLP_CALL
_Sl_global<_Dummy>::__reverse(_Slist_node_base* __node)
{
_Slist_node_base* __result = __node;
__node = __node->_M_next;
__result->_M_next = 0;
while(__node) {
_Slist_node_base* __next = __node->_M_next;
__node->_M_next = __result;
__result = __node;
__node = __next;
}
return __result;
}
template <class _Dummy>
size_t _STLP_CALL
_Sl_global<_Dummy>::size(_Slist_node_base* __node)
{
size_t __result = 0;
for ( ; __node != 0; __node = __node->_M_next)
++__result;
return __result;
}
#endif /* defined (__BUILDING_STLPORT) || ! defined (_STLP_OWN_IOSTREAMS) */
_STLP_END_NAMESPACE
#endif /* _STLP_SLIST_BASE_C */
// Local Variables:
// mode:C++
// End:
+87
View File
@@ -0,0 +1,87 @@
/*
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_SLIST_BASE_H
#define _STLP_INTERNAL_SLIST_BASE_H
#ifndef _STLP_CSTDDEF
#include <cstddef>
#endif
_STLP_BEGIN_NAMESPACE
struct _Slist_node_base
{
_Slist_node_base* _M_next;
};
inline _Slist_node_base*
__slist_make_link(_Slist_node_base* __prev_node,
_Slist_node_base* __new_node)
{
__new_node->_M_next = __prev_node->_M_next;
__prev_node->_M_next = __new_node;
return __new_node;
}
template <class _Dummy>
class _Sl_global {
public:
// those used to be global functions
// moved here to reduce code bloat without templatizing _Slist_iterator_base
static size_t _STLP_CALL size(_Slist_node_base* __node);
static _Slist_node_base* _STLP_CALL __reverse(_Slist_node_base* __node);
static void _STLP_CALL __splice_after(_Slist_node_base* __pos,
_Slist_node_base* __before_first,
_Slist_node_base* __before_last);
static void _STLP_CALL __splice_after(_Slist_node_base* __pos, _Slist_node_base* __head);
static _Slist_node_base* _STLP_CALL __previous(_Slist_node_base* __head,
const _Slist_node_base* __node);
static const _Slist_node_base* _STLP_CALL __previous(const _Slist_node_base* __head,
const _Slist_node_base* __node) {
return _Sl_global<_Dummy>::__previous((_Slist_node_base*)__head, __node);
}
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS _Sl_global<bool>;
# endif
typedef _Sl_global<bool> _Sl_global_inst;
_STLP_END_NAMESPACE
# if !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_slist_base.c>
# endif
#endif /* _STLP_INTERNAL_SLIST_BASE_H */
// Local Variables:
// mode:C++
// End:
+60
View File
@@ -0,0 +1,60 @@
// Currently, SUN CC requires object file
#if defined (__GNUC__)
/*
** int _STLP_atomic_exchange (__stl_atomic_t *pvalue, __stl_atomic_t value)
*/
# ifdef __sparc_v9__
# ifdef __arch64__
# define _STLP_EXCH_ASM asm volatile ("casx [%3], %4, %0 ; membar #LoadLoad | #LoadStore " : \
"=r" (_L_value2), "=m" (*_L_pvalue1) : \
"m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
# else /* __arch64__ */
# define _STLP_EXCH_ASM asm volatile ("cas [%3], %4, %0" : \
"=r" (_L_value2), "=m" (*_L_pvalue1) : \
"m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
# endif
# else /* __sparc_v9__ */
# define _STLP_EXCH_ASM asm volatile ("swap [%3], %0 " : \
"=r" (_L_value2), "=m" (*_L_pvalue1) : \
"m" (*_L_pvalue1), "r" (_L_pvalue1), "0" (_L_value2) )
# endif
# define _STLP_ATOMIC_EXCHANGE(__pvalue1, __value2) \
({ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
register __stl_atomic_t _L_value1, _L_value2 = __value2 ; \
do { _L_value1 = *_L_pvalue1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
_L_value1; })
# define _STLP_ATOMIC_INCREMENT(__pvalue1) \
{ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
register __stl_atomic_t _L_value1, _L_value2; \
do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1+1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; }
# define _STLP_ATOMIC_DECREMENT(__pvalue1) \
{ register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
register __stl_atomic_t _L_value1, _L_value2; \
do { _L_value1 = *_L_pvalue1; _L_value2 = _L_value1-1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; }
# elif ! defined (_STLP_NO_EXTERN_INLINE)
extern "C" __stl_atomic_t _STLP_atomic_exchange(__stl_atomic_t * __x, __stl_atomic_t __v);
extern "C" void _STLP_atomic_decrement(__stl_atomic_t* i);
extern "C" void _STLP_atomic_increment(__stl_atomic_t* i);
# define _STLP_ATOMIC_INCREMENT(__x) _STLP_atomic_increment((__stl_atomic_t*)__x)
# define _STLP_ATOMIC_DECREMENT(__x) _STLP_atomic_decrement((__stl_atomic_t*)__x)
# define _STLP_ATOMIC_EXCHANGE(__x, __y) _STLP_atomic_exchange((__stl_atomic_t*)__x, (__stl_atomic_t)__y)
# endif
+543
View File
@@ -0,0 +1,543 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_SSTREAM_C
#define _STLP_SSTREAM_C
#ifndef _STLP_SSTREAM_H
# include <stl/_sstream.h>
#endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
# if defined ( _STLP_NESTED_TYPE_PARAM_BUG )
// no wint_t is supported for this mode
# define __BSB_int_type__ int
# define __BSB_pos_type__ streampos
# else
# define __BSB_int_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::int_type
# define __BSB_pos_type__ _STLP_TYPENAME_ON_RETURN_TYPE basic_stringbuf<_CharT, _Traits, _Alloc>::pos_type
# endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// Non-inline stringbuf member functions.
// Constructors. Note that the base class constructor sets all of the
// get and area pointers to null.
template <class _CharT, class _Traits, class _Alloc>
basic_stringbuf<_CharT, _Traits, _Alloc>
::basic_stringbuf(ios_base::openmode __mode)
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str()
{}
template <class _CharT, class _Traits, class _Alloc>
basic_stringbuf<_CharT, _Traits, _Alloc>
::basic_stringbuf(const basic_string<_CharT, _Traits, _Alloc>& __s, ios_base::openmode __mode)
: basic_streambuf<_CharT, _Traits>(), _M_mode(__mode), _M_str(__s)
{
_M_set_ptrs();
}
template <class _CharT, class _Traits, class _Alloc>
basic_stringbuf<_CharT, _Traits, _Alloc>::~basic_stringbuf()
{}
// Set the underlying string to a new value.
template <class _CharT, class _Traits, class _Alloc>
void
basic_stringbuf<_CharT, _Traits, _Alloc>::str(const basic_string<_CharT, _Traits, _Alloc>& __s)
{
_M_str = __s;
_M_set_ptrs();
}
template <class _CharT, class _Traits, class _Alloc>
void
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_set_ptrs() {
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
_CharT* __data_end = __data_ptr + _M_str.size();
// The initial read position is the beginning of the string.
if (_M_mode & ios_base::in)
this->setg(__data_ptr, __data_ptr, __data_end);
// The initial write position is the beginning of the string.
if (_M_mode & ios_base::out) {
if (_M_mode & ios_base::app)
this->setp(__data_end, __data_end);
else
this->setp(__data_ptr, __data_end);
}
}
// Precondition: gptr() >= egptr(). Returns a character, if one is available.
template <class _CharT, class _Traits, class _Alloc>
__BSB_int_type__
basic_stringbuf<_CharT, _Traits, _Alloc>::underflow()
{
return this->gptr() != this->egptr()
? _Traits::to_int_type(*this->gptr())
: _Traits::eof();
}
// Precondition: gptr() >= egptr().
template <class _CharT, class _Traits, class _Alloc>
__BSB_int_type__
basic_stringbuf<_CharT, _Traits, _Alloc>::uflow()
{
if (this->gptr() != this->egptr()) {
int_type __c = _Traits::to_int_type(*this->gptr());
this->gbump(1);
return __c;
}
else
return _Traits::eof();
}
template <class _CharT, class _Traits, class _Alloc>
__BSB_int_type__
basic_stringbuf<_CharT, _Traits, _Alloc>::pbackfail(int_type __c)
{
if (this->gptr() != this->eback()) {
if (!_Traits::eq_int_type(__c, _Traits::eof())) {
if (_Traits::eq(_Traits::to_char_type(__c), this->gptr()[-1])) {
this->gbump(-1);
return __c;
}
else if (_M_mode & ios_base::out) {
this->gbump(-1);
*this->gptr() = __c;
return __c;
}
else
return _Traits::eof();
}
else {
this->gbump(-1);
return _Traits::not_eof(__c);
}
}
else
return _Traits::eof();
}
template <class _CharT, class _Traits, class _Alloc>
__BSB_int_type__
basic_stringbuf<_CharT, _Traits, _Alloc>::overflow(int_type __c)
{
// fbp : reverse order of "ifs" to pass Dietmar's test.
// Apparently, standard allows overflow with eof even for read-only streams.
if (!_Traits::eq_int_type(__c, _Traits::eof())) {
if (_M_mode & ios_base::out) {
if (!(_M_mode & ios_base::in)) {
// It's a write-only streambuf, so we can use special append buffer.
if (this->pptr() == this->epptr())
this->_M_append_buffer();
if (this->pptr() != this->epptr()) {
*this->pptr() = _Traits::to_char_type(__c);
this->pbump(1);
return __c;
}
else
return _Traits::eof();
}
else {
// We're not using a special append buffer, just the string itself.
if (this->pptr() == this->epptr()) {
ptrdiff_t __offset = this->gptr() - this->eback();
_M_str.push_back(_Traits::to_char_type(__c));
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
size_t __data_size = _M_str.size();
this->setg(__data_ptr, __data_ptr + __offset, __data_ptr+__data_size);
this->setp(__data_ptr, __data_ptr + __data_size);
this->pbump((int)__data_size);
return __c;
}
else {
*this->pptr() = _Traits::to_char_type(__c);
this->pbump(1);
return __c;
}
}
}
else // Overflow always fails if it's read-only
return _Traits::eof();
}
else // __c is EOF, so we don't have to do anything
return _Traits::not_eof(__c);
}
template <class _CharT, class _Traits, class _Alloc>
streamsize
basic_stringbuf<_CharT, _Traits, _Alloc>::xsputn(const char_type* __s,
streamsize __n)
{
streamsize __nwritten = 0;
if ((_M_mode & ios_base::out) && __n > 0) {
// If the put pointer is somewhere in the middle of the string,
// then overwrite instead of append.
if (this->pbase() == _M_str.data() ) {
ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
if (__avail > __n) {
_Traits::copy(this->pptr(), __s, __n);
this->pbump((int)__n);
return __n;
}
else {
_Traits::copy(this->pptr(), __s, __avail);
__nwritten += __avail;
__n -= __avail;
__s += __avail;
this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
}
}
// At this point we know we're appending.
if (_M_mode & ios_base::in) {
ptrdiff_t __get_offset = this->gptr() - this->eback();
_M_str.append(__s, __s + __n);
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
size_t __data_size = _M_str.size();
this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
this->setp(__data_ptr, __data_ptr + __data_size);
this->pbump((int)__data_size);
}
else {
_M_append_buffer();
_M_str.append(__s, __s + __n);
}
__nwritten += __n;
}
return __nwritten;
}
template <class _CharT, class _Traits, class _Alloc>
streamsize
basic_stringbuf<_CharT, _Traits, _Alloc>::_M_xsputnc(char_type __c,
streamsize __n)
{
streamsize __nwritten = 0;
if ((_M_mode & ios_base::out) && __n > 0) {
// If the put pointer is somewhere in the middle of the string,
// then overwrite instead of append.
if (this->pbase() == _M_str.data()) {
ptrdiff_t __avail = _M_str.data() + _M_str.size() - this->pptr();
if (__avail > __n) {
_Traits::assign(this->pptr(), __n, __c);
this->pbump((int)__n);
return __n;
}
else {
_Traits::assign(this->pptr(), __avail, __c);
__nwritten += __avail;
__n -= __avail;
this->setp(_M_Buf, _M_Buf + __STATIC_CAST(int,_S_BufSiz));
}
}
// At this point we know we're appending.
if (this->_M_mode & ios_base::in) {
ptrdiff_t __get_offset = this->gptr() - this->eback();
_M_str.append(__n, __c);
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
size_t __data_size = _M_str.size();
this->setg(__data_ptr, __data_ptr + __get_offset, __data_ptr+__data_size);
this->setp(__data_ptr, __data_ptr + __data_size);
this->pbump((int)__data_size);
}
else {
_M_append_buffer();
_M_str.append(__n, __c);
}
__nwritten += __n;
}
return __nwritten;
}
// According to the C++ standard the effects of setbuf are implementation
// defined, except that setbuf(0, 0) has no effect. In this implementation,
// setbuf(<anything>, n), for n > 0, calls reserve(n) on the underlying
// string.
template <class _CharT, class _Traits, class _Alloc>
basic_streambuf<_CharT, _Traits>*
basic_stringbuf<_CharT, _Traits, _Alloc>::setbuf(_CharT*, streamsize __n)
{
if (__n > 0) {
bool __do_get_area = false;
bool __do_put_area = false;
ptrdiff_t __offg = 0;
ptrdiff_t __offp = 0;
if (this->pbase() == _M_str.data()) {
__do_put_area = true;
__offp = this->pptr() - this->pbase();
}
if (this->eback() == _M_str.data()) {
__do_get_area = true;
__offg = this->gptr() - this->eback();
}
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
_M_append_buffer();
_M_str.reserve(__n);
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
size_t __data_size = _M_str.size();
if (__do_get_area) {
this->setg(__data_ptr, __data_ptr + __offg, __data_ptr+__data_size);
}
if (__do_put_area) {
this->setp(__data_ptr, __data_ptr+__data_size);
this->pbump((int)__offp);
}
}
return this;
}
template <class _CharT, class _Traits, class _Alloc>
__BSB_pos_type__
basic_stringbuf<_CharT, _Traits, _Alloc>::seekoff(off_type __off,
ios_base::seekdir __dir,
ios_base::openmode __mode)
{
bool __in = false;
bool __out = false;
if ((__mode & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) ) {
if (__dir == ios_base::beg || __dir == ios_base::end)
__in = __out = true;
}
else if (__mode & ios_base::in)
__in = true;
else if (__mode & ios_base::out)
__out = true;
if (!__in && !__out)
return pos_type(off_type(-1));
else if ((__in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
(__out && (!(_M_mode & ios_base::out) || this->pptr() == 0)))
return pos_type(off_type(-1));
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
_M_append_buffer();
streamoff __newoff;
switch(__dir) {
case ios_base::beg:
__newoff = 0;
break;
case ios_base::end:
__newoff = _M_str.size();
break;
case ios_base::cur:
__newoff = __in ? this->gptr() - this->eback()
: this->pptr() - this->pbase();
break;
default:
return pos_type(off_type(-1));
}
__off += __newoff;
if (__in) {
ptrdiff_t __n = this->egptr() - this->eback();
if (__off < 0 || __off > __n)
return pos_type(off_type(-1));
else
this->setg(this->eback(), this->eback() + __off, this->eback() + __n);
}
if (__out) {
ptrdiff_t __n = this->epptr() - this->pbase();
if (__off < 0 || __off > __n)
return pos_type(off_type(-1));
else {
this->setp(this->pbase(), this->pbase() + __n);
this->pbump((int)__off);
}
}
return pos_type(__off);
}
template <class _CharT, class _Traits, class _Alloc>
__BSB_pos_type__
basic_stringbuf<_CharT, _Traits, _Alloc>
::seekpos(pos_type __pos, ios_base::openmode __mode)
{
bool __in = (__mode & ios_base::in) != 0;
bool __out = (__mode & ios_base::out) != 0;
if ((__in && (!(_M_mode & ios_base::in) || this->gptr() == 0)) ||
(__out && (!(_M_mode & ios_base::out) || this->pptr() == 0)))
return pos_type(off_type(-1));
const off_type __n = __pos - pos_type(off_type(0));
if ((_M_mode & ios_base::out) && !(_M_mode & ios_base::in))
_M_append_buffer();
if (__in) {
if (__n < 0 || __n > this->egptr() - this->eback())
return pos_type(off_type(-1));
this->setg(this->eback(), this->eback() + __n, this->egptr());
}
if (__out) {
if (__n < 0 || size_t(__n) > _M_str.size())
return pos_type(off_type(-1));
_CharT* __data_ptr = __CONST_CAST(_CharT*,_M_str.data());
size_t __data_size = _M_str.size();
this->setp(__data_ptr, __data_ptr+__data_size);
this->pbump((int)__n);
}
return __pos;
}
// This is declared as a const member function because it is
// called by basic_stringbuf<>::str(). Precondition: this is a
// write-only stringbuf. We can't use an output buffer for read-
// write stringbufs. Postcondition: pptr is reset to the beginning
// of the buffer.
template <class _CharT, class _Traits, class _Alloc>
void basic_stringbuf<_CharT, _Traits, _Alloc>::_M_append_buffer() const
{
// Do we have a buffer to append?
if (this->pbase() == this->_M_Buf && this->pptr() != this->_M_Buf) {
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
__this->_M_str.append((const _CharT*)this->pbase(), (const _CharT*)this->pptr());
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
}
// Have we run off the end of the string?
else if (this->pptr() == this->epptr()) {
basic_stringbuf<_CharT, _Traits, _Alloc>* __this = __CONST_CAST(_Self*,this);
__this->setp(__CONST_CAST(_CharT*,_M_Buf),
__CONST_CAST(_CharT*,_M_Buf + __STATIC_CAST(int,_S_BufSiz)));
}
}
//----------------------------------------------------------------------
// Non-inline istringstream member functions.
template <class _CharT, class _Traits, class _Alloc>
basic_istringstream<_CharT, _Traits, _Alloc>
::basic_istringstream(ios_base::openmode __mode)
: basic_istream<_CharT, _Traits>(0),
_M_buf(__mode | ios_base::in)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_istringstream<_CharT, _Traits, _Alloc>
::basic_istringstream(const _String& __str,ios_base::openmode __mode)
: basic_istream<_CharT, _Traits>(0),
_M_buf(__str, __mode | ios_base::in)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_istringstream<_CharT, _Traits, _Alloc>::~basic_istringstream()
{}
//----------------------------------------------------------------------
// Non-inline ostringstream member functions.
template <class _CharT, class _Traits, class _Alloc>
basic_ostringstream<_CharT, _Traits, _Alloc>
::basic_ostringstream(ios_base::openmode __mode)
: basic_ostream<_CharT, _Traits>(0),
_M_buf(__mode | ios_base::out)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_ostringstream<_CharT, _Traits, _Alloc>
::basic_ostringstream(const _String& __str, ios_base::openmode __mode)
: basic_ostream<_CharT, _Traits>(0),
_M_buf(__str, __mode | ios_base::out)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_ostringstream<_CharT, _Traits, _Alloc>::~basic_ostringstream()
{}
//----------------------------------------------------------------------
// Non-inline stringstream member functions.
template <class _CharT, class _Traits, class _Alloc>
basic_stringstream<_CharT, _Traits, _Alloc>
::basic_stringstream(ios_base::openmode __mode)
: basic_iostream<_CharT, _Traits>(0), _M_buf(__mode)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_stringstream<_CharT, _Traits, _Alloc>
::basic_stringstream(const _String& __str, ios_base::openmode __mode)
: basic_iostream<_CharT, _Traits>(0), _M_buf(__str, __mode)
{
this->init(&_M_buf);
}
template <class _CharT, class _Traits, class _Alloc>
basic_stringstream<_CharT, _Traits, _Alloc>::~basic_stringstream()
{}
_STLP_END_NAMESPACE
# undef __BSB_int_type__
# undef __BSB_pos_type__
# endif /* EXPOSE */
#endif /* _STLP_SSTREAM_C */
+252
View File
@@ -0,0 +1,252 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// This header defines classes basic_stringbuf, basic_istringstream,
// basic_ostringstream, and basic_stringstream. These classes
// represent streamsbufs and streams whose sources or destinations are
// C++ strings.
#ifndef _STLP_SSTREAM_H
#define _STLP_SSTREAM_H
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
#ifndef _STLP_INTERNAL_ISTREAM_H
# include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
#endif
#ifndef _STLP_STRING_H
# include <stl/_string.h>
#endif
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// This version of basic_stringbuf relies on the internal details of
// basic_string. It relies on the fact that, in this implementation,
// basic_string's iterators are pointers. It also assumes (as allowed
// by the standard) that _CharT is a POD type.
// We have a very small buffer for the put area, just so that we don't
// have to use append() for every sputc. Conceptually, the buffer
// immediately follows the end of the underlying string. We use this
// buffer when appending to write-only streambufs, but we don't use it
// for read-write streambufs.
template <class _CharT, class _Traits, class _Alloc>
class basic_stringbuf : public basic_streambuf<_CharT, _Traits>
{
public: // Typedefs.
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 basic_streambuf<_CharT, _Traits> _Base;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Self;
typedef basic_string<_CharT, _Traits, _Alloc> _String;
public: // Constructors, destructor.
explicit basic_stringbuf(ios_base::openmode __mode
= ios_base::in | ios_base::out);
explicit basic_stringbuf(const _String& __s, ios_base::openmode __mode
= ios_base::in | ios_base::out);
virtual ~basic_stringbuf();
public: // Get or set the string.
_String str() const { _M_append_buffer(); return _M_str; }
void str(const _String& __s);
protected: // Overridden virtual member functions.
virtual int_type underflow();
virtual int_type uflow();
virtual int_type pbackfail(int_type __c);
virtual int_type overflow(int_type __c);
int_type pbackfail() {return pbackfail(_Traits::eof());}
int_type overflow() {return overflow(_Traits::eof());}
virtual streamsize xsputn(const char_type* __s, streamsize __n);
virtual streamsize _M_xsputnc(char_type __c, streamsize __n);
virtual _Base* setbuf(_CharT* __buf, streamsize __n);
virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
ios_base::openmode __mode
= ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
= ios_base::in | ios_base::out);
private: // Helper functions.
// Append the internal buffer to the string if necessary.
void _M_append_buffer() const;
void _M_set_ptrs();
private:
ios_base::openmode _M_mode;
mutable basic_string<_CharT, _Traits, _Alloc> _M_str;
enum _JustName { _S_BufSiz = 8 };
_CharT _M_Buf[ 8 /* _S_BufSiz */];
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<char, char_traits<char>, allocator<char> >;
# if !defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_stringbuf<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
//----------------------------------------------------------------------
// Class basic_istringstream, an input stream that uses a stringbuf.
template <class _CharT, class _Traits, class _Alloc>
class basic_istringstream : public basic_istream<_CharT, _Traits>
{
public: // Typedefs
typedef typename _Traits::char_type 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 basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_istream<_CharT, _Traits> _Base;
typedef basic_string<_CharT, _Traits, _Alloc> _String;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
public: // Constructors, destructor.
basic_istringstream(ios_base::openmode __mode = ios_base::in);
basic_istringstream(const _String& __str,
ios_base::openmode __mode = ios_base::in);
~basic_istringstream();
public: // Member functions
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
_String str() const { return _M_buf.str(); }
void str(const _String& __s) { _M_buf.str(__s); }
private:
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
};
//----------------------------------------------------------------------
// Class basic_ostringstream, an output stream that uses a stringbuf.
template <class _CharT, class _Traits, class _Alloc>
class basic_ostringstream : public basic_ostream<_CharT, _Traits>
{
public: // Typedefs
typedef typename _Traits::char_type 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 basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_ostream<_CharT, _Traits> _Base;
typedef basic_string<_CharT, _Traits, _Alloc> _String;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
public: // Constructors, destructor.
basic_ostringstream(ios_base::openmode __mode = ios_base::out);
basic_ostringstream(const _String& __str,
ios_base::openmode __mode = ios_base::out);
~basic_ostringstream();
public: // Member functions.
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
_String str() const { return _M_buf.str(); }
void str(const _String& __s) { _M_buf.str(__s); } // dwa 02/07/00 - BUG STOMPER DAVE
private:
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
};
//----------------------------------------------------------------------
// Class basic_stringstream, a bidirectional stream that uses a stringbuf.
template <class _CharT, class _Traits, class _Alloc>
class basic_stringstream : public basic_iostream<_CharT, _Traits>
{
public: // Typedefs
typedef typename _Traits::char_type 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 basic_ios<_CharT, _Traits> _Basic_ios;
typedef basic_iostream<_CharT, _Traits> _Base;
typedef basic_string<_CharT, _Traits, _Alloc> _String;
typedef basic_stringbuf<_CharT, _Traits, _Alloc> _Buf;
typedef ios_base::openmode openmode;
public: // Constructors, destructor.
basic_stringstream(openmode __mod = ios_base::in | ios_base::out);
basic_stringstream(const _String& __str,
openmode __mod = ios_base::in | ios_base::out);
~basic_stringstream();
public: // Member functions.
basic_stringbuf<_CharT, _Traits, _Alloc>* rdbuf() const
{ return __CONST_CAST(_Buf*,&_M_buf); }
_String str() const { return _M_buf.str(); }
void str(const _String& __s) { _M_buf.str(__s); }
private:
basic_stringbuf<_CharT, _Traits, _Alloc> _M_buf;
};
# if defined (_STLP_USE_TEMPLATE_EXPORT)
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<char, char_traits<char>, allocator<char> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<char, char_traits<char>, allocator<char> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<char, char_traits<char>, allocator<char> >;
# if !defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_istringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_ostringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
_STLP_EXPORT_TEMPLATE_CLASS basic_stringstream<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
_STLP_END_NAMESPACE
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
# include <stl/_sstream.c>
# endif
#endif /* _STLP_SSTREAM_H */
// Local Variables:
// mode:C++
// End:
+105
View File
@@ -0,0 +1,105 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996,1997
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#ifndef _STLP_INTERNAL_STACK_H
#define _STLP_INTERNAL_STACK_H
#ifndef _STLP_INTERNAL_DEQUE_H
# include <stl/_deque.h>
#endif
_STLP_BEGIN_NAMESPACE
# if !defined ( _STLP_LIMITED_DEFAULT_TEMPLATES )
template <class _Tp, class _Sequence = deque<_Tp> >
# elif defined ( _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS )
# define _STLP_STACK_ARGS _Tp
template <class _Tp>
# else
template <class _Tp, class _Sequence>
# endif
class stack {
# ifdef _STLP_STACK_ARGS
typedef deque<_Tp> _Sequence;
# endif
public:
typedef typename _Sequence::value_type value_type;
typedef typename _Sequence::size_type size_type;
typedef _Sequence container_type;
typedef typename _Sequence::reference reference;
typedef typename _Sequence::const_reference const_reference;
protected:
_Sequence c;
public:
stack() : c() {}
explicit stack(const _Sequence& __s) : c(__s) {}
bool empty() const { return c.empty(); }
size_type size() const { return c.size(); }
reference top() { return c.back(); }
const_reference top() const { return c.back(); }
void push(const value_type& __x) { c.push_back(__x); }
void pop() { c.pop_back(); }
const _Sequence& _Get_c() const { return c; }
};
# ifndef _STLP_STACK_ARGS
# define _STLP_STACK_ARGS _Tp, _Sequence
# define _STLP_STACK_HEADER_ARGS class _Tp, class _Sequence
# else
# define _STLP_STACK_HEADER_ARGS class _Tp
# endif
template < _STLP_STACK_HEADER_ARGS >
inline bool _STLP_CALL operator==(const stack< _STLP_STACK_ARGS >& __x, const stack< _STLP_STACK_ARGS >& __y)
{
return __x._Get_c() == __y._Get_c();
}
template < _STLP_STACK_HEADER_ARGS >
inline bool _STLP_CALL operator<(const stack< _STLP_STACK_ARGS >& __x, const stack< _STLP_STACK_ARGS >& __y)
{
return __x._Get_c() < __y._Get_c();
}
_STLP_RELOPS_OPERATORS(template < _STLP_STACK_HEADER_ARGS >, stack< _STLP_STACK_ARGS >)
_STLP_END_NAMESPACE
# undef _STLP_STACK_ARGS
# undef _STLP_STACK_HEADER_ARGS
#endif /* _STLP_INTERNAL_STACK_H */
// Local Variables:
// mode:C++
// End:
+758
View File
@@ -0,0 +1,758 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
// WARNING: This is an internal header file, included by other C++
// standard library headers. You should not attempt to use this header
// file directly.
#ifndef _STLP_STDIO_FILE_H
#define _STLP_STDIO_FILE_H
// This file provides a low-level interface between the internal
// representation of struct FILE, from the C stdio library, and
// the C++ I/O library. The C++ I/O library views a FILE object as
// a collection of three pointers: the beginning of the buffer, the
// current read/write position, and the end of the buffer.
// The interface:
// - char* _FILE_[IO]_begin(const FILE *__f);
// Returns a pointer to the beginning of the buffer.
// - char* _FILE_[IO]_next(const FILE *__f);
// Returns the current read/write position within the buffer.
// - char* _FILE_[IO]_end(const FILE *__f);
// Returns a pointer immediately past the end of the buffer.
// - char* _FILE_[IO]_avail(const FILE *__f);
// Returns the number of characters remaining in the buffer, i.e.
// _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f).
// - char& _FILE_[IO]_preincr(FILE *__f)
// Increments the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_postincr(FILE *__f)
// Increments the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_predecr(FILE *__f)
// Decrements the current read/write position by 1, returning the
// character at the old position.
// - char& _FILE_[IO]_postdecr(FILE *__f)
// Decrements the current read/write position by 1, returning the
// character at the old position.
// - void _FILE_[IO]_bump(FILE *__f, int __n)
// Increments the current read/write position by __n.
// - void _FILE_[IO]_set(FILE *__f, char* __begin, char* __next, char* __end);
// Sets the beginning of the bufer to __begin, the current read/write
// position to __next, and the buffer's past-the-end pointer to __end.
// If any of those pointers is null, then all of them must be null.
// Each function comes in two versions, one for a FILE used as an input
// buffer and one for a FILE used as an output buffer. In some stdio
// implementations the two functions are identical, but in others they are
// not.
#ifndef _STLP_CSTDIO
# include <cstdio>
#endif
#ifndef _STLP_CSTDDEF
# include <cstddef>
#endif
#if defined(__MSL__)
# include <unix.h> // get the definition of fileno
#endif
_STLP_BEGIN_NAMESPACE
#if !defined(_STLP_WINCE)
//----------------------------------------------------------------------
// Implementation for the IRIX C library.
// Solaris interface looks to be identical.
#if !defined(_STLP_USE_GLIBC) && \
( defined(__sgi) || \
( defined(__sun) && ! defined (_LP64) ) || \
defined (__osf__) || defined(__DECCXX) || \
defined (_STLP_MSVC) || defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP) || defined (_AIX) || defined (_CRAY))
#if defined ( _MSC_VER ) || defined (__ICL) || defined (__MINGW32__) || defined(__DJGPP)
typedef char* _File_ptr_type;
#else
typedef unsigned char* _File_ptr_type;
#endif
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_ptr + __f->_cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_cnt; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_cnt; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_ptr += __n; __f->_cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->_base = (_File_ptr_type) __begin;
__f->_ptr = (_File_ptr_type) __next;
__f->_cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL 1
#elif defined(__EMX__)
inline int _FILE_fd(const FILE* __f) { return __f->_handle; }
inline char* _FILE_I_begin(const FILE* __f) { return (char*) __f->_buffer; }
inline char* _FILE_I_next(const FILE* __f) { return (char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE* __f) { return (char *) __f->_ptr + __f->_rcount; }
inline ptrdiff_t _FILE_I_avail(const FILE* __f) { return __f->_rcount; }
inline char& _FILE_I_preincr(FILE* __f) { --__f->_rcount; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE* __f) { --__f->_rcount; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE* __f) { ++__f->_rcount; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE* __f) { ++__f->_rcount; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_rcount -= __n; }
inline void _FILE_I_set(FILE* __f, char* __begin, char* __next, char* __end) {
__f->_buffer = __begin;
__f->_ptr = __next;
__f->_rcount = __end - __next;
}
inline char* _FILE_O_begin(const FILE* __f) { return (char*) __f->_buffer; }
inline char* _FILE_O_next(const FILE* __f) { return (char*) __f->_ptr; }
inline char* _FILE_O_end(const FILE* __f) { return (char*) __f->_ptr + __f->_wcount; }
inline ptrdiff_t _FILE_O_avail(const FILE* __f) { return __f->_wcount; }
inline char& _FILE_O_preincr(FILE* __f) { --__f->_wcount; return *(char*) (++__f->_ptr); }
inline char& _FILE_O_postincr(FILE* __f) { --__f->_wcount; return *(char*) (__f->_ptr++); }
inline char& _FILE_O_predecr(FILE* __f) { ++__f->_wcount; return *(char*) (--__f->_ptr); }
inline char& _FILE_O_postdecr(FILE* __f) { ++__f->_wcount; return *(char*) (__f->_ptr--); }
inline void _FILE_O_bump(FILE* __f, int __n) { __f->_ptr += __n; __f->_wcount -= __n; }
inline void _FILE_O_set(FILE* __f, char* __begin, char* __next, char* __end) {
__f->_buffer = __begin;
__f->_ptr = __next;
__f->_wcount = __end - __next;
}
# undef _STLP_FILE_I_O_IDENTICAL
# elif defined(_STLP_SCO_OPENSERVER) || defined(__NCR_SVR)
typedef unsigned char* _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return __f->__file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->__base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->__ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->__ptr + __f->__cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->__cnt; return *(char*) (++__f->__ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->__cnt; return *(char*) (__f->__ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->__cnt; return *(char*) (--__f->__ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->__cnt; return *(char*) (__f->__ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->__ptr += __n; __f->__cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->__base = (_File_ptr_type) __begin;
__f->__ptr = (_File_ptr_type) __next;
__f->__cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL 1
# elif defined(__sun) && defined( _LP64)
typedef long _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return (int) __f->__pad[2]; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*)
__f->__pad[1]; }
inline char* _FILE_I_next(const FILE *__f) { return (char*)
__f->__pad[0]; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->__pad[0] + __f->__pad[3]; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__pad[3]; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->__pad[3]; return *(char*) (++__f->__pad[0]); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->__pad[3]; return *(char*) (__f->__pad[0]++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->__pad[3]; return *(char*) (--__f->__pad[0]); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->__pad[3]; return *(char*) (__f->__pad[0]--); }
inline void _FILE_I_bump(FILE *__f, long __n)
{ __f->__pad[0] += __n; __f->__pad[3] -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char*
__end) {
__f->__pad[1] = (_File_ptr_type) __begin;
__f->__pad[0] = (_File_ptr_type) __next;
__f->__pad[3] = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined (__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
|| defined(__amigaos__) || ( defined(__GNUC__) && defined(__APPLE__) )
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*)
__f->_bf._base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_p; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_p + __f->_r; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_r; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_r; --__f->_bf._size; return *(char*) (++__f->_p); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_r; --__f->_bf._size; return *(char*) (__f->_p++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_r; ++ __f->_bf._size; return *(char*) (--__f->_p); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_r; ++__f->_bf._size; return *(char*) (__f->_p--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_p += __n; __f->_bf._size+=__n; __f->_r -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char*
__end) {
__f->_bf._base = (unsigned char*) __begin;
__f->_p = (unsigned char*) __next;
__f->_r = __f->_bf._size = __end - __next;
}
inline char* _FILE_O_begin(const FILE *__f) { return (char*)
__f->_bf._base; }
inline char* _FILE_O_next(const FILE *__f) { return (char*) __f->_p; }
inline char* _FILE_O_end(const FILE *__f)
{ return (char*) __f->_p + __f->_w; }
inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return __f->_w; }
inline char& _FILE_O_preincr(FILE *__f)
{ --__f->_w; --__f->_bf._size; return *(char*) (++__f->_p); }
inline char& _FILE_O_postincr(FILE *__f)
{ --__f->_w; --__f->_bf._size; return *(char*) (__f->_p++); }
inline char& _FILE_O_predecr(FILE *__f)
{ ++__f->_w; ++__f->_bf._size; return *(char*) (--__f->_p); }
inline char& _FILE_O_postdecr(FILE *__f)
{ ++__f->_w; ++__f->_bf._size; return *(char*) (__f->_p--); }
inline void _FILE_O_bump(FILE *__f, int __n)
{ __f->_p += __n; __f->_bf._size+=__n; __f->_w -= __n; }
inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char*
__end) {
__f->_bf._base = (unsigned char*) __begin;
__f->_p = (unsigned char*) __next;
__f->_w = __f->_bf._size = __end - __next;
}
# undef _STLP_FILE_I_O_IDENTICAL
#elif defined(_STLP_USE_GLIBC)
inline int _FILE_fd(const FILE *__f) { return __f->_fileno; }
inline char* _FILE_I_begin(const FILE *__f) { return __f->_IO_read_base; }
inline char* _FILE_I_next(const FILE *__f) { return __f->_IO_read_ptr; }
inline char* _FILE_I_end(const FILE *__f) { return __f->_IO_read_end; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f)
{ return __f->_IO_read_end - __f->_IO_read_ptr; }
inline char& _FILE_I_preincr(FILE *__f) { return *++__f->_IO_read_ptr; }
inline char& _FILE_I_postincr(FILE *__f) { return *__f->_IO_read_ptr++; }
inline char& _FILE_I_predecr(FILE *__f) { return *--__f->_IO_read_ptr; }
inline char& _FILE_I_postdecr(FILE *__f) { return *__f->_IO_read_ptr--; }
inline void _FILE_I_bump(FILE *__f, int __n) { __f->_IO_read_ptr += __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->_IO_read_base = __begin;
__f->_IO_read_ptr = __next;
__f->_IO_read_end = __end;
}
inline char* _FILE_O_begin(const FILE *__f) { return __f->_IO_write_base; }
inline char* _FILE_O_next(const FILE *__f) { return __f->_IO_write_ptr; }
inline char* _FILE_O_end(const FILE *__f) { return __f->_IO_write_end; }
inline ptrdiff_t _FILE_O_avail(const FILE *__f)
{ return __f->_IO_write_end - __f->_IO_write_ptr; }
inline char& _FILE_O_preincr(FILE *__f) { return *++__f->_IO_write_ptr; }
inline char& _FILE_O_postincr(FILE *__f) { return *__f->_IO_write_ptr++; }
inline char& _FILE_O_predecr(FILE *__f) { return *--__f->_IO_write_ptr; }
inline char& _FILE_O_postdecr(FILE *__f) { return *__f->_IO_write_ptr--; }
inline void _FILE_O_bump(FILE *__f, int __n) { __f->_IO_write_ptr += __n; }
inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->_IO_write_base = __begin;
__f->_IO_write_ptr = __next;
__f->_IO_write_end = __end;
}
#elif defined(__hpux) /* && defined(__hppa) && defined(__HP_aCC)) */
#ifndef _INCLUDE_HPUX_SOURCE
extern "C" unsigned char *__bufendtab[];
# undef _bufend
# define _bufend(__p) \
(*(((__p)->__flag & _IOEXT) ? &(((_FILEX *)(__p))->__bufendp) \
: &(__bufendtab[(__p) - __iob])))
# define _bufsiz(__p) (_bufend(__p) - (__p)->__base)
#endif /* _INCLUDE_HPUX_SOURCE */
#if defined(_STLP_HPACC_BROKEN_BUFEND)
# undef _bufend
# define _bufend(__p) \
(*(((__p)->__flag & _IOEXT) ? &((__REINTERPRET_CAST(_FILEX*,(__p)))->__bufendp) \
: &(__bufendtab[__REINTERPRET_CAST(FILE*,(__p)) - __iob])))
#endif
inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE *,__f)); }
inline char* _FILE_I_begin(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__base)); }
inline char* _FILE_I_next(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__ptr)); }
inline char* _FILE_I_end(const FILE *__f) { return (__REINTERPRET_CAST(char*, __f->__ptr +__f->__cnt)); }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->__cnt; }
inline char& _FILE_I_preincr(FILE *__f) { --__f->__cnt; return *__REINTERPRET_CAST(char*, ++__f->__ptr); }
inline char& _FILE_I_postincr(FILE *__f) { --__f->__cnt; return *__REINTERPRET_CAST(char*, __f->__ptr++); }
inline char& _FILE_I_predecr(FILE *__f) { ++__f->__cnt; return *__REINTERPRET_CAST(char*,--__f->__ptr); }
inline char& _FILE_I_postdecr(FILE *__f) { ++__f->__cnt; return *__REINTERPRET_CAST(char*,__f->__ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n) { __f->__cnt -= __n; __f->__ptr += __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
# if defined(__hpux)
if( (unsigned long) (__f - &__iob[0]) > _NFILE)
__f->__flag |= _IOEXT; // used by stdio's _bufend macro and goodness knows what else...
# endif
__f->__cnt = __end - __next;
__f->__base = __REINTERPRET_CAST(unsigned char*, __begin);
__f->__ptr = __REINTERPRET_CAST(unsigned char*, __next);
_bufend(__f) = __REINTERPRET_CAST(unsigned char*, __end);
}
// For HPUX stdio, input and output FILE manipulation is identical.
# define _STLP_FILE_I_O_IDENTICAL
#elif defined (__BORLANDC__)
typedef unsigned char* _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return __f->fd; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->buffer;
}
inline char* _FILE_I_next(const FILE *__f)
{ return (char*)__f->curp; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->curp + __f->level; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->level; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->level; return *(char*) (++__f->curp); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->level; return *(char*) (__f->curp++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->level; return *(char*) (--__f->curp); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->level; return *(char*) (__f->curp--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->curp += __n; __f->level -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char*
__end) {
__f->buffer = (_File_ptr_type) __begin;
__f->curp = (_File_ptr_type) __next;
__f->level = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined( __MWERKS__ )
// using MWERKS-specific defines here to detect other OS targets
// dwa: I'm not sure they provide fileno for all OS's, but this should
// work for Win32 and WinCE
# if __dest_os == __mac_os
inline int _FILE_fd(const FILE *__f) { return ::fileno(__CONST_CAST(FILE*, __f)); }
# else
inline int _FILE_fd(const FILE *__f) { return ::_fileno(__CONST_CAST(FILE*, __f)); }
# endif
// Returns a pointer to the beginning of the buffer.
inline char* _FILE_I_begin(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer); }
// Returns the current read/write position within the buffer.
inline char* _FILE_I_next(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer_ptr); }
// Returns a pointer immediately past the end of the buffer.
inline char* _FILE_I_end(const FILE *__f) { return __REINTERPRET_CAST(char*, __f->buffer_ptr + __f->buffer_len); }
// Returns the number of characters remaining in the buffer, i.e.
// _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f).
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->buffer_len; }
// Increments the current read/write position by 1, returning the
// character at the old position.
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->buffer_len; return *(char*) (++__f->buffer_ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->buffer_len; return *(char*) (__f->buffer_ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->buffer_len; return *(char*) (--__f->buffer_ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->buffer_len; return *(char*) (__f->buffer_ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->buffer_ptr += __n; __f->buffer_len -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->buffer = __REINTERPRET_CAST(unsigned char*, __begin);
__f->buffer_ptr = __REINTERPRET_CAST(unsigned char*, __next);
__f->buffer_len = __end - __next;
__f->buffer_size = __end - __begin;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined(__DMC__)
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
// Returns a pointer to the beginning of the buffer.
inline char* _FILE_I_begin(const FILE *__f) { return __f->_base; }
// Returns the current read/write position within the buffer.
inline char* _FILE_I_next(const FILE *__f) { return __f->_ptr; }
// Returns a pointer immediately past the end of the buffer.
inline char* _FILE_I_end(const FILE *__f) { return __f->_ptr + __f->_cnt; }
// Returns the number of characters remaining in the buffer, i.e.
// _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f).
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; }
// Increments the current read/write position by 1, returning the
// character at the NEW position.
inline char& _FILE_I_preincr(FILE *__f) { --__f->_cnt; return *(++__f->_ptr); }
// Increments the current read/write position by 1, returning the
// character at the old position.
inline char& _FILE_I_postincr(FILE *__f) { --__f->_cnt; return *(__f->_ptr++); }
// Decrements the current read/write position by 1, returning the
// character at the NEW position.
inline char& _FILE_I_predecr(FILE *__f) { ++__f->_cnt; return *(--__f->_ptr); }
// Decrements the current read/write position by 1, returning the
// character at the old position.
inline char& _FILE_I_postdecr(FILE *__f) { ++__f->_cnt; return *(__f->_ptr--); }
// Increments the current read/write position by __n.
inline void _FILE_I_bump(FILE *__f, int __n) { __f->_cnt -= __n; __f->_ptr += __n; }
// Sets the beginning of the bufer to __begin, the current read/write
// position to __next, and the buffer's past-the-end pointer to __end.
// If any of those pointers is null, then all of them must be null.
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end)
{
__f->_base = __begin;
__f->_ptr = __next;
__f->_cnt = __end - __next;
__f->_bufsiz = __end - __begin;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined(__MRC__) || defined(__SC__) //*TY 02/24/2000 - added support for MPW
inline int _FILE_fd(const FILE *__f) { return __f->_file; }
// Returns a pointer to the beginning of the buffer.
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; }
// Returns the current read/write position within the buffer.
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; }
// Returns a pointer immediately past the end of the buffer.
inline char* _FILE_I_end(const FILE *__f) { return (char*)__f->_end; }
// Returns the number of characters remaining in the buffer, i.e.
// _FILE_[IO]_end(__f) - _FILE_[IO]_next(__f).
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; }
// Increments the current read/write position by 1, returning the
// character at the NEW position.
inline char& _FILE_I_preincr(FILE *__f) { --__f->_cnt; return*(char*) (++__f->_ptr); }
// Increments the current read/write position by 1, returning the
// character at the old position.
inline char& _FILE_I_postincr(FILE *__f) { --__f->_cnt; return*(char*) (__f->_ptr++); }
// Decrements the current read/write position by 1, returning the
// character at the NEW position.
inline char& _FILE_I_predecr(FILE *__f) { ++__f->_cnt; return*(char*) (--__f->_ptr); }
// Decrements the current read/write position by 1, returning the
// character at the old position.
inline char& _FILE_I_postdecr(FILE *__f) { ++__f->_cnt; return*(char*) (__f->_ptr--); }
// Increments the current read/write position by __n.
inline void _FILE_I_bump(FILE *__f, int __n) { __f->_cnt -= __n; __f->_ptr += __n; }
// Sets the beginning of the bufer to __begin, the current read/write
// position to __next, and the buffer's past-the-end pointer to __end.
// If any of those pointers is null, then all of them must be null.
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end)
{
__f->_base = (unsigned char*)__begin;
__f->_ptr = (unsigned char*)__next;
__f->_end = (unsigned char*)__end;
__f->_cnt = __end - __next;
__f->_size = __end - __begin;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined (__MVS__)
typedef unsigned char* _File_ptr_type;
inline int _FILE_fd(const FILE *__f) { return fileno(__CONST_CAST(FILE
*,__f)); }
inline char* _FILE_I_begin(const FILE *__f) { return (char*)
__f->__fp->__bufPtr; }
inline char* _FILE_I_next(const FILE *__f) { return (char*)
__f->__fp->__bufPtr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->__fp->__bufPtr + __f->__fp->__countIn; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return
__f->__fp->__countIn; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->__fp->__countIn; return *(char*) (++__f->__fp->__bufPtr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->__fp->__countIn; return *(char*) (__f->__fp->__bufPtr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->__fp->__countIn; return *(char*) (--__f->__fp->__bufPtr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->__fp->__countIn; return *(char*) (__f->__fp->__bufPtr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->__fp->__bufPtr += __n; __f->__fp->__countIn -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char*
__end) {
// __f->_base = (_File_ptr_type) __begin;
if(__f->__fp) {
__f->__fp->__bufPtr = (_File_ptr_type) __next;
__f->__fp->__countIn = __end - __next;
}
}
inline char* _FILE_O_begin(const FILE *__f) { return (char*)__f->__fp->__bufPtr;}
inline char* _FILE_O_next(const FILE *__f) { return (char*) __f->__fp->__bufPtr;}
inline char* _FILE_O_end(const FILE *__f) { return (char*) __f->__fp->__bufPtr + __f->__fp->__countOut; }
inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return __f->__fp->__countOut; }
inline char& _FILE_O_preincr(FILE *__f)
{ --__f->__fp->__countOut; return *(char*) (++__f->__fp->__bufPtr); }
inline char& _FILE_O_postincr(FILE *__f)
{ --__f->__fp->__countOut; return *(char*) (__f->__fp->__bufPtr++); }
inline char& _FILE_O_predecr(FILE *__f)
{ ++__f->__fp->__countOut; return *(char*) (--__f->__fp->__bufPtr); }
inline char& _FILE_O_postdecr(FILE *__f)
{ ++__f->__fp->__countOut; return *(char*) (__f->__fp->__bufPtr--); }
inline void _FILE_O_bump(FILE *__f, int __n)
{ __f->__fp->__bufPtr += __n; __f->__fp->__countOut -= __n; }
inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char*
__end) {
// __f->_base = (_File_ptr_type) __begin;
if(__f->__fp) {
__f->__fp->__bufPtr = (_File_ptr_type) __next;
__f->__fp->__countOut = __end - __next;
}
}
#elif defined(__QNXNTO__)
inline int _FILE_fd(const FILE *__f) { return __f->_handle;
}
inline char* _FILE_I_begin(const FILE *__f) { return
(char*) __f->_base; }
inline char* _FILE_I_next(const FILE *__f) { return
(char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_ptr + __f->_cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return
__f->_cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_cnt; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_cnt; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_ptr += __n; __f->_cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char*
__next, char*
__end) {
__f->_base = (unsigned char*) __begin;
__f->_ptr = (unsigned char*) __next;
__f->_cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined(__WATCOMC__) // Nikolaev
inline int _FILE_fd (const FILE *__f) { return __f->_handle;}
inline char* _FILE_I_begin (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_link); }
inline char* _FILE_I_next (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr); }
inline char* _FILE_I_end (const FILE *__f) { return __REINTERPRET_CAST(char*, __f->_ptr + __f->_cnt); }
inline ptrdiff_t _FILE_I_avail (const FILE *__f) { return __f->_cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{
--__f->_cnt;
return *__REINTERPRET_CAST(char*, ++__f->_ptr);
}
inline char& _FILE_I_postincr(FILE *__f)
{
--__f->_cnt;
return *__REINTERPRET_CAST(char*, __f->_ptr++);
}
inline char& _FILE_I_predecr(FILE *__f)
{
++__f->_cnt;
return *__REINTERPRET_CAST(char*, --__f->_ptr);
}
inline char& _FILE_I_postdecr(FILE *__f)
{
++__f->_cnt;
return *__REINTERPRET_CAST(char*, __f->_ptr--);
}
inline void _FILE_I_bump(FILE *__f, int __n)
{
__f->_ptr += __n;
__f->_cnt -= __n;
}
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end)
{
__f->_link = __REINTERPRET_CAST(__stream_link*, __begin);
__f->_ptr = __REINTERPRET_CAST(unsigned char*, __next);
__f->_cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#elif defined (__Lynx__)
// the prototypes are taken from LynxOS patch for STLport 4.0
inline int _FILE_fd(const FILE *__f) { return __f->_fd; }
inline char* _FILE_I_begin(const FILE *__f) { return (char*) __f->_base; }
inline char* _FILE_I_next(const FILE *__f) { return (char*) __f->_ptr; }
inline char* _FILE_I_end(const FILE *__f)
{ return (char*) __f->_ptr + __f->_cnt; }
inline ptrdiff_t _FILE_I_avail(const FILE *__f) { return __f->_cnt; }
inline char& _FILE_I_preincr(FILE *__f)
{ --__f->_cnt; return *(char*) (++__f->_ptr); }
inline char& _FILE_I_postincr(FILE *__f)
{ --__f->_cnt; return *(char*) (__f->_ptr++); }
inline char& _FILE_I_predecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (--__f->_ptr); }
inline char& _FILE_I_postdecr(FILE *__f)
{ ++__f->_cnt; return *(char*) (__f->_ptr--); }
inline void _FILE_I_bump(FILE *__f, int __n)
{ __f->_ptr += __n; __f->_cnt -= __n; }
inline void _FILE_I_set(FILE *__f, char* __begin, char* __next, char* __end) {
__f->_base = __begin;
__f->_ptr = __next;
__f->_cnt = __end - __next;
}
# define _STLP_FILE_I_O_IDENTICAL
#else /* A C library that we don't have an implementation for. */
# error The C++ I/O library is not configured for this compiler
#endif
// For most stdio's , input and output FILE manipulation is identical.
# ifdef _STLP_FILE_I_O_IDENTICAL
inline char* _FILE_O_begin(const FILE *__f) { return _FILE_I_begin(__f); }
inline char* _FILE_O_next(const FILE *__f) { return _FILE_I_next(__f); }
inline char* _FILE_O_end(const FILE *__f) { return _FILE_I_end(__f); }
inline ptrdiff_t _FILE_O_avail(const FILE *__f) { return _FILE_I_avail(__f); }
inline char& _FILE_O_preincr(FILE *__f) { return _FILE_I_preincr(__f); }
inline char& _FILE_O_postincr(FILE *__f) { return _FILE_I_postincr(__f); }
inline char& _FILE_O_predecr(FILE *__f) { return _FILE_I_predecr(__f); }
inline char& _FILE_O_postdecr(FILE *__f) { return _FILE_I_postdecr(__f); }
inline void _FILE_O_bump(FILE *__f, int __n) { _FILE_I_bump(__f, __n); }
inline void _FILE_O_set(FILE *__f, char* __begin, char* __next, char* __end)
{ _FILE_I_set(__f, __begin, __next, __end); }
# endif
#else
inline int _FILE_fd(const FILE *__f) { return (int)::_fileno(__CONST_CAST(FILE *, __f)); }
#endif /* _STLP_WINCE */
_STLP_END_NAMESPACE
#endif /* _STLP_STDIO_FILE_H */
// Local Variables:
// mode:C++
// End:
+343
View File
@@ -0,0 +1,343 @@
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1997
* Moscow Center for SPARC Technology
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
/* NOTE: This is an internal header file, included by other STL headers.
* You should not attempt to use it directly.
*/
#if !defined (_STLP_INTERNAL_STREAM_ITERATOR_H) && ! defined (_STLP_USE_NO_IOSTREAMS)
#define _STLP_INTERNAL_STREAM_ITERATOR_H
#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
# include <stl/_iterator_base.h>
#endif
// streambuf_iterators predeclarations must appear first
#ifndef _STLP_IOSFWD
# include <iosfwd>
#endif
#ifndef _STLP_INTERNAL_ALGOBASE_H
#include <stl/_algobase.h>
#endif
#if defined (_STLP_OWN_IOSTREAMS)
#ifndef _STLP_INTERNAL_OSTREAMBUF_ITERATOR_H
# include <stl/_ostreambuf_iterator.h>
#endif
#ifndef _STLP_INTERNAL_ISTREAMBUF_ITERATOR_H
# include <stl/_istreambuf_iterator.h>
#endif
#ifndef _STLP_INTERNAL_ISTREAM_H
# include <stl/_istream.h>
#endif
#endif /* _STLP_OWN_IOSTREAMS */
// istream_iterator and ostream_iterator look very different if we're
// using new, templatized iostreams than if we're using the old cfront
// version.
# if defined (_STLP_USE_NEW_IOSTREAMS)
_STLP_BEGIN_NAMESPACE
# ifndef _STLP_LIMITED_DEFAULT_TEMPLATES
template <class _Tp,
class _CharT = _STLP_DEFAULTCHAR, class _Traits = char_traits<_CharT>,
class _Dist = ptrdiff_t>
# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _CharT, class _Traits, class _Dist
# define __ISI_TMPL_ARGUMENTS _Tp, _CharT, _Traits, _Dist
class istream_iterator : public iterator<input_iterator_tag, _Tp , _Dist,
const _Tp*, const _Tp& > {
# else
# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
# define __ISI_TMPL_ARGUMENTS _Tp
template <class _Tp>
class istream_iterator : public iterator<input_iterator_tag, _Tp , ptrdiff_t,
const _Tp*, const _Tp& > {
# else
# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
# define __ISI_TMPL_ARGUMENTS _Tp, _Dist
template <class _Tp,__DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist ,
const _Tp*, const _Tp& > {
# endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
# endif /* _STLP_LIMITED_DEFAULT_TEMPLATES */
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
typedef char _CharT;
typedef char_traits<char> _Traits;
# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
typedef ptrdiff_t _Dist;
# endif
# endif
typedef istream_iterator< __ISI_TMPL_ARGUMENTS > _Self;
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_istream<_CharT, _Traits> istream_type;
typedef input_iterator_tag iterator_category;
typedef _Tp value_type;
typedef _Dist difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
istream_iterator() : _M_stream(0), _M_ok(false) {}
istream_iterator(istream_type& __s) : _M_stream(&__s) { _M_read(); }
reference operator*() const { return _M_value; }
_STLP_DEFINE_ARROW_OPERATOR
_Self& operator++() {
_M_read();
return *this;
}
_Self operator++(int) {
_Self __tmp = *this;
_M_read();
return __tmp;
}
bool _M_equal(const _Self& __x) const
{ return (_M_ok == __x._M_ok) && (!_M_ok || _M_stream == __x._M_stream); }
private:
istream_type* _M_stream;
_Tp _M_value;
bool _M_ok;
void _M_read() {
_M_ok = (_M_stream && *_M_stream) ? true : false;
if (_M_ok) {
*_M_stream >> _M_value;
_M_ok = *_M_stream ? true : false;
}
}
};
#ifndef _STLP_LIMITED_DEFAULT_TEMPLATES
template <class _TpP,
class _CharT = _STLP_DEFAULTCHAR, class _Traits = char_traits<_CharT> >
#else
template <class _TpP>
#endif
class ostream_iterator: public iterator<output_iterator_tag, void, void, void, void> {
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
typedef char _CharT;
typedef char_traits<char> _Traits;
typedef ostream_iterator<_TpP> _Self;
# else
typedef ostream_iterator<_TpP, _CharT, _Traits> _Self;
# endif
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_ostream<_CharT, _Traits> ostream_type;
typedef output_iterator_tag iterator_category;
ostream_iterator(ostream_type& __s) : _M_stream(&__s), _M_string(0) {}
ostream_iterator(ostream_type& __s, const _CharT* __c)
: _M_stream(&__s), _M_string(__c) {}
_Self& operator=(const _TpP& __val) {
*_M_stream << __val;
if (_M_string) *_M_stream << _M_string;
return *this;
}
_Self& operator*() { return *this; }
_Self& operator++() { return *this; }
_Self& operator++(int) { return *this; }
private:
ostream_type* _M_stream;
const _CharT* _M_string;
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
# ifdef _STLP_LIMITED_DEFAULT_TEMPLATES
template <class _TpP>
inline output_iterator_tag _STLP_CALL
iterator_category(const ostream_iterator<_TpP>&) { return output_iterator_tag(); }
# else
template <class _TpP, class _CharT, class _Traits>
inline output_iterator_tag _STLP_CALL
iterator_category(const ostream_iterator<_TpP, _CharT, _Traits>&) { return output_iterator_tag(); }
# endif
# endif
_STLP_END_NAMESPACE
# elif ! defined(_STLP_USE_NO_IOSTREAMS)
_STLP_BEGIN_NAMESPACE
# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp
# define __ISI_TMPL_ARGUMENTS _Tp
template <class _Tp>
class istream_iterator : public iterator<input_iterator_tag, _Tp, ptrdiff_t,
const _Tp*, const _Tp& > {
# else
# define __ISI_TMPL_HEADER_ARGUMENTS class _Tp, class _Dist
# define __ISI_TMPL_ARGUMENTS _Tp, _Dist
template <class _Tp, __DFL_TYPE_PARAM(_Dist, ptrdiff_t)>
class istream_iterator : public iterator<input_iterator_tag, _Tp, _Dist,
const _Tp*, const _Tp& > {
# endif
protected:
istream* _M_stream;
_Tp _M_value;
bool _M_end_marker;
void _M_read() {
_M_end_marker = (*_M_stream) ? true : false;
if (_M_end_marker) *_M_stream >> _M_value;
_M_end_marker = (*_M_stream) ? true : false;
}
public:
typedef input_iterator_tag iterator_category;
typedef _Tp value_type;
typedef _Dist difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
istream_iterator() : _M_stream(&cin), _M_end_marker(false) {}
istream_iterator(istream& __s) : _M_stream(&__s) { _M_read(); }
reference operator*() const { return _M_value; }
_STLP_DEFINE_ARROW_OPERATOR
istream_iterator< __ISI_TMPL_ARGUMENTS >& operator++() {
_M_read();
return *this;
}
istream_iterator< __ISI_TMPL_ARGUMENTS > operator++(int) {
istream_iterator< __ISI_TMPL_ARGUMENTS > __tmp = *this;
_M_read();
return __tmp;
}
inline bool _M_equal(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) const {
return (_M_stream == __y._M_stream &&
_M_end_marker == __y._M_end_marker) ||
_M_end_marker == false && __y._M_end_marker == false;
}
};
template <class _Tp>
class ostream_iterator {
protected:
ostream* _M_stream;
const char* _M_string;
public:
typedef output_iterator_tag iterator_category;
# ifdef _STLP_CLASS_PARTIAL_SPECIALIZATION
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
# endif
ostream_iterator(ostream& __s) : _M_stream(&__s), _M_string(0) {}
ostream_iterator(ostream& __s, const char* __c)
: _M_stream(&__s), _M_string(__c) {}
ostream_iterator<_Tp>& operator=(const _Tp& __val) {
*_M_stream << __val;
if (_M_string) *_M_stream << _M_string;
return *this;
}
ostream_iterator<_Tp>& operator*() { return *this; }
ostream_iterator<_Tp>& operator++() { return *this; }
ostream_iterator<_Tp>& operator++(int) { return *this; }
};
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _Tp> inline output_iterator_tag
iterator_category(const ostream_iterator<_Tp>&) { return output_iterator_tag(); }
#endif
_STLP_END_NAMESPACE
#endif /* _STLP_USE_NEW_IOSTREAMS */
// form-independent definiotion of stream iterators
_STLP_BEGIN_NAMESPACE
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline bool _STLP_CALL
operator==(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) {
return __x._M_equal(__y);
}
# ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline bool _STLP_CALL
operator!=(const istream_iterator< __ISI_TMPL_ARGUMENTS >& __x,
const istream_iterator< __ISI_TMPL_ARGUMENTS >& __y) {
return !__x._M_equal(__y);
}
# endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
# ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline input_iterator_tag _STLP_CALL
iterator_category(const istream_iterator< __ISI_TMPL_ARGUMENTS >&)
{ return input_iterator_tag(); }
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline _Tp* _STLP_CALL
value_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Tp*) 0; }
# if defined (_STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS) && ! defined (_STLP_DEFAULT_TYPE_PARAM)
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline ptrdiff_t* _STLP_CALL
distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (ptrdiff_t*)0; }
# else
template < __ISI_TMPL_HEADER_ARGUMENTS >
inline _Dist* _STLP_CALL
distance_type(const istream_iterator< __ISI_TMPL_ARGUMENTS >&) { return (_Dist*)0; }
# endif /* _STLP_MINIMUM_DEFAULT_TEMPLATE_PARAMS */
# endif
_STLP_END_NAMESPACE
# undef __ISI_TMPL_HEADER_ARGUMENTS
# undef __ISI_TMPL_ARGUMENTS
#endif /* _STLP_INTERNAL_STREAM_ITERATOR_H */
// Local Variables:
// mode:C++
// End:
+216
View File
@@ -0,0 +1,216 @@
/*
* Copyright (c) 1999
* Silicon Graphics Computer Systems, Inc.
*
* Copyright (c) 1999
* Boris Fomitchev
*
* This material is provided "as is", with absolutely no warranty expressed
* or implied. Any use is at your own risk.
*
* Permission to use or copy this software for any purpose is hereby granted
* without fee, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*
*/
#ifndef _STLP_STREAMBUF_C
#define _STLP_STREAMBUF_C
#ifndef _STLP_INTERNAL_STREAMBUF
# include <stl/_streambuf.h>
#endif
# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION)
_STLP_BEGIN_NAMESPACE
//----------------------------------------------------------------------
// Non-inline basic_streambuf<> member functions.
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>::basic_streambuf()
: _M_gbegin(0), _M_gnext(0), _M_gend(0),
_M_pbegin(0), _M_pnext(0), _M_pend(0),
_M_locale()
{
// _M_lock._M_initialize();
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>::~basic_streambuf()
{}
template <class _CharT, class _Traits>
locale
basic_streambuf<_CharT, _Traits>::pubimbue(const locale& __loc) {
this->imbue(__loc);
locale __tmp = _M_locale;
_M_locale = __loc;
return __tmp;
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::xsgetn(_CharT* __s, streamsize __n)
{
streamsize __result = 0;
const int_type __eof = _Traits::eof();
while (__result < __n) {
if (_M_gnext < _M_gend) {
size_t __chunk = (min) (__STATIC_CAST(size_t,_M_gend - _M_gnext),
__STATIC_CAST(size_t,__n - __result));
_Traits::copy(__s, _M_gnext, __chunk);
__result += __chunk;
__s += __chunk;
_M_gnext += __chunk;
}
else {
int_type __c = this->sbumpc();
if (!_Traits::eq_int_type(__c, __eof)) {
*__s = __c;
++__result;
++__s;
}
else
break;
}
}
return __result;
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::xsputn(const _CharT* __s, streamsize __n)
{
streamsize __result = 0;
const int_type __eof = _Traits::eof();
while (__result < __n) {
if (_M_pnext < _M_pend) {
size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
__STATIC_CAST(size_t,__n - __result));
_Traits::copy(_M_pnext, __s, __chunk);
__result += __chunk;
__s += __chunk;
_M_pnext += __chunk;
}
else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(*__s)),
__eof)) {
++__result;
++__s;
}
else
break;
}
return __result;
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::_M_xsputnc(_CharT __c, streamsize __n)
{
streamsize __result = 0;
const int_type __eof = _Traits::eof();
while (__result < __n) {
if (_M_pnext < _M_pend) {
size_t __chunk = (min) (__STATIC_CAST(size_t,_M_pend - _M_pnext),
__STATIC_CAST(size_t,__n - __result));
_Traits::assign(_M_pnext, __chunk, __c);
__result += __chunk;
_M_pnext += __chunk;
}
else if (!_Traits::eq_int_type(this->overflow(_Traits::to_int_type(__c)),
__eof))
++__result;
else
break;
}
return __result;
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::_M_snextc_aux()
{
int_type __eof = _Traits::eof();
if (_M_gend == _M_gnext)
return _Traits::eq_int_type(this->uflow(), __eof) ? __eof : this->sgetc();
else {
_M_gnext = _M_gend;
return this->underflow();
}
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::pbackfail(int_type) {
return _Traits::eof();
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::overflow(int_type) {
return _Traits::eof();
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::uflow() {
return ( _Traits::eq_int_type(this->underflow(),_Traits::eof()) ?
_Traits::eof() :
_Traits::to_int_type(*_M_gnext++));
}
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::underflow()
{ return _Traits::eof(); }
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::showmanyc()
{ return 0; }
template <class _CharT, class _Traits>
void
basic_streambuf<_CharT, _Traits>::imbue(const locale&) {}
template <class _CharT, class _Traits>
int
basic_streambuf<_CharT, _Traits>::sync() { return 0; }
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
{ return pos_type(-1); }
template <class _CharT, class _Traits>
_STLP_TYPENAME_ON_RETURN_TYPE basic_streambuf<_CharT, _Traits>::pos_type
basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
ios_base::openmode)
{ return pos_type(-1); }
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>*
basic_streambuf<_CharT, _Traits>:: setbuf(char_type*, streamsize)
{ return this; }
# if defined (_STLP_USE_TEMPLATE_EXPORT)
# if !defined (_STLP_NO_WCHAR_T)
_STLP_EXPORT_TEMPLATE_CLASS basic_streambuf<wchar_t, char_traits<wchar_t> >;
# endif
# endif /* _STLP_USE_TEMPLATE_EXPORT */
_STLP_END_NAMESPACE
# endif /* EXPOSE */
#endif

Some files were not shown because too many files have changed in this diff Show More