LCOV - code coverage report
Current view: top level - Core - TypedBaseFilter.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 3 3 100.0 %
Date: 2021-02-18 20:07:22 Functions: 18 39 46.2 %

          Line data    Source code
       1             : /**
       2             :  * \file TypedBaseFilter.h
       3             :  */
       4             : 
       5             : #ifndef ATK_CORE_TYPEDBASEFILTER_H
       6             : #define ATK_CORE_TYPEDBASEFILTER_H
       7             : 
       8             : #include <ATK/Core/BaseFilter.h>
       9             : #include <ATK/Core/TypeTraits.h>
      10             : 
      11             : #include <boost/align/aligned_allocator.hpp>
      12             : 
      13             : #include <gsl/gsl>
      14             : 
      15             : #include <memory>
      16             : #include <vector>
      17             : 
      18             : namespace ATK
      19             : {
      20             :   const gsl::index ALIGNMENT = 32;
      21             : 
      22             :   /// Interface for output filters
      23             :   template<typename DataType>
      24             :   class ATK_CORE_EXPORT OutputArrayInterface
      25             :   {
      26             :   public:
      27        2326 :     virtual ~OutputArrayInterface() = default;
      28             : 
      29             :     /**
      30             :      * @brief Returns an array with the processed output
      31             :      * @param port is the port that the next plugin listens to
      32             :      */
      33             :     virtual DataType* get_output_array(gsl::index port) const = 0;
      34             :     /**
      35             :      * Returns the size of the output arrays (usually the last size processed)
      36             :      */
      37             :     virtual gsl::index get_output_array_size() const = 0;
      38             :   };
      39             : 
      40             :   /// Base class for typed filters, contains arrays
      41             :   template<typename DataType_, typename DataType__ = DataType_>
      42             :   class ATK_CORE_EXPORT TypedBaseFilter : public BaseFilter, public OutputArrayInterface<DataType__>
      43             :   {
      44             :   protected:
      45             :     /// Simplify parent calls
      46             :     using Parent = BaseFilter;
      47             :   public:
      48             :     /// To be used by inherited APIs
      49             :     using DataType = DataType_;
      50             :     /// To be used by inherited APIs
      51             :     using DataTypeInput = DataType_;
      52             :     /// To be used by inherited APIs
      53             :     using DataTypeOutput = DataType__;
      54             :     /// To be used for filters that require aligned data
      55             :     using AlignedVector = std::vector<DataTypeInput, boost::alignment::aligned_allocator<DataTypeInput, ALIGNMENT> >;
      56             :     /// To be used for filters that require aligned data for output data
      57             :     using AlignedOutVector = std::vector<DataTypeOutput, boost::alignment::aligned_allocator<DataTypeOutput, ALIGNMENT> >;
      58             :     /// To be used for filters that required aligned data for parameters (like EQ)
      59             :     using AlignedScalarVector = std::vector<typename TypeTraits<DataType>::Scalar, boost::alignment::aligned_allocator<typename TypeTraits<DataType>::Scalar, ALIGNMENT> >;
      60             : 
      61             :     /// Base constructor for filters with actual data
      62             :     TypedBaseFilter(gsl::index nb_input_ports, gsl::index nb_output_ports);
      63             :     /// Destructor
      64        2326 :     ~TypedBaseFilter() override = default;
      65             : 
      66             :     TypedBaseFilter(const TypedBaseFilter&) = delete;
      67             :     TypedBaseFilter& operator=(const TypedBaseFilter&) = delete;
      68          35 :     TypedBaseFilter(TypedBaseFilter&&) = default;
      69             :     TypedBaseFilter& operator=(TypedBaseFilter&&) = default;
      70             : 
      71             :     /**
      72             :      * @brief Returns an array with the processed output
      73             :      * @param port is the port that the next plugin listens to
      74             :      */
      75             :     DataType__* get_output_array(gsl::index port) const final;
      76             :     gsl::index get_output_array_size() const final;
      77             : 
      78             :     void set_nb_input_ports(gsl::index nb_ports) override;
      79             :     void set_nb_output_ports(gsl::index nb_ports) override;
      80             : 
      81             :     void full_setup() override;
      82             : 
      83             :     /// Connects this filter input to another's output
      84             :     void set_input_port(gsl::index input_port, gsl::not_null<BaseFilter*> filter, gsl::index output_port) final;
      85             :     void set_input_port(gsl::index input_port, BaseFilter& filter, gsl::index output_port) final;
      86             : 
      87             :   private:
      88             :     int get_type() const override;
      89             :   protected:
      90             :     /// This implementation does nothing
      91             :     void process_impl(gsl::index size) const override;
      92             :     /// Prepares the filter by retrieving the inputs arrays
      93             :     void prepare_process(gsl::index size) final;
      94             :     /// Prepares the filter by resizing the outputs arrays
      95             :     void prepare_outputs(gsl::index size) final;
      96             : 
      97             :     /// Used to convert other filter outputs to DataType*
      98             :     void convert_inputs(gsl::index size);
      99             : 
     100             :     /// Input arrays with the input delay, owned here
     101             :     std::vector<AlignedVector> converted_inputs_delay;
     102             :     /// Input arrays, starting from t=0 (without input delay)
     103             :     std::vector<DataTypeInput*> converted_inputs;
     104             :     /// Current size of the input arrays, without delay
     105             :     std::vector<gsl::index> converted_inputs_size;
     106             :     /// Current input delay
     107             :     std::vector<gsl::index> converted_in_delays;
     108             :     /// Pointer to the output interface of the connected filters
     109             :     std::vector<OutputArrayInterface<DataType_>*> direct_filters;
     110             : 
     111             :     /// Output arrays with the output delay, owned here
     112             :     std::vector<AlignedOutVector> outputs_delay;
     113             :     /// Output arrays, starting from t=0 (without output delay)
     114             :     std::vector<DataTypeOutput*> outputs;
     115             :     /// Current size of the output arrays, without delay
     116             :     std::vector<gsl::index> outputs_size;
     117             :     /// Current output delay
     118             :     std::vector<gsl::index> out_delays;
     119             : 
     120             :     /// A vector containing the default values for the input arrays
     121             :     AlignedVector default_input;
     122             :     /// A vector containing the default values for the output arrays
     123             :     AlignedOutVector default_output;
     124             :   };
     125             : }
     126             : 
     127             : #endif

Generated by: LCOV version TK-3.3.0-4-gdba42eea