CppADCodeGen  2.3.0
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  *
7  * CppADCodeGen is distributed under multiple licenses:
8  *
9  * - Eclipse Public License Version 1.0 (EPL1), and
10  * - GNU General Public License Version 3 (GPL3).
11  *
12  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14  * ----------------------------------------------------------------------------
15  * Author: Joao Leal
16  */
17 
18 namespace CppAD {
19 namespace cg {
20 
29 template<class Base>
30 class LoopEndOperationNode : public OperationNode<Base> {
31  friend class CodeHandler<Base>;
32 public:
33 
34  inline const LoopStartOperationNode<Base>& getLoopStart() const {
35  const std::vector<Argument<Base> >& args = this->getArguments();
36  CPPADCG_ASSERT_KNOWN(args.size() > 0, "There must be at least one argument");
37 
38  OperationNode<Base>* aNode = args[0].getOperation();
39  CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::LoopStart, "The first argument must be the loop start operation");
40 
41  return dynamic_cast<LoopStartOperationNode<Base>&> (*aNode);
42  }
43 
44  inline virtual ~LoopEndOperationNode() {
45  }
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.