A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
traced-value.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005,2006,2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef TRACED_VALUE_H
9#define TRACED_VALUE_H
10
11#include "boolean.h"
12#include "double.h"
13#include "enum.h"
14#include "integer.h"
15#include "traced-callback.h"
16#include "uinteger.h"
17
18/**
19 * @file
20 * @ingroup tracing
21 * ns3::TracedValue declaration and template implementation.
22 */
23
24/**
25 * Logging macro for TracedValue.
26 *
27 * No NS_LOG_... here. When logging is needed use something like
28 * @code
29 * #define TRACED_VALUE_DEBUG(x) \
30 * std::cout << __FILE__ << ":" << __FUNCTION__ \
31 * << "(" << __LINE__ << ") " \
32 * << x << std::endl
33 * @endcode
34 */
35#define TRACED_VALUE_DEBUG(x)
36
37namespace ns3
38{
39
40/**
41 * @ingroup core
42 * @defgroup tracing Tracing
43 * @brief Publish/subscribe tools to collect and report changes to any
44 * values used by the various model components.
45 *
46 * Additional callback function signatures defined elsewhere:
47 * - TracedValueCallback::Time
48 * - TracedValueCallback::SequenceNumber32
49 * - TracedValueCallback::LrWpanMacState
50 * - TracedValueCallback::LrWpanPhyEnumeration
51 */
52
53/**
54 * @ingroup tracing
55 *
56 * @brief TracedValue Callback function types.
57 */
58namespace TracedValueCallback
59{
60
61/**
62 * @name TracedValueCallback Signatures for POD.
63 * @{
64 */
65/**
66 * TracedValue Callback signature for POD.
67 * @{
68 * @param [in] oldValue original value of the traced variable
69 * @param [in] newValue new value of the traced variable
70 */
71typedef void (*Bool)(bool oldValue, bool newValue);
72typedef void (*Int8)(int8_t oldValue, int8_t newValue);
73typedef void (*Uint8)(uint8_t oldValue, uint8_t newValue);
74typedef void (*Int16)(int16_t oldValue, int16_t newValue);
75typedef void (*Uint16)(uint16_t oldValue, uint16_t newValue);
76typedef void (*Int32)(int32_t oldValue, int32_t newValue);
77typedef void (*Uint32)(uint32_t oldValue, uint32_t newValue);
78typedef void (*Int64)(int64_t oldValue, int64_t newValue);
79typedef void (*Uint64)(uint64_t oldValue, uint64_t newValue);
80typedef void (*Double)(double oldValue, double newValue);
81/**@}*/
82/** TracedValue Callback signature for void. */
83typedef void (*Void)();
84/**@}*/
85
86} // namespace TracedValueCallback
87
88/**
89 * @ingroup tracing
90 *
91 * @brief Trace classes with value semantics
92 *
93 * If you want to trace the change of value of a class or
94 * primitive type which have value semantics (they _must_
95 * support operator !=), you can wrap them in an instance of
96 * this template. This instance will behave just like
97 * the original class (if it did not export any special method),
98 * and will define Connect/DisconnectWithoutContext methods to work
99 * with MakeTraceSourceAccessor.
100 *
101 * @tparam T \explicit The type of the underlying value being traced.
102 */
103template <typename T>
105{
106 public:
107 /** Default constructor. */
109 : m_v()
110 {
111 }
112
113 /**
114 * Copy constructor.
115 * @param [in] o The value to copy.
116 */
118 : m_v(o.m_v)
119 {
120 }
121
122 /**
123 * Construct from an explicit variable.
124 * @param [in] v The variable to trace.
125 */
126 TracedValue(const T& v)
127 : m_v(v)
128 {
129 }
130
131 /**
132 * Cast to the underlying type.
133 * @returns The underlying value.
134 */
135 operator T() const
136 {
137 return m_v;
138 }
139
140 /**
141 * Assignment.
142 * @param [in] o The value to assign to this instance.
143 * @return This TracedValue.
144 */
146 {
147 TRACED_VALUE_DEBUG("x=");
148 Set(o.m_v);
149 return *this;
150 }
151
152 /**
153 * Copy from a TracedValue of a compatible type.
154 * @tparam U \deduced The underlying type of the other TracedValue.
155 * @param [in] other The other TracedValuet to copy.
156 */
157 template <typename U>
159 : m_v(other.Get())
160 {
161 }
162
163 /**
164 * Copy from a variable type compatible with this underlying type.
165 * @tparam U \deduced Type of the other variable.
166 * @param [in] other The other variable to copy.
167 */
168 template <typename U>
169 TracedValue(const U& other)
170 : m_v((T)other)
171 {
172 }
173
174 /**
175 * Connect a Callback (without context.)
176 *
177 * @param [in] cb The callback to connect.
178 */
180 {
182 }
183
184 /**
185 * Connect a Callback with a context string.
186 *
187 * The context string will be provided as the first argument to the
188 * Callback function.
189 *
190 * @param [in] cb The Callback to connect to the target trace source.
191 * @param [in] path The context to bind to the user callback.
192 */
193 void Connect(const CallbackBase& cb, std::string path)
194 {
195 m_cb.Connect(cb, path);
196 }
197
198 /**
199 * Disconnect a Callback which was connected without context.
200 *
201 * @param [in] cb The Callback to disconnect.
202 */
207
208 /**
209 * Disconnect a Callback which was connected with context.
210 *
211 * @param [in] cb The Callback to disconnect.
212 * @param [in] path The context to bind to the user callback.
213 */
214 void Disconnect(const CallbackBase& cb, std::string path)
215 {
216 m_cb.Disconnect(cb, path);
217 }
218
219 /**
220 * Set the value of the underlying variable.
221 *
222 * If the new value differs from the old, the Callback will be invoked.
223 * @param [in] v The new value.
224 */
225 void Set(const T& v)
226 {
227 if (m_v != v)
228 {
229 m_cb(m_v, v);
230 m_v = v;
231 }
232 }
233
234 /**
235 * Get the underlying value.
236 * @returns The value.
237 */
238 T Get() const
239 {
240 return m_v;
241 }
242
243 /**
244 * Pre/post- increment/decrement operator.
245 *
246 * This invokes the Callback.
247 * @returns This TracedValue.
248 */
249 /**@{*/
251 {
252 TRACED_VALUE_DEBUG("++x");
253 T tmp = Get();
254 ++tmp;
255 Set(tmp);
256 return *this;
257 }
258
260 {
261 TRACED_VALUE_DEBUG("--x");
262 T tmp = Get();
263 --tmp;
264 Set(tmp);
265 return *this;
266 }
267
269 {
270 TRACED_VALUE_DEBUG("x++");
271 TracedValue old(*this);
272 T tmp = Get();
273 tmp++;
274 Set(tmp);
275 return old;
276 }
277
279 {
280 TRACED_VALUE_DEBUG("x--");
281 TracedValue old(*this);
282 T tmp = Get();
283 tmp--;
284 Set(tmp);
285 return old;
286 }
287
288 /**@}*/
289
290 private:
291 /** The underlying value. */
293 /** The connected Callback. */
295};
296
297/********************************************************************
298 Operator implementations for TracedValue
299 ********************************************************************/
300
301/**
302 * @ingroup tracing
303 */
304/**@{*/
305/**
306 * Output streamer for TracedValue.
307 *
308 * The underlying value will be written to the stream.
309 *
310 * @tparam T \deduced The underlying type of the TracedValue.
311 * @param [in,out] os The output stream.
312 * @param [in] rhs The TracedValue to stream.
313 * @returns The stream.
314 */
315template <typename T>
316std::ostream&
317operator<<(std::ostream& os, const TracedValue<T>& rhs)
318{
319 return os << rhs.Get();
320}
321
322/**
323 * Boolean operator for TracedValue.
324 * @tparam T \deduced The underlying type held by the left-hand argument.
325 * @tparam U \deduced The underlying type held by the right-hand argument.
326 * @param [in] lhs The left-hand argument.
327 * @param [in] rhs The right-hand argument.
328 * @returns The Boolean result of comparing the underlying values.
329 */
330template <typename T, typename U>
331bool
333{
334 TRACED_VALUE_DEBUG("x==x");
335 return lhs.Get() == rhs.Get();
336}
337
338/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
339template <typename T, typename U>
340bool
341operator==(const TracedValue<T>& lhs, const U& rhs)
342{
343 TRACED_VALUE_DEBUG("x==");
344 return lhs.Get() == rhs;
345}
346
347/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
348template <typename T, typename U>
349bool
350operator==(const U& lhs, const TracedValue<T>& rhs)
351{
352 TRACED_VALUE_DEBUG("==x");
353 return lhs == rhs.Get();
354}
355
356/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
357template <typename T, typename U>
358bool
360{
361 TRACED_VALUE_DEBUG("x!=x");
362 return lhs.Get() != rhs.Get();
363}
364
365/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
366template <typename T, typename U>
367bool
368operator!=(const TracedValue<T>& lhs, const U& rhs)
369{
370 TRACED_VALUE_DEBUG("x!=");
371 return lhs.Get() != rhs;
372}
373
374/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
375template <typename T, typename U>
376bool
377operator!=(const U& lhs, const TracedValue<T>& rhs)
378{
379 TRACED_VALUE_DEBUG("!=x");
380 return lhs != rhs.Get();
381}
382
383/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
384template <typename T, typename U>
385bool
386operator<=(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
387{
388 TRACED_VALUE_DEBUG("x<=x");
389 return lhs.Get() <= rhs.Get();
390}
391
392/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
393template <typename T, typename U>
394bool
395operator<=(const TracedValue<T>& lhs, const U& rhs)
396{
397 TRACED_VALUE_DEBUG("x<=");
398 return lhs.Get() <= rhs;
399}
400
401/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
402template <typename T, typename U>
403bool
404operator<=(const U& lhs, const TracedValue<T>& rhs)
405{
406 TRACED_VALUE_DEBUG("<=x");
407 return lhs <= rhs.Get();
408}
409
410/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
411template <typename T, typename U>
412bool
414{
415 TRACED_VALUE_DEBUG("x>=x");
416 return lhs.Get() >= rhs.Get();
417}
418
419/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
420template <typename T, typename U>
421bool
422operator>=(const TracedValue<T>& lhs, const U& rhs)
423{
424 TRACED_VALUE_DEBUG("x>=");
425 return lhs.Get() >= rhs;
426}
427
428/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
429template <typename T, typename U>
430bool
431operator>=(const U& lhs, const TracedValue<T>& rhs)
432{
433 TRACED_VALUE_DEBUG(">=x");
434 return lhs >= rhs.Get();
435}
436
437/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
438template <typename T, typename U>
439bool
440operator<(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
441{
442 TRACED_VALUE_DEBUG("x<x");
443 return lhs.Get() < rhs.Get();
444}
445
446/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
447template <typename T, typename U>
448bool
449operator<(const TracedValue<T>& lhs, const U& rhs)
450{
451 TRACED_VALUE_DEBUG("x<");
452 return lhs.Get() < rhs;
453}
454
455/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
456template <typename T, typename U>
457bool
458operator<(const U& lhs, const TracedValue<T>& rhs)
459{
460 TRACED_VALUE_DEBUG("<x");
461 return lhs < rhs.Get();
462}
463
464/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
465template <typename T, typename U>
466bool
468{
469 TRACED_VALUE_DEBUG("x>x");
470 return lhs.Get() > rhs.Get();
471}
472
473/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
474template <typename T, typename U>
475bool
476operator>(const TracedValue<T>& lhs, const U& rhs)
477{
478 TRACED_VALUE_DEBUG("x>");
479 return lhs.Get() > rhs;
480}
481
482/** @copydoc operator==(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
483template <typename T, typename U>
484bool
485operator>(const U& lhs, const TracedValue<T>& rhs)
486{
487 TRACED_VALUE_DEBUG(">x");
488 return lhs > rhs.Get();
489}
490
491/**
492 * Infix arithmetic operator for TracedValue.
493 *
494 * This returns the arithmetic result in a new TracedValue,
495 * which has no Callback connected.
496 *
497 * @tparam T \deduced The underlying type held by the left-hand argument.
498 * @tparam U \deduced The underlying type held by the right-hand argument.
499 * @param [in] lhs The left-hand argument.
500 * @param [in] rhs The right-hand argument.
501 * @returns The result of doing the operator on
502 * the underlying values.
503 */
504template <typename T, typename U>
505auto
507 -> TracedValue<decltype(lhs.Get() + rhs.Get())>
508{
509 TRACED_VALUE_DEBUG("x+x");
510 return TracedValue<decltype(lhs.Get() + rhs.Get())>(lhs.Get() + rhs.Get());
511}
512
513/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
514template <typename T, typename U>
515auto
516operator+(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() + rhs)>
517{
518 TRACED_VALUE_DEBUG("x+");
519 return TracedValue<decltype(lhs.Get() + rhs)>(lhs.Get() + rhs);
520}
521
522/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
523template <typename T, typename U>
524auto
525operator+(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
526{
527 TRACED_VALUE_DEBUG("+x");
528 return TracedValue<decltype(lhs + rhs.Get())>(lhs + rhs.Get());
529}
530
531/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
532template <typename T, typename U>
533auto
535 -> TracedValue<decltype(lhs.Get() - rhs.Get())>
536{
537 TRACED_VALUE_DEBUG("x-x");
538 return TracedValue<decltype(lhs.Get() - rhs.Get())>(lhs.Get() - rhs.Get());
539}
540
541/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
542template <typename T, typename U>
543auto
544operator-(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() - rhs)>
545{
546 TRACED_VALUE_DEBUG("x-");
547 return TracedValue<decltype(lhs.Get() - rhs)>(lhs.Get() - rhs);
548}
549
550/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
551template <typename T, typename U>
552auto
553operator-(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs - rhs.Get())>
554{
555 TRACED_VALUE_DEBUG("-x");
556 return TracedValue<decltype(lhs - rhs.Get())>(lhs - rhs.Get());
557}
558
559/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
560template <typename T, typename U>
561auto
563 -> TracedValue<decltype(lhs.Get() * rhs.Get())>
564{
565 TRACED_VALUE_DEBUG("x*x");
566 return TracedValue<decltype(lhs.Get() * rhs.Get())>(lhs.Get() * rhs.Get());
567}
568
569/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
570template <typename T, typename U>
571auto
572operator*(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() * rhs)>
573{
574 TRACED_VALUE_DEBUG("x*");
575 return TracedValue<decltype(lhs.Get() * rhs)>(lhs.Get() * rhs);
576}
577
578/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
579template <typename T, typename U>
580auto
581operator*(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
582{
583 TRACED_VALUE_DEBUG("*x");
584 return TracedValue<decltype(lhs + rhs.Get())>(lhs * rhs.Get());
585}
586
587/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
588template <typename T, typename U>
589auto
591 -> TracedValue<decltype(lhs.Get() / rhs.Get())>
592{
593 TRACED_VALUE_DEBUG("x/x");
594 return TracedValue<decltype(lhs.Get() / rhs.Get())>(lhs.Get() / rhs.Get());
595}
596
597/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
598template <typename T, typename U>
599auto
600operator/(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() / rhs)>
601{
602 TRACED_VALUE_DEBUG("x/");
603 return TracedValue<decltype(lhs.Get() / rhs)>(lhs.Get() / rhs);
604}
605
606/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
607template <typename T, typename U>
608auto
609operator/(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs / rhs.Get())>
610{
611 TRACED_VALUE_DEBUG("/x");
612 return TracedValue<decltype(lhs / rhs.Get())>(lhs / rhs.Get());
613}
614
615/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
616template <typename T, typename U>
617auto
619 -> TracedValue<decltype(lhs.Get() % rhs.Get())>
620{
621 TRACED_VALUE_DEBUG("x%x");
622 return TracedValue<decltype(lhs.Get() % rhs.Get())>(lhs.Get() % rhs.Get());
623}
624
625/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
626template <typename T, typename U>
627auto
628operator%(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() % rhs)>
629{
630 TRACED_VALUE_DEBUG("x%");
631 return TracedValue<decltype(lhs.Get() % rhs)>(lhs.Get() % rhs);
632}
633
634/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
635template <typename T, typename U>
636auto
637operator%(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs % rhs.Get())>
638{
639 TRACED_VALUE_DEBUG("%x");
640 return TracedValue<decltype(lhs % rhs.Get())>(lhs % rhs.Get());
641}
642
643/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
644template <typename T, typename U>
645auto
647 -> TracedValue<decltype(lhs.Get() ^ rhs.Get())>
648{
649 TRACED_VALUE_DEBUG("x^x");
650 return TracedValue<decltype(lhs.Get() ^ rhs.Get())>(lhs.Get() ^ rhs.Get());
651}
652
653/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
654template <typename T, typename U>
655auto
656operator^(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() ^ rhs)>
657{
658 TRACED_VALUE_DEBUG("x^");
659 return TracedValue<decltype(lhs.Get() ^ rhs)>(lhs.Get() ^ rhs);
660}
661
662/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
663template <typename T, typename U>
664auto
665operator^(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs ^ rhs.Get())>
666{
667 TRACED_VALUE_DEBUG("^x");
668 return TracedValue<decltype(lhs ^ rhs.Get())>(lhs ^ rhs.Get());
669}
670
671/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
672template <typename T, typename U>
673auto
675 -> TracedValue<decltype(lhs.Get() | rhs.Get())>
676{
677 TRACED_VALUE_DEBUG("x|x");
678 return TracedValue<decltype(lhs.Get() | rhs.Get())>(lhs.Get() | rhs.Get());
679}
680
681/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
682template <typename T, typename U>
683auto
684operator|(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() | rhs)>
685{
686 TRACED_VALUE_DEBUG("x|");
687 return TracedValue<decltype(lhs.Get() | rhs)>(lhs.Get() | rhs);
688}
689
690/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
691template <typename T, typename U>
692auto
693operator|(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs | rhs.Get())>
694{
695 TRACED_VALUE_DEBUG("|x");
696 return TracedValue<decltype(lhs | rhs.Get())>(lhs | rhs.Get());
697}
698
699/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
700template <typename T, typename U>
701auto
703 -> TracedValue<decltype(lhs.Get() & rhs.Get())>
704{
705 TRACED_VALUE_DEBUG("x&x");
706 return TracedValue<decltype(lhs.Get() & rhs.Get())>(lhs.Get() & rhs.Get());
707}
708
709/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
710template <typename T, typename U>
711auto
712operator&(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() & rhs)>
713{
714 TRACED_VALUE_DEBUG("x&");
715 return TracedValue<decltype(lhs.Get() & rhs)>(lhs.Get() & rhs);
716}
717
718/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
719template <typename T, typename U>
720auto
721operator&(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs & rhs.Get())>
722{
723 TRACED_VALUE_DEBUG("&x");
724 return TracedValue<decltype(lhs & rhs.Get())>(lhs & rhs.Get());
725}
726
727/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
728template <typename T, typename U>
729auto
730operator<<(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
731 -> TracedValue<decltype(lhs.Get() << rhs.Get())>
732{
733 TRACED_VALUE_DEBUG("x<<x");
734 return TracedValue<decltype(lhs.Get() << rhs.Get())>(lhs.Get() << rhs.Get());
735}
736
737/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
738template <typename T, typename U>
739auto
740operator<<(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() << rhs)>
741{
742 TRACED_VALUE_DEBUG("x<<");
743 return TracedValue<decltype(lhs.Get() << rhs)>(lhs.Get() << rhs);
744}
745
746/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
747template <typename T, typename U>
748auto
749operator<<(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs << rhs.Get())>
750{
751 TRACED_VALUE_DEBUG("<<x");
752 return TracedValue<decltype(lhs << rhs.Get())>(lhs << rhs.Get());
753}
754
755/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
756template <typename T, typename U>
757auto
759 -> TracedValue<decltype(lhs.Get() >> rhs.Get())>
760{
761 TRACED_VALUE_DEBUG("x>>x");
762 return TracedValue<decltype(lhs.Get() >> rhs.Get())>(lhs.Get() >> rhs.Get());
763}
764
765/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
766template <typename T, typename U>
767auto
768operator>>(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() >> rhs)>
769{
770 TRACED_VALUE_DEBUG("x>>");
771 return TracedValue<decltype(lhs.Get() >> rhs)>(lhs.Get() >> rhs);
772}
773
774/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
775template <typename T, typename U>
776auto
777operator>>(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs >> rhs.Get())>
778{
779 TRACED_VALUE_DEBUG(">>x");
780 return TracedValue<decltype(lhs >> rhs.Get())>(lhs >> rhs.Get());
781}
782
783/**
784 * Operator assignment for TracedValue.
785 *
786 * The result of the arithmetic operation on the underlying values
787 * is assigned to the \c lhs TracedValue. If the new value
788 * is different, the Callback will be invoked.
789 *
790 * @tparam T \deduced The underlying type held by the left-hand argument.
791 * @tparam U \deduced The underlying type held by the right-hand argument.
792 * @param [in] lhs The left-hand argument.
793 * @param [in] rhs The right-hand argument.
794 * @returns The result of doing the operator on
795 * the underlying values.
796 */
797template <typename T, typename U>
798TracedValue<T>&
799operator+=(TracedValue<T>& lhs, const U& rhs)
800{
801 TRACED_VALUE_DEBUG("x+=");
802 T tmp = lhs.Get();
803 tmp += rhs;
804 lhs.Set(tmp);
805 return lhs;
806}
807
808/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
809template <typename T, typename U>
810TracedValue<T>&
811operator-=(TracedValue<T>& lhs, const U& rhs)
812{
813 TRACED_VALUE_DEBUG("x-=");
814 T tmp = lhs.Get();
815 tmp -= rhs;
816 lhs.Set(tmp);
817 return lhs;
818}
819
820/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
821template <typename T, typename U>
822TracedValue<T>&
823operator*=(TracedValue<T>& lhs, const U& rhs)
824{
825 TRACED_VALUE_DEBUG("x*=");
826 T tmp = lhs.Get();
827 tmp *= rhs;
828 lhs.Set(tmp);
829 return lhs;
830}
831
832/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
833template <typename T, typename U>
834TracedValue<T>&
835operator/=(TracedValue<T>& lhs, const U& rhs)
836{
837 TRACED_VALUE_DEBUG("x/=");
838 T tmp = lhs.Get();
839 tmp /= rhs;
840 lhs.Set(tmp);
841 return lhs;
842}
843
844/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
845template <typename T, typename U>
846TracedValue<T>&
847operator%=(TracedValue<T>& lhs, const U& rhs)
848{
849 TRACED_VALUE_DEBUG("x%=");
850 T tmp = lhs.Get();
851 tmp %= rhs;
852 lhs.Set(tmp);
853 return lhs;
854}
855
856/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
857template <typename T, typename U>
858TracedValue<T>&
859operator<<=(TracedValue<T>& lhs, const U& rhs)
860{
861 TRACED_VALUE_DEBUG("x<<=");
862 T tmp = lhs.Get();
863 tmp <<= rhs;
864 lhs.Set(tmp);
865 return lhs;
866}
867
868/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
869template <typename T, typename U>
870TracedValue<T>&
871operator>>=(TracedValue<T>& lhs, const U& rhs)
872{
873 TRACED_VALUE_DEBUG("x>>=");
874 T tmp = lhs.Get();
875 tmp >>= rhs;
876 lhs.Set(tmp);
877 return lhs;
878}
879
880/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
881template <typename T, typename U>
882TracedValue<T>&
883operator&=(TracedValue<T>& lhs, const U& rhs)
884{
885 TRACED_VALUE_DEBUG("x&=");
886 T tmp = lhs.Get();
887 tmp &= rhs;
888 lhs.Set(tmp);
889 return lhs;
890}
891
892/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
893template <typename T, typename U>
894TracedValue<T>&
895operator|=(TracedValue<T>& lhs, const U& rhs)
896{
897 TRACED_VALUE_DEBUG("x|=");
898 T tmp = lhs.Get();
899 tmp |= rhs;
900 lhs.Set(tmp);
901 return lhs;
902}
903
904/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
905template <typename T, typename U>
906TracedValue<T>&
907operator^=(TracedValue<T>& lhs, const U& rhs)
908{
909 TRACED_VALUE_DEBUG("x^=");
910 T tmp = lhs.Get();
911 tmp ^= rhs;
912 lhs.Set(tmp);
913 return lhs;
914}
915
916/**
917 * Unary arithmetic operator for TracedValue.
918 *
919 * @tparam T \deduced The underlying type held by the TracedValue.
920 * @param [in] lhs The TracedValue.
921 * @returns The result of doing the operator on
922 * the underlying values.
923 */
924template <typename T>
925TracedValue<T>
927{
928 TRACED_VALUE_DEBUG("(+x)");
929 return TracedValue<T>(+lhs.Get());
930}
931
932/** @copydoc operator+(const TracedValue<T>&lhs) */
933template <typename T>
934TracedValue<T>
936{
937 TRACED_VALUE_DEBUG("(-x)");
938 return TracedValue<T>(-lhs.Get());
939}
940
941/** @copydoc operator+(const TracedValue<T>&lhs) */
942template <typename T>
943TracedValue<T>
945{
946 TRACED_VALUE_DEBUG("(~x)");
947 return TracedValue<T>(~lhs.Get());
948}
949
950/** @copydoc operator+(const TracedValue<T>&lhs) */
951template <typename T>
952TracedValue<T>
954{
955 TRACED_VALUE_DEBUG("(!x)");
956 return TracedValue<T>(!lhs.Get());
957}
958
959/**@}*/ // \ingroup tracing
960
961} // namespace ns3
962
963#endif /* TRACED_VALUE_H */
ns3::BooleanValue attribute value declarations.
Base class for Callback class.
Definition callback.h:344
Forward calls to a chain of Callback.
void Disconnect(const CallbackBase &callback, std::string path)
Remove from the chain a Callback which was connected with a context.
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
void DisconnectWithoutContext(const CallbackBase &callback)
Remove from the chain a Callback which was connected without a context.
void Connect(const CallbackBase &callback, std::string path)
Append a Callback to the chain with a context.
Trace classes with value semantics.
TracedValue(const T &v)
Construct from an explicit variable.
TracedValue & operator++()
Pre/post- increment/decrement operator.
void DisconnectWithoutContext(const CallbackBase &cb)
Disconnect a Callback which was connected without context.
TracedCallback< T, T > m_cb
The connected Callback.
T m_v
The underlying value.
TracedValue & operator--()
Pre/post- increment/decrement operator.
void Connect(const CallbackBase &cb, std::string path)
Connect a Callback with a context string.
void Disconnect(const CallbackBase &cb, std::string path)
Disconnect a Callback which was connected with context.
TracedValue operator--(int)
Pre/post- increment/decrement operator.
TracedValue & operator=(const TracedValue &o)
Assignment.
TracedValue(const TracedValue &o)
Copy constructor.
void ConnectWithoutContext(const CallbackBase &cb)
Connect a Callback (without context.)
T Get() const
Get the underlying value.
TracedValue()
Default constructor.
TracedValue(const U &other)
Copy from a variable type compatible with this underlying type.
void Set(const T &v)
Set the value of the underlying variable.
TracedValue operator++(int)
Pre/post- increment/decrement operator.
TracedValue(const TracedValue< U > &other)
Copy from a TracedValue of a compatible type.
ns3::DoubleValue attribute value declarations and template implementations.
ns3::EnumValue attribute value declarations.
int64x64_t operator/(const int64x64_t &lhs, const int64x64_t &rhs)
Division operator.
Definition int64x64.h:121
bool operator>=(const int64x64_t &lhs, const int64x64_t &rhs)
Greater or equal operator.
Definition int64x64.h:162
bool operator<=(const int64x64_t &lhs, const int64x64_t &rhs)
Less or equal operator.
Definition int64x64.h:149
int64x64_t operator-(const int64x64_t &lhs, const int64x64_t &rhs)
Subtraction operator.
Definition int64x64.h:91
int64x64_t operator+(const int64x64_t &lhs, const int64x64_t &rhs)
Addition operator.
Definition int64x64.h:76
int64x64_t operator*(const int64x64_t &lhs, const int64x64_t &rhs)
Multiplication operator.
Definition int64x64.h:106
bool operator>(const Length &left, const Length &right)
Check if left has a value greater than right.
Definition length.cc:410
TracedValue< T > & operator/=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > & operator|=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > operator!(const TracedValue< T > &lhs)
Unary arithmetic operator for TracedValue.
TracedValue< T > & operator%=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
auto operator^(const TracedValue< T > &lhs, const TracedValue< U > &rhs) -> TracedValue< decltype(lhs.Get() ^ rhs.Get())>
Infix arithmetic operator for TracedValue.
auto operator|(const TracedValue< T > &lhs, const TracedValue< U > &rhs) -> TracedValue< decltype(lhs.Get()|rhs.Get())>
Infix arithmetic operator for TracedValue.
TracedValue< T > & operator^=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > & operator*=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > & operator<<=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > operator~(const TracedValue< T > &lhs)
Unary arithmetic operator for TracedValue.
TracedValue< T > & operator>>=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
TracedValue< T > & operator&=(TracedValue< T > &lhs, const U &rhs)
Operator assignment for TracedValue.
auto operator&(const TracedValue< T > &lhs, const TracedValue< U > &rhs) -> TracedValue< decltype(lhs.Get() &rhs.Get())>
Infix arithmetic operator for TracedValue.
ns3::IntegerValue attribute value declarations and template implementations.
void(* Uint16)(uint16_t oldValue, uint16_t newValue)
TracedValue Callback signature for POD.
void(* Bool)(bool oldValue, bool newValue)
TracedValue Callback signature for POD.
void(* Int8)(int8_t oldValue, int8_t newValue)
TracedValue Callback signature for POD.
void(* Void)()
TracedValue Callback signature for void.
void(* Int16)(int16_t oldValue, int16_t newValue)
TracedValue Callback signature for POD.
void(* Uint8)(uint8_t oldValue, uint8_t newValue)
TracedValue Callback signature for POD.
void(* Int64)(int64_t oldValue, int64_t newValue)
TracedValue Callback signature for POD.
void(* Uint32)(uint32_t oldValue, uint32_t newValue)
TracedValue Callback signature for POD.
void(* Uint64)(uint64_t oldValue, uint64_t newValue)
TracedValue Callback signature for POD.
void(* Int32)(int32_t oldValue, int32_t newValue)
TracedValue Callback signature for POD.
void(* Double)(double oldValue, double newValue)
TracedValue Callback signature for POD.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
Definition callback.h:658
Time operator%(const Time &lhs, const Time &rhs)
Remainder (modulus) from the quotient of two Times.
Definition nstime.h:1145
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:155
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
Time & operator+=(Time &lhs, const Time &rhs)
Compound addition assignment for Time.
Definition nstime.h:1191
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:168
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition nstime.h:1204
ns3::TracedCallback declaration and template implementation.
#define TRACED_VALUE_DEBUG(x)
Logging macro for TracedValue.
ns3::UintegerValue attribute value declarations and template implementations.