Like.cpp
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/dataaccess/query/Like.cpp
22 
23  \brief It is intended to encode a character string comparison operator with pattern matching.
24 */
25 
26 // TerraLib
27 #include "Expression.h"
28 #include "FunctionNames.h"
29 #include "Like.h"
30 #include "LiteralString.h"
31 
32 // STL
33 #include <cassert>
34 
36  const std::string& pattern,
37  const std::string& wildCard,
38  const std::string& singleChar,
39  const std::string& escapeChar)
40  : Function(FunctionNames::sm_Like),
41  m_pattern(pattern),
42  m_wildCard(wildCard),
43  m_singleChar(singleChar),
44  m_escapeChar(escapeChar)
45 {
46  m_args.push_back(str);
47 }
48 
50  const std::string& pattern,
51  const std::string& wildCard,
52  const std::string& singleChar,
53  const std::string& escapeChar)
54  : Function(FunctionNames::sm_Like),
55  m_pattern(pattern),
56  m_wildCard(wildCard),
57  m_singleChar(singleChar),
58  m_escapeChar(escapeChar)
59 {
60  m_args.push_back(str.clone());
61 }
62 
63 te::da::Like::~Like() = default;
64 
65 te::da::Like::Like(const Like& rhs)
66 
67  = default;
68 
70 {
71  if(this != &rhs)
72  {
74  m_pattern = rhs.m_pattern;
75  m_wildCard = rhs.m_wildCard;
78  }
79 
80  return *this;
81 }
82 
84 {
85  return new Like(*this);
86 }
87 
89 {
90  return m_args[0];
91 }
92 
94 {
95  delete m_args[0];
96  m_args[0] = str;
97 }
98 
99 const std::string& te::da::Like::getPattern()
100 {
101  return m_pattern;
102 }
103 
104 void te::da::Like::setPattern(const std::string& p)
105 {
106  m_pattern = p;
107 }
108 
109 void te::da::Like::setWildCard(const std::string& w)
110 {
111  m_wildCard = w;
112 }
113 
114 const std::string& te::da::Like::getWildCard() const
115 {
116  return m_wildCard;
117 }
118 
119 void te::da::Like::setSingleChar(const std::string& s)
120 {
121  m_singleChar = s;
122 }
123 
124 const std::string& te::da::Like::getSingleChar() const
125 {
126  return m_singleChar;
127 }
128 
129 void te::da::Like::setEscapeChar(const std::string& e)
130 {
131  m_escapeChar = e;
132 }
133 
134 const std::string& te::da::Like::getEscapeChar() const
135 {
136  return m_escapeChar;
137 }
138 
const std::string & getEscapeChar() const
It returns the escape character.
Definition: Like.cpp:134
Expression * getString() const
It returns the string expression to be compared with the like operator.
Definition: Like.cpp:88
~Like()
Destructor.
void setPattern(const std::string &p)
It sets the pattern to be used in the comparison.
Definition: Like.cpp:104
virtual Expression * clone() const =0
It creates a new copy of this expression.
const std::string & getPattern()
It returns the pattern used in the comparison.
Definition: Like.cpp:99
std::string m_escapeChar
The escape char character is used to escape the meaning of the wild card, single char and escape char...
Definition: Like.h:154
It is intended to encode a character string comparison operator with pattern matching.
void setEscapeChar(const std::string &e)
It sets the escape character.
Definition: Like.cpp:129
This is an abstract class that models a query expression.
Expression * clone() const
It creates a new copy of this expression.
Definition: Like.cpp:83
const std::string & getWildCard() const
It returns the wild character.
Definition: Like.cpp:114
TE_DEFINE_VISITABLE Like(Expression *str, const std::string &pattern, const std::string &wildCard="%", const std::string &singleChar="_", const std::string &escapeChar="\\")
Constructor.
Definition: Like.cpp:35
void setWildCard(const std::string &w)
It sets the wild character.
Definition: Like.cpp:109
It is intended to encode a character string comparison operator with pattern matching.
Definition: Like.h:43
te::gm::Polygon * p
This is an abstract class that models a query expression.
A class that models a Function expression.
A class that models a Literal String value.
Like & operator=(const Like &rhs)
Definition: Like.cpp:69
std::string m_pattern
The literal string pattern.
Definition: Like.h:151
void setString(Expression *str)
It sets the string expression to be compared with the like operator.
Definition: Like.cpp:93
const std::string & getSingleChar() const
It returns the single wild character.
Definition: Like.cpp:124
A static class with global function name definitions.
Function & operator=(const Function &rhs)
std::string m_singleChar
The single char character matches exactly one character.
Definition: Like.h:153
std::vector< Expression * > m_args
The list of arguments.
void setSingleChar(const std::string &s)
It sets the wild single character.
Definition: Like.cpp:119
A static class with global function name definitions.
Definition: FunctionNames.h:45
std::string m_wildCard
The wild card character matches zero or more characters.
Definition: Like.h:152