activemq-cpp-3.9.5
Equals.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#ifndef _DECAF_UTIL_COMPARATORS_EQUALS_H_
18#define _DECAF_UTIL_COMPARATORS_EQUALS_H_
19
21
22#include <decaf/lang/Pointer.h>
23
24namespace decaf {
25namespace util {
26namespace comparators {
27
33 template< typename E >
34 class Equals : public decaf::util::Comparator<E> {
35 public:
36
37 Equals() {}
38 virtual ~Equals() {}
39
40 virtual bool operator()(const E& left, const E& right) const {
41 return left == right;
42 }
43
44 virtual int compare(const E& o1, const E& o2) const {
45
46 if (o1 == o2) {
47 return 0;
48 }
49
50 if (o1 < o2) {
51 return -1;
52 }
53
54 return 1;
55 }
56
57 };
58
59 template< typename E >
60 class Equals< decaf::lang::Pointer<E> > : public decaf::util::Comparator<decaf::lang::Pointer<E> > {
61 public:
62
63 Equals() {}
64 virtual ~Equals() {}
65
66 virtual bool operator()(const decaf::lang::Pointer<E>& left, const decaf::lang::Pointer<E>& right) const {
67 if (left != NULL && right != NULL) {
68 return left->equals(*right);
69 } else if (left == NULL && right == NULL) {
70 return true;
71 }
72
73 return false;
74 }
75
76 virtual int compare(const decaf::lang::Pointer<E>& o1, const decaf::lang::Pointer<E>& o2) const {
77 if (o1 != NULL && o2 != NULL) {
78 return o1->compareTo(*o2);
79 }
80
81 if (o1.get() > o2.get()) {
82 return 1;
83 } else if (o1.get() < o2.get()) {
84 return -1;
85 }
86
87 return 0;
88 }
89
90 };
91
92}}}
93
94#endif /* _DECAF_UTIL_COMPARATORS_EQUALS_H_ */
Decaf's implementation of a Smart Pointer that is a template on a Type and is Thread Safe if the defa...
Definition Pointer.h:53
PointerType get() const
Gets the real pointer that is contained within this Pointer.
Definition Pointer.h:188
A comparison function, which imposes a total ordering on some collection of objects.
Definition Comparator.h:40
virtual int compare(const decaf::lang::Pointer< E > &o1, const decaf::lang::Pointer< E > &o2) const
Compares its two arguments for order.
Definition Equals.h:76
virtual bool operator()(const decaf::lang::Pointer< E > &left, const decaf::lang::Pointer< E > &right) const
Implementation of the Binary function interface as a means of allowing a Comparator to be passed to a...
Definition Equals.h:66
virtual int compare(const E &o1, const E &o2) const
Compares its two arguments for order.
Definition Equals.h:44
Equals()
Definition Equals.h:37
virtual ~Equals()
Definition Equals.h:38
virtual bool operator()(const E &left, const E &right) const
Implementation of the Binary function interface as a means of allowing a Comparator to be passed to a...
Definition Equals.h:40
#define NULL
Definition Config.h:33
Definition Equals.h:26
Definition AbstractCollection.h:33
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25