attributeHandler.h 4.57 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __ATTRIBUTE_HANDLER_H__
#define __ATTRIBUTE_HANDLER_H__

#include <vector>
#include <map>

#include "Topology/generic/genericmap.h"

namespace CGoGN
{

/**
 * Class that create an access-table to an existing attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
38
 * Main available operations are:
Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 * - [ index ]
 * - [ dart ]
 * - begin / end / next to manage indexing
 */
template <typename T>
class AttributeHandler
{
	friend class AttribMap ;

protected:
	// we need the map to use dart as index
	GenericMap* m_map;

	// id of the attribute
	unsigned int m_id;

	// access to the data
56
	AttributeMultiVector<T>* m_attrib;
Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
59
60
61
62
63
64
65
66
67
68

protected:
	/**
	 * Constructor
	 * @param idAttr identifiant of attribute
	 * @param m the map which belong attribute
	 */
	AttributeHandler(GenericMap* m, unsigned int idAttr) ;

public:
	typedef T DATA_TYPE ;

69
	AttributeHandler() : m_map(NULL), m_id(AttributeContainer::UNKNOWN), m_attrib(NULL) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

	/**
	 * Copy constructor
	 * @param ta the table attribute
	 */
	AttributeHandler(const AttributeHandler<T>& ta) ;

	/**
	 * affectation operator
	 * @param ta the table attribute to affect to this
	 */
	void operator=(const AttributeHandler<T>& ta) ;

	/**
	 * Destructor (empty & virtual)
	 */
	virtual ~AttributeHandler() ;

	/**
	 * get associated map
	 */
	GenericMap* map() const ;

	/**
	 * get attribute data vector
	 */
96
	AttributeMultiVector<T>* getDataVector() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

	/**
	 * get attribute id
	 */
	unsigned int id() const ;

	/**
	 * get attribute name
	 */
	const std::string& name() const ;

	/**
	 * check if the attribute handler is linked to a valid attribute
	 * -> MUST BE USED AFTER A CALL TO :
	 * getAttribute(unsigned int orbit, const std::string& nameAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
112
	 * addAttribute(unsigned int orbit, const std::string& nameAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
	 */
	bool isValid() const ;

	/**
	 * [] operator with dart parameter
	 */
	T& operator[](Dart d) ;

	/**
	 * const [] operator with dart parameter
	 */
	const T& operator[](Dart d) const ;

	/**
	 * at operator (same as [] but with index parameter)
	 */
	T& operator[](unsigned int a) ;

	/**
	 * const at operator (same as [] but with index parameter)
	 */
	const T& operator[](unsigned int a) const ;

	/**
	 * insert an element (warning we add here a complete line in container)
	 */
	unsigned int insert(const T& elt) ;

	/**
	 * insert un element with default value (warning we add here a complete line in container)
	 */
	unsigned int newElt() ;

	/**
	 * begin of table
	 * @return the iterator of the begin of container
	 */
	unsigned int begin() const;

	/**
	 * begin of table
	 * @return the iterator of the end of container
	 */
	unsigned int end() const;

	/**
	 * Next on iterator (equivalent too stl ++)
	 * @param iter iterator to
	 */
	void next(unsigned int& iter) const;
} ;

} // namespace CGoGN

#include "Topology/generic/attributeHandler.hpp"

#endif