Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

attributeHandler.h 9.59 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __ATTRIBUTE_HANDLER_H__
#define __ATTRIBUTE_HANDLER_H__

#include <vector>
#include <map>

#include "Topology/generic/genericmap.h"

namespace CGoGN
{

36
37
38
class AttributeHandlerGen
{
protected:
39
40
41
	friend class GenericMap ;
	friend class AttribMap ;

42
	// the map that contains the linked attribute
43
44
45
	GenericMap* m_map ;
	// boolean that states the validity of the handler
	bool valid ;
46
47

public:
48
49
50
	AttributeHandlerGen(GenericMap* m, bool v) :
		m_map(m),
		valid(v)
51
52
53
54
55
56
	{}

	GenericMap* map() const
	{
		return m_map ;
	}
57

58
59
60
61
62
	bool isValid() const
	{
		return valid ;
	}

63
64
65
66
	virtual int getSizeOfType() const = 0;

	virtual unsigned int getOrbit() const = 0;

67
	virtual const std::string& name() const = 0;
68
69
70
	virtual const std::string& typeName() const = 0;

	virtual AttributeMultiVectorGen* getDataVectorGen() const = 0;
71

72
protected:
73
74
	void setInvalid()
	{
75
		valid = false ;
76
	}
77
} ;
78

Pierre Kraemer's avatar
Pierre Kraemer committed
79
80
/**
 * Class that create an access-table to an existing attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
81
 * Main available operations are:
Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
84
85
 * - [ index ]
 * - [ dart ]
 * - begin / end / next to manage indexing
 */
86
template <typename T, unsigned int ORBIT>
87
class AttributeHandler : public AttributeHandlerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
88
89
{
protected:
90
	// the multi-vector that contains attribute data
91
	AttributeMultiVector<T>* m_attrib;
Pierre Kraemer's avatar
Pierre Kraemer committed
92

93
94
95
	void registerInMap() ;
	void unregisterFromMap() ;

96
97
98
public:
	typedef T DATA_TYPE ;

99
100
101
102
103
104
	/**
	 * Default constructor
	 * Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
	 */
	AttributeHandler() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
105
106
107
	/**
	 * Constructor
	 * @param m the map which belong attribute
108
	 * @param amv a pointer to the AttributeMultiVector
Pierre Kraemer's avatar
Pierre Kraemer committed
109
	 */
110
	AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
115

	/**
	 * Copy constructor
	 * @param ta the table attribute
	 */
116
	AttributeHandler(const AttributeHandler<T, ORBIT>& ta) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
117

untereiner's avatar
untereiner committed
118
119
120
121
122
123
124
125
	/**
	 * Transmute Constructor
	 * Construct an attribute of Orbit from Orbit2
	 * @param h the table attribute
	 */
	template <unsigned int ORBIT2>
	AttributeHandler(const AttributeHandler<T, ORBIT2>& h) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
128
129
	/**
	 * affectation operator
	 * @param ta the table attribute to affect to this
	 */
130
	AttributeHandler<T, ORBIT>& operator=(const AttributeHandler<T, ORBIT>& ta) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
131

untereiner's avatar
untereiner committed
132
133
134
135
136
137
138
	/**
	 * transmuted affectation operator
	 * @param ta the table attribute to affect to this
	 */
	template <unsigned int ORBIT2>
	AttributeHandler<T, ORBIT>& operator=(const AttributeHandler<T, ORBIT2>& ta) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
141
142
143
144
145
146
	/**
	 * Destructor (empty & virtual)
	 */
	virtual ~AttributeHandler() ;

	/**
	 * get attribute data vector
	 */
147
	AttributeMultiVector<T>* getDataVector() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
148

149
150
151
152
153
154
155
156
157
158
	/**
	 * get attribute data vector (generic MultiVector)
	 */
	virtual AttributeMultiVectorGen* getDataVectorGen() const ;

	/**
	 * get size of attribute type
	 */
	virtual int getSizeOfType() const ;

Pierre Kraemer's avatar
Pierre Kraemer committed
159
	/**
160
	 * get attribute orbit
Pierre Kraemer's avatar
Pierre Kraemer committed
161
	 */
162
	virtual unsigned int getOrbit() const ;
163
164
165
166
167

	/**
	 * get attribute index
	 */
	unsigned int getIndex() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
168
169
170
171

	/**
	 * get attribute name
	 */
172
	virtual const std::string& name() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
173

174
175
176
177
	/**
	 * get attribute type name
	 */
	virtual const std::string& typeName() const ;
178

179
180
181
182
183
	/**
	 * give the number of elements of the attribute container
	 */
	unsigned int nbElements() const;

Pierre Kraemer's avatar
Pierre Kraemer committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	/**
	 * [] 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) ;

	/**
untereiner's avatar
ihm3    
untereiner committed
210
	 * insert an element with default value (warning we add here a complete line in container)
Pierre Kraemer's avatar
Pierre Kraemer committed
211
212
213
	 */
	unsigned int newElt() ;

214
	/**
215
	 * initialize all the lines of the attribute with the given value
216
	 */
217
	void setAllValues(const T& v) ;
218

Pierre Kraemer's avatar
Pierre Kraemer committed
219
220
221
222
223
224
225
	/**
	 * begin of table
	 * @return the iterator of the begin of container
	 */
	unsigned int begin() const;

	/**
226
	 * end of table
Pierre Kraemer's avatar
Pierre Kraemer committed
227
228
229
230
231
	 * @return the iterator of the end of container
	 */
	unsigned int end() const;

	/**
232
	 * Next on iterator (equivalent to stl ++)
Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
235
236
237
	 * @param iter iterator to
	 */
	void next(unsigned int& iter) const;
} ;

238
239
240
241
242
243
244
245
246
/**
 *  shortcut class for Vertex Attribute (Handler)
 */
template <typename T>
class DartAttribute : public AttributeHandler<T, DART>
{
public:
	DartAttribute() : AttributeHandler<T, DART>() {}
	DartAttribute(const AttributeHandler<T, DART>& ah) : AttributeHandler<T, DART>(ah) {}
247
	DartAttribute(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, DART>(m,amv) {}
248
249
250
	DartAttribute<T>& operator=(const AttributeHandler<T, DART>& ah) { this->AttributeHandler<T, DART>::operator=(ah); return *this; }
};

251
252
253
254
/**
 *  shortcut class for Vertex Attribute (Handler)
 */
template <typename T>
Pierre Kraemer's avatar
bla    
Pierre Kraemer committed
255
class VertexAttribute : public AttributeHandler<T, VERTEX>
256
257
{
public:
258
259
	VertexAttribute() : AttributeHandler<T, VERTEX>() {}
	VertexAttribute(const AttributeHandler<T, VERTEX>& ah) : AttributeHandler<T, VERTEX>(ah) {}
260
	VertexAttribute(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, VERTEX>(m,amv) {}
261
	VertexAttribute<T>& operator=(const AttributeHandler<T, VERTEX>& ah) { this->AttributeHandler<T, VERTEX>::operator=(ah); return *this; }
untereiner's avatar
untereiner committed
262
263
264
	VertexAttribute<T>& operator=(const AttributeHandler<T, EDGE>& ah) { this->AttributeHandler<T,VERTEX>::operator=(ah); return *this; }
	VertexAttribute<T>& operator=(const AttributeHandler<T, FACE>& ah) { this->AttributeHandler<T,VERTEX>::operator=(ah); return *this; }
	VertexAttribute<T>& operator=(const AttributeHandler<T, VOLUME>& ah) { this->AttributeHandler<T,VERTEX>::operator=(ah); return *this; }
265
266
267
268
269
270
};

/**
 *  shortcut class for Edge Attribute (Handler)
 */
template <typename T>
271
class EdgeAttribute : public AttributeHandler<T, EDGE>
272
273
{
public:
274
275
	EdgeAttribute() : AttributeHandler<T, EDGE>() {}
	EdgeAttribute(const AttributeHandler<T, EDGE>& ah) : AttributeHandler<T, EDGE>(ah) {}
276
	EdgeAttribute(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, EDGE>(m,amv) {}
277
	EdgeAttribute<T>& operator=(const AttributeHandler<T, EDGE>& ah) { this->AttributeHandler<T, EDGE>::operator=(ah); return *this; }
278
279
280
281
282
283
};

/**
 *  shortcut class for Face Attribute (Handler)
 */
template <typename T>
284
class FaceAttribute : public AttributeHandler<T, FACE>
285
286
{
public:
287
288
	FaceAttribute() : AttributeHandler<T, FACE>() {}
	FaceAttribute(const AttributeHandler<T, FACE>& ah) : AttributeHandler<T, FACE>(ah) {}
289
	FaceAttribute(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, FACE>(m,amv) {}
290
	FaceAttribute<T>& operator=(const AttributeHandler<T, FACE>& ah) { this->AttributeHandler<T, FACE>::operator=(ah); return *this; }
untereiner's avatar
untereiner committed
291
	FaceAttribute<T>& operator=(const AttributeHandler<T, VERTEX>& ah) { this->AttributeHandler<T,FACE>::operator=(ah); return *this; }
292
293
294
295
296
297
};

/**
 *  shortcut class for Volume Attribute (Handler)
 */
template <typename T>
298
class VolumeAttribute : public AttributeHandler<T, VOLUME>
299
300
{
public:
301
302
	VolumeAttribute() : AttributeHandler<T, VOLUME>() {}
	VolumeAttribute(const AttributeHandler<T, VOLUME>& ah) : AttributeHandler<T, VOLUME>(ah) {}
303
	VolumeAttribute(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, VOLUME>(m,amv) {}
304
	VolumeAttribute<T>& operator=(const AttributeHandler<T, VOLUME>& ah) { this->AttributeHandler<T, VOLUME>::operator=(ah); return *this; }
untereiner's avatar
untereiner committed
305
	VolumeAttribute<T>& operator=(const AttributeHandler<T, VERTEX>& ah) { this->AttributeHandler<T, VOLUME>::operator=(ah); return *this; }
306
307
};

untereiner's avatar
untereiner committed
308
309
310
311
312
313
314
315
316
317
318

// turn_to<b>(A*</b> obj) changes class of the object
// that means it just replaces VTBL of the object by VTBL of another class.
// NOTE: these two classes has to be ABI compatible!
template <typename TO_T, typename FROM_T>
  inline void turn_to(FROM_T* p)
  {
    assert( sizeof(FROM_T) == sizeof(TO_T));
    ::new(p) TO_T(); // use of placement new
  }

Pierre Kraemer's avatar
Pierre Kraemer committed
319
320
321
322
323
} // namespace CGoGN

#include "Topology/generic/attributeHandler.hpp"

#endif