registered.h 3.3 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24

Pierre Kraemer's avatar
Pierre Kraemer committed
25 26
#ifndef _REGISTERED_ATTRIBUTE_H_
#define _REGISTERED_ATTRIBUTE_H_
Pierre Kraemer's avatar
Pierre Kraemer committed
27 28 29 30 31 32 33 34 35 36 37 38 39

namespace CGoGN
{

/**
 * Classe d'enregistrement d'attribut
 */
class RegisteredBaseAttribute
{
protected:
	std::string m_name; // TODO inutile ??

public:
Thery Sylvain's avatar
Thery Sylvain committed
40 41

	virtual ~RegisteredBaseAttribute() {}
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44
	/**
	 * affecte un nom de type a l'attribut
	 */
45
	void setTypeName(const std::string& nameType) { m_name = nameType; }
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48 49

	/**
	 * recupere le nom de type affecté à l'attribut
	 */
50
	const std::string& getTypeName() { return m_name; }
Pierre Kraemer's avatar
Pierre Kraemer committed
51

52 53
	virtual unsigned int size() = 0;

Pierre Kraemer's avatar
Pierre Kraemer committed
54
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	 * Ajout de l'attribut au container (A IMPLEMENTER)
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	 */
57
	virtual AttributeMultiVectorGen* addAttribute(AttributeContainer& container, const std::string& attribName) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59 60 61 62 63 64 65 66 67 68 69 70
};

/**
 * Version template de la classe d'enregistrement d'attribut
 * Fonction avec tout type qui répond aux contraintes suivantes:
 *  - I/O avec les flux (operator >> et <<)
 *  - copie mémoire directe utilisable (pas de pointeurs dans la structure)
 */
template<typename T>
class RegisteredAttribute : public RegisteredBaseAttribute
{
public:

71
	AttributeMultiVectorGen* addAttribute(AttributeContainer& container, const std::string& attribName)
Pierre Kraemer's avatar
Pierre Kraemer committed
72
	{
Sylvain Thery's avatar
Sylvain Thery committed
73 74 75 76 77 78
		unsigned int id = container.getAttributeIndex(attribName);
		// new attribute
		if (id == AttributeContainer::UNKNOWN)
			return container.addAttribute<T>(attribName);
		// or existing one
		return container.getDataVector<T>(id);
Pierre Kraemer's avatar
Pierre Kraemer committed
79
	}
80 81 82 83 84

	unsigned int size()
	{
		return sizeof(T);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86
};

Pierre Kraemer's avatar
Pierre Kraemer committed
87
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
88

Pierre Kraemer's avatar
Pierre Kraemer committed
89
#endif // _REGISTERED_ATTRIBUTE_H_