// // 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_IMPL_H__ #define MP_SHORT_QUEUE_IMPL_H__ namespace mp { template short_queue::short_queue() : start(NULL) { } template short_queue::~short_queue() { clear(); } template void short_queue::push() { item_t* i = get_allocator().allocate(1); new (i->object) T(); i->next = start; start = i; } MP_ARGS_BEGIN template template void short_queue::push(MP_ARGS_PARAMS) { item_t* i = get_allocator().allocate(1); new (i->object) T(MP_ARGS_FUNC); i->next = start; start = i; } MP_ARGS_END template void short_queue::pop() { if(empty()) { return; } // FIXME item_t* i = start; while(i->next != NULL) { i = i->next; } reinterpret_cast(i->object)->~T(); get_allocator().deallocate(i, 1); i->next = NULL; } template void short_queue::clear() { // FIXME 逆順 while(start != NULL) { item_t* i = start; start = start->next; reinterpret_cast(i->object)->~T(); get_allocator().deallocate(i, 1); } } template bool short_queue::empty() const { return start == NULL; } template typename short_queue::iterator short_queue::begin() { return iterator(start); } template typename short_queue::iterator short_queue::end() { return iterator(NULL); } template typename short_queue::reference short_queue::top() { return *begin(); } template typename short_queue::const_reference short_queue::top() const { return *begin(); } template typename short_queue::allocator_type short_queue::get_allocator() const { return allocator_type(); } } // namespace mp #endif /* mp/queue_impl.h */