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 */
504// clang-format off
505template <typename T, typename U>
506auto
508 -> TracedValue<decltype(lhs.Get() + rhs.Get())>
509// clang-format on
510{
511 TRACED_VALUE_DEBUG("x+x");
512 return TracedValue<decltype(lhs.Get() + rhs.Get())>(lhs.Get() + rhs.Get());
513}
514
515/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
516template <typename T, typename U>
517auto
518operator+(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() + rhs)>
519{
520 TRACED_VALUE_DEBUG("x+");
521 return TracedValue<decltype(lhs.Get() + rhs)>(lhs.Get() + rhs);
522}
523
524/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
525template <typename T, typename U>
526auto
527operator+(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
528{
529 TRACED_VALUE_DEBUG("+x");
530 return TracedValue<decltype(lhs + rhs.Get())>(lhs + rhs.Get());
531}
532
533/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
534// clang-format off
535template <typename T, typename U>
536auto
538 -> TracedValue<decltype(lhs.Get() - rhs.Get())>
539// clang-format on
540{
541 TRACED_VALUE_DEBUG("x-x");
542 return TracedValue<decltype(lhs.Get() - rhs.Get())>(lhs.Get() - rhs.Get());
543}
544
545/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
546template <typename T, typename U>
547auto
548operator-(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() - rhs)>
549{
550 TRACED_VALUE_DEBUG("x-");
551 return TracedValue<decltype(lhs.Get() - rhs)>(lhs.Get() - rhs);
552}
553
554/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
555template <typename T, typename U>
556auto
557operator-(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs - rhs.Get())>
558{
559 TRACED_VALUE_DEBUG("-x");
560 return TracedValue<decltype(lhs - rhs.Get())>(lhs - rhs.Get());
561}
562
563/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
564// clang-format off
565template <typename T, typename U>
566auto
568 -> TracedValue<decltype(lhs.Get() * rhs.Get())>
569// clang-format on
570{
571 TRACED_VALUE_DEBUG("x*x");
572 return TracedValue<decltype(lhs.Get() * rhs.Get())>(lhs.Get() * rhs.Get());
573}
574
575/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
576template <typename T, typename U>
577auto
578operator*(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() * rhs)>
579{
580 TRACED_VALUE_DEBUG("x*");
581 return TracedValue<decltype(lhs.Get() * rhs)>(lhs.Get() * rhs);
582}
583
584/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
585template <typename T, typename U>
586auto
587operator*(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
588{
589 TRACED_VALUE_DEBUG("*x");
590 return TracedValue<decltype(lhs + rhs.Get())>(lhs * rhs.Get());
591}
592
593/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
594// clang-format off
595template <typename T, typename U>
596auto
598 -> TracedValue<decltype(lhs.Get() / rhs.Get())>
599// clang-format on
600{
601 TRACED_VALUE_DEBUG("x/x");
602 return TracedValue<decltype(lhs.Get() / rhs.Get())>(lhs.Get() / rhs.Get());
603}
604
605/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
606template <typename T, typename U>
607auto
608operator/(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() / rhs)>
609{
610 TRACED_VALUE_DEBUG("x/");
611 return TracedValue<decltype(lhs.Get() / rhs)>(lhs.Get() / rhs);
612}
613
614/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
615template <typename T, typename U>
616auto
617operator/(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs / rhs.Get())>
618{
619 TRACED_VALUE_DEBUG("/x");
620 return TracedValue<decltype(lhs / rhs.Get())>(lhs / rhs.Get());
621}
622
623/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
624// clang-format off
625template <typename T, typename U>
626auto
628 -> TracedValue<decltype(lhs.Get() % rhs.Get())>
629// clang-format on
630{
631 TRACED_VALUE_DEBUG("x%x");
632 return TracedValue<decltype(lhs.Get() % rhs.Get())>(lhs.Get() % rhs.Get());
633}
634
635/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
636template <typename T, typename U>
637auto
638operator%(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() % rhs)>
639{
640 TRACED_VALUE_DEBUG("x%");
641 return TracedValue<decltype(lhs.Get() % rhs)>(lhs.Get() % rhs);
642}
643
644/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
645template <typename T, typename U>
646auto
647operator%(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs % rhs.Get())>
648{
649 TRACED_VALUE_DEBUG("%x");
650 return TracedValue<decltype(lhs % rhs.Get())>(lhs % rhs.Get());
651}
652
653/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
654// clang-format off
655template <typename T, typename U>
656auto
658 -> TracedValue<decltype(lhs.Get() ^ rhs.Get())>
659// clang-format on
660{
661 TRACED_VALUE_DEBUG("x^x");
662 return TracedValue<decltype(lhs.Get() ^ rhs.Get())>(lhs.Get() ^ rhs.Get());
663}
664
665/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
666template <typename T, typename U>
667auto
668operator^(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() ^ rhs)>
669{
670 TRACED_VALUE_DEBUG("x^");
671 return TracedValue<decltype(lhs.Get() ^ rhs)>(lhs.Get() ^ rhs);
672}
673
674/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
675template <typename T, typename U>
676auto
677operator^(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs ^ rhs.Get())>
678{
679 TRACED_VALUE_DEBUG("^x");
680 return TracedValue<decltype(lhs ^ rhs.Get())>(lhs ^ rhs.Get());
681}
682
683/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
684// clang-format off
685template <typename T, typename U>
686auto
688 -> TracedValue<decltype(lhs.Get() | rhs.Get())>
689// clang-format on
690{
691 TRACED_VALUE_DEBUG("x|x");
692 return TracedValue<decltype(lhs.Get() | rhs.Get())>(lhs.Get() | rhs.Get());
693}
694
695/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
696template <typename T, typename U>
697auto
698operator|(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() | rhs)>
699{
700 TRACED_VALUE_DEBUG("x|");
701 return TracedValue<decltype(lhs.Get() | rhs)>(lhs.Get() | rhs);
702}
703
704/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
705template <typename T, typename U>
706auto
707operator|(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs | rhs.Get())>
708{
709 TRACED_VALUE_DEBUG("|x");
710 return TracedValue<decltype(lhs | rhs.Get())>(lhs | rhs.Get());
711}
712
713/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
714// clang-format off
715template <typename T, typename U>
716auto
718 -> TracedValue<decltype(lhs.Get() & rhs.Get())>
719// clang-format on
720{
721 TRACED_VALUE_DEBUG("x&x");
722 return TracedValue<decltype(lhs.Get() & rhs.Get())>(lhs.Get() & rhs.Get());
723}
724
725/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
726template <typename T, typename U>
727auto
728operator&(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() & rhs)>
729{
730 TRACED_VALUE_DEBUG("x&");
731 return TracedValue<decltype(lhs.Get() & rhs)>(lhs.Get() & rhs);
732}
733
734/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
735template <typename T, typename U>
736auto
737operator&(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs & rhs.Get())>
738{
739 TRACED_VALUE_DEBUG("&x");
740 return TracedValue<decltype(lhs & rhs.Get())>(lhs & rhs.Get());
741}
742
743/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
744// clang-format off
745template <typename T, typename U>
746auto
747operator<<(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
748 -> TracedValue<decltype(lhs.Get() << rhs.Get())>
749// clang-format on
750{
751 TRACED_VALUE_DEBUG("x<<x");
752 return TracedValue<decltype(lhs.Get() << rhs.Get())>(lhs.Get() << rhs.Get());
753}
754
755/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
756template <typename T, typename U>
757auto
758operator<<(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() << rhs)>
759{
760 TRACED_VALUE_DEBUG("x<<");
761 return TracedValue<decltype(lhs.Get() << rhs)>(lhs.Get() << rhs);
762}
763
764/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
765template <typename T, typename U>
766auto
767operator<<(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs << rhs.Get())>
768{
769 TRACED_VALUE_DEBUG("<<x");
770 return TracedValue<decltype(lhs << rhs.Get())>(lhs << rhs.Get());
771}
772
773/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
774// clang-format off
775template <typename T, typename U>
776auto
778 -> TracedValue<decltype(lhs.Get() >> rhs.Get())>
779// clang-format on
780{
781 TRACED_VALUE_DEBUG("x>>x");
782 return TracedValue<decltype(lhs.Get() >> rhs.Get())>(lhs.Get() >> rhs.Get());
783}
784
785/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
786template <typename T, typename U>
787auto
788operator>>(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() >> rhs)>
789{
790 TRACED_VALUE_DEBUG("x>>");
791 return TracedValue<decltype(lhs.Get() >> rhs)>(lhs.Get() >> rhs);
792}
793
794/** @copydoc operator+(const TracedValue<T>&lhs,const TracedValue<U>&rhs) */
795template <typename T, typename U>
796auto
797operator>>(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs >> rhs.Get())>
798{
799 TRACED_VALUE_DEBUG(">>x");
800 return TracedValue<decltype(lhs >> rhs.Get())>(lhs >> rhs.Get());
801}
802
803/**
804 * Operator assignment for TracedValue.
805 *
806 * The result of the arithmetic operation on the underlying values
807 * is assigned to the \c lhs TracedValue. If the new value
808 * is different, the Callback will be invoked.
809 *
810 * @tparam T \deduced The underlying type held by the left-hand argument.
811 * @tparam U \deduced The underlying type held by the right-hand argument.
812 * @param [in] lhs The left-hand argument.
813 * @param [in] rhs The right-hand argument.
814 * @returns The result of doing the operator on
815 * the underlying values.
816 */
817template <typename T, typename U>
818TracedValue<T>&
819operator+=(TracedValue<T>& lhs, const U& rhs)
820{
821 TRACED_VALUE_DEBUG("x+=");
822 T tmp = lhs.Get();
823 tmp += rhs;
824 lhs.Set(tmp);
825 return lhs;
826}
827
828/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
829template <typename T, typename U>
830TracedValue<T>&
831operator-=(TracedValue<T>& lhs, const U& rhs)
832{
833 TRACED_VALUE_DEBUG("x-=");
834 T tmp = lhs.Get();
835 tmp -= rhs;
836 lhs.Set(tmp);
837 return lhs;
838}
839
840/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
841template <typename T, typename U>
842TracedValue<T>&
843operator*=(TracedValue<T>& lhs, const U& rhs)
844{
845 TRACED_VALUE_DEBUG("x*=");
846 T tmp = lhs.Get();
847 tmp *= rhs;
848 lhs.Set(tmp);
849 return lhs;
850}
851
852/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
853template <typename T, typename U>
854TracedValue<T>&
855operator/=(TracedValue<T>& lhs, const U& rhs)
856{
857 TRACED_VALUE_DEBUG("x/=");
858 T tmp = lhs.Get();
859 tmp /= rhs;
860 lhs.Set(tmp);
861 return lhs;
862}
863
864/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
865template <typename T, typename U>
866TracedValue<T>&
867operator%=(TracedValue<T>& lhs, const U& rhs)
868{
869 TRACED_VALUE_DEBUG("x%=");
870 T tmp = lhs.Get();
871 tmp %= rhs;
872 lhs.Set(tmp);
873 return lhs;
874}
875
876/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
877template <typename T, typename U>
878TracedValue<T>&
879operator<<=(TracedValue<T>& lhs, const U& rhs)
880{
881 TRACED_VALUE_DEBUG("x<<=");
882 T tmp = lhs.Get();
883 tmp <<= rhs;
884 lhs.Set(tmp);
885 return lhs;
886}
887
888/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
889template <typename T, typename U>
890TracedValue<T>&
891operator>>=(TracedValue<T>& lhs, const U& rhs)
892{
893 TRACED_VALUE_DEBUG("x>>=");
894 T tmp = lhs.Get();
895 tmp >>= rhs;
896 lhs.Set(tmp);
897 return lhs;
898}
899
900/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
901template <typename T, typename U>
902TracedValue<T>&
903operator&=(TracedValue<T>& lhs, const U& rhs)
904{
905 TRACED_VALUE_DEBUG("x&=");
906 T tmp = lhs.Get();
907 tmp &= rhs;
908 lhs.Set(tmp);
909 return lhs;
910}
911
912/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
913template <typename T, typename U>
914TracedValue<T>&
915operator|=(TracedValue<T>& lhs, const U& rhs)
916{
917 TRACED_VALUE_DEBUG("x|=");
918 T tmp = lhs.Get();
919 tmp |= rhs;
920 lhs.Set(tmp);
921 return lhs;
922}
923
924/** @copydoc operator+=(TracedValue<T>&lhs,const U&rhs) */
925template <typename T, typename U>
926TracedValue<T>&
927operator^=(TracedValue<T>& lhs, const U& rhs)
928{
929 TRACED_VALUE_DEBUG("x^=");
930 T tmp = lhs.Get();
931 tmp ^= rhs;
932 lhs.Set(tmp);
933 return lhs;
934}
935
936/**
937 * Unary arithmetic operator for TracedValue.
938 *
939 * @tparam T \deduced The underlying type held by the TracedValue.
940 * @param [in] lhs The TracedValue.
941 * @returns The result of doing the operator on
942 * the underlying values.
943 */
944template <typename T>
945TracedValue<T>
947{
948 TRACED_VALUE_DEBUG("(+x)");
949 return TracedValue<T>(+lhs.Get());
950}
951
952/** @copydoc operator+(const TracedValue<T>&lhs) */
953template <typename T>
954TracedValue<T>
956{
957 TRACED_VALUE_DEBUG("(-x)");
958 return TracedValue<T>(-lhs.Get());
959}
960
961/** @copydoc operator+(const TracedValue<T>&lhs) */
962template <typename T>
963TracedValue<T>
965{
966 TRACED_VALUE_DEBUG("(~x)");
967 return TracedValue<T>(~lhs.Get());
968}
969
970/** @copydoc operator+(const TracedValue<T>&lhs) */
971template <typename T>
972TracedValue<T>
974{
975 TRACED_VALUE_DEBUG("(!x)");
976 return TracedValue<T>(!lhs.Get());
977}
978
979/**@}*/ // \ingroup tracing
980
981} // namespace ns3
982
983#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:1146
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:1192
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:1205
ns3::TracedCallback declaration and template implementation.
#define TRACED_VALUE_DEBUG(x)
Logging macro for TracedValue.
ns3::UintegerValue attribute value declarations and template implementations.