A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fourth.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  */
16 
17 #include "ns3/object.h"
18 #include "ns3/uinteger.h"
19 #include "ns3/traced-value.h"
20 #include "ns3/trace-source-accessor.h"
21 
22 #include <iostream>
23 
24 using namespace ns3;
25 
26 class MyObject : public Object
27 {
28 public:
29  static TypeId GetTypeId (void)
30  {
31  static TypeId tid = TypeId ("MyObject")
34  .AddTraceSource ("MyInteger",
35  "An integer value to trace.",
37  ;
38  return tid;
39  }
40 
41  MyObject () {}
43 };
44 
45 void
46 IntTrace (int32_t oldValue, int32_t newValue)
47 {
48  std::cout << "Traced " << oldValue << " to " << newValue << std::endl;
49 }
50 
51 int
52 main (int argc, char *argv[])
53 {
54  Ptr<MyObject> myObject = CreateObject<MyObject> ();
55  myObject->TraceConnectWithoutContext ("MyInteger", MakeCallback (&IntTrace));
56 
57  myObject->m_myInt = 1234;
58 }
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
TypeId AddConstructor(void)
Definition: type-id.h:418
TracedValue< int32_t > m_myInt
Definition: fourth.cc:42
static TypeId GetTypeId(void)
Definition: fourth.cc:29
int main(int argc, char *argv[])
Definition: fourth.cc:52
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: object-base.cc:284
void IntTrace(int32_t oldValue, int32_t newValue)
Definition: fourth.cc:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
MyObject()
Definition: fourth.cc:41
static TypeId GetTypeId(void)
Register this type.
Definition: object.cc:83
a base class which provides memory management and object aggregation
Definition: object.h:64
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610