src/terralib/fe/Utils.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 Utils.cpp
22 
23 \brief This file has util functions for this module.
24 */
25 
26 // TerraLib
27 #include "../fe.h"
28 #include "Utils.h"
29 
30 
31 te::fe::Filter* te::fe::CreateFilterByUniqueValue(const std::string& attrName, const std::string& value)
32 {
33  te::fe::PropertyName* propName = new te::fe::PropertyName(attrName);
34  te::fe::Literal* propValue = new te::fe::Literal(value);
36 
37  te::fe::Filter* filter = new te::fe::Filter;
38  filter->setOp(equal);
39 
40  return filter;
41 }
42 
43 void te::fe::GetFilterUniqueValue(const te::fe::Filter* filter, std::string& value)
44 {
45  if (!filter)
46  return;
47 
48  const te::fe::BinaryComparisonOp* equal = dynamic_cast<te::fe::BinaryComparisonOp*>(filter->getOp());
49 
50  if (equal)
51  {
52  const te::fe::Literal* propValue = dynamic_cast<te::fe::Literal*>(equal->getSecond());
53 
54  if (propValue)
55  {
56  value = propValue->getValue();
57  }
58  }
59 }
60 
61 te::fe::Filter* te::fe::CreateFilterByStep(const std::string& attrName, const std::string& minValue, const std::string& maxValue)
62 {
63  te::fe::PropertyName* propMinName = new te::fe::PropertyName(attrName);
64  te::fe::Literal* propMinValue = new te::fe::Literal(minValue);
66 
67  te::fe::PropertyName* propMaxName = new te::fe::PropertyName(attrName);
68  te::fe::Literal* propMaxValue = new te::fe::Literal(maxValue);
70 
72 
73  te::fe::Filter* filter = new te::fe::Filter;
74  filter->setOp(andOp);
75 
76  return filter;
77 }
78 
79 void te::fe::GetFilterStepValues(const te::fe::Filter* filter, std::string& valueMin, std::string& valueMax)
80 {
81  if (!filter)
82  return;
83 
84  te::fe::BinaryLogicOp* andOp = dynamic_cast<te::fe::BinaryLogicOp*>(filter->getOp());
85 
86  if (andOp)
87  {
88  te::fe::BinaryComparisonOp* greater = dynamic_cast<te::fe::BinaryComparisonOp*>(andOp->getOp(0));
89 
90  if (greater)
91  {
92  const te::fe::Literal* propValue = dynamic_cast<te::fe::Literal*>(greater->getSecond());
93 
94  if (propValue)
95  {
96  valueMin = propValue->getValue();
97  }
98  }
99 
100  te::fe::BinaryComparisonOp* less = dynamic_cast<te::fe::BinaryComparisonOp*>(andOp->getOp(1));
101 
102  if (less)
103  {
104  const te::fe::Literal* propValue = dynamic_cast<te::fe::Literal*>(less->getSecond());
105 
106  if (propValue)
107  {
108  valueMax = propValue->getValue();
109  }
110  }
111  }
112 }
static const char * sm_propertyIsLessThan
void Filter()
AbstractOp * getOp() const
It returns main filter operation.
static const char * sm_propertyIsEqualTo
TEFEEXPORT void GetFilterStepValues(const te::fe::Filter *filter, std::string &valueMin, std::string &valueMax)
TEFEEXPORT te::fe::Filter * CreateFilterByStep(const std::string &attrName, const std::string &minValue, const std::string &maxValue)
TEFEEXPORT te::fe::Filter * CreateFilterByUniqueValue(const std::string &attrName, const std::string &value)
void setOp(AbstractOp *o)
It sets the filter main operation (expression).
This class is used to encode the name of any property of an object.
AbstractOp * getOp(std::size_t i) const
It returns a specified operand.
Expression * getSecond() const
It returns the second operand.
A filter is any valid predicate expression.
Definition: fe/Filter.h:55
A class for binary comparison operators.
static const char * sm_and
This class can be used to represent literal values.
Definition: fe/Literal.h:56
A logical operator can be used to combine two or more conditional expressions.
Definition: BinaryLogicOp.h:58
const std::string & getValue() const
It returns the literal value.
Definition: fe/Literal.cpp:36
static const char * sm_propertyIsLessThanOrEqualTo
TEFEEXPORT void GetFilterUniqueValue(const te::fe::Filter *filter, std::string &value)