diff --git a/src/core/attribute-test.cc b/src/core/attribute-test.cc index 15f0e6c0d..480fe13d7 100644 --- a/src/core/attribute-test.cc +++ b/src/core/attribute-test.cc @@ -8,7 +8,7 @@ #include "random-variable.h" #include "double.h" #include "object-vector.h" -#include "integer-trace-source.h" +#include "value-trace-source.h" #include "trace-source-accessor.h" namespace ns3 { @@ -19,7 +19,7 @@ public: AttributeTest (); virtual bool RunTests (void); private: - void NotifySource1 (int64_t old, int64_t n) { + void NotifySource1 (int8_t old, int8_t n) { m_got1 = n; } void NotifySource2 (double a, int b, float c) { @@ -115,7 +115,6 @@ public: MakeIntegerChecker ()) .AddTraceSource ("Source1", "help test", MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1)) - .AddTraceSource ("Source2", "help text", MakeTraceSourceAccessor (&AttributeObjectTest::m_cb)) ; @@ -171,8 +170,8 @@ private: RandomVariable m_random; std::vector > m_vector1; std::vector > m_vector2; - IntegerTraceSource m_intSrc1; - IntegerTraceSource m_intSrc2; + ValueTraceSource m_intSrc1; + ValueTraceSource m_intSrc2; EventTraceSource m_cb; }; diff --git a/src/core/integer-trace-source.h b/src/core/integer-trace-source.h deleted file mode 100644 index 823d7b62f..000000000 --- a/src/core/integer-trace-source.h +++ /dev/null @@ -1,225 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2006,2008 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#ifndef INTEGER_TRACE_SOURCE_H -#define INTEGER_TRACE_SOURCE_H - -#include -#include "event-trace-source.h" -#include "integer.h" - -namespace ns3 { - -class IntegerTraceSourceBase -{ -public: - typedef EventTraceSource ChangeNotifyCallback; - - IntegerTraceSourceBase () {} - IntegerTraceSourceBase (const IntegerTraceSourceBase &o) {} - IntegerTraceSourceBase &operator = (const IntegerTraceSourceBase &o) { - return *this; - } - - void Connect (const CallbackBase & callback) { - m_callback.Connect (callback); - } - void Disconnect (const CallbackBase & callback) { - m_callback.Disconnect (callback); - } -protected: - void Notify (int64_t oldVal, int64_t newVal) { - if (oldVal != newVal) - { - m_callback (oldVal, newVal); - } - } -private: - ChangeNotifyCallback m_callback; -}; - -#if 0 -template -class UIntegerTraceSource; -#endif - - -template -class IntegerTraceSource : public IntegerTraceSourceBase { -public: - IntegerTraceSource () - : m_var (0) - {} - IntegerTraceSource (T const &var) - : m_var (var) - {} - - IntegerTraceSource &operator = (IntegerTraceSource const &o) { - Set (o.Get ()); - return *this; - } - template - IntegerTraceSource &operator = (IntegerTraceSource const &o) { - Set (o.Get ()); - return *this; - } -#if 0 - template - IntegerTraceSource &operator = (UintegerTraceSource const &o) { - Set (o.Get ()); - return *this; - } -#endif - IntegerTraceSource &operator++ () { - Set (Get () + 1); - return *this; - } - IntegerTraceSource &operator-- () { - Set (Get () - 1); - return *this; - } - IntegerTraceSource operator++ (int) { - IntegerTraceSource old (*this); - ++*this; - return old; - } - IntegerTraceSource operator-- (int) { - IntegerTraceSource old (*this); - --*this; - return old; - } - operator T () const { - return Get (); - } - void Set (T var) { - Notify (m_var, var); - m_var = var; - } - T Get (void) const { - return m_var; - } - - IntegerTraceSource (Integer value) - : m_var (value.Get ()) {} - operator Integer () const { - return Integer (m_var); - } - -private: - T m_var; -}; - -template -IntegerTraceSource &operator += (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () + rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator -= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () - rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator *= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () * rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator /= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () / rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator <<= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () << rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator >>= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () >> rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator &= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () & rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator |= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () | rhs.Get ()); - return lhs; -} -template -IntegerTraceSource &operator ^= (IntegerTraceSource &lhs, IntegerTraceSource const &rhs) { - lhs.Set (lhs.Get () ^ rhs.Get ()); - return lhs; -} - - -template -IntegerTraceSource &operator += (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () + rhs); - return lhs; -} -template -IntegerTraceSource &operator -= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () - rhs); - return lhs; -} -template -IntegerTraceSource &operator *= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () * rhs); - return lhs; -} -template -IntegerTraceSource &operator /= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () / rhs); - return lhs; -} -template -IntegerTraceSource &operator <<= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () << rhs); - return lhs; -} -template -IntegerTraceSource &operator >>= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () >> rhs); - return lhs; -} -template -IntegerTraceSource &operator &= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () & rhs); - return lhs; -} -template -IntegerTraceSource &operator |= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () | rhs); - return lhs; -} -template -IntegerTraceSource &operator ^= (IntegerTraceSource &lhs, U const &rhs) { - lhs.Set (lhs.Get () ^ rhs); - return lhs; -} - -} // namespace ns3 - -#endif /* INTEGER_TRACE_SOURCE_H */ diff --git a/src/core/value-trace-source.h b/src/core/value-trace-source.h new file mode 100644 index 000000000..18d08b98f --- /dev/null +++ b/src/core/value-trace-source.h @@ -0,0 +1,480 @@ +#ifndef VALUE_TRACE_SOURCE_H +#define VALUE_TRACE_SOURCE_H + +#include "event-trace-source.h" +#include "integer.h" +#include "uinteger.h" +#include "boolean.h" +#include "double.h" +#include "enum.h" + +#define TRACE(x) + +namespace ns3 { + +template +class ValueTraceSource +{ +public: + ValueTraceSource () + : m_v () {} + ValueTraceSource (const ValueTraceSource &o) + : m_v (o.m_v) {} + ValueTraceSource (const T &v) + : m_v (v) {} + operator T () const { + return m_v; + } + ValueTraceSource &operator = (const ValueTraceSource &o) { + TRACE ("x="); + Set (o.m_v); + return *this; + } + ValueTraceSource (const Integer &value) + : m_v (value.Get ()) {} + operator Integer () const { + return Integer (m_v); + } + ValueTraceSource (const Uinteger &value) + : m_v (value.Get ()) {} + operator Uinteger () const { + return Uinteger (m_v); + } + ValueTraceSource (const Boolean &value) + : m_v (value.Get ()) {} + operator Boolean () const { + return Boolean (m_v); + } + ValueTraceSource (const Enum &value) + : m_v (value.Get ()) {} + operator Enum () const { + return Enum (m_v); + } + void Connect (const CallbackBase &cb) { + m_cb.Connect (cb); + } + void Disconnect (const CallbackBase &cb) { + m_cb.Disconnect (cb); + } + void Set (const T &v) { + if (m_v != v) + { + m_cb (m_v, v); + m_v = v; + } + } + T Get (void) const { + return m_v; + } + ValueTraceSource &operator++ () { + TRACE ("++x"); + T tmp = Get (); + ++tmp; + Set (tmp); + return *this; + } + ValueTraceSource &operator-- () { + TRACE ("--x"); + T tmp = Get (); + --tmp; + Set (tmp); + return *this; + } + ValueTraceSource operator++ (int) { + TRACE ("x++"); + ValueTraceSource old (*this); + T tmp = Get (); + tmp++; + Set (tmp); + return old; + } + ValueTraceSource operator-- (int) { + TRACE ("x--"); + ValueTraceSource old (*this); + T tmp = Get (); + tmp--; + Set (tmp); + return old; + } +private: + T m_v; + EventTraceSource m_cb; +}; + +template +bool operator == (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x==x"); + return lhs.Get () == rhs.Get (); +} +template +bool operator == (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x=="); + return lhs.Get () == rhs; +} +template +bool operator == (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE ("==x"); + return lhs == rhs.Get (); +} + +template +bool operator != (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x!=x"); + return lhs.Get () != rhs.Get (); +} +template +bool operator != (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x!="); + return lhs.Get () != rhs; +} +template +bool operator != (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE ("!=x"); + return lhs != rhs.Get (); +} + +template +bool operator <= (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x<=x"); + return lhs.Get () <= rhs.Get (); +} +template +bool operator <= (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x<="); + return lhs.Get () <= rhs; +} +template +bool operator <= (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE ("<=x"); + return lhs <= rhs.Get (); +} +template +bool operator >= (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x>=x"); + return lhs.Get () >= rhs.Get (); +} +template +bool operator >= (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x>="); + return lhs.Get () >= rhs; +} +template +bool operator >= (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE (">=x"); + return lhs >= rhs.Get (); +} + +template +bool operator < (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x +bool operator < (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x<"); + return lhs.Get () < rhs; +} +template +bool operator < (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE (" +bool operator > (const ValueTraceSource &lhs, const ValueTraceSource &rhs) +{ + TRACE ("x>x"); + return lhs.Get () > rhs.Get (); +} +template +bool operator > (const ValueTraceSource &lhs, const U &rhs) +{ + TRACE ("x>"); + return lhs.Get () > rhs; +} +template +bool operator > (const U &lhs, const ValueTraceSource &rhs) +{ + TRACE (">x"); + return lhs > rhs.Get (); +} +template +ValueTraceSource &operator += (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x+="); + T tmp = lhs.Get (); + tmp += rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator -= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x-="); + T tmp = lhs.Get (); + tmp -= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator *= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x*="); + T tmp = lhs.Get (); + tmp *= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator /= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x/="); + T tmp = lhs.Get (); + tmp /= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator %= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x%="); + T tmp = lhs.Get (); + tmp %= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator <<= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x<<="); + T tmp = lhs.Get (); + tmp <<= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator >>= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x>>="); + T tmp = lhs.Get (); + tmp >>= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator &= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x&="); + T tmp = lhs.Get (); + tmp &= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator |= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x|="); + T tmp = lhs.Get (); + tmp |= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource &operator ^= (ValueTraceSource &lhs, const U &rhs) { + TRACE ("x^="); + T tmp = lhs.Get (); + tmp ^= rhs; + lhs.Set (tmp); + return lhs; +} +template +ValueTraceSource operator + (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x+x"); + return ValueTraceSource (lhs.Get () + rhs.Get ()); +} +template +ValueTraceSource operator + (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x+"); + return ValueTraceSource (lhs.Get () + rhs); +} +template +ValueTraceSource operator + (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("+x"); + return ValueTraceSource (lhs + rhs.Get ()); +} + +template +ValueTraceSource operator - (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x-x"); + return ValueTraceSource (lhs.Get () - rhs.Get ()); +} +template +ValueTraceSource operator - (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x-"); + return ValueTraceSource (lhs.Get () - rhs); +} +template +ValueTraceSource operator - (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("-x"); + return ValueTraceSource (lhs - rhs.Get ()); +} + +template +ValueTraceSource operator * (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x*x"); + return ValueTraceSource (lhs.Get () * rhs.Get ()); +} +template +ValueTraceSource operator * (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x*"); + return ValueTraceSource (lhs.Get () * rhs); +} +template +ValueTraceSource operator * (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("*x"); + return ValueTraceSource (lhs - rhs.Get ()); +} + +template +ValueTraceSource operator / (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x/x"); + return ValueTraceSource (lhs.Get () / rhs.Get ()); +} +template +ValueTraceSource operator / (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x/"); + return ValueTraceSource (lhs.Get () / rhs); +} +template +ValueTraceSource operator / (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("/x"); + return ValueTraceSource (lhs / rhs.Get ()); +} + +template +ValueTraceSource operator % (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x%x"); + return ValueTraceSource (lhs.Get () % rhs.Get ()); +} +template +ValueTraceSource operator % (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x%"); + return ValueTraceSource (lhs.Get () % rhs); +} +template +ValueTraceSource operator % (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("%x"); + return ValueTraceSource (lhs % rhs.Get ()); +} + +template +ValueTraceSource operator ^ (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x^x"); + return ValueTraceSource (lhs.Get () ^ rhs.Get ()); +} +template +ValueTraceSource operator ^ (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x^"); + return ValueTraceSource (lhs.Get () ^ rhs); +} +template +ValueTraceSource operator ^ (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("^x"); + return ValueTraceSource (lhs ^ rhs.Get ()); +} + +template +ValueTraceSource operator | (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x|x"); + return ValueTraceSource (lhs.Get () | rhs.Get ()); +} +template +ValueTraceSource operator | (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x|"); + return ValueTraceSource (lhs.Get () | rhs); +} +template +ValueTraceSource operator | (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("|x"); + return ValueTraceSource (lhs | rhs.Get ()); +} + +template +ValueTraceSource operator & (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x&x"); + return ValueTraceSource (lhs.Get () & rhs.Get ()); +} +template +ValueTraceSource operator & (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x&"); + return ValueTraceSource (lhs.Get () & rhs); +} +template +ValueTraceSource operator & (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("&x"); + return ValueTraceSource (lhs & rhs.Get ()); +} + +template +ValueTraceSource operator << (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x< (lhs.Get () << rhs.Get ()); +} +template +ValueTraceSource operator << (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x<<"); + return ValueTraceSource (lhs.Get () << rhs); +} +template +ValueTraceSource operator << (const U &lhs, const ValueTraceSource &rhs) { + TRACE ("< (lhs << rhs.Get ()); +} + +template +ValueTraceSource operator >> (const ValueTraceSource &lhs, const ValueTraceSource &rhs) { + TRACE ("x>>x"); + return ValueTraceSource (lhs.Get () >> rhs.Get ()); +} +template +ValueTraceSource operator >> (const ValueTraceSource &lhs, const U &rhs) { + TRACE ("x>>"); + return ValueTraceSource (lhs.Get () >> rhs); +} +template +ValueTraceSource operator >> (const U &lhs, const ValueTraceSource &rhs) { + TRACE (">>x"); + return ValueTraceSource (lhs >> rhs.Get ()); +} + + +template +ValueTraceSource operator + (const ValueTraceSource &lhs) { + TRACE ("(+x)"); + return ValueTraceSource (+lhs.Get ()); +} +template +ValueTraceSource operator - (const ValueTraceSource &lhs) { + TRACE ("(-x)"); + return ValueTraceSource (-lhs.Get ()); +} +template +ValueTraceSource operator ~ (const ValueTraceSource &lhs) { + TRACE ("(~x)"); + return ValueTraceSource (~lhs.Get ()); +} +template +ValueTraceSource operator ! (const ValueTraceSource &lhs) { + TRACE ("(!x)"); + return ValueTraceSource (!lhs.Get ()); +} + + +} // namespace ns3 + +#endif /* VALUE_TRACE_SOURCE_H */ diff --git a/src/core/wscript b/src/core/wscript index 000c4457d..6da532b0e 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -120,7 +120,7 @@ def build(bld): 'attribute-helper.h', 'global-value.h', 'event-trace-source.h', - 'integer-trace-source.h', + 'value-trace-source.h', 'trace-source-accessor.h', ]