32 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 33 TypeName(const TypeName&); \ 34 void operator=(const TypeName&) 54 template<
typename T,
size_t stack_capacity>
57 typedef typename std::allocator<T>::pointer pointer;
58 typedef typename std::allocator<T>::size_type size_type;
64 Source() : used_stack_buffer_(
false) {
68 T* stack_buffer() {
return reinterpret_cast<T*
>(stack_buffer_); }
69 const T* stack_buffer()
const {
70 return reinterpret_cast<const T*
>(stack_buffer_);
83 char stack_buffer_[
sizeof(T[stack_capacity])];
87 bool used_stack_buffer_;
98 : source_(rhs.source_) {
110 template<
typename U,
size_t other_capacity>
115 explicit StackAllocator(
Source* source) : source_(source) {
121 pointer allocate(size_type n,
void* hint = 0) {
122 if (source_ != NULL && !source_->used_stack_buffer_
123 && n <= stack_capacity) {
124 source_->used_stack_buffer_ =
true;
125 return source_->stack_buffer();
127 return std::allocator<T>::allocate(n, hint);
133 void deallocate(pointer p, size_type n) {
134 if (source_ != NULL && p == source_->stack_buffer())
135 source_->used_stack_buffer_ =
false;
137 std::allocator<T>::deallocate(p, n);
152 template<
typename TContainerType,
int stack_capacity>
155 typedef TContainerType ContainerType;
156 typedef typename ContainerType::value_type ContainedType;
160 StackContainer() : allocator_(&stack_data_), container_(allocator_) {
163 container_.reserve(stack_capacity);
172 ContainerType& container() {
return container_; }
173 const ContainerType& container()
const {
return container_; }
178 ContainerType* operator->() {
return &container_; }
179 const ContainerType* operator->()
const {
return &container_; }
184 const typename Allocator::Source& stack_data()
const {
190 typename Allocator::Source stack_data_;
191 Allocator allocator_;
192 ContainerType container_;
198 template<
size_t stack_capacity>
200 std::basic_string<char,
201 std::char_traits<char>,
202 StackAllocator<char, stack_capacity> >,
206 std::basic_string<char,
207 std::char_traits<char>,
222 template<
typename T,
size_t stack_capacity>
224 std::vector<T, StackAllocator<T, stack_capacity> >,
228 std::vector<T, StackAllocator<T, stack_capacity> >,
238 std::vector<T, StackAllocator<T, stack_capacity> >,
240 this->container().assign(other->begin(), other->end());
245 this->container().assign(other->begin(), other->end());
251 T& operator[](
size_t i) {
return this->container().operator[](i); }
252 const T& operator[](
size_t i)
const {
253 return this->container().operator[](i);
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: stack_containers.hpp:63
Definition: stack_containers.hpp:223
Definition: stack_containers.hpp:92
Definition: stack_containers.hpp:55
Definition: stack_containers.hpp:153
Definition: stack_containers.hpp:199