@@ -20,7 +20,7 @@ namespace cg {
20
20
21
21
/* *
22
22
* An operation node.
23
- *
23
+ *
24
24
* @author Joao Leal
25
25
*/
26
26
template <class Base >
@@ -35,7 +35,7 @@ class OperationNode {
35
35
static const std::set<CGOpCode> CUSTOM_NODE_CLASS;
36
36
private:
37
37
/* *
38
- * the source code handler that own this node
38
+ * the source code handler that own this node
39
39
* (only null for temporary OperationNodes)
40
40
*/
41
41
CodeHandler<Base>* handler_;
@@ -48,7 +48,7 @@ class OperationNode {
48
48
*/
49
49
std::vector<size_t > info_;
50
50
/* *
51
- * arguments required by the operation
51
+ * arguments required by the operation
52
52
* (empty for independent variables and possibly for the 1st assignment
53
53
* of a dependent variable)
54
54
*/
@@ -60,7 +60,7 @@ class OperationNode {
60
60
/* *
61
61
* name for the result of this operation
62
62
*/
63
- std::string* name_;
63
+ std::unique_ptr<std:: string> name_;
64
64
public:
65
65
/* *
66
66
* Changes the current operation type into an Alias.
@@ -72,14 +72,13 @@ class OperationNode {
72
72
operation_ = CGOpCode::Alias;
73
73
arguments_.resize (1 );
74
74
arguments_[0 ] = other;
75
- delete name_;
76
- name_ = nullptr ;
75
+ name_.reset ();
77
76
}
78
-
77
+
79
78
/* *
80
79
* Provides the source code handler that owns this node.
81
80
* It can only be null for temporary nodes.
82
- *
81
+ *
83
82
* @return a CodeHandler which owns this nodes memory (possibly null)
84
83
*/
85
84
inline CodeHandler<Base>* getCodeHandler () const {
@@ -96,7 +95,7 @@ class OperationNode {
96
95
97
96
/* *
98
97
* Changes the current operation type.
99
- * The previous operation information/options might also have to be
98
+ * The previous operation information/options might also have to be
100
99
* changed, use getInfo() to change it if required.
101
100
* @param op the new operation type
102
101
* @param arguments the arguments for the new operation
@@ -149,7 +148,7 @@ class OperationNode {
149
148
* no name was assigned to this node yet
150
149
*/
151
150
inline const std::string* getName () const {
152
- return name_;
151
+ return name_. get () ;
153
152
}
154
153
155
154
/* *
@@ -160,29 +159,28 @@ class OperationNode {
160
159
if (name_ != nullptr )
161
160
*name_ = name;
162
161
else
163
- name_ = new std::string (name);
162
+ name_. reset ( new std::string (name) );
164
163
}
165
164
166
165
/* *
167
166
* Clears any name assigned to this node.
168
167
*/
169
168
inline void clearName () {
170
- delete name_;
171
- name_ = nullptr ;
169
+ name_.reset ();
172
170
}
173
-
171
+
174
172
/* *
175
173
* Provides the index in CodeHandler which owns this OperationNode.
176
- * A value of std::numeric_limits<size_t>::max() means that it is not
174
+ * A value of std::numeric_limits<size_t>::max() means that it is not
177
175
* managed by any CodeHandler.
178
176
* This value can change if its position changes in the CodeHandler.
179
- *
180
- * @return the index in the CodeHandler's array of managed nodes
177
+ *
178
+ * @return the index in the CodeHandler's array of managed nodes
181
179
*/
182
180
inline size_t getHandlerPosition () const {
183
181
return pos_;
184
182
}
185
-
183
+
186
184
// argument iterators
187
185
188
186
inline iterator begin () {
@@ -232,13 +230,11 @@ class OperationNode {
232
230
inline const_reverse_iterator crend () const noexcept {
233
231
return arguments_.crend ();
234
232
}
235
-
236
- inline virtual ~OperationNode () {
237
- delete name_;
238
- }
239
-
233
+
234
+ inline virtual ~OperationNode () = default ;
235
+
240
236
protected:
241
-
237
+
242
238
inline OperationNode (const OperationNode& orig) :
243
239
handler_(orig.handler_),
244
240
operation_(orig.operation_),
@@ -252,8 +248,7 @@ class OperationNode {
252
248
CGOpCode op) :
253
249
handler_(handler),
254
250
operation_(op),
255
- pos_(std::numeric_limits<size_t >::max()),
256
- name_(nullptr ) {
251
+ pos_(std::numeric_limits<size_t >::max()) {
257
252
}
258
253
259
254
inline OperationNode (CodeHandler<Base>* handler,
@@ -262,8 +257,7 @@ class OperationNode {
262
257
handler_(handler),
263
258
operation_(op),
264
259
arguments_ {arg},
265
- pos_ (std::numeric_limits<size_t >::max()),
266
- name_ (nullptr ) {
260
+ pos_ (std::numeric_limits<size_t >::max()) {
267
261
}
268
262
269
263
inline OperationNode (CodeHandler<Base>* handler,
@@ -272,8 +266,7 @@ class OperationNode {
272
266
handler_(handler),
273
267
operation_(op),
274
268
arguments_(std::move(args)),
275
- pos_(std::numeric_limits<size_t >::max()),
276
- name_(nullptr ) {
269
+ pos_(std::numeric_limits<size_t >::max()) {
277
270
}
278
271
279
272
inline OperationNode (CodeHandler<Base>* handler,
@@ -284,8 +277,7 @@ class OperationNode {
284
277
operation_(op),
285
278
info_(std::move(info)),
286
279
arguments_(std::move(args)),
287
- pos_(std::numeric_limits<size_t >::max()),
288
- name_(nullptr ) {
280
+ pos_(std::numeric_limits<size_t >::max()) {
289
281
}
290
282
291
283
inline OperationNode (CodeHandler<Base>* handler,
@@ -296,10 +288,9 @@ class OperationNode {
296
288
operation_(op),
297
289
info_(info),
298
290
arguments_(args),
299
- pos_(std::numeric_limits<size_t >::max()),
300
- name_(nullptr ) {
291
+ pos_(std::numeric_limits<size_t >::max()) {
301
292
}
302
-
293
+
303
294
inline void setHandlerPosition (size_t pos) {
304
295
pos_ = pos;
305
296
}
@@ -308,15 +299,15 @@ class OperationNode {
308
299
309
300
/* *
310
301
* Creates a temporary operation node.
311
- *
302
+ *
312
303
* @warning This node should never be provided to a CodeHandler.
313
304
*/
314
305
static std::unique_ptr<OperationNode<Base>> makeTemporaryNode (CGOpCode op,
315
306
const std::vector<size_t >& info,
316
307
const std::vector<Argument<Base> >& args) {
317
308
return std::unique_ptr<OperationNode<Base>> (new OperationNode<Base>(nullptr , op, info, args));
318
309
}
319
-
310
+
320
311
protected:
321
312
static inline std::set<CGOpCode> makeCustomNodeClassesSet ();
322
313
@@ -371,4 +362,4 @@ inline std::ostream& operator<<(
371
362
} // END cg namespace
372
363
} // END CppAD namespace
373
364
374
- #endif
365
+ #endif
0 commit comments