Promoter.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/qt/widgets/table/Promoter.h
22 
23  \brief Defines an mechanism for logical ordering of rows.
24 */
25 #ifndef __TERRALIB_QT_WIDGETS_TABLE_INTERNAL_PROMOTER_H
26 #define __TERRALIB_QT_WIDGETS_TABLE_INTERNAL_PROMOTER_H
27 
28 // TerraLib
29 #include "../../../common/Comparators.h"
30 
31 // STL
32 #include <map>
33 #include <vector>
34 #include <string>
35 
36 // Forward declarations
37 namespace te
38 {
39  namespace da
40  {
41  class ObjectId;
42  class ObjectIdSet;
43  class DataSet;
44  }
45 }
46 
47 
49 {
51 };
52 
53 namespace te
54 {
55  namespace qt
56  {
57  namespace widgets
58  {
59  /*!
60  \class Promoter
61 
62  \brief A class used for logical ordering of rows.
63 
64  The promotion just group a set of ObjectIds on the begining of table. When enable promotion requires some time to preproccess the primary
65  keys of each data on the DataSet. Next time promotion is instantaneous.
66 
67  \note When enabled, promotion consumes additional memory, because each primary key is stored.
68  */
69  class Promoter
70  {
71  public:
72 
73  /*!
74  \brief Constructor.
75  */
76  Promoter ();
77 
78  /*!
79  \brief Destructor.
80  */
81  ~Promoter();
82 
83  /*!
84  \brief Returns the rows to its original positions.
85  */
86  void resetPromotion();
87 
88  /*!
89  \breif Cleans pre processed keys and vector of mapping logical rows.
90  */
92 
93  /*!
94  \brief Proccess primary keys and stores it.
95 
96  \param dset Dataset to be used.
97 
98  \param pkeys Positions of the primary keys columns.
99 
100  \note This operation DOES NOT take the ownership of \a dset.
101  */
102  void preProcessKeys(te::da::DataSet* dset, const std::vector<size_t>& pkeys);
103 
104  /*!
105  \brief Returns the logical position of the row \a visualRow.
106 
107  \param visualRow The visible row.
108  */
109  size_t getLogicalRow(const size_t& visualRow);
110 
111  /*!
112  \brief Cleans the storage of the primary keys. Next time enabled, will be necessary to proccess all primary keys again.
113  */
114  void cleanPreproccessKeys();
115 
116  /*!
117  \brief Promotes the rows identified by \a oids primary keys.
118 
119  \param oids Set of object ids to be promoted.
120  */
121  void promote(const te::da::ObjectIdSet* oids);
122 
123  /*!
124  \brief Given an object id returns its row.
125 
126  \param oid Identifier of some row.
127 
128  \return Position of the row identified by \a oid.
129  */
130  size_t map2Row(te::da::ObjectId* oid);
131 
132  protected:
133 
134  std::map<std::string, size_t> m_PkeysRows; //!< Map object id to its position in DataSet.
135 
136  std::vector<size_t> m_logicalRows; //!< Map original row to logical postion.
137  };
138  }
139  }
140 }
141 
142 #endif //__TERRALIB_QT_WIDGETS_TABLE_INTERNAL_PROMOTER_H
bool operator()(te::da::ObjectId *lhs, te::da::ObjectId *rhs)
size_t map2Row(te::da::ObjectId *oid)
Given an object id returns its row.
std::vector< size_t > m_logicalRows
Map original row to logical postion.
Definition: Promoter.h:136
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
URI C++ Library.
void promote(const te::da::ObjectIdSet *oids)
Promotes the rows identified by oids primary keys.
A class used for logical ordering of rows.
Definition: Promoter.h:69
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
void preProcessKeys(te::da::DataSet *dset, const std::vector< size_t > &pkeys)
Proccess primary keys and stores it.
void cleanPreproccessKeys()
Cleans the storage of the primary keys. Next time enabled, will be necessary to proccess all primary ...
size_t getLogicalRow(const size_t &visualRow)
Returns the logical position of the row visualRow.
std::map< std::string, size_t > m_PkeysRows
Map object id to its position in DataSet.
Definition: Promoter.h:134
void resetPromotion()
Returns the rows to its original positions.