attributeHandler.h 7.14 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
	AttributeHandlerGen(GenericMap* m, bool v) : m_map(m), valid(v)
49 50 51 52 53 54
	{}

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

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

protected:
62 63
	void setInvalid()
	{
64
		valid = false ;
65
	}
66
} ;
67

Pierre Kraemer's avatar
Pierre Kraemer committed
68 69
/**
 * Class that create an access-table to an existing attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
70
 * Main available operations are:
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73 74
 * - [ index ]
 * - [ dart ]
 * - begin / end / next to manage indexing
 */
75
template <typename T, unsigned int ORBIT>
76
class AttributeHandler : public AttributeHandlerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78
{
protected:
79
	// the multi-vector that contains attribute data
80
	AttributeMultiVector<T>* m_attrib;
Pierre Kraemer's avatar
Pierre Kraemer committed
81

82 83 84
	void registerInMap() ;
	void unregisterFromMap() ;

85 86 87
public:
	typedef T DATA_TYPE ;

88 89 90 91 92 93
	/**
	 * Default constructor
	 * Constructs a non-valid AttributeHandler (i.e. not linked to any attribute)
	 */
	AttributeHandler() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
94 95 96
	/**
	 * Constructor
	 * @param m the map which belong attribute
97
	 * @param amv a pointer to the AttributeMultiVector
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	 */
99
	AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101 102 103 104

	/**
	 * Copy constructor
	 * @param ta the table attribute
	 */
105
	AttributeHandler(const AttributeHandler<T, ORBIT>& ta) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108 109 110

	/**
	 * affectation operator
	 * @param ta the table attribute to affect to this
	 */
111
	AttributeHandler<T, ORBIT>& operator=(const AttributeHandler<T, ORBIT>& ta) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112 113 114 115 116 117 118 119 120

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

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

	/**
124
	 * get attribute orbit
Pierre Kraemer's avatar
Pierre Kraemer committed
125
	 */
126 127 128 129 130 131
	unsigned int getOrbit() const ;

	/**
	 * get attribute index
	 */
	unsigned int getIndex() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135 136 137

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

138 139 140 141 142
	/**
	 * give the number of elements of the attribute container
	 */
	unsigned int nbElements() const;

Pierre Kraemer's avatar
Pierre Kraemer committed
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
	/**
	 * [] 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
169
	 * insert an element with default value (warning we add here a complete line in container)
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172
	 */
	unsigned int newElt() ;

173
	/**
174
	 * initialize all the lines of the attribute with the given value
175
	 */
176
	void setAllValues(const T& v) ;
177

Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181 182 183 184
	/**
	 * begin of table
	 * @return the iterator of the begin of container
	 */
	unsigned int begin() const;

	/**
185
	 * end of table
Pierre Kraemer's avatar
Pierre Kraemer committed
186 187 188 189 190
	 * @return the iterator of the end of container
	 */
	unsigned int end() const;

	/**
191
	 * Next on iterator (equivalent to stl ++)
Pierre Kraemer's avatar
Pierre Kraemer committed
192 193 194 195 196
	 * @param iter iterator to
	 */
	void next(unsigned int& iter) const;
} ;

197 198 199 200 201 202 203 204 205 206 207 208
/**
 *  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) {}
	DartAttribute<T>& operator=(const AttributeHandler<T, DART>& ah) { this->AttributeHandler<T, DART>::operator=(ah); return *this; }
};

209 210 211 212
/**
 *  shortcut class for Vertex Attribute (Handler)
 */
template <typename T>
Pierre Kraemer's avatar
bla  
Pierre Kraemer committed
213
class VertexAttribute : public AttributeHandler<T, VERTEX>
214 215
{
public:
216 217 218
	VertexAttribute() : AttributeHandler<T, VERTEX>() {}
	VertexAttribute(const AttributeHandler<T, VERTEX>& ah) : AttributeHandler<T, VERTEX>(ah) {}
	VertexAttribute<T>& operator=(const AttributeHandler<T, VERTEX>& ah) { this->AttributeHandler<T, VERTEX>::operator=(ah); return *this; }
219 220 221 222 223 224
};

/**
 *  shortcut class for Edge Attribute (Handler)
 */
template <typename T>
225
class EdgeAttribute : public AttributeHandler<T, EDGE>
226 227
{
public:
228 229 230
	EdgeAttribute() : AttributeHandler<T, EDGE>() {}
	EdgeAttribute(const AttributeHandler<T, EDGE>& ah) : AttributeHandler<T, EDGE>(ah) {}
	EdgeAttribute<T>& operator=(const AttributeHandler<T, EDGE>& ah) { this->AttributeHandler<T, EDGE>::operator=(ah); return *this; }
231 232 233 234 235 236
};

/**
 *  shortcut class for Face Attribute (Handler)
 */
template <typename T>
237
class FaceAttribute : public AttributeHandler<T, FACE>
238 239
{
public:
240 241 242
	FaceAttribute() : AttributeHandler<T, FACE>() {}
	FaceAttribute(const AttributeHandler<T, FACE>& ah) : AttributeHandler<T, FACE>(ah) {}
	FaceAttribute<T>& operator=(const AttributeHandler<T, FACE>& ah) { this->AttributeHandler<T, FACE>::operator=(ah); return *this; }
243 244 245 246 247 248
};

/**
 *  shortcut class for Volume Attribute (Handler)
 */
template <typename T>
249
class VolumeAttribute : public AttributeHandler<T, VOLUME>
250 251
{
public:
252 253 254
	VolumeAttribute() : AttributeHandler<T, VOLUME>() {}
	VolumeAttribute(const AttributeHandler<T, VOLUME>& ah) : AttributeHandler<T, VOLUME>(ah) {}
	VolumeAttribute<T>& operator=(const AttributeHandler<T, VOLUME>& ah) { this->AttributeHandler<T, VOLUME>::operator=(ah); return *this; }
255 256
};

Pierre Kraemer's avatar
Pierre Kraemer committed
257 258 259 260 261
} // namespace CGoGN

#include "Topology/generic/attributeHandler.hpp"

#endif