source: XIOS/trunk/src/filter/input_pin.hpp @ 637

Last change on this file since 637 was 637, checked in by rlacroix, 6 years ago

Add the base classes for the new filter framework.

File size: 2.0 KB
Line 
1#ifndef __XIOS_CInputPin__
2#define __XIOS_CInputPin__
3
4#include <vector>
5#include <map>
6
7#include "data_packet.hpp"
8
9namespace xios
10{
11  /*!
12   * An input pin handles the data packets received by a filter.
13   */
14  class CInputPin
15  {
16    public:
17      /*!
18       * Constructs an input pin with the specified number of slots.
19       *
20       * \param slotsCount the number of slots
21       */
22      CInputPin(size_t slotsCount);
23
24      /*!
25       * Receives a data packet from an upstream filter on
26       * the specified input slot.
27       * The receiving filter takes ownership of the packet.
28       *
29       * \param inputSlot the input slot number
30       * \param packet the data packet to be received
31       */
32      void setInput(size_t inputSlot, CDataPacketPtr packet);
33
34    protected:
35      /*!
36       * Function triggered when all slots have been filled for a specific timestamp.
37       * It should be implemented by the filter class to process the data.
38       *
39       * \param data a vector of packets corresponding to each slot
40       */
41      void virtual onInputReady(std::vector<CDataPacketPtr> data) = 0;
42
43    private:
44      /*!
45       * Helper structure, groups a vector of packets corresponding to each slot
46       * with the number of slots currently filled
47       */
48      struct InputBuffer
49      {
50        size_t slotsFilled; //!< Number of slots currently filled
51        std::vector<CDataPacketPtr> packets; //< Vector of packets corresponding to each slot
52
53        /*!
54         * Initialize an empty input buffer for the specified number of slots.
55         *
56         * \param slotsCount the number of slots
57         */
58        InputBuffer(size_t slotsCount)
59          : slotsFilled(0)
60          , packets(slotsCount)
61        { /* Nothing to do */ };
62      };
63
64      size_t slotsCount; //!< The number of slots
65
66      //! Input buffer, store the packets until all slots are full for a timestep
67      std::map<Time, InputBuffer> inputs;
68  }; // class CInputPin
69} // namespace xios
70
71#endif //__XIOS_CInputPin__
Note: See TracBrowser for help on using the repository browser.