activemq-cpp-3.6.0
AbstractQueue.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef ABSTRACTQUEUE_H_
19 #define ABSTRACTQUEUE_H_
20 
21 #include <decaf/util/Config.h>
26 #include <decaf/lang/Iterable.h>
27 #include <decaf/util/Iterator.h>
28 #include <decaf/util/Queue.h>
29 #include <memory>
30 
31 namespace decaf {
32 namespace util {
33 
46  template< typename E >
47  class AbstractQueue : public decaf::util::Queue<E>,
49  public:
50 
51  AbstractQueue() : Queue<E>() {}
52 
53  virtual ~AbstractQueue() {}
54 
61  virtual bool add(const E& value) {
62 
63  if (this->offer(value )) {
64  return true;
65  }
66 
68  __FILE__, __LINE__, "Unable to add specified element to the Queue." );
69  }
70 
78  virtual bool addAll(const Collection<E>& collection) {
79 
80  if (this == &collection) {
82  __FILE__, __LINE__, "A Queue cannot be added to itself." );
83  }
84 
85  return AbstractCollection<E>::addAll(collection);
86  }
87 
89 
95  virtual E remove() {
96 
97  E result;
98  if (this->poll(result) == true) {
99  return result;
100  }
101 
103  __FILE__, __LINE__, "Unable to remove specified element from the Queue." );
104  }
105 
112  virtual E element() const {
113 
114  E result;
115  if (this->peek( result ) == true) {
116  return result;
117  }
118 
120  __FILE__, __LINE__, "Unable to remove specified element from the Queue." );
121  }
122 
128  virtual void clear() {
129 
130  if (this->isEmpty()) {
131  return;
132  }
133 
134  E result;
135  bool successful = true;
136 
137  do {
138  successful = this->poll(result);
139  } while(successful);
140  }
141  };
142 
143 }}
144 
145 #endif /* ABSTRACTQUEUE_H_ */