autoAttributeHandler.h 4 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __AUTO_ATTRIBUTE_HANDLER_H__
#define __AUTO_ATTRIBUTE_HANDLER_H__

#include "Topology/generic/attribmap.h"
#include "Topology/generic/attributeHandler.h"

namespace CGoGN
{

/**
Pierre Kraemer's avatar
Pierre Kraemer committed
35
 * Class that creates an access-table to an attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
36
 * that is added especially. The attribute is removed when
Pierre Kraemer's avatar
Pierre Kraemer committed
37
 * the AutoAttributeHandler object is destroyed
Pierre Kraemer's avatar
Pierre Kraemer committed
38
 */
39 40
template <typename T, unsigned int ORBIT>
class AutoAttributeHandler : public AttributeHandler<T, ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42 43 44 45 46 47 48 49
{
public:
	/**
	 * constructor
	 * @param m the map
	 * @param orbit the orbit of map
	 * @param nameAttr the name of attribute
	 * @param nameType the name of type of attribute
	 */
50
	AutoAttributeHandler(AttribMap& m, const std::string& nameAttr = "")
Pierre Kraemer's avatar
Pierre Kraemer committed
51 52
	{
		this->m_map = &m ;
53 54
		if(!m.isOrbitEmbedded<ORBIT>())
			m.addEmbedding<ORBIT>() ;
55
		AttributeMultiVector<T>* amv = this->m_map->m_attribs[ORBIT].template addAttribute<T>(nameAttr) ;
56
		this->m_attrib = amv ;
57 58
		this->valid = true ;
		this->registerInMap() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60 61 62
	}

	~AutoAttributeHandler()
	{
63 64
		if (this->valid)
			reinterpret_cast<AttribMap*>(this->m_map)->removeAttribute<T>(*this) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
65
	}
66
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
67

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

/**
 *  shortcut class for Vertex AutoAttribute (Handler)
 */
template <typename T>
class VertexAutoAttribute : public AutoAttributeHandler<T,VERTEX>
{
public:
	VertexAutoAttribute(AttribMap& m, const std::string& nameAttr = ""):AutoAttributeHandler<T,VERTEX>(m,nameAttr) {}
};

/**
 *  shortcut class for Edge AutoAttribute (Handler)
 */
template <typename T>
class EdgeAutoAttribute : public AutoAttributeHandler<T,EDGE>
{
public:
	EdgeAutoAttribute(AttribMap& m, const std::string& nameAttr = ""):AutoAttributeHandler<T,EDGE>(m,nameAttr) {}
};

/**
 *  shortcut class for Face AutoAttribute (Handler)
 */
template <typename T>
class FaceAutoAttribute : public AutoAttributeHandler<T,FACE>
{
public:
	FaceAutoAttribute(AttribMap& m, const std::string& nameAttr = ""):AutoAttributeHandler<T,FACE>(m,nameAttr) {}
};

/**
 *  shortcut class for Volume AutoAttribute (Handler)
 */
template <typename T>
class VolumeAutoAttribute : public AutoAttributeHandler<T,VOLUME>
{
public:
	VolumeAutoAttribute(AttribMap& m, const std::string& nameAttr = ""):AutoAttributeHandler<T,VOLUME>(m,nameAttr) {}
};


Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112
} // namespace CGoGN

#endif