VAObjectRegistry.h 3.59 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
// Forwards
26 27
class CVAObject;

Jonas Stienen's avatar
Jonas Stienen committed
28 29
//! Registry class for objects
/**
30 31
  * Handles VA object registration. Objects will be callable via object / module interface.
  */
32 33
class VABASE_API CVAObjectRegistry
{
Jonas Stienen's avatar
Jonas Stienen committed
34 35 36 37 38 39 40
public:
	//! Default constructor
	CVAObjectRegistry();

	//! Destructor
	~CVAObjectRegistry();

41
	//! Clear objects. Deregisters all modules.
Jonas Stienen's avatar
Jonas Stienen committed
42 43 44
	void Clear();

	//! Registers an object with the registry and returns its ID
45 46 47 48
	/**
	  * @param[in] pObject Object pointer
	  * @return Object identifier
	  */
49
	int RegisterObject( CVAObject* pObject );
Jonas Stienen's avatar
Jonas Stienen committed
50 51

	//! Deregisters an object from the registry
52 53 54
	/**
	  * @param[in] pObject Object pointer
	  */
55
	void UnregisterObject( CVAObject* pObject );
Jonas Stienen's avatar
Jonas Stienen committed
56 57

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

	//! Query information on all objects
61 62 63
	/**
	  * @param[in] viInfos Object infos
	  */
64
	void GetObjectInfos( std::vector< CVAObjectInfo >& viInfos ) const;
Jonas Stienen's avatar
Jonas Stienen committed
65 66 67

	//! Finds an object by its ID
	/**
68 69 70
	  * @param[in] iID Object identifier
	  * @return Pointer to the object, NULL if not found
	  */
71
	CVAObject* FindObjectByID( const int iID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
72 73 74

	//! Finds the object with the given name
	/**
75 76 77 78
	  * @param[in] sName Object name
	  * @return Pointer to the object, NULL if not found
	  * @note Object names are case-sensitive
	  */
79
	CVAObject* FindObjectByName( const std::string& sName ) const;
Jonas Stienen's avatar
Jonas Stienen committed
80 81 82

	//! Returns an object by its ID
	/**
83 84 85 86
	  * @param[in] iID Object identifier
	  * @return Pointer to the object
	  * @note Throws an exception "invalid object ID" in case the object does not exist
	  */
87
	CVAObject* GetObjectByID( const int iID ) const;
Jonas Stienen's avatar
Jonas Stienen committed
88 89 90

	//! Returns the object with the given name
	/**
91 92 93 94 95
	  * @param[in] sName Object name
	  * @return Pointer to the object, if existing,
	  * @note Throws an exception "unknown object" in case the object does not exist
	  * @note Object names are case-sensitive
	  */
96
	CVAObject* GetObjectByName( const std::string& sName ) const;
Jonas Stienen's avatar
Jonas Stienen committed
97 98 99

	//! Calls an object determined by its ID
	/**
100 101 102 103
	  * @param[in] iID Object identifier
	  * @param[in] oArgs Object call arguments
	  * @returns Throws an "invalid object ID" exception, if the object does not exist
	  */
104
	CVAStruct CallObjectByID( const int iID, const CVAStruct& oArgs ) const;
Jonas Stienen's avatar
Jonas Stienen committed
105 106 107

	//! Calls an object determined by its name
	/**
108 109 110
	  * @param[in] sName Object name
	  * @param[in] oArgs Object call arguments
	 * @returns Throws an "unknown object" exception, if the object does not exist
111
	 */
112
	CVAStruct CallObjectByName( const std::string& sName, const CVAStruct& oArgs ) const;
Jonas Stienen's avatar
Jonas Stienen committed
113 114

private:
115 116 117 118
	std::vector< CVAObject* > m_vpObjects;				//!< Object table (O(1) lookups!)
	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
Jonas Stienen's avatar
Jonas Stienen committed
119 120 121 122

	friend class CVAObject;
};

123
#endif // IW_VABASE_OBJECT_REGISTRY