|
|
|
@ -53,184 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|
|
|
|
#include <set> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* derived stl classes that use our heap manager |
|
|
|
|
* |
|
|
|
|
***/ |
|
|
|
|
|
|
|
|
|
// TEMPLATE CLASS cyallocator
|
|
|
|
|
template<class _Ty> |
|
|
|
|
class cyallocator |
|
|
|
|
: public std::allocator<_Ty> |
|
|
|
|
{ // generic cyallocator for objects of class _Ty
|
|
|
|
|
public: |
|
|
|
|
typedef std::allocator<_Ty> _Mybase; |
|
|
|
|
typedef typename _Mybase::value_type value_type; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef value_type* pointer; |
|
|
|
|
typedef value_type& reference; |
|
|
|
|
typedef const value_type* const_pointer; |
|
|
|
|
typedef const value_type& const_reference; |
|
|
|
|
|
|
|
|
|
typedef size_t size_type; |
|
|
|
|
typedef ptrdiff_t difference_type; |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
struct rebind |
|
|
|
|
{ // convert an cyallocator<_Ty> to an cyallocator <_Other>
|
|
|
|
|
typedef cyallocator<_Other> other; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
pointer address(reference _Val) const |
|
|
|
|
{ // return address of mutable _Val
|
|
|
|
|
return (&_Val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const_pointer address(const_reference _Val) const |
|
|
|
|
{ // return address of nonmutable _Val
|
|
|
|
|
return (&_Val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cyallocator() |
|
|
|
|
{ // construct default cyallocator (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cyallocator(const cyallocator<_Ty>&) |
|
|
|
|
{ // construct by copying (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
cyallocator(const cyallocator<_Other>&) |
|
|
|
|
{ // construct from a related cyallocator (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
cyallocator<_Ty>& operator=(const cyallocator<_Other>&) |
|
|
|
|
{ // assign from a related cyallocator (do nothing)
|
|
|
|
|
return (*this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void deallocate(pointer _Ptr, size_type) |
|
|
|
|
{ // deallocate object at _Ptr, ignore size
|
|
|
|
|
free(_Ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pointer allocate(size_type _Count) |
|
|
|
|
{ // allocate array of _Count elements
|
|
|
|
|
return (pointer)malloc(_Count * sizeof(_Ty)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pointer allocate(size_type _Count, const void*) |
|
|
|
|
{ // allocate array of _Count elements, ignore hint
|
|
|
|
|
return (allocate(_Count)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void construct(pointer _Ptr, const _Ty& _Val) |
|
|
|
|
{ // construct object at _Ptr with value _Val
|
|
|
|
|
std::_Construct(_Ptr, _Val); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void destroy(pointer _Ptr) |
|
|
|
|
{ // destroy object at _Ptr
|
|
|
|
|
std::_Destroy(_Ptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
size_t max_size() const |
|
|
|
|
{ // estimate maximum array size
|
|
|
|
|
size_t _Count = (size_t)(-1) / sizeof (_Ty); |
|
|
|
|
return (0 < _Count ? _Count : 1); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// cyallocator TEMPLATE OPERATORS
|
|
|
|
|
template<class _Ty, |
|
|
|
|
class _Other> inline |
|
|
|
|
bool operator==(const cyallocator<_Ty>&, const cyallocator<_Other>&) |
|
|
|
|
{ // test for cyallocator equality (always true)
|
|
|
|
|
return (true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class _Ty, |
|
|
|
|
class _Other> inline |
|
|
|
|
bool operator!=(const cyallocator<_Ty>&, const cyallocator<_Other>&) |
|
|
|
|
{ // test for cyallocator inequality (always false)
|
|
|
|
|
return (false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifndef _CRTIMP2 |
|
|
|
|
#define _CRTIMP2 |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// CLASS cyallocator<void>
|
|
|
|
|
template<> class _CRTIMP2 cyallocator<void> |
|
|
|
|
{ // generic cyallocator for type void
|
|
|
|
|
public: |
|
|
|
|
typedef void _Ty; |
|
|
|
|
typedef _Ty* pointer; |
|
|
|
|
typedef const _Ty* const_pointer; |
|
|
|
|
typedef _Ty value_type; |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
struct rebind |
|
|
|
|
{ // convert an cyallocator<void> to an cyallocator <_Other>
|
|
|
|
|
typedef cyallocator<_Other> other; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
cyallocator() |
|
|
|
|
{ // construct default cyallocator (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cyallocator(const cyallocator<_Ty>&) |
|
|
|
|
{ // construct by copying (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
cyallocator(const cyallocator<_Other>&) |
|
|
|
|
{ // construct from related cyallocator (do nothing)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template<class _Other> |
|
|
|
|
cyallocator<_Ty>& operator=(const cyallocator<_Other>&) |
|
|
|
|
{ // assign from a related cyallocator (do nothing)
|
|
|
|
|
return (*this); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* Drop-in replacements for stl classes. Uses our allocator instead of the default one. |
|
|
|
|
* |
|
|
|
|
***/ |
|
|
|
|
|
|
|
|
|
typedef std::basic_string<char, std::char_traits<char>, cyallocator<char> > cystring; |
|
|
|
|
typedef std::basic_string<wchar_t, std::char_traits<wchar_t>, cyallocator<wchar_t> > cywstring; |
|
|
|
|
// cyistring and cyiwstring declared later in this file
|
|
|
|
|
|
|
|
|
|
// TEMPLATE CLASS cyvector
|
|
|
|
|
template<class _Ty> |
|
|
|
|
class cyvector : public std::vector<_Ty, cyallocator<_Ty> > { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// TEMPLATE CLASS cymap
|
|
|
|
|
template<class _Kty, class _Ty, class _Pr=std::less<_Kty> > |
|
|
|
|
class cymap : public std::map<_Kty, _Ty, _Pr, cyallocator<std::pair<_Kty, _Ty > > > { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// TEMPLATE CLASS cylist
|
|
|
|
|
template<class _Ty> |
|
|
|
|
class cylist : public std::list<_Ty, cyallocator<_Ty> > { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// TEMPLATE CLASS cyset
|
|
|
|
|
template<class _Kty, class _Pr = std::less<_Kty> > |
|
|
|
|
class cyset : public std::set<_Kty, _Pr, cyallocator< _Kty > > { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* stl extensions |
|
|
|
@ -347,11 +169,6 @@ struct wstricmp_char_traits : public std::char_traits< wchar_t >
|
|
|
|
|
typedef std::basic_string<char, stricmp_char_traits> istring; |
|
|
|
|
typedef std::basic_string<wchar_t, wstricmp_char_traits> iwstring; |
|
|
|
|
|
|
|
|
|
// cyallocator version of istring
|
|
|
|
|
typedef std::basic_string<char, stricmp_char_traits, cyallocator<char> > cyistring; |
|
|
|
|
typedef std::basic_string<wchar_t, wstricmp_char_traits, cyallocator<wchar_t> > cyiwstring; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// std::string trim
|
|
|
|
|
std::string & trimleft(std::string & s, const char * charset=" \t\n\r"); |
|
|
|
|
std::wstring & trimleft(std::wstring & s, const wchar_t * charset=L" \t\n\r"); |
|
|
|
|