A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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"
)
32
.
SetParent
(
Object::GetTypeId
())
33
.
AddConstructor
<
MyObject
> ()
34
.AddTraceSource (
"MyInteger"
,
35
"An integer value to trace."
,
36
MakeTraceSourceAccessor
(&
MyObject::m_myInt
),
37
"ns3::TracedValue::Int32Callback"
)
38
;
39
return
tid;
40
}
41
42
MyObject
() {}
43
TracedValue<int32_t>
m_myInt
;
44
};
45
46
void
47
IntTrace
(int32_t oldValue, int32_t newValue)
48
{
49
std::cout <<
"Traced "
<< oldValue <<
" to "
<< newValue << std::endl;
50
}
51
52
int
53
main (
int
argc,
char
*argv[])
54
{
55
Ptr<MyObject>
myObject = CreateObject<MyObject> ();
56
myObject->
TraceConnectWithoutContext
(
"MyInteger"
,
MakeCallback
(&
IntTrace
));
57
58
myObject->
m_myInt
= 1234;
59
}
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
ns3::TypeId::AddConstructor
TypeId AddConstructor(void)
Definition:
type-id.h:460
MyObject::m_myInt
TracedValue< int32_t > m_myInt
Definition:
fourth.cc:43
ns3::TracedValue< int32_t >
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition:
trace-source-accessor.h:185
MyObject::GetTypeId
static TypeId GetTypeId(void)
Definition:
fourth.cc:29
MyObject
Definition:
fourth.cc:26
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1296
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition:
object-base.cc:298
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
IntTrace
void IntTrace(int32_t oldValue, int32_t newValue)
Definition:
fourth.cc:47
MyObject::MyObject
MyObject()
Definition:
fourth.cc:42
ns3::Object::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition:
object.cc:86
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:87
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
examples
tutorial
fourth.cc
Generated on Wed May 13 2015 14:59:05 for ns-3 by
1.8.9.1