VAAttributable.h 2.33 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/*
 *
 *    VVV        VVV A
 *     VVV      VVV AAA        Virtual Acoustics
 *      VVV    VVV   AAA       Real-time auralisation for virtual reality    
 *       VVV  VVV     AAA
 *        VVVVVV       AAA     (c) Copyright Institut fr Technische Akustik (ITA)
 *         VVVV         AAA        RWTH Aachen (http://www.akustik.rwth-aachen.de)
 *
 *  ---------------------------------------------------------------------------------
 *
 *    File:				VAAttributable.h   
 *
 *    Purpose:			Attribute aspect interface
 *
 *    Autor(en):		Frank Wefers (Frank.Wefers@akustik.rwth-aachen.de)
 *
 *  ---------------------------------------------------------------------------------
 */
  
// $Id:  $

#ifndef __VABASE_ATTRIBUTABLE_H__
#define __VABASE_ATTRIBUTABLE_H__

#include <VABaseDefinitions.h>
#include <map>

//! Attribute base class
/**
 * This is the base class for attributes.
 * Currently it only defines the destructor.
 */
class VABASE_API IVAAttribute {
public:
	virtual ~IVAAttribute();
};

//! Attributation interface
/**
 * This aspect allows attaching/detaching attributes by means of a pointer
 * to some instance of a class. The attributes are associated with their owner,
 * the instance, which added/removed them. Thereby 1 instance can be associated
 * with N attributes. The interface is used, so that other class can extend
 * previously created instances of some base class with their own runtime data.
 * Example: An HRIR dataset can be attach with some frequency-domain HRTF representation.
 */

class VABASE_API IVAAttributable {
public:
	virtual ~IVAAttributable();

	virtual void AttachAttribute(void* pOwner, IVAAttribute* pAttr)=0;
	virtual void DetachAttribute(void* pOwner)=0;
	virtual IVAAttribute* GetAttribute(void* pOwner)=0;
};

//! Attributation interface default implementation
/**
 * Implements the IVAAttributable interface using std::map.
 * This implementation is not thread-safe! You need to take care yourself!
 */
class VABASE_API CVAAttributableImpl : public IVAAttributable {
public:
	virtual ~CVAAttributableImpl();
	virtual void AttachAttribute(void* pOwner, IVAAttribute* pAttr);
	virtual void DetachAttribute(void* pOwner);
	virtual IVAAttribute* GetAttribute(void* pOwner);

private:
	typedef std::map<void*, IVAAttribute*> AttrMap;
	typedef AttrMap::iterator AttrMapIt;

	AttrMap m_mAttr;
};

#endif // __VABASE_ATTRIBUTABLE_H__