audibility_filter_interface.h 4.46 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
17
18
19
20
21
22
23
24
25

namespace ITA
{
	namespace simulation_scheduler
	{
		class CUpdateScene;

		namespace audibility_filter
		{
			///
			/// \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:
41
42
43
44
45
46
				enum class UsageMode
				{
					filter,
					condition
				};
				
47
				///
48
49
				/// \brief Configuration class for an audibility filter.
				///
50
				struct ITA_SIMULATION_SCHEDULER_API AudibilityFilterConfig : public IConfig
51
				{
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
					explicit AudibilityFilterConfig ( std::string sType );
					
					std::string sFilterName = "Unknown";

					const std::string sFilterType;

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

					bool bInvert = false;
					
					VistaPropertyList store() const override;
					
					void load(const VistaPropertyList& oProperties) override;
67
				};
68

69
70
71
72
73
				///
				/// \brief Pure virtual destructor.
				/// 
				virtual ~IAudibilityFilter ( ) = 0;

74
75
76
				///
				/// \brief Check if the change between \p previousState and \p newUpdate is audible.
				///
Pascal Palenda's avatar
Pascal Palenda committed
77
				/// \note Default behaviour it to return false.
78
79
80
				/// \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.
81
				///
82
				virtual bool changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) const = 0;
83
84
85

			protected:
				///
Pascal Palenda's avatar
Pascal Palenda committed
86
87
88
89
				/// \brief Checks weather the \p newUpdate happened after \p previousState.
				/// \throws ITAExcept when \p previousState happened after \p newUpdate.
				/// \param previousState CUpdateScene of the previous state.
				/// \param newUpdate new CUpdateScene.
90
				/// 
91
				static void checkUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate );
92
93
94
95
96
97
98
			};

			///
			/// \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
99
			///
100
101
102
103
			class ITA_SIMULATION_SCHEDULER_API CAudibilityFilterFactory
			{
			public:
				///
Pascal Palenda's avatar
Pascal Palenda committed
104
105
				/// \brief The function signature for a create function.
				///
106
				typedef std::function<std::unique_ptr<IAudibilityFilter> ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )> CreateCallback;
107
108
109
110
111

				///
				/// \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
112
				///
113
114
115
116
117
				static void registerFilter ( const std::string& type, CreateCallback createFunction );

				///
				/// \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
118
				///
119
120
121
122
123
124
				static void unregisterFilter ( const std::string& type );

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

Pascal Palenda's avatar
Pascal Palenda committed
128
			private:
129
130
				///
				/// \brief Map containing all creation functions.
Pascal Palenda's avatar
Pascal Palenda committed
131
				///
132
133
134
135
136
137
138
				static std::map<std::string, CreateCallback> m_mFilters;
			};
		} // namespace audibility_filter
	} // namespace simulation_scheduler
} // namespace ITA

#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_AUDIBILITY_FILTER_INTERFACE