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