Commit 2a474473 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add audibility filter interface and factory - WIP

parent 979ea1a5
#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>
// std includes
#include <memory>
#include <functional>
// Vista includes
#include <VistaAspects/VistaPropertyList.h>
namespace ITA
{
namespace simulation_scheduler
{
class CUpdateScene;
namespace audibility_filter
{
///
/// \brief The interface for an audibility filter.
///
/// A audibility filter is used to determine the audibility of the change between two CUpdateScenes.
/// These filters can deploy other filters to increase their possibilities.
///
/// A filter is created by CFilterFactory.
/// For this, a function like this is necessary:
/// \code{.cpp}
/// ///
/// /// \brief Factory function for a filter.
/// /// \remark This function should to be static.
/// ///
/// static std::unique_ptr<IWorkerInterface> createFilter ( const IAudibilityFilter::AudibilityFilterConfig& );
/// \endcode
///
class ITA_SIMULATION_SCHEDULER_API IAudibilityFilter
{
public:
///
/// \brief Configuration class for filter.
/// \todo This class might be only used to hold other filter configs. See if we should keep this.
///
class ITA_SIMULATION_SCHEDULER_API AudibilityFilterConfig : public VistaPropertyList
{
int i = 6;
};
virtual ~IAudibilityFilter ( ) = 0;
///
/// \brief Check if the condition is met.
///
/// A filter might have a condition that has to be fulfilled to be actually useful.
/// Another filter might just be a conditional filter.
/// This function should handle both of these cases.
/// \note Default behaviour it to return true;
/// \param previousState the previous state of the scene to check against.
/// \param newUpdate the CUpdateScene to check.
/// \return true if the condition is fulfilled, else false.
/// \todo Check time stamps that this function was used correctly.
///
virtual bool conditionFulfilled(const CUpdateScene& previousState, const CUpdateScene& newUpdate);
//
///
/// \brief Check if the change between \p previousState and \p newUpdate is audible.
///
/// This function might call ::conditionFulfilled to check if the condition for its test is fulfilled.
/// \note Default behaviour it to return true;
/// \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.
/// \todo Check time stamps that this function was used correctly.
///
virtual bool changeIsAudible(const CUpdateScene& previousState, const CUpdateScene& newUpdate);
};
///
/// \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.
///
class ITA_SIMULATION_SCHEDULER_API CAudibilityFilterFactory
{
public:
///
/// \brief The function signature for a create function.
///
typedef std::function<std::unique_ptr<IAudibilityFilter> ( const IAudibilityFilter::AudibilityFilterConfig& )> CreateCallback;
///
/// \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.
///
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.
///
static void unregisterFilter ( const std::string& type );
///
/// \brief Factory method.
/// \param pConfig the configuration for the filter.
/// \return a pointer to the created filter.
///
static std::unique_ptr<IAudibilityFilter> createFilter ( const IAudibilityFilter::AudibilityFilterConfig& pConfig );
private:
///
/// \brief Map containing all creation functions.
///
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
\ No newline at end of file
#include <ITA/simulation_scheduler/audibility_filter/audibility_filter_interface.h>
namespace ITA
{
namespace simulation_scheduler
{
namespace audibility_filter
{
std::map<std::string, CAudibilityFilterFactory::CreateCallback> CAudibilityFilterFactory::m_mFilters;
// Definition of the pure virtual destructor.
IAudibilityFilter::~IAudibilityFilter()
{
}
bool IAudibilityFilter::conditionFulfilled(const CUpdateScene& previousState, const CUpdateScene& newUpdate)
{
return true;
}
bool IAudibilityFilter::changeIsAudible(const CUpdateScene& previousState, const CUpdateScene& newUpdate)
{
return true;
}
void CAudibilityFilterFactory::registerFilter ( const std::string& type, CreateCallback createFunction )
{
m_mFilters [type] = createFunction;
}
void CAudibilityFilterFactory::unregisterFilter ( const std::string& type )
{
m_mFilters.erase ( type );
}
std::unique_ptr<IAudibilityFilter> CAudibilityFilterFactory::createFilter ( const IAudibilityFilter::AudibilityFilterConfig& pConfig )
{
auto it = m_mFilters.find ( pConfig.begin ( )->first );
if ( it != m_mFilters.end ( ) )
{
// call the creation callback to construct this derived type
return it->second ( pConfig );
}
return nullptr;
}
} // namespace audibility_filter
} // namespace simulation_scheduler
} // namespace ITA
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment