src/core/model/config.cc
author Mathieu Lacage <mathieu.lacage@gmail.com>
Wed, 10 Aug 2011 11:48:19 -0400
changeset 7412 d79278c6e51c
parent 7399 520706f801e8
child 7784 549a235e73a1
child 8253 6faee3d1d1d0
permissions -rw-r--r--
refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2586
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     2
/*
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     3
 * Copyright (c) 2008 INRIA
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     4
 *
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     7
 * published by the Free Software Foundation;
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     8
 *
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    12
 * GNU General Public License for more details.
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    13
 *
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    14
 * You should have received a copy of the GNU General Public License
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    15
 * along with this program; if not, write to the Free Software
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    17
 *
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
50d78910a997 add missing copyright/license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2570
diff changeset
    19
 */
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "config.h"
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "singleton.h"
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "object.h"
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "global-value.h"
7412
d79278c6e51c refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7399
diff changeset
    24
#include "object-ptr-container.h"
4147
5d8530130930 rename object-names.{cc,h} to names.{cc,h} per convention
Craig Dowell <craigdo@ee.washington.edu>
parents: 4145
diff changeset
    25
#include "names.h"
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
    26
#include "pointer.h"
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "log.h"
5257
fc9fd5cbc007 Remove and replace config unit test (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
    28
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include <sstream>
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
NS_LOG_COMPONENT_DEFINE ("Config");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
namespace ns3 {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    35
namespace Config {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    36
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    37
MatchContainer::MatchContainer ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    38
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    39
}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    40
MatchContainer::MatchContainer (const std::vector<Ptr<Object> > &objects,
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    41
                                const std::vector<std::string> &contexts,
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    42
                                std::string path)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    43
  : m_objects (objects),
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    44
    m_contexts (contexts),
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    45
    m_path (path)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    46
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    47
}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    48
MatchContainer::Iterator
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    49
MatchContainer::Begin (void) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    50
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    51
  return m_objects.begin ();
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    52
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    53
MatchContainer::Iterator
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    54
MatchContainer::End (void) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    55
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    56
  return m_objects.end ();
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    57
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    58
uint32_t
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    59
MatchContainer::GetN (void) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    60
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    61
  return m_objects.size ();
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    62
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    63
Ptr<Object>
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    64
MatchContainer::Get (uint32_t i) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    65
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    66
  return m_objects[i];
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    67
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    68
std::string
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    69
MatchContainer::GetMatchedPath (uint32_t i) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    70
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    71
  return m_contexts[i];
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    72
}
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    73
std::string
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    74
MatchContainer::GetPath (void) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    75
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    76
  return m_path;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    77
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    78
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
    79
