// // mp::short_queue // // Copyright (C) 2008 FURUHASHI Sadayuki // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef MP_SHORT_QUEUE_H__ #define MP_SHORT_QUEUE_H__ namespace mp { template struct short_queue_item { char object[sizeof(T)]; short_queue_item* next; }; template > > class short_queue { public: short_queue(); ~short_queue(); public: typedef T value_type; typedef T* pointer; typedef const T* const_pointer; typedef T& reference; typedef const T& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; typedef Allocator allocator_type; public: typedef short_queue_item item_t; class iterator { public: iterator() : node(NULL) {} iterator(item_t* n) : node(n) {} public: typedef ptrdiff_t difference_type; typedef std::forward_iterator_tag iterator_category; typedef T value_type; typedef T* pointer; typedef T& reference; public: reference operator* () const { return *reinterpret_cast(node->object); } pointer operator-> () const { return reinterpret_cast(node->object); } iterator& operator++ () { node = node->next; return *this; } iterator operator++ (int) { iterator tmp = *this; node = node->next; return tmp; } bool operator== (const iterator& x) const { return node == x.node; } bool operator!= (const iterator& x) const { return node != x.node; } private: item_t* node; }; class const_iterator { public: const_iterator() : node(NULL) {} const_iterator(const item_t* n) : node(n) {} public: typedef ptrdiff_t difference_type; typedef std::forward_iterator_tag iterator_category; typedef T value_type; typedef const T* pointer; typedef const T& reference; public: reference operator* () const { return *reinterpret_cast(node->object); } pointer operator-> () const { return reinterpret_cast(node->object); } iterator& operator++ () { node = node->next; return *this; } iterator operator++ (int) { iterator tmp = *this; node = node->next; return tmp; } bool operator== (const iterator& x) const { return node == x.node; } bool operator!= (const iterator& x) const { return node != x.node; } private: const item_t* node; }; public: void push(); MP_ARGS_BEGIN template void push(MP_ARGS_PARAMS); MP_ARGS_END void pop(); void clear(); iterator begin(); iterator end(); reference top(); const_reference top() const; bool empty() const; private: item_t* start; private: allocator_type get_allocator() const; }; } // namespace mp #include "mp/short_queue_impl.h" #endif /* mp/short_queue.h */