attributeHandler.h 4.6 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
 * - [ 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;

	// access to the data
53
	AttributeMultiVector<T>* m_attrib;
Pierre Kraemer's avatar
Pierre Kraemer committed
54 55 56 57 58

protected:
	/**
	 * Constructor
	 * @param m the map which belong attribute
59 60
	 * @param orbit orbit of attribute
	 * @param orbit index of attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
61
	 */
62
	AttributeHandler(GenericMap* m, AttributeMultiVector<T>* amv) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65 66

public:
	typedef T DATA_TYPE ;

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

	/**
	 * 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
	 */
94
	AttributeMultiVector<T>* getDataVector() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96

	/**
97
	 * get attribute orbit
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	 */
99 100 101 102 103 104
	unsigned int getOrbit() const ;

	/**
	 * get attribute index
	 */
	unsigned int getIndex() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106 107 108 109 110 111 112 113 114

	/**
	 * 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
115
	 * addAttribute(unsigned int orbit, const std::string& nameAttr)
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	 */
	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;

	/**
156
	 * end of table
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158 159 160 161
	 * @return the iterator of the end of container
	 */
	unsigned int end() const;

	/**
162
	 * Next on iterator (equivalent to stl ++)
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164 165 166 167 168 169 170 171 172
	 * @param iter iterator to
	 */
	void next(unsigned int& iter) const;
} ;

} // namespace CGoGN

#include "Topology/generic/attributeHandler.hpp"

#endif