audibility_filter_interface.h 5.98 KB
Newer Older
1
2
3
4
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE

// API includes
Pascal Palenda's avatar
Pascal Palenda committed
5
#include <ITA/SimulationScheduler/definitions.h>
6

7
// simulation scheduler includes
Pascal Palenda's avatar
Pascal Palenda committed
8
#include <ITA/SimulationScheduler/config_interface.h>
9
#include <ITA/SimulationScheduler/factory.h>
10

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

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

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

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

					AudibilityFilterConfig& operator=( const AudibilityFilterConfig& other );

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

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

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

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

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

85
86
87
88
89
				///
				/// \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.
90
				///
91
				virtual bool ChangeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) const = 0;
92
93
94

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

104
105
106
			typedef CFactory<IAudibilityFilter, IAudibilityFilter::AudibilityFilterConfig> ITA_SIMULATION_SCHEDULER_API CAudibilityFilterFactory;

			/*
107
108
109
110
111
			///
			/// \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
112
			/// \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
113
			///
114
115
116
117
			class ITA_SIMULATION_SCHEDULER_API CAudibilityFilterFactory
			{
			public:
				///
Pascal Palenda's avatar
Pascal Palenda committed
118
119
				/// \brief The function signature for a create function.
				///
120
				typedef std::function<std::unique_ptr<IAudibilityFilter> ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )> CreateCallback;
121

Pascal Palenda's avatar
Pascal Palenda committed
122
123
124
125
126
				///
				/// \brief The function signature for a config create function.
				///
				typedef std::function<std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig> ()> ConfigCreateCallback;

127
128
129
130
				///
				/// \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
131
				/// \param configCreateFunction the corresponding config create function.
Pascal Palenda's avatar
Pascal Palenda committed
132
				///
Pascal Palenda's avatar
Pascal Palenda committed
133
				static void RegisterFilter ( const std::string& type, CreateCallback createFunction, ConfigCreateCallback configCreateFunction );
134
135
136
137

				///
				/// \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
138
				///
139
				static void UnregisterFilter ( const std::string& type );
140
141
142
143
144

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

Pascal Palenda's avatar
Pascal Palenda committed
148
149
150
151
152
153
154
				///
				/// \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
155
			private:
156
157
				///
				/// \brief Map containing all creation functions.
Pascal Palenda's avatar
Pascal Palenda committed
158
				///
Pascal Palenda's avatar
Pascal Palenda committed
159
				static std::map<std::string, std::pair<CreateCallback, ConfigCreateCallback>> m_mFilters;
160
			};
161
			*/
162
		} // namespace AudibilityFilter
163
164
165

		ENABLE_FACTORY ( AudibilityFilter::IAudibilityFilter::AudibilityFilterConfig );
		
166
	} // namespace SimulationScheduler
167
168
169
} // namespace ITA

#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE