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 TracedValue 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 {
181 m_cb.ConnectWithoutContext(cb);
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 */
204 {
205 m_cb.DisconnectWithoutContext(cb);
206 }
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 */
330/**@{*/
331template <typename T, typename U>
332bool
334{
335 TRACED_VALUE_DEBUG("x==x");
336 return lhs.Get() == rhs.Get();
337}
338
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
347template <typename T, typename U>
348bool
349operator==(const U& lhs, const TracedValue<T>& rhs)
350{
351 TRACED_VALUE_DEBUG("==x");
352 return lhs == rhs.Get();
353}
354
355template <typename T, typename U>
356bool
358{
359 TRACED_VALUE_DEBUG("x!=x");
360 return lhs.Get() != rhs.Get();
361}
362
363template <typename T, typename U>
364bool
365operator!=(const TracedValue<T>& lhs, const U& rhs)
366{
367 TRACED_VALUE_DEBUG("x!=");
368 return lhs.Get() != rhs;
369}
370
371template <typename T, typename U>
372bool
373operator!=(const U& lhs, const TracedValue<T>& rhs)
374{
375 TRACED_VALUE_DEBUG("!=x");
376 return lhs != rhs.Get();
377}
378
379template <typename T, typename U>
380bool
381operator<=(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
382{
383 TRACED_VALUE_DEBUG("x<=x");
384 return lhs.Get() <= rhs.Get();
385}
386
387template <typename T, typename U>
388bool
389operator<=(const TracedValue<T>& lhs, const U& rhs)
390{
391 TRACED_VALUE_DEBUG("x<=");
392 return lhs.Get() <= rhs;
393}
394
395template <typename T, typename U>
396bool
397operator<=(const U& lhs, const TracedValue<T>& rhs)
398{
399 TRACED_VALUE_DEBUG("<=x");
400 return lhs <= rhs.Get();
401}
402
403template <typename T, typename U>
404bool
406{
407 TRACED_VALUE_DEBUG("x>=x");
408 return lhs.Get() >= rhs.Get();
409}
410
411template <typename T, typename U>
412bool
413operator>=(const TracedValue<T>& lhs, const U& rhs)
414{
415 TRACED_VALUE_DEBUG("x>=");
416 return lhs.Get() >= rhs;
417}
418
419template <typename T, typename U>
420bool
421operator>=(const U& lhs, const TracedValue<T>& rhs)
422{
423 TRACED_VALUE_DEBUG(">=x");
424 return lhs >= rhs.Get();
425}
426
427template <typename T, typename U>
428bool
429operator<(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
430{
431 TRACED_VALUE_DEBUG("x<x");
432 return lhs.Get() < rhs.Get();
433}
434
435template <typename T, typename U>
436bool
437operator<(const TracedValue<T>& lhs, const U& rhs)
438{
439 TRACED_VALUE_DEBUG("x<");
440 return lhs.Get() < rhs;
441}
442
443template <typename T, typename U>
444bool
445operator<(const U& lhs, const TracedValue<T>& rhs)
446{
447 TRACED_VALUE_DEBUG("<x");
448 return lhs < rhs.Get();
449}
450
451template <typename T, typename U>
452bool
454{
455 TRACED_VALUE_DEBUG("x>x");
456 return lhs.Get() > rhs.Get();
457}
458
459template <typename T, typename U>
460bool
461operator>(const TracedValue<T>& lhs, const U& rhs)
462{
463 TRACED_VALUE_DEBUG("x>");
464 return lhs.Get() > rhs;
465}
466
467template <typename T, typename U>
468bool
469operator>(const U& lhs, const TracedValue<T>& rhs)
470{
471 TRACED_VALUE_DEBUG(">x");
472 return lhs > rhs.Get();
473}
474
475/**@}*/
476
477/**
478 * Infix arithmetic operator for TracedValue.
479 *
480 * This returns the arithmetic result in a new TracedValue,
481 * which has no Callback connected.
482 *
483 * @tparam T \deduced The underlying type held by the left-hand argument.
484 * @tparam U \deduced The underlying type held by the right-hand argument.
485 * @param [in] lhs The left-hand argument.
486 * @param [in] rhs The right-hand argument.
487 * @returns The result of doing the operator on the underlying values.
488 */
489/**@{*/
490template <typename T, typename U>
491auto
493 -> TracedValue<decltype(lhs.Get() + rhs.Get())>
494{
495 TRACED_VALUE_DEBUG("x+x");
496 return TracedValue<decltype(lhs.Get() + rhs.Get())>(lhs.Get() + rhs.Get());
497}
498
499template <typename T, typename U>
500auto
501operator+(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() + rhs)>
502{
503 TRACED_VALUE_DEBUG("x+");
504 return TracedValue<decltype(lhs.Get() + rhs)>(lhs.Get() + rhs);
505}
506
507template <typename T, typename U>
508auto
509operator+(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
510{
511 TRACED_VALUE_DEBUG("+x");
512 return TracedValue<decltype(lhs + rhs.Get())>(lhs + rhs.Get());
513}
514
515template <typename T, typename U>
516auto
518 -> TracedValue<decltype(lhs.Get() - rhs.Get())>
519{
520 TRACED_VALUE_DEBUG("x-x");
521 return TracedValue<decltype(lhs.Get() - rhs.Get())>(lhs.Get() - rhs.Get());
522}
523
524template <typename T, typename U>
525auto
526operator-(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() - rhs)>
527{
528 TRACED_VALUE_DEBUG("x-");
529 return TracedValue<decltype(lhs.Get() - rhs)>(lhs.Get() - rhs);
530}
531
532template <typename T, typename U>
533auto
534operator-(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs - rhs.Get())>
535{
536 TRACED_VALUE_DEBUG("-x");
537 return TracedValue<decltype(lhs - rhs.Get())>(lhs - rhs.Get());
538}
539
540template <typename T, typename U>
541auto
543 -> TracedValue<decltype(lhs.Get() * rhs.Get())>
544{
545 TRACED_VALUE_DEBUG("x*x");
546 return TracedValue<decltype(lhs.Get() * rhs.Get())>(lhs.Get() * rhs.Get());
547}
548
549template <typename T, typename U>
550auto
551operator*(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() * rhs)>
552{
553 TRACED_VALUE_DEBUG("x*");
554 return TracedValue<decltype(lhs.Get() * rhs)>(lhs.Get() * rhs);
555}
556
557template <typename T, typename U>
558auto
559operator*(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs + rhs.Get())>
560{
561 TRACED_VALUE_DEBUG("*x");
562 return TracedValue<decltype(lhs + rhs.Get())>(lhs * rhs.Get());
563}
564
565template <typename T, typename U>
566auto
568 -> TracedValue<decltype(lhs.Get() / rhs.Get())>
569{
570 TRACED_VALUE_DEBUG("x/x");
571 return TracedValue<decltype(lhs.Get() / rhs.Get())>(lhs.Get() / rhs.Get());
572}
573
574template <typename T, typename U>
575auto
576operator/(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() / rhs)>
577{
578 TRACED_VALUE_DEBUG("x/");
579 return TracedValue<decltype(lhs.Get() / rhs)>(lhs.Get() / rhs);
580}
581
582template <typename T, typename U>
583auto
584operator/(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs / rhs.Get())>
585{
586 TRACED_VALUE_DEBUG("/x");
587 return TracedValue<decltype(lhs / rhs.Get())>(lhs / rhs.Get());
588}
589
590template <typename T, typename U>
591auto
593 -> TracedValue<decltype(lhs.Get() % rhs.Get())>
594{
595 TRACED_VALUE_DEBUG("x%x");
596 return TracedValue<decltype(lhs.Get() % rhs.Get())>(lhs.Get() % rhs.Get());
597}
598
599template <typename T, typename U>
600auto
601operator%(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() % rhs)>
602{
603 TRACED_VALUE_DEBUG("x%");
604 return TracedValue<decltype(lhs.Get() % rhs)>(lhs.Get() % rhs);
605}
606
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
615template <typename T, typename U>
616auto
618 -> TracedValue<decltype(lhs.Get() ^ rhs.Get())>
619{
620 TRACED_VALUE_DEBUG("x^x");
621 return TracedValue<decltype(lhs.Get() ^ rhs.Get())>(lhs.Get() ^ rhs.Get());
622}
623
624template <typename T, typename U>
625auto
626operator^(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() ^ rhs)>
627{
628 TRACED_VALUE_DEBUG("x^");
629 return TracedValue<decltype(lhs.Get() ^ rhs)>(lhs.Get() ^ rhs);
630}
631
632template <typename T, typename U>
633auto
634operator^(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs ^ rhs.Get())>
635{
636 TRACED_VALUE_DEBUG("^x");
637 return TracedValue<decltype(lhs ^ rhs.Get())>(lhs ^ rhs.Get());
638}
639
640template <typename T, typename U>
641auto
643 -> TracedValue<decltype(lhs.Get() | rhs.Get())>
644{
645 TRACED_VALUE_DEBUG("x|x");
646 return TracedValue<decltype(lhs.Get() | rhs.Get())>(lhs.Get() | rhs.Get());
647}
648
649template <typename T, typename U>
650auto
651operator|(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() | rhs)>
652{
653 TRACED_VALUE_DEBUG("x|");
654 return TracedValue<decltype(lhs.Get() | rhs)>(lhs.Get() | rhs);
655}
656
657template <typename T, typename U>
658auto
659operator|(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs | rhs.Get())>
660{
661 TRACED_VALUE_DEBUG("|x");
662 return TracedValue<decltype(lhs | rhs.Get())>(lhs | rhs.Get());
663}
664
665template <typename T, typename U>
666auto
668 -> TracedValue<decltype(lhs.Get() & rhs.Get())>
669{
670 TRACED_VALUE_DEBUG("x&x");
671 return TracedValue<decltype(lhs.Get() & rhs.Get())>(lhs.Get() & rhs.Get());
672}
673
674template <typename T, typename U>
675auto
676operator&(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() & rhs)>
677{
678 TRACED_VALUE_DEBUG("x&");
679 return TracedValue<decltype(lhs.Get() & rhs)>(lhs.Get() & rhs);
680}
681
682template <typename T, typename U>
683auto
684operator&(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs & rhs.Get())>
685{
686 TRACED_VALUE_DEBUG("&x");
687 return TracedValue<decltype(lhs & rhs.Get())>(lhs & rhs.Get());
688}
689
690template <typename T, typename U>
691auto
692operator<<(const TracedValue<T>& lhs, const TracedValue<U>& rhs)
693 -> TracedValue<decltype(lhs.Get() << rhs.Get())>
694{
695 TRACED_VALUE_DEBUG("x<<x");
696 return TracedValue<decltype(lhs.Get() << rhs.Get())>(lhs.Get() << rhs.Get());
697}
698
699template <typename T, typename U>
700auto
701operator<<(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() << rhs)>
702{
703 TRACED_VALUE_DEBUG("x<<");
704 return TracedValue<decltype(lhs.Get() << rhs)>(lhs.Get() << rhs);
705}
706
707template <typename T, typename U>
708auto
709operator<<(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs << rhs.Get())>
710{
711 TRACED_VALUE_DEBUG("<<x");
712 return TracedValue<decltype(lhs << rhs.Get())>(lhs << rhs.Get());
713}
714
715template <typename T, typename U>
716auto
718 -> TracedValue<decltype(lhs.Get() >> rhs.Get())>
719{
720 TRACED_VALUE_DEBUG("x>>x");
721 return TracedValue<decltype(lhs.Get() >> rhs.Get())>(lhs.Get() >> rhs.Get());
722}
723
724template <typename T, typename U>
725auto
726operator>>(const TracedValue<T>& lhs, const U& rhs) -> TracedValue<decltype(lhs.Get() >> rhs)>
727{
728 TRACED_VALUE_DEBUG("x>>");
729 return TracedValue<decltype(lhs.Get() >> rhs)>(lhs.Get() >> rhs);
730}
731
732template <typename T, typename U>
733auto
734operator>>(const U& lhs, const TracedValue<T>& rhs) -> TracedValue<decltype(lhs >> rhs.Get())>
735{
736 TRACED_VALUE_DEBUG(">>x");
737 return TracedValue<decltype(lhs >> rhs.Get())>(lhs >> rhs.Get());
738}
739
740/**@}*/
741
742/**
743 * Operator assignment for TracedValue.
744 *
745 * The result of the arithmetic operation on the underlying values
746 * is assigned to the \c lhs TracedValue. If the new value
747 * is different, the Callback will be invoked.
748 *
749 * @tparam T \deduced The underlying type held by the left-hand argument.
750 * @tparam U \deduced The underlying type held by the right-hand argument.
751 * @param [in] lhs The left-hand argument.
752 * @param [in] rhs The right-hand argument.
753 * @returns The result of doing the operator on the underlying values.
754 */
755/**@{*/
756template <typename T, typename U>
757TracedValue<T>&
758operator+=(TracedValue<T>& lhs, const U& rhs)
759{
760 TRACED_VALUE_DEBUG("x+=");
761 T tmp = lhs.Get();
762 tmp += rhs;
763 lhs.Set(tmp);
764 return lhs;
765}
766
767template <typename T, typename U>
768TracedValue<T>&
769operator-=(TracedValue<T>& lhs, const U& rhs)
770{
771 TRACED_VALUE_DEBUG("x-=");
772 T tmp = lhs.Get();
773 tmp -= rhs;
774 lhs.Set(tmp);
775 return lhs;
776}
777
778template <typename T, typename U>
779TracedValue<T>&
780operator*=(TracedValue<T>& lhs, const U& rhs)
781{
782 TRACED_VALUE_DEBUG("x*=");
783 T tmp = lhs.Get();
784 tmp *= rhs;
785 lhs.Set(tmp);
786 return lhs;
787}
788
789template <typename T, typename U>
790TracedValue<T>&
791operator/=(TracedValue<T>& lhs, const U& rhs)
792{
793 TRACED_VALUE_DEBUG("x/=");
794 T tmp = lhs.Get();
795 tmp /= rhs;
796 lhs.Set(tmp);
797 return lhs;
798}
799
800template <typename T, typename U>
801TracedValue<T>&
802operator%=(TracedValue<T>& lhs, const U& rhs)
803{
804 TRACED_VALUE_DEBUG("x%=");
805 T tmp = lhs.Get();
806 tmp %= rhs;
807 lhs.Set(tmp);
808 return lhs;
809}
810
811template <typename T, typename U>
812TracedValue<T>&
813operator<<=(TracedValue<T>& lhs, const U& rhs)
814{
815 TRACED_VALUE_DEBUG("x<<=");
816 T tmp = lhs.Get();
817 tmp <<= rhs;
818 lhs.Set(tmp);
819 return lhs;
820}
821
822template <typename T, typename U>
824operator>>=(TracedValue<T>& lhs, const U& rhs)
825{
826 TRACED_VALUE_DEBUG("x>>=");
827 T tmp = lhs.Get();
828 tmp >>= rhs;
829 lhs.Set(tmp);
830 return lhs;
831}
832
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
844template <typename T, typename U>
845TracedValue<T>&
846operator|=(TracedValue<T>& lhs, const U& rhs)
847{
848 TRACED_VALUE_DEBUG("x|=");
849 T tmp = lhs.Get();
850 tmp |= rhs;
851 lhs.Set(tmp);
852 return lhs;
853}
854
855template <typename T, typename U>
856TracedValue<T>&
857operator^=(TracedValue<T>& lhs, const U& rhs)
858{
859 TRACED_VALUE_DEBUG("x^=");
860 T tmp = lhs.Get();
861 tmp ^= rhs;
862 lhs.Set(tmp);
863 return lhs;
864}
865
866/**@}*/
867
868/**
869 * Unary arithmetic operator for TracedValue.
870 *
871 * @tparam T \deduced The underlying type held by the TracedValue.
872 * @param [in] lhs The TracedValue.
873 * @returns The result of doing the operator on the underlying values.
874 */
875/**@{*/
876template <typename T>
877TracedValue<T>
879{
880 TRACED_VALUE_DEBUG("(+x)");
881 return TracedValue<T>(+lhs.Get());
882}
883
884template <typename T>
885TracedValue<T>
887{
888 TRACED_VALUE_DEBUG("(-x)");
889 return TracedValue<T>(-lhs.Get());
890}
891
892template <typename T>
893TracedValue<T>
895{
896 TRACED_VALUE_DEBUG("(~x)");
897 return TracedValue<T>(~lhs.Get());
898}
899
900template <typename T>
901TracedValue<T>
903{
904 TRACED_VALUE_DEBUG("(!x)");
905 return TracedValue<T>(!lhs.Get());
906}
907
908/**@}*/
909
910/**@}*/ // \ingroup tracing
911
912} // namespace ns3
913
914#endif /* TRACED_VALUE_H */
ns3::BooleanValue attribute value declarations.
uint32_t v
Base class for Callback class.
Definition callback.h:344
Forward calls to a chain of Callback.
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:1170
bool operator==(const EventId &a, const EventId &b)
Definition event-id.h:146
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:1216
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
bool operator<(const EventId &a, const EventId &b)
Definition event-id.h:159
Time & operator-=(Time &lhs, const Time &rhs)
Compound subtraction assignment for Time.
Definition nstime.h:1229
ns3::TracedCallback declaration and template implementation.
#define TRACED_VALUE_DEBUG(x)
Logging macro for TracedValue.
ns3::UintegerValue attribute value declarations and template implementations.