A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
28 namespace ns3 {
29 
30 class ObjectBase;
31 
40 class TraceSourceAccessor : public SimpleRefCount<TraceSourceAccessor>
41 {
42 public:
44  virtual ~TraceSourceAccessor ();
45 
50  virtual bool ConnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const = 0;
56  virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0;
61  virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const = 0;
67  virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const = 0;
68 };
69 
79 template <typename T>
81 
82 } // namespace ns3
83 
84 namespace ns3 {
85 
86 template <typename T, typename SOURCE>
87 Ptr<const TraceSourceAccessor>
89 {
90  struct Accessor : public TraceSourceAccessor
91  {
92  virtual bool ConnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
93  T *p = dynamic_cast<T*> (obj);
94  if (p == 0)
95  {
96  return false;
97  }
98  (p->*m_source).ConnectWithoutContext (cb);
99  return true;
100  }
101  virtual bool Connect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
102  T *p = dynamic_cast<T*> (obj);
103  if (p == 0)
104  {
105  return false;
106  }
107  (p->*m_source).Connect (cb, context);
108  return true;
109  }
110  virtual bool DisconnectWithoutContext (ObjectBase *obj, const CallbackBase &cb) const {
111  T *p = dynamic_cast<T*> (obj);
112  if (p == 0)
113  {
114  return false;
115  }
116  (p->*m_source).DisconnectWithoutContext (cb);
117  return true;
118  }
119  virtual bool Disconnect (ObjectBase *obj, std::string context, const CallbackBase &cb) const {
120  T *p = dynamic_cast<T*> (obj);
121  if (p == 0)
122  {
123  return false;
124  }
125  (p->*m_source).Disconnect (cb, context);
126  return true;
127  }
128  SOURCE T::*m_source;
129  } *accessor = new Accessor ();
130  accessor->m_source = a;
131  return Ptr<const TraceSourceAccessor> (accessor, false);
132 }
133 
134 template <typename T>
136 {
137  return DoMakeTraceSourceAccessor (a);
138 }
139 
140 } // namespace ns3
141 
142 
143 #endif /* TRACE_SOURCE_ACCESSOR_H */
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
virtual bool ConnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
virtual bool DisconnectWithoutContext(ObjectBase *obj, const CallbackBase &cb) const =0
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:734
Base class for Callback class.
Definition: callback.h:844
implement the ns-3 type and attribute system
Definition: object-base.h:70
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
virtual bool Disconnect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
virtual bool Connect(ObjectBase *obj, std::string context, const CallbackBase &cb) const =0
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
control access to objects' trace sources
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:722
A template-based reference counting class.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:717
Ptr< const TraceSourceAccessor > DoMakeTraceSourceAccessor(SOURCE T::*a)