src/terralib/dataaccess/query/Field.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/Field.cpp
22 
23  \brief The Field class can be used to model an expression that takes part of the output items of a SELECT.
24 */
25 
26 // TerraLib
27 #include "Expression.h"
28 #include "Field.h"
29 #include "PropertyName.h"
30 
31 te::da::Field::Field(const Expression& e, const std::string& alias)
32  : m_field(e.clone())
33 
34 {
35  m_alias.reset(alias.empty() ? nullptr : new std::string(alias));
36 }
37 
38 te::da::Field::Field(Expression* e, std::string* alias)
39  : m_field(e),
40  m_alias(alias)
41 {
42 }
43 
44 te::da::Field::Field(const std::string& propertyName, const std::string& alias)
45 
46 {
47  m_field.reset(new PropertyName(propertyName));
48  m_alias.reset(alias.empty() ? nullptr : new std::string(alias));
49 }
50 
52 
53 {
54  m_field.reset(rhs.m_field.get() ? rhs.m_field->clone() : nullptr);
55  m_alias.reset(rhs.m_alias.get() ? new std::string(*rhs.m_alias) : nullptr);
56 }
57 
58 te::da::Field::~Field() = default;
59 
61 {
62  if(this != &rhs)
63  {
64  m_field.reset(rhs.m_field.get() ? rhs.m_field->clone() : nullptr);
65  m_alias.reset(rhs.m_alias.get() ? new std::string(*rhs.m_alias) : nullptr);
66  }
67 
68  return *this;
69 }
70 
72 {
73  m_field.reset(e);
74 }
75 
77 {
78  return m_field.get();
79 }
80 
81 void te::da::Field::setAlias(std::string* alias)
82 {
83  m_alias.reset(alias);
84 }
85 
86 std::string* te::da::Field::getAlias() const
87 {
88  return m_alias.get();
89 }
90 
The Field class can be used to model an expression that takes part of the output items of a SELECT...
A class that models the name of any property of an object.
A class that models the name of any property of an object.
Expression * getExpression() const
It returns the expression set for an output select query.
~Field()
Destructor.
std::unique_ptr< std::string > m_alias
An alias for the output name.
This is an abstract class that models a query expression.
Field(const Expression &e, const std::string &alias=std::string(""))
Constructor.
std::string * getAlias() const
It returns the alias for the outout expression.
This is an abstract class that models a query expression.
void setAlias(std::string *alias)
As you know, sometimes is better to give an alias to an output expression.
std::unique_ptr< Expression > m_field
A valid expression.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
void setExpression(Expression *e)
It sets the an expression that can be used in a Select query.
Field & operator=(const Field &rhs)