CppADCodeGen  2.3.0
A C++ Algorithmic Differentiation Package with Source Code Generation
loop_start_operation_node.hpp
1 #ifndef CPPAD_CG_LOOP_START_OPERATION_NODE_INCLUDED
2 #define CPPAD_CG_LOOP_START_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 LoopStartOperationNode : public OperationNode<Base> {
31  friend class CodeHandler<Base>;
32 public:
33 
34  inline OperationNode<Base>& getIndex() const {
35  const std::vector<Argument<Base> >& args = this->getArguments();
36  CPPADCG_ASSERT_KNOWN(!args.empty(), "Invalid number of arguments");
37 
38  OperationNode<Base>* aNode = args[0].getOperation();
39  CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::IndexDeclaration, "Invalid argument operation type");
40 
41  return static_cast<OperationNode<Base>&> (*aNode);
42  }
43 
44  inline IndexOperationNode<Base>* getIterationCountNode() const {
45  if (this->getInfo().empty()) {
46  CPPADCG_ASSERT_KNOWN(this->getArguments().size() > 1, "Invalid number of arguments.");
47 
48  OperationNode<Base>* aNode = this->getArguments()[1].getOperation();
49  CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::Index, "Invalid argument node type");
50 
51  return static_cast<IndexOperationNode<Base>*> (aNode);
52  }
53 
54  return nullptr;
55  }
56 
57  inline const size_t getIterationCount() const {
58  if (this->getInfo().empty()) {
59  return 0;
60  }
61  return this->getInfo()[0];
62  }
63 
64  inline virtual ~LoopStartOperationNode() {
65  }
66 
67 protected:
68 
69  inline LoopStartOperationNode(CodeHandler<Base>* handler,
70  OperationNode<Base>& indexDcl,
71  size_t iterationCount) :
72  OperationNode<Base>(handler, CGOpCode::LoopStart, indexDcl) {
73  this->getInfo().push_back(iterationCount);
74  }
75 
76  inline LoopStartOperationNode(CodeHandler<Base>* handler,
77  OperationNode<Base>& indexDcl,
78  IndexOperationNode<Base>& iterCount) :
79  OperationNode<Base>(handler, CGOpCode::LoopStart,{indexDcl, iterCount}) {
80  }
81 
82 };
83 
84 } // END cg namespace
85 } // END CppAD namespace
86 
87 #endif
const std::vector< Argument< Base > > & getArguments() const
const std::vector< size_t > & getInfo() const