VAObjectRegistry.h 2.99 KB
Newer Older
Jonas Stienen's avatar
Jonas Stienen committed
1
/*
2
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
3
 *
4 5 6 7 8 9
 *    VVV        VVV A           Virtual Acoustics (VA) | http://www.virtualacoustics.org
 *     VVV      VVV AAA          Licensed under the Apache License, Version 2.0
 *      VVV    VVV   AAA
 *       VVV  VVV     AAA        Copyright 2015-2017
 *        VVVVVV       AAA       Institute of Technical Acoustics (ITA)
 *         VVVV         AAA      RWTH Aachen University
Jonas Stienen's avatar
Jonas Stienen committed
10
 *
11
 *  --------------------------------------------------------------------------------------------
Jonas Stienen's avatar
Jonas Stienen committed
12
 */
13 14 15

#ifndef IW_VABASE_OBJECT_REGISTRY
#define IW_VABASE_OBJECT_REGISTRY
Jonas Stienen's avatar
Jonas Stienen committed
16 17

#include <VABaseDefinitions.h>
18
#include <VABase.h>
19
#include <VAStruct.h>
Jonas Stienen's avatar
Jonas Stienen committed
20 21 22 23 24

#include <map>
#include <string>
#include <vector>

25 26
class CVAObject;

Jonas Stienen's avatar
Jonas Stienen committed
27 28
//! Registry class for objects
/**
29
 *
Jonas Stienen's avatar
Jonas Stienen committed
30
 */
31 32
class VABASE_API CVAObjectRegistry
{
Jonas Stienen's avatar
Jonas Stienen committed
33 34 35 36 37 38 39 40 41 42 43
public:
	//! Default constructor
	CVAObjectRegistry();

	//! Destructor
	~CVAObjectRegistry();

	//! Clear up. Deregisters all modules.
	void Clear();

	//! Registers an object with the registry and returns its ID
44
	int RegisterObject( CVAObject* pObject );
Jonas Stienen's avatar
Jonas Stienen committed
45 46

	//! Deregisters an object from the registry
47
	void UnregisterObject( CVAObject* pObject );
Jonas Stienen's avatar
Jonas Stienen committed
48 49

	//! Query the IDs of all objects
50
	void GetObjectIDs( std::vector< int >& viIDs ) const;
Jonas Stienen's avatar
Jonas Stienen committed
51 52

	//! Query information on all objects
53
	void GetObjectInfos( std::vector< CVAObjectInfo >& viInfos ) const;
Jonas Stienen's avatar
Jonas Stienen committed
54 55 56 57 58

	//! Finds an object by its ID
	/**
	 * \return Pointer to the object, NULL if not found
	 */
59
	CVAObject* FindObjectByID( const int iID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
60 61 62

	//! Finds the object with the given name
	/**
63
	 * \return Pointer to the object, NULL if not found
Jonas Stienen's avatar
Jonas Stienen committed
64 65
	 * \note Object names are case-sensitive
	 */
66
	CVAObject* FindObjectByName( const std::string& sName ) const;
Jonas Stienen's avatar
Jonas Stienen committed
67 68 69 70 71 72

	//! Returns an object by its ID
	/**
	 * \return Pointer to the object
	 * \note Throws an exception "invalid object ID" in case the object does not exist
	 */
73
	CVAObject* GetObjectByID( const int iID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
74 75 76

	//! Returns the object with the given name
	/**
77
	 * \return Pointer to the object, if existing,
Jonas Stienen's avatar
Jonas Stienen committed
78 79 80
	 * \note Throws an exception "unknown object" in case the object does not exist
	 * \note Object names are case-sensitive
	 */
81
	CVAObject* GetObjectByName( const std::string& sName ) const;
Jonas Stienen's avatar
Jonas Stienen committed
82 83 84 85 86

	//! Calls an object determined by its ID
	/**
	 * \returns Throws an "invalid object ID" exception, if the object does not exist
	 */
87
	CVAStruct CallObjectByID( const int iID, const CVAStruct& oArgs ) const;
Jonas Stienen's avatar
Jonas Stienen committed
88 89 90 91

	//! Calls an object determined by its name
	/**
	 * \returns Throws an "unknown object" exception, if the object does not exist
92
	 */
93
	CVAStruct CallObjectByName( const std::string& sName, const CVAStruct& oArgs ) const;
Jonas Stienen's avatar
Jonas Stienen committed
94 95

private:
96
	std::vector< CVAObject* > m_vpObjects;				// Object table (O(1) lookups!)
Jonas Stienen's avatar
Jonas Stienen committed
97 98 99 100 101 102 103
	std::map< std::string, CVAObject* > m_mpObjects;	// Fast name search structure (O(log N) queries!)
	size_t m_nObjects;									// Number of registered objects
	int m_iIDLast;										// ID counter

	friend class CVAObject;
};

104
#endif // IW_VABASE_OBJECT_REGISTRY