void
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    80
MatchContainer::Set (std::string name, const AttributeValue &value)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    81
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    82
  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    83
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    84
      Ptr<Object> object = *tmp;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    85
      object->SetAttribute (name, value);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    86
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    87
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    88
void 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    89
MatchContainer::Connect (std::string name, const CallbackBase &cb)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    90
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    91
  NS_ASSERT (m_objects.size () == m_contexts.size ());
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    92
  for (uint32_t i = 0; i < m_objects.size (); ++i)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    93
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    94
      Ptr<Object> object = m_objects[i];
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    95
      std::string ctx = m_contexts[i] + name;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    96
      object->TraceConnect (name, ctx, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    97
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    98
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
    99
void 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   100
MatchContainer::ConnectWithoutContext (std::string name, const CallbackBase &cb)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   101
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   102
  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   103
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   104
      Ptr<Object> object = *tmp;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   105
      object->TraceConnectWithoutContext (name, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   106
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   107
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   108
void 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   109
MatchContainer::Disconnect (std::string name, const CallbackBase &cb)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   110
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   111
  NS_ASSERT (m_objects.size () == m_contexts.size ());
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   112
  for (uint32_t i = 0; i < m_objects.size (); ++i)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   113
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   114
      Ptr<Object> object = m_objects[i];
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   115
      std::string ctx = m_contexts[i] + name;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   116
      object->TraceDisconnect (name, ctx, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   117
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   118
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   119
void 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   120
MatchContainer::DisconnectWithoutContext (std::string name, const CallbackBase &cb)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   121
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   122
  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   123
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   124
      Ptr<Object> object = *tmp;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   125
      object->TraceDisconnectWithoutContext (name, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   126
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   127
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   128
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   129
} // namespace Config
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   130
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
class ArrayMatcher
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
public:
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
  ArrayMatcher (std::string element);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
  bool Matches (uint32_t i) const;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
private:
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
  bool StringToUint32 (std::string str, uint32_t *value) const;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
  std::string m_element;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
};
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   142
ArrayMatcher::ArrayMatcher (std::string element)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
  : m_element (element)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   144
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   145
}
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   146
bool
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
ArrayMatcher::Matches (uint32_t i) const
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
  if (m_element == "*")
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
      NS_LOG_DEBUG ("Array "<<i<<" matches *");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
      return true;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
  std::string::size_type tmp;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
  tmp = m_element.find ("|");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
  if (tmp != std::string::npos)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
      std::string left = m_element.substr (0, tmp-0);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
      std::string right = m_element.substr (tmp+1, m_element.size () - (tmp + 1));
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   160
      ArrayMatcher matcher = ArrayMatcher (left);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
      if (matcher.Matches (i))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   162
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   163
          NS_LOG_DEBUG ("Array "<<i<<" matches "<<left);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   164
          return true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   165
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
      matcher = ArrayMatcher (right);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
      if (matcher.Matches (i))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   168
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   169
          NS_LOG_DEBUG ("Array "<<i<<" matches "<<right);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   170
          return true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   171
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
      NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
      return false;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
  std::string::size_type leftBracket = m_element.find ("[");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
  std::string::size_type rightBracket = m_element.find ("]");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
  std::string::size_type dash = m_element.find ("-");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
  if (leftBracket == 0 && rightBracket == m_element.size () - 1 &&
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
      dash > leftBracket && dash < rightBracket)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
      std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
      std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
      uint32_t min;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
      uint32_t max;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
      if (StringToUint32 (lowerBound, &min) && 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   186
          StringToUint32 (upperBound, &max) &&
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   187
          i >= min && i <= max)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
        {
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   189
          NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
          return true;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
        }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
      else
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   193
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   194
          NS_LOG_DEBUG ("Array "<<i<<" does not "<<m_element);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   195
          return false;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   196
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   198
  uint32_t value;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
  if (StringToUint32 (m_element, &value) &&
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
      i == value)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
      NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
      return true;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
  return false;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
bool
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
  std::istringstream iss;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
  iss.str (str);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
  iss >> (*value);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
  return !iss.bad () && !iss.fail ();
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   217
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
class Resolver
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
public:
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
  Resolver (std::string path);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   223
  virtual ~Resolver ();
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
  void Resolve (Ptr<Object> root);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
private:
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   227
  void Canonicalize (void);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
  void DoResolve (std::string path, Ptr<Object> root);
7412
d79278c6e51c refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7399
diff changeset
   229
  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   230
  void DoResolveOne (Ptr<Object> object);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   231
  std::string GetResolvedPath (void) const;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   232
  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
  std::vector<std::string> m_workStack;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
  std::string m_path;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
};
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
Resolver::Resolver (std::string path)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
  : m_path (path)
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   239
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   240
  Canonicalize ();
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   241
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
Resolver::~Resolver ()
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   243
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   244
}
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   245
void
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   246
Resolver::Canonicalize (void)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   247
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   248
  // ensure that we start and end with a '/'
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   249
  std::string::size_type tmp = m_path.find ("/");
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   250
  if (tmp != 0)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   251
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   252
      // no slash at start
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   253
      m_path = "/" + m_path;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   254
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   255
  tmp = m_path.find_last_of ("/");
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   256
  if (tmp != (m_path.size () - 1))
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   257
    {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   258
      // no slash at end
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   259
      m_path = m_path + "/";
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   260
    }
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   261
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
void 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
Resolver::Resolve (Ptr<Object> root)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   266
  DoResolve (m_path, root);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   269
