src/core/array-trace-resolver.h
changeset 2198 ebe61d20a7ae
parent 1420 3feedd3e4f5f
equal deleted inserted replaced
2197:2a729c1b2e68 2198:ebe61d20a7ae
    21 #ifndef ARRAY_TRACE_RESOLVER_H
    21 #ifndef ARRAY_TRACE_RESOLVER_H
    22 #define ARRAY_TRACE_RESOLVER_H
    22 #define ARRAY_TRACE_RESOLVER_H
    23 
    23 
    24 #include <stdint.h>
    24 #include <stdint.h>
    25 #include <string>
    25 #include <string>
       
    26 #include <sstream>
    26 #include "callback.h"
    27 #include "callback.h"
    27 #include "trace-resolver.h"
    28 #include "trace-resolver.h"
    28 #include "object.h"
    29 #include "object.h"
    29 
    30 
    30 namespace ns3 {
    31 namespace ns3 {
    76     virtual Ptr<Object> Get (void) = 0;
    77     virtual Ptr<Object> Get (void) = 0;
    77     virtual void Rewind (void) = 0;
    78     virtual void Rewind (void) = 0;
    78   };
    79   };
    79   IteratorBase *m_iter;
    80   IteratorBase *m_iter;
    80 };
    81 };
       
    82 
       
    83 class ArrayTraceResolverMatcher
       
    84 {
       
    85 public:
       
    86   ArrayTraceResolverMatcher (std::string element);
       
    87   bool Matches (uint32_t i) const;
       
    88   bool StringToUint32 (std::string str, uint32_t *value) const;
       
    89 private:
       
    90   std::string m_element;
       
    91 };
       
    92 
    81 }//namespace ns3
    93 }//namespace ns3
    82 
    94 
    83 
    95 
    84 // implementation
    96 // implementation
    85 namespace ns3 {
    97 namespace ns3 {
   131     {
   143     {
   132       return;
   144       return;
   133     }
   145     }
   134   std::string id = GetElement (path);
   146   std::string id = GetElement (path);
   135   std::string subpath = GetSubpath (path);
   147   std::string subpath = GetSubpath (path);
   136   if (id == "*")
   148   ArrayTraceResolverMatcher matcher = ArrayTraceResolverMatcher (id);
   137   {
   149   uint32_t i = 0;
   138     uint32_t j = 0;
   150   for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ())
   139     for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ())
   151     {
   140       {
   152       if (matcher.Matches (i))
   141         TraceContext tmp = context;
   153         {
   142         INDEX index = j;
   154           TraceContext tmp = context;
   143         tmp.AddElement (index);
   155           INDEX index = i;
   144         Ptr<Object> obj = m_iter->Get ();
   156           tmp.AddElement (index);
   145         obj->GetTraceResolver ()->Connect (subpath, cb, tmp);
   157           Ptr<Object> obj = m_iter->Get ();
   146         j++;
   158           obj->GetTraceResolver ()->Connect (subpath, cb, tmp);
   147       }
   159         }
   148   }
   160         i++;
       
   161     }
   149 }
   162 }
   150 template <typename INDEX>
   163 template <typename INDEX>
   151 void 
   164 void 
   152 ArrayTraceResolver<INDEX>::Disconnect (std::string path, CallbackBase const &cb)
   165 ArrayTraceResolver<INDEX>::Disconnect (std::string path, CallbackBase const &cb)
   153 {
   166 {
   155     {
   168     {
   156       return;
   169       return;
   157     }
   170     }
   158   std::string id = GetElement (path);
   171   std::string id = GetElement (path);
   159   std::string subpath = GetSubpath (path);
   172   std::string subpath = GetSubpath (path);
   160   if (id == "*")
   173   ArrayTraceResolverMatcher matcher = ArrayTraceResolverMatcher (id);
   161   {
   174   uint32_t i = 0;
   162     for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ())
   175   for (m_iter->Rewind (); m_iter->HasNext (); m_iter->Next ())
   163       {
   176     {
   164         Ptr<Object> obj = m_iter->Get ();
   177       if (matcher.Matches (i))
   165         obj->TraceDisconnect (subpath, cb);
   178         {
   166       }
   179           Ptr<Object> obj = m_iter->Get ();
   167   }
   180           obj->TraceDisconnect (subpath, cb);
       
   181         }
       
   182       i++;
       
   183     }
   168 }
   184 }
   169 template <typename INDEX>
   185 template <typename INDEX>
   170 void 
   186 void 
   171 ArrayTraceResolver<INDEX>::CollectSources (std::string path, const TraceContext &context, 
   187 ArrayTraceResolver<INDEX>::CollectSources (std::string path, const TraceContext &context, 
   172                                            SourceCollection *collection)
   188                                            SourceCollection *collection)