DSPatch  v.7.0.1
Component.h
1 /******************************************************************************
2 DSPatch - The Refreshingly Simple C++ Dataflow Framework
3 Copyright (c) 2020, Marcus Tomlinson
4 
5 BSD 2-Clause License
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice, this
11  list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ******************************************************************************/
28 
29 #pragma once
30 
31 #include <dspatch/SignalBus.h>
32 
33 #include <string>
34 
35 namespace DSPatch
36 {
37 
38 namespace internal
39 {
40 class Component;
41 } // namespace internal
42 
44 
72 class DLLEXPORT Component
73 {
74 public:
75  NONCOPYABLE( Component );
76  DEFINE_PTRS( Component );
77 
78  enum class ProcessOrder
79  {
80  InOrder,
81  OutOfOrder
82  };
83 
84  enum class TickMode
85  {
86  Series,
87  Parallel
88  };
89 
90  Component( ProcessOrder processOrder = ProcessOrder::InOrder );
91  virtual ~Component();
92 
93  bool ConnectInput( Component::SPtr const& fromComponent, int fromOutput, int toInput );
94 
95  void DisconnectInput( int inputNo );
96  void DisconnectInput( Component::SCPtr const& fromComponent );
97  void DisconnectAllInputs();
98 
99  int GetInputCount() const;
100  int GetOutputCount() const;
101 
102  std::string GetInputName( int inputNo ) const;
103  std::string GetOutputName( int outputNo ) const;
104 
105  void SetBufferCount( int bufferCount );
106  int GetBufferCount() const;
107 
108  bool Tick( TickMode mode = TickMode::Parallel, int bufferNo = 0 );
109  void Reset( int bufferNo = 0 );
110 
111 protected:
112  virtual void Process_( SignalBus const&, SignalBus& ) = 0;
113 
114  void SetInputCount_( int inputCount, std::vector<std::string> const& inputNames = {} );
115  void SetOutputCount_( int outputCount, std::vector<std::string> const& outputNames = {} );
116 
117 private:
118  std::unique_ptr<internal::Component> p;
119 };
120 
121 } // namespace DSPatch
DSPatch::SignalBus
Signal container.
Definition: SignalBus.h:76