activemq-cpp-3.4.0

src/main/decaf/internal/util/TimerTaskHeap.h

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef _DECAF_INTERNAL_UTIL_TIMERTASKHEAP_H_
00019 #define _DECAF_INTERNAL_UTIL_TIMERTASKHEAP_H_
00020 
00021 #include <decaf/util/Config.h>
00022 
00023 #include <decaf/util/TimerTask.h>
00024 #include <decaf/lang/Pointer.h>
00025 
00026 namespace decaf {
00027 namespace internal {
00028 namespace util {
00029 
00030     using decaf::lang::Pointer;
00031     using decaf::util::TimerTask;
00032 
00038     class DECAF_API TimerTaskHeap {
00039     private:
00040 
00041         // The default size of the Heap at creation.
00042         static const int DEFAULT_HEAP_SIZE = 256;
00043 
00044         // Dynamic Array of TimerTasks used to represent the heap
00045         std::vector< Pointer<TimerTask> > heap;
00046 
00047     public:
00048 
00049         TimerTaskHeap();
00050         virtual ~TimerTaskHeap();
00051 
00058         Pointer<TimerTask> peek();
00059 
00063         bool isEmpty() const;
00064 
00068         std::size_t size() const;
00069 
00077         void insert( const Pointer<TimerTask>& task );
00078 
00086         void remove( std::size_t pos );
00087 
00091         void reset();
00092 
00096         void adjustMinimum();
00097 
00105         std::size_t deleteIfCancelled();
00106 
00113         std::size_t find( const Pointer<TimerTask>& task ) const;
00114 
00115     private:
00116 
00117         void upHeap();
00118         void downHeap( std::size_t pos );
00119 
00120     };
00121 
00122 }}}
00123 
00124 #endif /* _DECAF_INTERNAL_UTIL_TIMERTASKHEAP_H_ */