ddc
DDCLessOperators.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 //
3 // DDC originally by Alexey Sokirko
4 // Changes and modifications 2011-2018 by Bryan Jurish
5 //
6 // This file is part of DDC.
7 //
8 // DDC is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // DDC is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with DDC. If not, see <http://www.gnu.org/licenses/>.
20 //
21 #ifndef DDCLessOperators_h
22 #define DDCLessOperators_h
23 
24 
25 
30 template <class IndexType, typename VectorType=vector<char> >
31 class LessIndexString1 : public binary_function<bool, const IndexType&, const char&>
32 {
33  const VectorType* m_pBuffer;
34 
35 public:
36 
37  LessIndexString1(const VectorType* pBuffer)
38  {
39  m_pBuffer = pBuffer;
40  }
42  bool operator()(const IndexType& Ref, const char* S2) const
43  {
44  const char* S1 = &((*m_pBuffer)[0]) + Ref.GetIndexItemOffset();
45  return strcmp(S1, S2) < 0;
46  }
47  bool operator()(const char* S1, const IndexType& Ref) const
48  {
49  const char* S2 = &((*m_pBuffer)[0]) + Ref.GetIndexItemOffset();
50  return strcmp(S1, S2) < 0;
51  }
52  bool operator()(const IndexType& Ref1, const IndexType& Ref2) const
53  {
54  const char* S1 = &((*m_pBuffer)[0]) + Ref1.GetIndexItemOffset();
55  const char* S2 = &((*m_pBuffer)[0]) + Ref2.GetIndexItemOffset();
56  return strcmp(S1, S2) < 0;
57  }
58 
60  bool are_equal(const IndexType& Ref, const char* S2) const
61  {
62  const char* S1 = &((*m_pBuffer)[0]) + Ref.GetIndexItemOffset();
63  return strcmp(S1, S2) == 0;
64  };
65 
66 };
67 
68 
69 
74 template <class IndexType, typename VectorType=vector<char> >
75 class LessIndexString2 : public binary_function<bool, const IndexType&, const IndexType&>
76 {
77  const VectorType* m_pBuffer1;
78  const VectorType* m_pBuffer2;
79 public:
80 
81  LessIndexString2(const VectorType* pBuffer1, const VectorType* pBuffer2 = 0)
82  {
83  m_pBuffer1 = pBuffer1;
84  m_pBuffer2 = (pBuffer2 != 0) ? pBuffer2 : pBuffer1;
85  }
86 
88  bool operator()(const IndexType& W1, const IndexType& W2) const
89  {
90  const char* S1 = &((*m_pBuffer1)[0]) + W1.GetIndexItemOffset();
91  const char* S2 = &((*m_pBuffer2)[0]) + W2.GetIndexItemOffset();
92  return strcmp(S1, S2) < 0;
93  }
94 
96  bool Greater(const IndexType& W1, const IndexType& W2) const
97  {
98  const char* S1 = &((*m_pBuffer1)[0]) + W1.GetIndexItemOffset();
99  const char* S2 = &((*m_pBuffer2)[0]) + W2.GetIndexItemOffset();
100  return strcmp(S1, S2) > 0;
101  }
102 };
103 
104 #endif
105 
106 /*--- emacs style variables ---
107  * Local Variables:
108  * mode: C++
109  * c-file-style: "ellemtel"
110  * c-basic-offset: 4
111  * tab-width: 8
112  * indent-tabs-mode: nil
113  * End:
114  */
const VectorType * m_pBuffer2
Definition: DDCLessOperators.h:78
const VectorType * m_pBuffer
Definition: DDCLessOperators.h:33
LessIndexString1(const VectorType *pBuffer)
Definition: DDCLessOperators.h:37
bool operator()(const IndexType &Ref, const char *S2) const
operator less for strings
Definition: DDCLessOperators.h:42
Definition: DDCLessOperators.h:31
const VectorType * m_pBuffer1
Definition: DDCLessOperators.h:77
bool Greater(const IndexType &W1, const IndexType &W2) const
operator greater for strings
Definition: DDCLessOperators.h:96
Definition: DDCLessOperators.h:75
bool operator()(const char *S1, const IndexType &Ref) const
Definition: DDCLessOperators.h:47
bool operator()(const IndexType &W1, const IndexType &W2) const
operator less for strings
Definition: DDCLessOperators.h:88
bool are_equal(const IndexType &Ref, const char *S2) const
operator == for strings
Definition: DDCLessOperators.h:60
LessIndexString2(const VectorType *pBuffer1, const VectorType *pBuffer2=0)
Definition: DDCLessOperators.h:81
bool operator()(const IndexType &Ref1, const IndexType &Ref2) const
Definition: DDCLessOperators.h:52