std::string
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   270
Resolver::GetResolvedPath (void) const
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   272
  std::string fullPath = "/";
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
    {
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   275
      fullPath += *i + "/";
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
  return fullPath;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   278
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
void 
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   281
Resolver::DoResolveOne (Ptr<Object> object)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   283
  NS_LOG_DEBUG ("resolved="<<GetResolvedPath ());
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   284
  DoOne (object, GetResolvedPath ());
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
void
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
Resolver::DoResolve (std::string path, Ptr<Object> root)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   290
  NS_LOG_FUNCTION (path << root);
7219
b7b128801f7c Bug 1153 - optimized build : variable ?tmp? set but not used, g++4.6.0
John Abraham<john.abraham@gatech.edu>
parents: 7169
diff changeset
   291
  NS_ASSERT ((path.find ("/")) == 0);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   292
  std::string::size_type next = path.find ("/", 1);
4143
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   293
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
  if (next == std::string::npos)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
    {
4143
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   296
      //
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   297
      // If root is zero, we're beginning to see if we can use the object name 
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   298
      // service to resolve this path.  It is impossible to have a object name 
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   299
      // associated with the root of the object name service since that root
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   300
      // is not an object.  This path must be referring to something in another
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   301
      // namespace and it will have been found already since the name service
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   302
      // is always consulted last.
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   303
      // 
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   304
      if (root)
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   305
        {
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   306
          DoResolveOne (root);
7f7823a31f77 fix crasher in config unit tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 4142
diff changeset
   307
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
      return;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   310
  std::string item = path.substr (1, next-1);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
  std::string pathLeft = path.substr (next, path.size ()-next);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   313
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   314
  // If root is zero, we're beginning to see if we can use the object name 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   315
  // service to resolve this path.  In this case, we must see the name space 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   316
  // "/Names" on the front of this path.  There is no object associated with 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   317
  // the root of the "/Names" namespace, so we just ignore it and move on to 
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   318
  // the next segment.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   319
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   320
  if (root == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   321
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   322
      std::string::size_type offset = path.find ("/Names");
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   323
      if (offset == 0)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   324
        {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   325
          m_workStack.push_back (item);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   326
          DoResolve (pathLeft, root);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   327
          m_workStack.pop_back ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   328
          return;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   329
        }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   330
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   331
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   332
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   333
  // We have an item (possibly a segment of a namespace path.  Check to see if
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   334
  // we can determine that this segment refers to a named object.  If root is
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   335
  // zero, this means to look in the root of the "/Names" name space, otherwise
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   336
  // it refers to a name space context (level).
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   337
  //
4158
2b6dba4062e1 some naming changes suggested by Gustavo
Craig Dowell <craigdo@ee.washington.edu>
parents: 4147
diff changeset
   338
  Ptr<Object> namedObject = Names::Find<Object> (root, item);
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   339
  if (namedObject)
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   340
    {
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   341
      NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   342
      m_workStack.push_back (item);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   343
      DoResolve (pathLeft, namedObject);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   344
      m_workStack.pop_back ();
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   345
      return;
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   346
    }
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   347
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   348
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   349
  // We're done with the object name service hooks, so proceed down the path
4142
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   350
  // of types and attributes; but only if root is nonzero.  If root is zero
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   351
  // and we find ourselves here, we are trying to check in the namespace for
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   352
  // a path that is not in the "/Names" namespace.  We will have previously
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   353
  // found any matches, so we just bail out.
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   354
  //
4142
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   355
  if (root == 0)
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   356
    {
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   357
      return;
59f784af5db6 fix crasher in config
Craig Dowell <craigdo@ee.washington.edu>
parents: 4139
diff changeset
   358
    }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   359
  std::string::size_type dollarPos = item.find ("$");
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   360
  if (dollarPos == 0)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   361
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   362
      // This is a call to GetObject
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   363
      std::string tidString = item.substr (1, item.size () - 1);
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   364
      NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath ());
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   365
      TypeId tid = TypeId::LookupByName (tidString);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   366
      Ptr<Object> object = root->GetObject<Object> (tid);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   367
      if (object == 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   368
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   369
          NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath ());
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   370
          return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   371
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   372
      m_workStack.push_back (item);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   373
      DoResolve (pathLeft, object);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   374
      m_workStack.pop_back ();
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   375
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   376
  else 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   377
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   378
      // this is a normal attribute.
2634
44a92f1d3728 introduce ObjectBase::GetInstanceTypeId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2594
diff changeset
   379
      TypeId tid = root->GetInstanceTypeId ();
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7219
diff changeset
   380
      struct TypeId::AttributeInformation info;
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   381
      if (!tid.LookupAttributeByName (item, &info))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   382
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   383
          NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   384
          return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   385
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   386
      // attempt to cast to a pointer checker.
2927
73b47ce1d805 get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   387
      const PointerChecker *ptr = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   388
      if (ptr != 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   389
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   390
          NS_LOG_DEBUG ("GetAttribute(ptr)="<<item<<" on path="<<GetResolvedPath ());
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   391
          PointerValue ptr;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   392
          root->GetAttribute (item, ptr);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   393
          Ptr<Object> object = ptr.Get<Object> ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   394
          if (object == 0)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   395
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   396
              NS_LOG_ERROR ("Requested object name=\""<<item<<
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   397
                            "\" exists on path=\""<<GetResolvedPath ()<<"\""
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   398
                            " but is null.");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   399
              return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   400
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   401
          m_workStack.push_back (item);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   402
          DoResolve (pathLeft, object);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   403
          m_workStack.pop_back ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   404
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   405
      // attempt to cast to an object vector.
7412
d79278c6e51c refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7399
diff changeset
   406
      const ObjectPtrContainerChecker *vectorChecker = dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   407
      if (vectorChecker != 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   408
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   409
          NS_LOG_DEBUG ("GetAttribute(vector)="<<item<<" on path="<<GetResolvedPath ());
7412
d79278c6e51c refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7399
diff changeset
   410
          ObjectPtrContainerValue vector;
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   411
          root->GetAttribute (item, vector);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   412
          m_workStack.push_back (item);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   413
          DoArrayResolve (pathLeft, vector);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   414
          m_workStack.pop_back ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   415
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   416
      // this could be anything else and we don't know what to do with it.
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   417
      // So, we just ignore it.
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   418
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   419
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   420
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   421
void 
7412
d79278c6e51c refactor ObjectVector generic code into a separate file and introduce ObjectMap.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7399
diff changeset
   422
Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   423
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   424
  NS_ASSERT (path != "");
7219
b7b128801f7c Bug 1153 - optimized build : variable ?tmp? set but not used, g++4.6.0
John Abraham<john.abraham@gatech.edu>
parents: 7169
diff changeset
   425
  NS_ASSERT ((path.find ("/")) == 0);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   426
  std::string::size_type next = path.find ("/", 1);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   427
  if (next == std::string::npos)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   428
    {
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   429
      NS_FATAL_ERROR ("vector path includes no index data on path=\""<<path<<"\"");
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   430
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   431
  std::string item = path.substr (1, next-1);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   432
  std::string pathLeft = path.substr (next, path.size ()-next);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   433
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   434
  ArrayMatcher matcher = ArrayMatcher (item);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   435
  for (uint32_t i = 0; i < vector.GetN (); i++)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   436
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   437
      if (matcher.Matches (i))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   438
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   439
          std::ostringstream oss;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   440
          oss << i;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   441
          m_workStack.push_back (oss.str ());
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   442
          DoResolve (pathLeft, vector.Get (i));
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   443
          m_workStack.pop_back ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   444
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   445
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   446
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   447
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   448
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   449
class ConfigImpl 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   450
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   451
public:
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   452
  void Set (std::string path, const AttributeValue &value);
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   453
  void ConnectWithoutContext (std::string path, const CallbackBase &cb);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   454
  void Connect (std::string path, const CallbackBase &cb);
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   455
  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   456
  void Disconnect (std::string path, const CallbackBase &cb);
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   457
  Config::MatchContainer LookupMatches (std::string path);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   458
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   459
  void RegisterRootNamespaceObject (Ptr<Object> obj);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   460
  void UnregisterRootNamespaceObject (Ptr<Object> obj);
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   461
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   462
  uint32_t GetRootNamespaceObjectN (void) const;
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   463
  Ptr<Object> GetRootNamespaceObject (uint32_t i) const;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   464
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   465
private:
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   466
  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   467
  typedef std::vector<Ptr<Object> > Roots;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   468
  Roots m_roots;
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   469
};
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   470
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   471
void 
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   472
ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   473
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   474
  std::string::size_type slash = path.find_last_of ("/");
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   475
  NS_ASSERT (slash != std::string::npos);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   476
  *root = path.substr (0, slash);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   477
  *leaf = path.substr (slash+1, path.size ()-(slash+1));
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   478
  NS_LOG_FUNCTION (path << *root << *leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   479
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   480
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   481
void 
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   482
ConfigImpl::Set (std::string path, const AttributeValue &value)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   483
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   484
  std::string root, leaf;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   485
  ParsePath (path, &root, &leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   486
  Config::MatchContainer container = LookupMatches (root);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   487
  container.Set (leaf, value);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   488
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   489
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   490
ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   491
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   492
  std::string root, leaf;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   493
  ParsePath (path, &root, &leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   494
  Config::MatchContainer container = LookupMatches (root);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   495
  container.ConnectWithoutContext (leaf, cb);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   496
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   497
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   498
ConfigImpl::DisconnectWithoutContext (std::string path, const CallbackBase &cb)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   499
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   500
  std::string root, leaf;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   501
  ParsePath (path, &root, &leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   502
  Config::MatchContainer container = LookupMatches (root);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   503
  container.DisconnectWithoutContext (leaf, cb);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   504
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   505
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   506
ConfigImpl::Connect (std::string path, const CallbackBase &cb)
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   507
{
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   508
  std::string root, leaf;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   509
  ParsePath (path, &root, &leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   510
  Config::MatchContainer container = LookupMatches (root);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   511
  container.Connect (leaf, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   512
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   513
void 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   514
ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   515
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   516
  std::string root, leaf;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   517
  ParsePath (path, &root, &leaf);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   518
  Config::MatchContainer container = LookupMatches (root);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   519
  container.Disconnect (leaf, cb);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   520
}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   521
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   522
Config::MatchContainer 
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   523
ConfigImpl::LookupMatches (std::string path)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   524
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   525
  NS_LOG_FUNCTION (path);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   526
  class LookupMatchesResolver : public Resolver 
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   527
  {
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   528
public:
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   529
    LookupMatchesResolver (std::string path)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   530
      : Resolver (path)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   531
    {}
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   532
    virtual void DoOne (Ptr<Object> object, std::string path) {
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   533
      m_objects.push_back (object);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   534
      m_contexts.push_back (path);
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   535
    }
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   536
    std::vector<Ptr<Object> > m_objects;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   537
    std::vector<std::string> m_contexts;
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   538
  } resolver = LookupMatchesResolver (path);
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   539
  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   540
    {
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   541
      resolver.Resolve (*i);
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   542
    }
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   543
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   544
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   545
  // See if we can do something with the object name service.  Starting with
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   546
  // the root pointer zeroed indicates to the resolver that it should start
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   547
  // looking at the root of the "/Names" namespace during this go.
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   548
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   549
  resolver.Resolve (0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   550
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   551
  return Config::MatchContainer (resolver.m_objects, resolver.m_contexts, path);
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   552
}
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   553
2569
d5cff2968984 make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2532
diff changeset
   554
void 
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   555
ConfigImpl::RegisterRootNamespaceObject (Ptr<Object> obj)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   556
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   557
  m_roots.push_back (obj);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   558
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   559
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   560
void 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   561
ConfigImpl::UnregisterRootNamespaceObject (Ptr<Object> obj)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   562
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   563
  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   564
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   565
      if (*i == obj)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   566
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   567
          m_roots.erase (i);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   568
          return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   569
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   570
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   571
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   572
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   573
uint32_t 
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   574
ConfigImpl::GetRootNamespaceObjectN (void) const
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   575
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   576
  return m_roots.size ();
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   577
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   578
Ptr<Object> 
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   579
ConfigImpl::GetRootNamespaceObject (uint32_t i) const
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   580
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   581
  return m_roots[i];
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   582
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   583
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   584
namespace Config {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   585
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   586
void Reset (void)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   587
{
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   588
  // First, let's reset the initial value of every attribute
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   589
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   590
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   591
      TypeId tid = TypeId::GetRegistered (i);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   592
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   593
        {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   594
          struct TypeId::AttributeInformation info = tid.GetAttribute (j);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   595
          tid.SetAttributeInitialValue (j, info.originalInitialValue);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   596
        }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   597
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   598
  // now, let's reset the initial value of every global value.
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   599
  for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   600
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   601
      (*i)->ResetInitialValue ();
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   602
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   603
}
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   604
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   605
void Set (std::string path, const AttributeValue &value)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   606
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   607
  Singleton<ConfigImpl>::Get ()->Set (path, value);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   608
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   609
void SetDefault (std::string name, const AttributeValue &value)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   610
{
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   611
  if (!SetDefaultFailSafe(name, value))
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   612
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   613
      NS_FATAL_ERROR ("Could not set default value for " << name);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   614
    }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   615
}
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   616
bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
2570
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   617
{
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   618
  std::string::size_type pos = fullName.rfind ("::");
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   619
  if (pos == std::string::npos)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   620
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   621
      return false;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   622
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   623
  std::string tidName = fullName.substr (0, pos);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   624
  std::string paramName = fullName.substr (pos+2, fullName.size () - (pos+2));
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   625
  TypeId tid;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   626
  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   627
  if (!ok)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   628
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   629
      return false;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   630
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   631
  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   632
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   633
      struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   634
      if (tmp.name == paramName)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   635
        {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   636
          Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   637
          if (v == 0)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   638
            {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   639
              return false;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   640
            }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   641
          tid.SetAttributeInitialValue (j, v);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   642
          return true;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   643
        }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   644
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   645
  return false;
2570
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   646
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   647
void SetGlobal (std::string name, const AttributeValue &value)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   648
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   649
  GlobalValue::Bind (name, value);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   650
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   651
bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
2570
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   652
{
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   653
  return GlobalValue::BindFailSafe (name, value);
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   654
}
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   655
void ConnectWithoutContext (std::string path, const CallbackBase &cb)
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   656
{
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   657
  Singleton<ConfigImpl>::Get ()->ConnectWithoutContext (path, cb);
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   658
}
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   659
void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   660
{
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   661
  Singleton<ConfigImpl>::Get ()->DisconnectWithoutContext (path, cb);
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   662
}
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   663
void 
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   664
Connect (std::string path, const CallbackBase &cb)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   665
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   666
  Singleton<ConfigImpl>::Get ()->Connect (path, cb);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   667
}
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   668
void 
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   669
Disconnect (std::string path, const CallbackBase &cb)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   670
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   671
  Singleton<ConfigImpl>::Get ()->Disconnect (path, cb);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   672
}
3787
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   673
Config::MatchContainer LookupMatches (std::string path)
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   674
{
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   675
  return Singleton<ConfigImpl>::Get ()->LookupMatches (path);
985324e2caaa bug 284: cannot use config paths to get a handle on an object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3033
diff changeset
   676
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   677
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   678
void RegisterRootNamespaceObject (Ptr<Object> obj)
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   679
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   680
  Singleton<ConfigImpl>::Get ()->RegisterRootNamespaceObject (obj);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   681
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   682
2532
86a40c7cbfe9 register and unregister the NodeList as a config root namespace
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2531
diff changeset
   683
void UnregisterRootNamespaceObject (Ptr<Object> obj)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   684
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   685
  Singleton<ConfigImpl>::Get ()->UnregisterRootNamespaceObject (obj);
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   686
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   687
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   688
uint32_t GetRootNamespaceObjectN (void)
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   689
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   690
  return Singleton<ConfigImpl>::Get ()->GetRootNamespaceObjectN ();
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   691
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   692
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   693
Ptr<Object> GetRootNamespaceObject (uint32_t i)
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   694
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   695
  return Singleton<ConfigImpl>::Get ()->GetRootNamespaceObject (i);
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   696
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   697
5257
fc9fd5cbc007 Remove and replace config unit test (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   698
} // namespace Config
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   699
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   700
} // namespace ns3