CompositeData.h
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/datatype/CompositeData.h
22 
23  \brief A base class for composite data values.
24 */
25 
26 #ifndef __TERRALIB_DATATYPE_INTERNAL_COMPOSITEDATA_H
27 #define __TERRALIB_DATATYPE_INTERNAL_COMPOSITEDATA_H
28 
29 // TerraLib
30 #include "AbstractData.h"
31 #include "Enums.h"
32 
33 // STL
34 #include <vector>
35 
36 namespace te
37 {
38  namespace dt
39  {
40  /*!
41  \class CompositeData
42 
43  \brief A base class for composite data values.
44 
45  \ingroup datatype
46 
47  \sa AbstractData, DataType, ByteArray, DateTime, SimpleData
48  */
50  {
51  public:
52 
53  /*! \brief Constructor. */
55 
56  /*!
57  \brief It prepares the internal container for at least nComponents.
58 
59  \param nComponents The number of expected components for the composite.
60  */
61  CompositeData(std::size_t nComponents);
62 
63  CompositeData(const std::string& name);
64 
65  /*!
66  \brief Copy constructor.
67 
68  \param rhs The right-hand-side composite.
69  */
70  CompositeData(const CompositeData& rhs);
71 
72  /*! \brief Destructor. */
73  ~CompositeData();
74 
75  /*!
76  \brief Copy constructor.
77 
78  \param rhs The right-hand-side composite.
79 
80  \return A reference to this composite.
81  */
82  CompositeData& operator=(const CompositeData& rhs);
83 
84  void setName(const std::string& name);
85 
86  void add(const std::string& name, AbstractData* value);
87 
88  /*!
89  \brief It returns the i-th component value of the composite data.
90 
91  \param i The position index of the component.
92 
93  \return The i-th component value. The caller will not take the ownership of the returned pointer.
94 
95  \note The component index is 0-based!
96  */
97  AbstractData* getValue(std::size_t i) const;
98 
99  /*!
100  \brief It sets the i-th component value of the composite data.
101 
102  \param i The position index of the component.
103  \param value The component value at the specified index. If there is another component at the specified index it will be released.
104 
105  \note The component index is 0-based!
106 
107  \warning Make sure you have prepared the composite for having at least i + 1 components.
108  */
109  void setValue(std::size_t i, AbstractData* value);
110 
111  /*!
112  \brief It adds the value as the last component of the composite data.
113 
114  \param value The component value at the specified index. If there is another component at the specified index it will be released.
115 
116  \note The component index is 0-based!
117  */
118  void add(AbstractData* value);
119 
120  /*!
121  \brief It creates a new clone of the composite.
122 
123  \return A new clone of the composite. The caller will take its ownership.
124  */
125  AbstractData* clone() const;
126 
127  /*!
128  \brief It returns the associated data type code.
129 
130  \return The associated data type code.
131  */
132  int getTypeCode() const { return COMPOSITE_TYPE; }
133 
134  /*!
135  \brief It returns the data value in a string representation.
136 
137  \return The data value in a string representation.
138  */
139  std::string toString() const;
140 
141  private:
142 
143  std::vector<AbstractData*> m_values; //!< The component values.
144  std::vector<std::string> m_names; //!< The component names.
145  std::string m_name; //!< The composite name.
146  };
147 
148  } // end namespace dt
149 } // end namespace te
150 
151 #endif // __TERRALIB_DATATYPE_INTERNAL_COMPOSITEDATA_H
152 
std::vector< AbstractData * > m_values
The component values.
A base class for objects that can be retrieved from the data access module.
std::string m_name
The composite name.
std::vector< std::string > m_names
The component names.
#define TEDATATYPEEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:61
CompositeData()
Constructor.
Definition: CompositeData.h:54
URI C++ Library.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A base class for composite data values.
Definition: CompositeData.h:49
int getTypeCode() const
It returns the associated data type code.
General enumerations for the data type module.