A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
trace-source-accessor.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef TRACE_SOURCE_ACCESSOR_H
21
#define TRACE_SOURCE_ACCESSOR_H
22
23
#include <stdint.h>
24
#include "
callback.h
"
25
#include "
ptr.h
"
26
#include "
simple-ref-count.h
"
27
34
namespace
ns3
{
35
36
class
ObjectBase;
37
46
class
TraceSourceAccessor
:
public
SimpleRefCount
<TraceSourceAccessor>
47
{
48
public
:
50
TraceSourceAccessor
();
52
virtual
~TraceSourceAccessor
();
53
62
virtual
bool
ConnectWithoutContext
(
ObjectBase
*obj,
const
CallbackBase
&cb)
const
= 0;
75
virtual
bool
Connect
(
ObjectBase
*obj, std::string context,
const
CallbackBase
&cb)
const
= 0;
84
virtual
bool
DisconnectWithoutContext
(
ObjectBase
*obj,
const
CallbackBase
&cb)
const
= 0;
97
virtual
bool
Disconnect
(
ObjectBase
*obj, std::string context,
const
CallbackBase
&cb)
const
= 0;
98
};
99
115
template
<
typename
T>
116
Ptr<const TraceSourceAccessor>
MakeTraceSourceAccessor
(T a);
117
125
static
inline
126
Ptr<const TraceSourceAccessor>
MakeEmptyTraceSourceAccessor
()
127
{
128
return
Ptr<const TraceSourceAccessor>
(0);
129
}
130
131
}
// namespace ns3
132
133
134
/********************************************************************
135
* Implementation of the templates declared above.
136
********************************************************************/
137
138
namespace
ns3
{
139
149
template
<
typename
T,
typename
SOURCE>
150
Ptr<const TraceSourceAccessor>
151
DoMakeTraceSourceAccessor
(SOURCE T::*a)
152
{
153
struct
Accessor :
public
TraceSourceAccessor
154
{
155
virtual
bool
ConnectWithoutContext
(
ObjectBase
*obj,
const
CallbackBase
&cb)
const
156
{
157
T *p =
dynamic_cast<
T*
>
(obj);
158
if
(p == 0)
159
{
160
return
false
;
161
}
162
(p->*m_source).
ConnectWithoutContext
(cb);
163
return
true
;
164
}
165
virtual
bool
Connect
(
ObjectBase
*obj, std::string context,
const
CallbackBase
&cb)
const
166
{
167
T *p =
dynamic_cast<
T*
>
(obj);
168
if
(p == 0)
169
{
170
return
false
;
171
}
172
(p->*m_source).
Connect
(cb, context);
173
return
true
;
174
}
175
virtual
bool
DisconnectWithoutContext
(
ObjectBase
*obj,
const
CallbackBase
&cb)
const
176
{
177
T *p =
dynamic_cast<
T*
>
(obj);
178
if
(p == 0)
179
{
180
return
false
;
181
}
182
(p->*m_source).
DisconnectWithoutContext
(cb);
183
return
true
;
184
}
185
virtual
bool
Disconnect
(
ObjectBase
*obj, std::string context,
const
CallbackBase
&cb)
const
186
{
187
T *p =
dynamic_cast<
T*
>
(obj);
188
if
(p == 0)
189
{
190
return
false
;
191
}
192
(p->*m_source).
Disconnect
(cb, context);
193
return
true
;
194
}
195
SOURCE T::*m_source;
196
} *accessor =
new
Accessor ();
197
accessor->m_source = a;
198
return
Ptr<const TraceSourceAccessor>
(accessor,
false
);
199
}
200
201
template
<
typename
T>
202
Ptr<const TraceSourceAccessor>
MakeTraceSourceAccessor
(T a)
203
{
204
return
DoMakeTraceSourceAccessor
(a);
205
}
206
207
}
// namespace ns3
208
209
210
#endif
/* TRACE_SOURCE_ACCESSOR_H */
ns3::TraceSourceAccessor::TraceSourceAccessor
TraceSourceAccessor()
Constructor.
Definition:
trace-source-accessor.cc:33
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DoMakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > DoMakeTraceSourceAccessor(SOURCE T::*a)
MakeTraceSourceAccessor() implementation.
Definition:
trace-source-accessor.h:151
ns3::SimpleRefCount
A template-based reference counting class.
Definition:
simple-ref-count.h:74
ns3::TraceSourceAccessor::~TraceSourceAccessor
virtual ~TraceSourceAccessor()
Destructor.
Definition:
trace-source-accessor.cc:35
callback.h
Declaration of the various callback functions.
ns3::TraceSourceAccessor::Disconnect
virtual bool Disconnect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
Disconnect a Callback from a TraceSource with a context string.
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:202
simple-ref-count.h
ns3::SimpleRefCount declaration and template implementation.
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
ns3::Config::ConnectWithoutContext
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition:
config.cc:901
ns3::TraceSourceAccessor::ConnectWithoutContext
virtual bool ConnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
Connect a Callback to a TraceSource (without context.)
ns3::MakeEmptyTraceSourceAccessor
static Ptr< const TraceSourceAccessor > MakeEmptyTraceSourceAccessor()
Create an empty TraceSourceAccessor.
Definition:
trace-source-accessor.h:126
ns3::Config::DisconnectWithoutContext
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition:
config.cc:914
ns3::TraceSourceAccessor::DisconnectWithoutContext
virtual bool DisconnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
Disconnect a Callback from a TraceSource (without context).
ns3::Config::Connect
void Connect(std::string path, const CallbackBase &cb)
Definition:
config.cc:920
ns3::TraceSourceAccessor::Connect
virtual bool Connect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
Connect a Callback to a TraceSource with a context string.
ns3::CallbackBase
Base class for Callback class.
Definition:
callback.h:1196
ns3::TraceSourceAccessor
Control access to objects' trace sources.
Definition:
trace-source-accessor.h:47
ptr.h
ns3::Ptr smart pointer declaration and implementation.
ns3::Config::Disconnect
void Disconnect(std::string path, const CallbackBase &cb)
Definition:
config.cc:935
ns3::ObjectBase
Anchor the ns-3 type and attribute system.
Definition:
object-base.h:120
src
core
model
trace-source-accessor.h
Generated on Fri Oct 1 2021 17:02:58 for ns-3 by
1.8.20