Loading...
Searching...
No Matches
Comparators.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file terralib/common/Comparators.h
22
23 \brief Several functor types for comparing objects.
24
25 \ingroup common
26 */
27
28#ifndef __TERRALIB_COMMON_INTERNAL_COMPARATORS_H
29#define __TERRALIB_COMMON_INTERNAL_COMPARATORS_H
30
31// STL
32#include <cstring>
33
34namespace te
35{
36 namespace common
37 {
38 /*!
39 \struct LessCmp
40
41 \brief It implements several compare functions.
42 */
43 template<class T> struct LessCmp
44 {
45 /*!
46 \brief It compares two NULL terminated C-strings.
47
48 \param f The first string.
49 \param s The second string.
50
51 \return True if the first string comes first in lexicographic order.
52 */
53 bool operator()(const T& f, const T& s) const
54 {
55 return f < s;
56 }
57 };
58
59 /*!
60 \struct LessCmp
61
62 \brief It implements several compare functions.
63 */
64 template<class T> struct LessCmp<T*>
65 {
66 /*!
67 \brief It compares two NULL terminated C-strings.
68
69 \param f The first string.
70 \param s The second string.
71
72 \return True if the first string comes first in lexicographic order.
73 */
74 bool operator()(const T* f, const T* s) const
75 {
76 return *f < *s;
77 }
78 };
79
80 /*!
81 \struct LessCmp
82
83 \brief It implements several compare functions.
84 */
85 template<> struct LessCmp<const char*>
86 {
87 /*!
88 \brief It compares two NULL terminated C-strings.
89
90 \param f The first string.
91 \param s The second string.
92
93 \return True if the first string comes first in lexicographic order.
94 */
95 bool operator()(const char* f, const char* s) const
96 {
97 return (strcmp(f, s) < 0 ? true : false);
98 }
99 };
100 } // end namespace common
101} // end namespace te
102
103#endif // __TERRALIB_COMMON_INTERNAL_COMPARATORS_H
104
TerraLib.
bool operator()(const T *f, const T *s) const
It compares two NULL terminated C-strings.
Definition: Comparators.h:74
bool operator()(const char *f, const char *s) const
It compares two NULL terminated C-strings.
Definition: Comparators.h:95
It implements several compare functions.
Definition: Comparators.h:44
bool operator()(const T &f, const T &s) const
It compares two NULL terminated C-strings.
Definition: Comparators.h:53