OgreMemorySTLAllocator.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _MemorySTLAllocator_H__
#define _MemorySTLAllocator_H__
#include "OgrePrerequisites.h"
#include "OgreHeaderPrefix.h"
namespace Ogre
{
// Base STL allocator class.
template<typename T>
struct STLAllocatorBase
{ // base class for generic allocators
typedef T value_type;
};
// Base STL allocator class. (const T version).
template<typename T>
struct STLAllocatorBase<const T>
{ // base class for generic allocators for const T
typedef T value_type;
};
template
<
typename T,
typename AllocPolicy
>
class STLAllocator : public STLAllocatorBase<T>
{
public :
typedef STLAllocatorBase<T> Base;
typedef typename Base::value_type value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
template<typename U>
struct rebind
{
typedef STLAllocator<U, AllocPolicy> other;
};
inline explicit STLAllocator()
{ }
virtual ~STLAllocator()
{ }
inline STLAllocator( STLAllocator const& )
{ }
template <typename U>
inline STLAllocator( STLAllocator<U, AllocPolicy> const& )
{ }
template <typename U, typename P>
inline STLAllocator( STLAllocator<U, P> const& )
{ }
inline pointer allocate( size_type count,
typename std::allocator<void>::const_pointer ptr = 0 )
{
(void)ptr;
// convert request to bytes
register size_type sz = count*sizeof( T );
pointer p = static_cast<pointer>(AllocPolicy::allocateBytes(sz));
return p;
}
inline void deallocate( pointer ptr, size_type )
{
// convert request to bytes, but we can't use this?
// register size_type sz = count*sizeof( T );
AllocPolicy::deallocateBytes(ptr);
}
pointer address(reference x) const
{
return &x;
}
const_pointer address(const_reference x) const
{
return &x;
}
size_type max_size() const throw()
{
// maximum size this can handle, delegate
return AllocPolicy::getMaxAllocationSize();
}
#if __cplusplus < 201103L
void construct(pointer p)
{
// call placement new
new(static_cast<void*>(p)) T();
}
#endif
void construct(pointer p, const T& val)
{
// call placement new
new(static_cast<void*>(p)) T(val);
}
void destroy(pointer p)
{
// do we have to protect against non-classes here?
// some articles suggest yes, some no
p->~T();
}
};
template<typename T, typename T2, typename P>
inline bool operator==(STLAllocator<T,P> const&,
STLAllocator<T2,P> const&)
{
// same alloc policy (P), memory can be freed
return true;
}
template<typename T, typename P, typename OtherAllocator>
inline bool operator==(STLAllocator<T,P> const&,
OtherAllocator const&)
{
return false;
}
template<typename T, typename T2, typename P>
inline bool operator!=(STLAllocator<T,P> const&,
STLAllocator<T2,P> const&)
{
// same alloc policy (P), memory can be freed
return false;
}
template<typename T, typename P, typename OtherAllocator>
inline bool operator!=(STLAllocator<T,P> const&,
OtherAllocator const&)
{
return true;
}
}// namespace Ogre
#include "OgreHeaderSuffix.h"
#endif // _MemorySTLAllocator_H__
Ogre::STLAllocator::Base
STLAllocatorBase< T > Base
define our types, as per ISO C++
Definition: OgreMemorySTLAllocator.h:85
Ogre::STLAllocator::reference
value_type & reference
Definition: OgreMemorySTLAllocator.h:89
Ogre::STLAllocator::address
const_pointer address(const_reference x) const
Definition: OgreMemorySTLAllocator.h:148
Ogre::STLAllocatorBase
Wrapper class for operating as an STL container allocator.
Definition: OgreMemorySTLAllocator.h:64
Ogre::STLAllocator
Definition: OgreMemorySTLAllocator.h:81
Ogre::STLAllocator::rebind
the standard rebind mechanism
Definition: OgreMemorySTLAllocator.h:97
Ogre::STLAllocator::destroy
void destroy(pointer p)
Definition: OgreMemorySTLAllocator.h:173
Ogre::STLAllocator::difference_type
std::ptrdiff_t difference_type
Definition: OgreMemorySTLAllocator.h:92
Ogre::STLAllocator::construct
void construct(pointer p)
Definition: OgreMemorySTLAllocator.h:160
Ogre::STLAllocatorBase::value_type
T value_type
Definition: OgreMemorySTLAllocator.h:66
Ogre::STLAllocator::construct
void construct(pointer p, const T &val)
Definition: OgreMemorySTLAllocator.h:167
Ogre::STLAllocator::value_type
Base::value_type value_type
Definition: OgreMemorySTLAllocator.h:86
Ogre::STLAllocator::rebind::other
STLAllocator< U, AllocPolicy > other
Definition: OgreMemorySTLAllocator.h:99
Ogre::STLAllocator::STLAllocator
STLAllocator(STLAllocator< U, P > const &)
cast
Definition: OgreMemorySTLAllocator.h:121
Ogre::STLAllocator::size_type
std::size_t size_type
Definition: OgreMemorySTLAllocator.h:91
Ogre::STLAllocatorBase< const T >::value_type
T value_type
Definition: OgreMemorySTLAllocator.h:73
Ogre::STLAllocator::STLAllocator
STLAllocator(STLAllocator const &)
copy ctor - done component wise
Definition: OgreMemorySTLAllocator.h:111
OgrePrerequisites.h
Ogre::operator!=
bool operator!=(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:202
Ogre::STLAllocator::const_pointer
const value_type * const_pointer
Definition: OgreMemorySTLAllocator.h:88
Ogre::STLAllocator::pointer
value_type * pointer
Definition: OgreMemorySTLAllocator.h:87
OgreHeaderSuffix.h
Ogre::STLAllocator::const_reference
const value_type & const_reference
Definition: OgreMemorySTLAllocator.h:90
Ogre::STLAllocator::deallocate
void deallocate(pointer ptr, size_type)
memory deallocation (elements, used by STL)
Definition: OgreMemorySTLAllocator.h:136
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::STLAllocator::allocate
pointer allocate(size_type count, typename std::allocator< void >::const_pointer ptr=0)
memory allocation (elements, used by STL)
Definition: OgreMemorySTLAllocator.h:125
OgreHeaderPrefix.h
Ogre::operator==
bool operator==(STLAllocator< T, P > const &, STLAllocator< T2, P > const &)
determine equality, can memory from another allocator be released by this allocator, (ISO C++)
Definition: OgreMemorySTLAllocator.h:184
Ogre::STLAllocator::STLAllocator
STLAllocator(STLAllocator< U, AllocPolicy > const &)
cast
Definition: OgreMemorySTLAllocator.h:116
Ogre::STLAllocator::~STLAllocator
virtual ~STLAllocator()
dtor
Definition: OgreMemorySTLAllocator.h:107
Ogre::STLAllocator::STLAllocator
STLAllocator()
ctor
Definition: OgreMemorySTLAllocator.h:103
Ogre::STLAllocator::address
pointer address(reference x) const
Definition: OgreMemorySTLAllocator.h:143
Ogre::STLAllocator::max_size
size_type max_size() const
Definition: OgreMemorySTLAllocator.h:153

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.