1 /*  $Id: stlp_defs.hpp 617780 2020-10-06 16:24:16Z gouriano $
2  * ===========================================================================
3  *
4  *                            PUBLIC DOMAIN NOTICE
5  *               National Center for Biotechnology Information
6  *
7  *  This software/database is a "United States Government Work" under the
8  *  terms of the United States Copyright Act.  It was written as part of
9  *  the author's official duties as a United States Government employee and
10  *  thus cannot be copyrighted.  This software/database is freely available
11  *  to the public for use. The National Library of Medicine and the U.S.
12  *  Government have not placed any restriction on its use or reproduction.
13  *
14  *  Although all reasonable efforts have been taken to ensure the accuracy
15  *  and reliability of the software and data, the NLM and the U.S.
16  *  Government do not and cannot warrant the performance or results that
17  *  may be obtained by using this software or data. The NLM and the U.S.
18  *  Government disclaim all warranties, express or implied, including
19  *  warranties of performance, merchantability or fitness for any particular
20  *  purpose.
21  *
22  *  Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Aleksey Grichenko
27  *
28  * File Description:
29  *   Wrapper for STLport internal sources
30  *
31  */
32 
33 /*
34 _STLP_USE_WRAPPER_FOR_ALLOC_PARAM
35     includes _hash_map_wrapper.h and _hash_set_wrapper.h
36     left defined to ignore the files
37 
38 _STLP_NO_SIGNED_BUILTINS
39     if defined, removes declaration of hash<signed char>
40 
41 _STLP_CLASS_PARTIAL_SPECIALIZATION
42     forces insert_iterator definition in _hash_map.h and _hash_set.h,
43     causing problems with namespaces (spec. in different namespace).
44 
45 _STLP_MEMBER_TEMPLATES
46     left undefined
47 
48 _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM
49     used with _Alloc_traits, allocate, deallocate.
50     -- defined for GCC, ICC
51 
52 _STLP_STATIC_TEMPLATE_DATA
53     always defined as 1 for correct initialization of static template members
54 
55 _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
56     switch between __Select1st_hint and _Select1st
57     -- need for WS, ICC, MSVC
58 
59 Additional flags for some compilers
60 NO_STD_CONSTRUCT
61 NO_STD_DESTROY
62 
63 USE_NO_ALLOC_TRAITS
64     some compilers already have _Alloc_traits -- do not redefine
65 */
66 
67 #ifndef STLP_DEFS__HPP
68 #define STLP_DEFS__HPP
69 
70 #include <corelib/ncbistl.hpp>
71 
72 // Use STL types
73 #include <iterator>
74 #include <algorithm>
75 #include <functional>
76 #include <vector>
77 
78 NCBI_USING_NAMESPACE_STD;
79 
80 
81 //////////////////////////////////////////////////////////////////////
82 //
83 // Define symbols used by STLport
84 //
85 
86 #define _STLP_STATIC_TEMPLATE_DATA 1
87 
88 // Do not try to include *.c from *.h - this is done
89 // explicitely in this header
90 #define _STLP_LINK_TIME_INSTANTIATION
91 #define _STLP_USE_EXCEPTIONS
92 
93 // Need to undefine to avoid namespace conflicts
94 #define _STLP_NO_CLASS_PARTIAL_SPECIALIZATION
95 #undef _STLP_CLASS_PARTIAL_SPECIALIZATION
96 
97 
98 // Generate correct operator!=() for iterators
99 #define _STLP_USE_SEPARATE_RELOPS_NAMESPACE
100 
101 
102 // Ignore STLport internal headers
103 #define _STLP_INTERNAL_VECTOR_H
104 #define _STLP_INTERNAL_ITERATOR_H
105 #define _STLP_INTERNAL_FUNCTION_H
106 #define _STLP_INTERNAL_ALGOBASE_H
107 
108 // long type name for hash<_STLP_LONG_LONG>
109 #ifdef SIZEOF_LONG_LONG
110 #  if SIZEOF_LONG_LONG > 0
111 #    define _STLP_LONG_LONG long long
112 #  endif
113 #endif
114 
115 
116 #define _STLP_BEGIN_NAMESPACE             BEGIN_NCBI_SCOPE
117 #define _STLP_END_NAMESPACE               END_NCBI_SCOPE
118 #define _STLP_STD                         std
119 #define _STLP_CALL
120 #define _STLP_FIX_LITERAL_BUG(x)
121 #define __WORKAROUND_RENAME(X)            X
122 #define _STLP_PLACEMENT_NEW               new
123 #define __STATIC_CAST(__x,__y)            static_cast<__x>(__y)
124 #define __REINTERPRET_CAST(__x,__y)       reinterpret_cast<__x>(__y)
125 #define _STLP_TEMPLATE_NULL               EMPTY_TEMPLATE
126 #define _STLP_TEMPLATE                    template
127 #define _STLP_TYPENAME_ON_RETURN_TYPE     typename
128 #define __vector__                        vector
129 #define _STLP_FORCE_ALLOCATORS(a,y)
130 #define _STLP_CONVERT_ALLOCATOR(__a, _Tp) __a
131 
132 
133 #define _STLP_TRY                     try
134 #define _STLP_UNWIND(action)          catch(...) { action; throw; }
135 
136 
137 #define __TRIVIAL_CONSTRUCTOR(__type)
138 #define __TRIVIAL_DESTRUCTOR(__type)
139 #define __TRIVIAL_STUFF(__type)  \
140   __TRIVIAL_CONSTRUCTOR(__type) __TRIVIAL_DESTRUCTOR(__type)
141 
142 
143 #define _STLP_DEFINE_ARROW_OPERATOR \
144     pointer operator->() const { return &(operator*()); }
145 
146 
147 #define __DFL_TMPL_PARAM( classname, defval ) class classname = defval
148 #define _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(_Key, _Tp ) \
149         class _Alloc = allocator< pair < _Key, _Tp > >
150 
151 
152 #define _STLP_DEFAULT_ALLOCATOR_SELECT( _Tp ) \
153         __DFL_TMPL_PARAM(_Alloc, allocator< _Tp >)
154 #define _STLP_DEFAULT_PAIR_ALLOCATOR_SELECT(_Key, _Tp ) \
155         class _Alloc = allocator< pair < _Key, _Tp > >
156 
157 
158 // Ignore distance in __lower_bound
159 #define __lower_bound(b,e,v,c,d) lower_bound(b,e,v,c)
160 
161 
162 //////////////////////////////////////////////////////////////////////
163 //
164 // Configuration dependent defines
165 //
166 
167 #if defined(NCBI_COMPILER_GCC)  ||  defined(NCBI_COMPILER_ANY_CLANG)
168 #  define _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM 1
169 #endif
170 
171 #ifdef NCBI_COMPILER_ICC
172 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
173 #  define _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM 1
174 #endif
175 
176 #ifdef NCBI_COMPILER_ANY_CLANG
177 #  define _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM 1
178 #endif
179 
180 #ifdef NCBI_COMPILER_MSVC
181 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
182 #endif
183 
184 #ifdef NCBI_COMPILER_WORKSHOP
185 #  define NO_STD_CONSTRUCT
186 #  define NO_STD_DESTROY
187 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
188 #endif
189 
190 #ifdef NCBI_COMPILER_COMPAQ
191 #  define NO_STD_CONSTRUCT
192 #  define NO_STD_DESTROY
193 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
194 #endif
195 
196 #ifdef NCBI_COMPILER_MIPSPRO
197 #  define NO_STD_CONSTRUCT
198 #  define NO_STD_DESTROY
199 // replace cstddef with stddef.h
200 #  define _STLP_CSTDDEF
201 #  include <stddef.h>
202 #  define USE_NO_ALLOC_TRAITS
203 #endif
204 
205 #ifdef NCBI_COMPILER_VISUALAGE
206 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
207 #endif
208 
209 #ifdef _LIBCPP_VERSION
210 #  define NO_STD_CONSTRUCT
211 #  define NO_STD_DESTROY
212 #  define _STLP_MULTI_CONST_TEMPLATE_ARG_BUG // Don't try to use _Select1st
213 #endif
214 
215 #ifdef _DEBUG
216 #  define _STLP_DEBUG_UNINITIALIZED
217 // uninitialized value filler
218 // This value is designed to cause problems if an error occurs
219 #  define _STLP_SHRED_BYTE 0xA3
220 #endif
221 
222 
223 // Defined for WS, ICC
224 #ifdef _STLP_MULTI_CONST_TEMPLATE_ARG_BUG
225 // fbp : sort of select1st just for maps
226 template <class _Pair, class _Whatever>
227 // JDJ (CW Pro1 doesn't like const when first_type is also const)
228 struct __Select1st_hint
229 {
operator ()__Select1st_hint230     const _Whatever& operator () (const _Pair& __x) const { return __x.first; }
231 };
232 #  define  _STLP_SELECT1ST(__x,__y) __Select1st_hint< __x, __y >
233 #else
234 #  define  _STLP_SELECT1ST(__x, __y) _Select1st< __x >
235 #endif
236 
237 
238 // Use better string hash function (by Eugene Vasilchenko)
239 #ifndef NCBI_USE_STRING_HASH_FUNC__STLP
240 #  define NCBI_USE_STRING_HASH_FUNC__NCBI
241 #endif
242 
243 
244 //////////////////////////////////////////////////////////////////////
245 //
246 // Functions and classes required by STLport
247 //
248 
249 template <class _Tp>
_stlp_less(_Tp *)250 less<_Tp> _stlp_less(_Tp* ) { return less<_Tp>(); }
251 
252 
253 #ifdef NO_STD_CONSTRUCT
254 
255 template <class _T1, class _T2>
_Construct(_T1 * __p,const _T2 & __val)256 inline void _Construct(_T1* __p, const _T2& __val) {
257 #  ifdef _STLP_DEBUG_UNINITIALIZED
258     memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
259 #  endif
260     _STLP_PLACEMENT_NEW (__p) _T1(__val);
261 }
262 
263 template <class _T1>
_Construct(_T1 * __p)264 inline void _Construct(_T1* __p) {
265 #  ifdef _STLP_DEBUG_UNINITIALIZED
266     memset((char*)__p, _STLP_SHRED_BYTE, sizeof(_T1));
267 #  endif /* _STLP_DEBUG_UNINITIALIZED */
268 #  ifdef _STLP_DEFAULT_CONSTRUCTOR_BUG
269     typedef typename _Is_integer<_T1>::_Integral _Is_Integral;
270     _Construct_aux (__p, _Is_Integral() );
271 #  else
272     _STLP_PLACEMENT_NEW (__p) _T1();
273 #  endif /* if_STLP_DEFAULT_CONSTRUCTOR_BUG */
274 }
275 
276 #endif /* NO_STD_CONSTRUCT */
277 
278 
279 #ifdef NO_STD_DESTROY
280 
281 // _Destroy needs to be defined in std
282 namespace std {
283 
284 template <class _Tp>
_Destroy(_Tp * __pointer)285 inline void _Destroy(_Tp* __pointer) {
286     __pointer->~_Tp();
287 #ifdef _STLP_DEBUG_UNINITIALIZED
288     memset((char*)__pointer, _STLP_SHRED_BYTE, sizeof(_Tp));
289 #endif /* if_STLP_DEBUG_UNINITIALIZED */
290 }
291 
292 } /* namespace std */
293 
294 #endif /* NO_STD_DESTROY */
295 
296 
297 template <class _Tp>
298 struct _STLP_Identity
299 {
operator ()_STLP_Identity300     const _Tp& operator()(const _Tp& __x) const { return __x; }
301 };
302 
303 
304 // fbp: those are being used for iterator/const_iterator definitions everywhere
305 template <class _Tp>
306 struct _Nonconst_traits;
307 
308 template <class _Tp>
309 struct _Const_traits {
310   typedef _Tp value_type;
311   typedef const _Tp&  reference;
312   typedef const _Tp*  pointer;
313   typedef _Nonconst_traits<_Tp> _Non_const_traits;
314 };
315 
316 template <class _Tp>
317 struct _Nonconst_traits {
318   typedef _Tp value_type;
319   typedef _Tp& reference;
320   typedef _Tp* pointer;
321   typedef _Nonconst_traits<_Tp> _Non_const_traits;
322 };
323 
324 
325 #ifndef USE_NO_ALLOC_TRAITS
326 // The fully general version.
327 template <class _Tp, class _Allocator>
328 struct _Alloc_traits
329 {
330     typedef _Allocator _Orig;
331 #  if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
332     typedef typename _Allocator::_STLP_TEMPLATE rebind<_Tp> _Rebind_type;
333     typedef typename _Rebind_type::other  allocator_type;
create_allocator_Alloc_traits334     static allocator_type create_allocator(const _Orig& __a)
335     { return allocator_type(__a); }
336 #  else
337     // this is not actually true, used only to pass this type through
338     // to dynamic overload selection in _STLP_alloc_proxy methods
339     typedef _Allocator allocator_type;
340 #  endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
341 };
342 #endif /* USE_NO_ALLOC_TRAITS */
343 
344 #if defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
345 template <class _Tp, class _Alloc>
346 inline _STLP_TYPENAME_ON_RETURN_TYPE
347 _Alloc_traits<_Tp, _Alloc>::allocator_type  _STLP_CALL
__stl_alloc_create(const _Alloc & __a,const _Tp *)348 __stl_alloc_create(const _Alloc& __a, const _Tp*) {
349     typedef typename _Alloc::_STLP_TEMPLATE rebind<_Tp>::other _Rebound_type;
350     return _Rebound_type(__a);
351 }
352 #else
353 #  if defined(_RWSTD_VER) && !defined(_RWSTD_ALLOCATOR)
354 // BW_1: non standard Sun's allocators
355 #    define ALLOCATOR(T) allocator_interface<allocator<T>, T >
356 #  else
357 #    define ALLOCATOR(T) allocator<T>
358 #  endif
359 
360 // If custom allocators are being used without member template classes support:
361 // user (on purpose) is forced to define rebind/get operations !!!
362 template <class _Tp1, class _Tp2>
ALLOCATOR(_Tp2)363 inline ALLOCATOR(_Tp2)& _STLP_CALL
364 __stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*)
365 {  return (ALLOCATOR(_Tp2)&)(__a); }
366 template <class _Tp1, class _Tp2>
ALLOCATOR(_Tp2)367 inline ALLOCATOR(_Tp2) _STLP_CALL
368 __stl_alloc_create(const allocator<_Tp1>&, const _Tp2*)
369 { return ALLOCATOR(_Tp2)(); }
370 #endif /* _STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
371 
372 
373 // inheritance is being used for EBO optimization
374 template <class _Value, class _Tp, class _MaybeReboundAlloc>
375 class _STLP_alloc_proxy : public _MaybeReboundAlloc {
376 private:
377     typedef _MaybeReboundAlloc _Base;
378     typedef _STLP_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
379 public:
380     _Value _M_data;
_STLP_alloc_proxy(const _MaybeReboundAlloc & __a,_Value __p)381     inline _STLP_alloc_proxy(const _MaybeReboundAlloc& __a, _Value __p)
382         : _MaybeReboundAlloc(__a), _M_data(__p) {}
383 
384     // Unified interface to perform allocate()/deallocate() with limited
385     // language support
386 #if ! defined (_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM)
387     // else it is rebound already, and allocate() member is accessible
allocate(size_t __n)388     inline _Tp* allocate(size_t __n) {
389         return __stl_alloc_rebind(__STATIC_CAST(_Base&,*this),
390                                   (_Tp*)0).allocate(__n,0);
391     }
deallocate(_Tp * __p,size_t __n)392     inline void deallocate(_Tp* __p, size_t __n) {
393         __stl_alloc_rebind(__STATIC_CAST(_Base&, *this),
394                            (_Tp*)0).deallocate(__p, __n);
395     }
396 #endif /* !_STLP_USE_NESTED_TCLASS_THROUGHT_TPARAM */
397 };
398 
399 
400 //////////////////////////////////////////////////////////////////////
401 //
402 // Include STLport headers
403 //
404 
405 #include <corelib/hash_impl/_hash_fun.h>
406 #include <corelib/hash_impl/_hashtable.h>
407 #include <corelib/hash_impl/_hashtable.c>
408 
409 #undef __lower_bound
410 
411 
412 BEGIN_NCBI_SCOPE
413 
414 // String hash functions, see also NCBI_USE_STRING_HASH_FUNC__NCBI
415 
__stl_hash_string(const char * __s,size_t __l)416 inline size_t __stl_hash_string(const char* __s, size_t __l)
417 {
418 #ifdef NCBI_USE_STRING_HASH_FUNC__NCBI
419     unsigned long __h = (unsigned long) __l;
420     for ( ; __l; ++__s, --__l)
421         __h = __h*17 + *__s;
422 #else
423     unsigned long __h = 0;
424     for ( ; __l; ++__s, --__l)
425         __h = 5*__h + *__s;
426 #endif
427     return size_t(__h);
428 }
429 
430 template<> struct hash<const string>
431 {
operator ()hash432     size_t operator()(const string& s) const
433     {
434         return __stl_hash_string(s.data(), s.size());
435     }
436 };
437 
438 template<> struct hash<string>
439 {
operator ()hash440     size_t operator()(const string& s) const
441     {
442         return __stl_hash_string(s.data(), s.size());
443     }
444 };
445 
446 END_NCBI_SCOPE
447 
448 #endif /* STLP_DEFS__HPP */
449