Lodestar
An integrated real-time control package in C++
DelayBlock.hpp
1 //
2 // Created by Hamza El-Kebir on 2/24/22.
3 //
4 
5 #ifndef LODESTAR_DELAYBLOCK_HPP
6 #define LODESTAR_DELAYBLOCK_HPP
7 
8 #include <Lodestar/blocks/Block.hpp>
9 #include <Lodestar/aux/ArrayStack.hpp>
10 
11 namespace ls {
12  namespace blocks {
13  namespace std {
14  template<typename TInput, unsigned int NDelay=1>
15  class DelayBlock
16  : public Block<
17  ::std::tuple<TInput>,
18  ::std::tuple<TInput>,
19  BlockProto::empty
20  > {
21  public:
22  using Base =
23  Block<
24  ::std::tuple<TInput>,
25  ::std::tuple<TInput>,
26  BlockProto::empty
27  >;
28 
29  DelayBlock()
30  {
31  bindFunction();
32  }
33 
34  void clear(TInput value)
35  {
36  fifoStack_.fill(value);
37  this->template o<0>() = value;
38  }
39 
40  void clear(TInput &value)
41  {
42  fifoStack_.fill(value);
43  this->template o<0>() = value;
44  }
45  protected:
47 
48  void bindFunction()
49  {
50  this->equation = ::std::bind(
52  this,
53  ::std::placeholders::_1
54  );
55  }
56 
57  void triggerFunction(Base &b)
58  {
59  fifoStack_.push(b.template i<0>().object);
60  b.template o<0>() = fifoStack_.back();
61  }
62  };
63  }
64 
65  template<typename TInput, unsigned int NDelay>
67  public:
68  static constexpr const BlockType blockType = BlockType::DelayBlock;
69  enum {
70  directFeedthrough = (NDelay < 1)
71  };
72 
74  using Base = typename type::Base;
75 
76  enum {
77  kIns = Base::kIns,
78  kOuts = Base::kOuts,
79  kPars = Base::kPars
80  };
81 
82  static const ::std::array<::std::string, kIns> inTypes;
83  static const ::std::array<::std::string, kOuts> outTypes;
84  static const ::std::array<::std::string, kPars> parTypes;
85 
86  static const ::std::array<::std::string, 2> templateTypes;
87  };
88 
89  template<typename TInput, unsigned int NDelay>
90  const ::std::array<::std::string, BlockTraits<std::DelayBlock<TInput, NDelay>>::kIns> BlockTraits<std::DelayBlock<TInput, NDelay>>::inTypes =
91  {demangle(typeid(TInput).name())};
92 
93  template<typename TInput, unsigned int NDelay>
94  const ::std::array<::std::string, BlockTraits<std::DelayBlock<TInput, NDelay>>::kOuts> BlockTraits<std::DelayBlock<TInput, NDelay>>::outTypes =
95  {demangle(typeid(TInput).name())};
96 
97  template<typename TInput, unsigned int NDelay>
98  const ::std::array<::std::string, BlockTraits<std::DelayBlock<TInput, NDelay>>::kPars> BlockTraits<std::DelayBlock<TInput, NDelay>>::parTypes =
99  {};
100 
101  template<typename TInput, unsigned int NDelay>
102  const ::std::array<::std::string, 2> BlockTraits<std::DelayBlock<TInput, NDelay>>::templateTypes =
103  {demangle(typeid(TInput).name()), "unsigned int"};
104  }
105 }
106 
107 
108 #endif //LODESTAR_DELAYBLOCK_HPP
ls::aux::ArrayStack::back
TType & back()
Returns a reference to the rear value in the stack.
Definition: ArrayStack.hpp:222
ls::blocks::BlockTraits
A traits object that exposes information about TBlock.
Definition: BlockTraits.hpp:37
ls::blocks::BlockType
BlockType
Block type information.
Definition: BlockType.hpp:25
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::blocks::std::DelayBlock
Definition: DelayBlock.hpp:15
ls::aux::ArrayStack
A statically sized stack with full member access.
Definition: ArrayStack.hpp:21
ls::blocks::BlockType::DelayBlock
@ DelayBlock
Delay block.
ls::blocks::Block
Generic base template class for all tuple-based Block instances.
Definition: Block.hpp:45
ls::aux::ArrayStack::push
void push(const TType &value)
Pushes value to front of ArrayStack.
Definition: ArrayStack.hpp:144