CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
loop_end_operation_node.hpp
1 #ifndef CPPAD_CG_LOOP_END_OPERATION_NODE_INCLUDED
2 #define CPPAD_CG_LOOP_END_OPERATION_NODE_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2013 Ciengis
6  * Copyright (C) 2020 Joao Leal
7  *
8  * CppADCodeGen is distributed under multiple licenses:
9  *
10  * - Eclipse Public License Version 1.0 (EPL1), and
11  * - GNU General Public License Version 3 (GPL3).
12  *
13  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15  * ----------------------------------------------------------------------------
16  * Author: Joao Leal
17  */
18 
19 namespace CppAD {
20 namespace cg {
21 
30 template<class Base>
31 class LoopEndOperationNode : public OperationNode<Base> {
32  friend class CodeHandler<Base>;
33 public:
34 
35  inline const LoopStartOperationNode<Base>& getLoopStart() const {
36  const std::vector<Argument<Base> >& args = this->getArguments();
37  CPPADCG_ASSERT_KNOWN(args.size() > 0, "There must be at least one argument")
38 
39  OperationNode<Base>* aNode = args[0].getOperation();
40  CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::LoopStart, "The first argument must be the loop start operation")
41 
42  return dynamic_cast<LoopStartOperationNode<Base>&> (*aNode);
43  }
44 
45  inline virtual ~LoopEndOperationNode() = default;
46 
47 protected:
48 
49  inline LoopEndOperationNode(CodeHandler<Base>* handler,
50  LoopStartOperationNode<Base>& loopStart,
51  const std::vector<Argument<Base> >& endArgs) :
52  OperationNode<Base>(handler, CGOpCode::LoopEnd, std::vector<size_t>(0), createArguments(loopStart, endArgs)) {
53  }
54 
55 private:
56 
57  static inline std::vector<Argument<Base> > createArguments(LoopStartOperationNode<Base>& lstart,
58  const std::vector<Argument<Base> >& endArgs) {
59  std::vector<Argument<Base> > args(1 + endArgs.size());
60  args[0] = lstart;
61  std::copy(endArgs.begin(), endArgs.end(), args.begin() + 1);
62  return args;
63  }
64 
65 };
66 
67 } // END cg namespace
68 } // END CppAD namespace
69 
70 #endif
const std::vector< Argument< Base > > & getArguments() const
STL namespace.