AttributeRestrictionVisitor.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/AttributeRestrictionVisitor.cpp
22 
23  \brief A visitor that retrieves attribute restrictions from a Query hierarchy.
24 */
25 
26 // TerraLib
27 #include "../../common/STLUtils.h"
28 #include "../../core/translator/Translator.h"
29 #include "../Exception.h"
31 #include "Expression.h"
32 #include "Function.h"
33 #include "FunctionNames.h"
34 #include "PropertyName.h"
35 #include "Select.h"
36 #include "Where.h"
37 
38 // STL
39 #include <cassert>
40 
42  : m_index(0),
43  m_op(""),
44  m_function(nullptr)
45 {
46 }
47 
49 
51  : m_index(0)
52 {
53  initialize();
54 }
55 
57 {
59 }
60 
62 {
64  {
65  addAttributeRestriction(visited);
66  return;
67  }
68 
69  std::size_t size = visited.getNumArgs();
70  for(std::size_t i = 0; i < size; ++i)
71  {
72  assert(visited[i]);
73  visited[i]->accept(*this);
74  }
75 }
76 
78 {
79  Where* restriction = visited.getWhere();
80 
81  if(!restriction)
82  return;
83 
84  Expression* e = restriction->getExp();
85  if(e)
86  e->accept(*this);
87 }
88 
90 {
91  return !m_attrRestrictions.empty();
92 }
93 
94 const std::vector<te::da::AttributeRestriction*>& te::da::AttributeRestrictionVisitor::getAttributeRestrictions() const
95 {
96  return m_attrRestrictions;
97 }
98 
100 {
101  // Initializes the map of attribute restriction functions
108  // ... more?!
109 }
110 
112 {
113  return m_attrFunctions.find(f.getName()) != m_attrFunctions.end();
114 }
115 
117 {
119 
120  return m_attrFunctions.find(f.getName())->second;
121 }
122 
124 {
125  // Creates the attribute restriction
126  AttributeRestriction* restriction = new AttributeRestriction;
127  restriction->m_index = m_index++;
128  restriction->m_op = getOperator(f);
129  restriction->m_function = dynamic_cast<const Function*>(&f);
130 
131  // Adds the attribute restriction
132  m_attrRestrictions.push_back(restriction);
133 }
std::size_t m_index
An internal visitor index.
static const std::string sm_LessThan
Definition: FunctionNames.h:59
A class that models a Function expression.
const Function * m_function
The function that represents the attribute restriction.
A class that models the name of any property of an object.
virtual ~AttributeRestrictionVisitor()
Virtual destructor.
std::map< std::string, std::string > m_attrFunctions
A map of attribute restriction functions.
~AttributeRestriction()
Destructor.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static const std::string sm_EqualTo
Definition: FunctionNames.h:55
std::vector< te::da::AttributeRestriction * > m_attrRestrictions
The set of attribute restrictions.
This is an abstract class that models a query expression.
A struct that represents an attribute restriction.
bool isAttributeRestrictionFunction(const Function &f) const
static const std::string sm_GreaterThanOrEqualTo
Definition: FunctionNames.h:58
std::size_t m_index
Internal index of the attribute restriction.
const std::vector< te::da::AttributeRestriction * > & getAttributeRestrictions() const
virtual void visit(const Expression &visited)
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
This is an abstract class that models a query expression.
static const std::string sm_NotEqualTo
Definition: FunctionNames.h:56
std::string m_op
The attribute restriction operator.
Expression * getExp() const
Definition: Where.cpp:58
A class that models a Function expression.
A Select models a query to be used when retrieving data from a data source.
std::string getOperator(const Function &f) const
const std::string & getName() const
It returns the function name.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
A visitor that retrieves attribute restrictions from a Query hierarchy.
static const std::string sm_LessThanOrEqualTo
Definition: FunctionNames.h:60
A class that can be used to model a filter expression that can be applied to a query.
Where * getWhere() const
It returns the filter condition.
Definition: Select.cpp:804
A static class with global function name definitions.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
static const std::string sm_GreaterThan
Definition: FunctionNames.h:57
std::size_t getNumArgs() const
It returns the number of arguments informed to the function.