audibility_filter_interface.h 5.72 KB
Newer Older
1
2
3
4
5
6
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE

// API includes
#include <ITA/simulation_scheduler/definitions.h>

7
8
9
// simulation scheduler includes
#include <ITA/simulation_scheduler/config_interface.h>

10
11
12
// std includes
#include <memory>
#include <functional>
13
#include <vector>
14
15
16

namespace ITA
{
17
	namespace SimulationScheduler
18
19
20
	{
		class CUpdateScene;

21
		namespace AudibilityFilter
22
23
24
25
		{
			///
			/// \brief The interface for an audibility filter.
			///
26
			/// An audibility filter is used to determine the audibility of the change between two CUpdateScenes.
27
			///
28
			/// An audibility filter is created by CAudibilityFilterFactory.
29
30
31
			/// For this, a function like this is necessary:
			/// \code{.cpp}
			/// ///
32
			/// /// \brief Factory function for an audibility filter.
33
34
			/// /// \remark This function should to be static.
			/// ///
35
			/// static std::unique_ptr<IAudibilityFilter> createFilter ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig );
36
37
			/// \endcode
			/// 
Pascal Palenda's avatar
Pascal Palenda committed
38
			class ITA_SIMULATION_SCHEDULER_API IAudibilityFilter
39
40
			{
			public:
Pascal Palenda's avatar
Pascal Palenda committed
41
42
43
				///
				/// \brief Usage mode for audibility filter.
				/// 
44
45
				enum class UsageMode
				{
Pascal Palenda's avatar
Pascal Palenda committed
46
47
					filter,   ///< Use the audibility filter as an actual filter.
					condition ///< Use the audibility filter as a condition for following filters.
48
49
				};
				
50
				///
Pascal Palenda's avatar
Pascal Palenda committed
51
52
53
54
				/// \brief Base configuration class for audibility filter.
				///
				/// \note ::sFilterType is a read only property of the AudibilityFilterConfig.
				/// Due to this the copy constructor and assignment operator are needed.
55
				///
56
				struct ITA_SIMULATION_SCHEDULER_API AudibilityFilterConfig : public IConfig
57
				{
58
					AudibilityFilterConfig ( );
59
					
60
					explicit AudibilityFilterConfig ( std::string sType );
61

62
63
64
65
66
67
68
					AudibilityFilterConfig ( const AudibilityFilterConfig& other );

					AudibilityFilterConfig& operator=( const AudibilityFilterConfig& other );

					std::string sFilterName = "Unknown";
					
					const std::string& sFilterType; 
69
70
71
72
73

					std::vector<std::string> sNextFilter;
					
					UsageMode eUsageMode = UsageMode::filter;

74
					bool bInvertCondition = false;
75
					
76
					VistaPropertyList Store() const override = 0;
77

78
					void Load(const VistaPropertyList& oProperties) override = 0;
79

80
81
82
				private:
					std::string m_sFilterType;
				};
83

84
85
86
87
88
				///
				/// \brief Check if the change between \p previousState and \p newUpdate is audible.
				/// \param previousState the previous state of the scene to check against.
				/// \param newUpdate the CUpdateScene to check for audibility.
				/// \return true if the change between \p previousState and \p newUpdate is audible, else false.
89
				///
90
				virtual bool ChangeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) const = 0;
91
92
93

			protected:
				///
Pascal Palenda's avatar
Pascal Palenda committed
94
				/// \brief Checks weather the \p newUpdate happened after \p previousState.
Pascal Palenda's avatar
Pascal Palenda committed
95
				/// \note This method should be called first in every ::changeIsAudible.
Pascal Palenda's avatar
Pascal Palenda committed
96
97
98
				/// \throws ITAExcept when \p previousState happened after \p newUpdate.
				/// \param previousState CUpdateScene of the previous state.
				/// \param newUpdate new CUpdateScene.
99
				/// 
100
				static void CheckUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate );
101
102
103
104
105
106
107
			};

			///
			/// \brief Factory class for filter.
			///
			/// This class implements an extensible factory for filter.
			/// After a type of filter is registered with its IAudibilityFilter::createFilter, it can be created using this factory.
Pascal Palenda's avatar
Pascal Palenda committed
108
			/// \todo Add a way to get the correct config from the type. The factory already knows of all possible filters.
Pascal Palenda's avatar
Pascal Palenda committed
109
			///
110
111
112
113
			class ITA_SIMULATION_SCHEDULER_API CAudibilityFilterFactory
			{
			public:
				///
Pascal Palenda's avatar
Pascal Palenda committed
114
115
				/// \brief The function signature for a create function.
				///
116
				typedef std::function<std::unique_ptr<IAudibilityFilter> ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )> CreateCallback;
117

Pascal Palenda's avatar
Pascal Palenda committed
118
119
120
121
122
				///
				/// \brief The function signature for a config create function.
				///
				typedef std::function<std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig> ()> ConfigCreateCallback;

123
124
125
126
				///
				/// \brief Register a type of filter to the factory.
				/// \param type name of the filter type to be registered.
				/// \param createFunction the corresponding create function.
Pascal Palenda's avatar
Pascal Palenda committed
127
				/// \param configCreateFunction the corresponding config create function.
Pascal Palenda's avatar
Pascal Palenda committed
128
				///
Pascal Palenda's avatar
Pascal Palenda committed
129
				static void RegisterFilter ( const std::string& type, CreateCallback createFunction, ConfigCreateCallback configCreateFunction );
130
131
132
133

				///
				/// \brief Unregister a type of filter from the factory.
				/// \param type name of the filter type to be removed.
Pascal Palenda's avatar
Pascal Palenda committed
134
				///
135
				static void UnregisterFilter ( const std::string& type );
136
137
138
139
140

				///
				/// \brief Factory method.
				/// \param pConfig the configuration for the filter.
				/// \return a pointer to the created filter.
Pascal Palenda's avatar
Pascal Palenda committed
141
				///
142
				static std::unique_ptr<IAudibilityFilter> CreateFilter ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig );
143

Pascal Palenda's avatar
Pascal Palenda committed
144
145
146
147
148
149
150
				///
				/// \brief Factory method for filter configs.
				/// \param sType the configuration for the filter.
				/// \return a pointer to the created filter config.
				///
				static std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig> CreateConfig ( const std::string& sType );
				
Pascal Palenda's avatar
Pascal Palenda committed
151
			private:
152
153
				///
				/// \brief Map containing all creation functions.
Pascal Palenda's avatar
Pascal Palenda committed
154
				///
Pascal Palenda's avatar
Pascal Palenda committed
155
				static std::map<std::string, std::pair<CreateCallback, ConfigCreateCallback>> m_mFilters;
156
			};
157
158
		} // namespace AudibilityFilter
	} // namespace SimulationScheduler
159
160
161
} // namespace ITA

#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE