All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Function.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 Function.cpp
22 
23  \brief A function is a named procedure that performs a distinct computation.
24  */
25 
26 // TerraLib
27 #include "../common/STLUtils.h"
28 #include "Function.h"
29 
30 // STL
31 #include <cassert>
32 
33 te::fe::Function::Function(const std::string& name)
34  : m_name(name)
35 {
36 }
37 
39 {
40  te::common::FreeContents(m_argumentList);
41 }
42 
43 const std::string& te::fe::Function::getName() const
44 {
45  return m_name;
46 }
47 
48 void te::fe::Function::setName(const std::string& n)
49 {
50  m_name = n;
51 }
52 
54 {
55  assert(i < m_argumentList.size());
56  return m_argumentList[i];
57 }
58 
60 {
61  assert(argument);
62  m_argumentList.push_back(argument);
63 }
64 
65 void te::fe::Function::setArgument(size_t i, Expression* argument)
66 {
67  assert(i < m_argumentList.size());
68  delete m_argumentList[i];
69  m_argumentList[i] = argument;
70 }
71 
73 {
74  assert(i < m_argumentList.size());
75  delete m_argumentList[i];
76  m_argumentList.erase(m_argumentList.begin() + i);
77 }
78 
80 {
81  te::fe::Function* f = new te::fe::Function(m_name);
82  for(std::size_t i = 0; i < m_argumentList.size(); ++i)
83  {
84  te::fe::Expression* e = m_argumentList[i];
85  if(e)
86  f->add(e->clone());
87  }
88 
89  return f;
90 }
void removeArgument(size_t i)
It removes the n-th argument.
Definition: Function.cpp:72
virtual Expression * clone() const =0
It returns a clone of this object.
A function is a named procedure that performs a distinct computation.
Definition: Function.h:54
void setName(const std::string &n)
It sets the function name.
Definition: Function.cpp:48
This is an abstract class that models a Filter Encoding expression.
Definition: Expression.h:50
Function(const std::string &name)
It initializes a new Function.
Definition: Function.cpp:33
virtual Expression * clone() const
It returns a clone of this object.
Definition: Function.cpp:79
const std::string & getName() const
It returns the function name.
Definition: Function.cpp:43
void add(Expression *argument)
It adds a new argument to the function.
Definition: Function.cpp:59
void setArgument(size_t i, Expression *argument)
It sets the argument in the specified position.
Definition: Function.cpp:65
A function is a named procedure that performs a distinct computation.
~Function()
Destructor.
Definition: Function.cpp:38
Expression * getArgument(size_t i) const
It returns the argument in the specified position.
Definition: Function.cpp:53
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