Lodestar
An integrated real-time control package in C++
SignumBlock.hpp
1 //
2 // Created by Hamza El-Kebir on 12/23/21.
3 //
4 
5 #ifndef LODESTAR_SIGNUMBLOCK_HPP
6 #define LODESTAR_SIGNUMBLOCK_HPP
7 
8 #include "Lodestar/blocks/Block.hpp"
9 
10 namespace ls {
11  namespace blocks {
12  namespace std {
13  template<typename TType, typename TOutput = int>
15  : public Block<
16  ::std::tuple<TType>,
17  ::std::tuple<TOutput>,
18  BlockProto::empty
19  > {
20  public:
21  using Base =
22  Block<
23  ::std::tuple<TType>,
24  ::std::tuple<TOutput>,
25  BlockProto::empty
26  >;
27 
28  SignumBlock()
29  {
30  bindFunction();
31  }
32 
33  bool isPositive() const
34  {
35  return (this->template o<0>() > 0);
36  }
37 
38  bool isNegative() const
39  {
40  return (this->template o<0>() < 0);
41  }
42 
43  bool isZero() const
44  {
45  return (this->template o<0>() == 0);
46  }
47 
48  bool isNonNegative() const
49  {
50  return (this->template o<0>() >= 0);
51  }
52 
53  bool isNonPositive() const
54  {
55  return (this->template o<0>() <= 0);
56  }
57 
58  protected:
59  void bindFunction()
60  {
61  this->equation = ::std::bind(
63  ::std::placeholders::_1);
64  }
65 
66  void triggerFunction(Base &b)
67  {
68  b.template o<0>() = (b.template i<0>() == 0 ? 0 : (
69  b.template i<0>() < 0 ? -1 : 1));
70  }
71  };
72  }
73 
74  template<typename TType, typename TOutput>
75  class BlockTraits<std::SignumBlock<TType, TOutput>> {
76  public:
77  static constexpr const BlockType blockType = BlockType::SignumBlock;
78  enum {
79  directFeedthrough = true
80  };
81 
83  using Base = typename type::Base;
84 
85  enum {
86  kIns = Base::kIns,
87  kOuts = Base::kOuts,
88  kPars = Base::kPars
89  };
90 
91  static const ::std::array<::std::string, kIns> inTypes;
92  static const ::std::array<::std::string, kOuts> outTypes;
93  static const ::std::array<::std::string, kPars> parTypes;
94 
95  static const ::std::array<::std::string, 2> templateTypes;
96  };
97 
98  template<typename TType, typename TOutput>
99  const ::std::array<::std::string, BlockTraits<std::SignumBlock<TType, TOutput>>::kIns> BlockTraits<std::SignumBlock<TType, TOutput>>::inTypes =
100  {demangle(typeid(TType).name())};
101 
102  template<typename TType, typename TOutput>
103  const ::std::array<::std::string, BlockTraits<std::SignumBlock<TType, TOutput>>::kOuts> BlockTraits<std::SignumBlock<TType, TOutput>>::outTypes =
104  {demangle(typeid(TOutput).name())};
105 
106  template<typename TType, typename TOutput>
107  const ::std::array<::std::string, BlockTraits<std::SignumBlock<TType, TOutput>>::kPars> BlockTraits<std::SignumBlock<TType, TOutput>>::parTypes =
108  {};
109 
110  template<typename TType, typename TOutput>
111  const ::std::array<::std::string, 2> BlockTraits<std::SignumBlock<TType, TOutput>>::templateTypes =
112  {demangle(typeid(TType).name()), demangle(typeid(TOutput).name())};
113  }
114 }
115 
116 
117 #endif //LODESTAR_SIGNUMBLOCK_HPP
ls::blocks::BlockTraits::directFeedthrough
static constexpr const bool directFeedthrough
Whether or not the block has direct feedthrough.
Definition: BlockTraits.hpp:44
ls::blocks::BlockTraits
A traits object that exposes information about TBlock.
Definition: BlockTraits.hpp:37
ls::blocks::BlockTraits::inTypes
static const ::std::array<::std::string, kIns > inTypes
Input types (as strings).
Definition: BlockTraits.hpp:59
ls::blocks::BlockType
BlockType
Block type information.
Definition: BlockType.hpp:25
ls::blocks::BlockType::SignumBlock
@ SignumBlock
Signum block.
ls
Main Lodestar code.
Definition: BilinearTransformation.hpp:12
ls::blocks::std::SignumBlock
Definition: SignumBlock.hpp:14
ls::blocks::BlockTraits::outTypes
static const ::std::array<::std::string, kOuts > outTypes
Output types (as strings).
Definition: BlockTraits.hpp:61
ls::blocks::BlockTraits::blockType
static constexpr const BlockType blockType
Block type.
Definition: BlockTraits.hpp:42
ls::blocks::BlockTraits::templateTypes
static const ::std::array<::std::string, 1 > templateTypes
Template parameter types (as strings).
Definition: BlockTraits.hpp:66
ls::blocks::Block
Generic base template class for all tuple-based Block instances.
Definition: Block.hpp:45
ls::blocks::BlockTraits::kIns
static const constexpr int kIns
Number of input slots.
Definition: BlockTraits.hpp:52
ls::blocks::BlockTraits::parTypes
static const ::std::array<::std::string, kPars > parTypes
Parameter types (as strings).
Definition: BlockTraits.hpp:63
ls::blocks::BlockTraits::kPars
static const constexpr int kPars
Number of parameters.
Definition: BlockTraits.hpp:56
ls::blocks::BlockTraits::kOuts
static const constexpr int kOuts
Number of output slots.
Definition: BlockTraits.hpp:54