All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
64 {
65 }
66 
68  : Function(rhs),
69  m_pattern(rhs.m_pattern),
70  m_wildCard(rhs.m_wildCard),
71  m_singleChar(rhs.m_singleChar),
72  m_escapeChar(rhs.m_escapeChar)
73 {
74 }
75 
77 {
78  if(this != &rhs)
79  {
81  m_pattern = rhs.m_pattern;
82  m_wildCard = rhs.m_wildCard;
83  m_singleChar = rhs.m_singleChar;
84  m_escapeChar = rhs.m_escapeChar;
85  }
86 
87  return *this;
88 }
89 
91 {
92  return new Like(*this);
93 }
94 
96 {
97  return m_args[0];
98 }
99 
101 {
102  delete m_args[0];
103  m_args[0] = str;
104 }
105 
106 const std::string& te::da::Like::getPattern()
107 {
108  return m_pattern;
109 }
110 
111 void te::da::Like::setPattern(const std::string& p)
112 {
113  m_pattern = p;
114 }
115 
116 void te::da::Like::setWildCard(const std::string& w)
117 {
118  m_wildCard = w;
119 }
120 
121 const std::string& te::da::Like::getWildCard() const
122 {
123  return m_wildCard;
124 }
125 
126 void te::da::Like::setSingleChar(const std::string& s)
127 {
128  m_singleChar = s;
129 }
130 
131 const std::string& te::da::Like::getSingleChar() const
132 {
133  return m_singleChar;
134 }
135 
136 void te::da::Like::setEscapeChar(const std::string& e)
137 {
138  m_escapeChar = e;
139 }
140 
141 const std::string& te::da::Like::getEscapeChar() const
142 {
143  return m_escapeChar;
144 }
145 
const std::string & getEscapeChar() const
It returns the escape character.
Definition: Like.cpp:141
Expression * getString() const
It returns the string expression to be compared with the like operator.
Definition: Like.cpp:95
~Like()
Destructor.
Definition: Like.cpp:63
void setPattern(const std::string &p)
It sets the pattern to be used in the comparison.
Definition: Like.cpp:111
const std::string & getPattern()
It returns the pattern used in the comparison.
Definition: Like.cpp:106
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:136
This is an abstract class that models a query expression.
Definition: Expression.h:47
Expression * clone() const
It creates a new copy of this expression.
Definition: Like.cpp:90
const std::string & getWildCard() const
It returns the wild character.
Definition: Like.cpp:121
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:116
It is intended to encode a character string comparison operator with pattern matching.
Definition: Like.h:43
This is an abstract class that models a query expression.
A class that models a Function expression.
Definition: Function.h:47
A class that models a Literal String value.
Like & operator=(const Like &rhs)
Definition: Like.cpp:76
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:100
const std::string & getSingleChar() const
It returns the single wild character.
Definition: Like.cpp:131
A static class with global function name definitions.
Function & operator=(const Function &rhs)
Definition: Function.cpp:44
virtual Expression * clone() const =0
It creates a new copy of this expression.
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.
Definition: Function.h:118
void setSingleChar(const std::string &s)
It sets the wild single character.
Definition: Like.cpp:126
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