MUQ  0.4.3
ConstantPiece.h
Go to the documentation of this file.
1 #ifndef CONSTANTPIECE_H_
2 #define CONSTANTPIECE_H_
3 
5 
6 namespace muq {
7  namespace Modeling {
9  class ConstantPiece : public WorkPiece {
10  public:
11 
13 
16  ConstantPiece(std::vector<boost::any> const& outs);
17 
19 
22  ConstantPiece();
23 
25 
30  template<typename ith, typename... Args>
31  ConstantPiece(ith const& in, Args... args) : ConstantPiece(args...) {
32  // add this output to the begining of the output vector
33  outputs.insert(outputs.begin(), in);
34 
35  // set the number of outputs
36  numOutputs = outputs.size();
37 
38  // set the output types
40  }
41 
43 
47  template<typename last>
48  ConstantPiece(last const& in) : WorkPiece(0, WorkPiece::Fix::Inputs) {
49  // the outputs will never change so we should not clear them
50  clearOutputs = false;
51 
52  // add this output to the begining of the output vector
53  outputs.insert(outputs.begin(), in);
54 
55  // set the number of outputs
56  numOutputs = outputs.size();
57 
58  // set the output types
60  }
61 
63  void SetOutputs();
64 
66 
69  void SetOutputs(std::vector<boost::any> const& outs);
70 
72 
76  template<typename ith, typename... Args>
77  void SetOutputs(ith const& in, Args... args) {
78  // create an empty vector of outputs
79  std::vector<boost::any> outs(0);
80 
81  // add this output to the begining of the output vector
82  outs.insert(outs.begin(), in);
83 
84  // call recursively
85  SetOutputs(outs, args...);
86  }
87 
88  private:
89 
91 
96  template<typename ith, typename... Args>
97  void SetOutputs(std::vector<boost::any>& outs, ith const& in, Args... args) {
98  // add this output
99  outs.push_back(in);
100 
101  // call recursively
102  SetOutputs(outs, args...);
103  }
104 
106 
110  template<typename last>
111  void SetOutputs(std::vector<boost::any>& outs, last const& in) {
112  // add this output
113  outs.push_back(in);
114 
115  // call recursively
116  SetOutputs(outs);
117  }
118 
120 
123  virtual void EvaluateImpl(muq::Modeling::ref_vector<boost::any> const& inputs) override;
124 
125  };
126  } // namespace Modeling
127 } // namespace muq
128 
129 #endif
A muq::Modeling::WorkPiece with no inputs and known, constant outputs.
Definition: ConstantPiece.h:9
ConstantPiece()
Create a muq::Modeling::ConstantPiece with no given outputs.
void SetOutputs(ith const &in, Args... args)
Create a muq::Modeling::ConstantPiece with the outputs given indivually.
Definition: ConstantPiece.h:77
Base class for MUQ's modelling envronment.
Definition: WorkPiece.h:40
std::map< unsigned int, std::string > outputTypes
The output types.
Definition: WorkPiece.h:558
WorkPiece()
Create a muq::Modeling::WorkPiece with no fixed number of inputs and outputs and variable input/outpu...
Definition: WorkPiece.cpp:10
virtual void EvaluateImpl(ref_vector< boost::any > const &inputs)=0
User-implemented function that determines the behavior of this muq::Modeling::WorkPiece.
std::vector< std::string > Types(std::vector< boost::any > const &vec) const
Get the types from a vector of boost::any's.
Definition: WorkPiece.cpp:201
bool clearOutputs
Clear outputs every time Evaluate is called.
Definition: WorkPiece.h:540
int numOutputs
The number of outputs.
Definition: WorkPiece.h:504
std::vector< boost::any > outputs
The outputs.
Definition: WorkPiece.h:546
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37
const char * last
Definition: json.h:15399