CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
default.hpp
1#ifndef CPPAD_CG_DEFAULT_INCLUDED
2#define CPPAD_CG_DEFAULT_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2012 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
18namespace CppAD {
19namespace cg {
20
24template <class Base>
25inline CG<Base>::CG() :
26 node_(nullptr),
27 value_(new Base(0.0)) {
28}
29
30template <class Base>
32 node_(&node) {
33}
34
35template <class Base>
36inline CG<Base>::CG(const Argument<Base>& arg) :
37 node_(arg.getOperation()),
38 value_(arg.getParameter() != nullptr ? new Base(*arg.getParameter()) : nullptr) {
39
40}
41
45template <class Base>
46inline CG<Base>::CG(const Base &b) :
47 node_(nullptr),
48 value_(new Base(b)) {
49}
50
54template <class Base>
55inline CG<Base>::CG(const CG<Base>& orig) :
56 node_(orig.node_),
57 value_(orig.value_ != nullptr ? new Base(*orig.value_) : nullptr) {
59
63template <class Base>
64inline CG<Base>::CG(CG<Base>&& orig):
65 node_(orig.node_),
66 value_(std::move(orig.value_)) {
67}
72template <class Base>
73inline CG<Base>& CG<Base>::operator=(const Base& b) {
74 node_ = nullptr;
75 if (value_ != nullptr) {
76 *value_ = b;
77 } else {
78 value_.reset(new Base(b)); // to replace with value_ = std::make_unique once c++14 is used
79 }
80 return *this;
81}
82
83template <class Base>
85 if (&rhs == this) {
86 return *this;
87 }
88 node_ = rhs.node_;
89 if (rhs.value_ != nullptr) {
90 if (value_ != nullptr) {
91 *value_ = *rhs.value_;
92 } else {
93 value_.reset(new Base(*rhs.value_)); // to replace with value_ = std::make_unique once c++14 is used
94 }
95 } else {
96 value_.reset();
97 }
98
99 return *this;
100}
101
102template <class Base>
104 assert(this != &rhs);
105
106 node_ = rhs.node_;
107
108 // steal the value
109 value_ = std::move(rhs.value_);
110
111 return *this;
112}
113
114template <class Base>
115CG<Base>::~CG() = default;
116
117} // END cg namespace
118} // END CppAD namespace
119
120#endif
CG & operator=(const CG< Base > &rhs)
Definition default.hpp:84