output_sx.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2014 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * K.U. Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_OUTPUT_SX_HPP
27 #define CASADI_OUTPUT_SX_HPP
28 
29 #include "sx_node.hpp"
30 #include "generic_shared_internal.hpp"
31 #include "generic_shared.hpp"
32 
34 namespace casadi {
35 
36  class OutputSX;
37 
38  class CASADI_EXPORT SharedSXElem :
39  public GenericShared<SharedSXElem, OutputSX> {
40  public:
41 
42  static bool test_cast(const OutputSX* ptr) {
43  return ptr;
44  }
45 
46  using internal_base_type = OutputSX;
47  using base_type = SharedSXElem;
48 
49  };
50 
51  class CASADI_EXPORT WeakRefSXElem :
52  public GenericWeakRef<SharedSXElem, OutputSX> {
53  public:
54  WeakRefSXElem(int dummy=0) : GenericWeakRef<SharedSXElem, OutputSX>(dummy) {
55  }
56  WeakRefSXElem(SharedSXElem shared) : GenericWeakRef<SharedSXElem, OutputSX>(shared) {
57  }
58  };
59 
60  typedef GenericWeakRefInternal<SharedSXElem, OutputSX> WeakRefInternalSXElem;
61 
62  class CASADI_EXPORT OutputSX :
63  public SXNode,
64  public GenericSharedInternal<SharedSXElem, OutputSX> {
65  friend class GenericShared<SharedSXElem, OutputSX>;
66  friend class SharedObject;
67  friend class GenericWeakRef<SharedSXElem, OutputSX>;
68  friend class GenericSharedInternal<SharedSXElem, OutputSX>;
69  friend class Memory;
70  friend class UniversalNodeOwner;
71  public:
72 
73  using weak_ref_type = WeakRefInternalSXElem;
74 
78  OutputSX(const SXElem& dep, int oind) : dep_(dep), oind_(oind) {
79  }
80 
82  OutputSX() {
83 
84  }
85 
86  // Class name
87  std::string class_name() const override {return "OutputSX";}
88 
92  std::string print(const std::string& arg1, const std::string& arg2) const override {
93  return arg1 + "{" + str(oind_) + "}";
94  }
95 
99  ~OutputSX() override {
100  safe_delete(dep_.assignNoDelete(casadi_limits<SXElem>::nan));
101  }
102 
106  casadi_int op() const override { return -1;}
107 
111  casadi_int n_dep() const override { return 1;}
112 
116  const SXElem& dep(casadi_int i) const override { return dep_; }
117  SXElem& dep(casadi_int i) override { return dep_; }
118 
122  SXElem dep_;
123 
127  int oind_;
128 
132  bool is_output() const override { return true; }
133 
137  casadi_int which_output() const override { return oind_; }
138 
139  static std::vector<SXElem> split(const SXElem& e, casadi_int n) {
140  std::vector<SXElem> ret(n);
141  for (casadi_int i=0;i<n;++i) {
142  ret[i] = e.get_output(i);
143  }
144  return ret;
145  }
146 
147  void serialize_node(SerializingStream& s) const override {
148  s.pack("OutputSX::dep", dep_);
149  s.pack("OutputSX::oind", oind_);
150  }
151 
152  static SXNode* deserialize(DeserializingStream& s) {
153  SXElem dep;
154  int oind;
155  s.unpack("OutputSX::dep", dep);
156  s.unpack("OutputSX::oind", oind);
157  return new OutputSX(dep, oind);
158  }
159 
160  };
161 
162 
163 } // namespace casadi
165 
166 #endif // CASADI_OUTPUT_SX_HPP
The casadi namespace.
Definition: archiver.hpp:32