src/core/model/config.cc
author Jaume Nin <jnin@cttc.es>
Fri, 11 May 2012 14:02:54 +0200
changeset 8748 87a141a38088
parent 7784 549a235e73a1
child 8749 4462ac63d4cf
permissions -rw-r--r--
fixed Resolver::DoArrayResolve after bug 1352 fix
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 ();
7784
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   380
      bool foundMatch = false;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   381
      for (uint32_t i = 0; i < tid.GetAttributeN(); i++)
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   382
        {
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   383
          struct TypeId::AttributeInformation info;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   384
          info = tid.GetAttribute(i);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   385
          if (info.name != item && item != "*")
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   386
            {
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   387
              continue;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   388
            }
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   389
          // attempt to cast to a pointer checker.
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   390
          const PointerChecker *ptr = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   391
          if (ptr != 0)
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   392
            {
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   393
              NS_LOG_DEBUG ("GetAttribute(ptr)="<<info.name<<" on path="<<GetResolvedPath ());
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   394
              PointerValue ptr;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   395
              root->GetAttribute (info.name, ptr);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   396
              Ptr<Object> object = ptr.Get<Object> ();
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   397
              if (object == 0)
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   398
                {
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   399
                  NS_LOG_ERROR ("Requested object name=\""<<item<<
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   400
                                "\" exists on path=\""<<GetResolvedPath ()<<"\""
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   401
                                " but is null.");
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   402
                  continue;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   403
                }
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   404
              foundMatch = true;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   405
              m_workStack.push_back (info.name);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   406
              DoResolve (pathLeft, object);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   407
              m_workStack.pop_back ();
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   408
            }
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   409
          // attempt to cast to an object vector.
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   410
          const ObjectPtrContainerChecker *vectorChecker = 
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   411
            dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   412
          if (vectorChecker != 0)
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   413
            {
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   414
              NS_LOG_DEBUG ("GetAttribute(vector)="<<info.name<<" on path="<<GetResolvedPath () << pathLeft);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   415
              foundMatch = true;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   416
              ObjectPtrContainerValue vector;
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   417
              root->GetAttribute (info.name, vector);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   418
              m_workStack.push_back (info.name);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   419
              DoArrayResolve (pathLeft, vector);
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   420
              m_workStack.pop_back ();
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   421
            }
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   422
          // this could be anything else and we don't know what to do with it.
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   423
          // So, we just ignore it.
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   424
        }
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   425
      if (!foundMatch)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   426
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   427
          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
   428
          return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   429
        }
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
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   432
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   433
void 
8748
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   434
Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   435
{
7784
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   436
  NS_LOG_FUNCTION(this << path);
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   437
  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
   438
  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
   439
  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
   440
  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
   441
    {
7784
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   442
      return;
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   443
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   444
  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
   445
  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
   446
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   447
  ArrayMatcher matcher = ArrayMatcher (item);
8748
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   448
  ObjectPtrContainerValue::Iterator it;
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   449
  for (it = container.Begin (); it != container.End (); ++it)
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   450
    {
8748
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   451
      if (matcher.Matches ((*it).first))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   452
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   453
          std::ostringstream oss;
8748
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   454
          oss << (*it).first;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   455
          m_workStack.push_back (oss.str ());
8748
87a141a38088 fixed Resolver::DoArrayResolve after bug 1352 fix
Jaume Nin <jnin@cttc.es>
parents: 7784
diff changeset
   456
          DoResolve (pathLeft, (*it).second);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   457
          m_workStack.pop_back ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   458
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   459
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   460
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   461
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   462
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   463
class ConfigImpl 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   464
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   465
public:
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   466
  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
   467
  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
   468
  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
   469
  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
   470
  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
   471
  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
   472
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   473
  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
   474
  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
   475
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   476
  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
   477
  Ptr<Object> GetRootNamespaceObject (uint32_t i) const;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   478
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   479
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
   480
  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
   481
  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
   482
  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
   483
};
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   484
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   485
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
   486
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
   487
{
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
   488
  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
   489
  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
   490
  *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
   491
  *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
   492
  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
   493
}
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
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
void 
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   496
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
   497
{
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
   498
  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
   499
  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
   500
  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
   501
  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
   502
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   503
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   504
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
   505
{
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
   506
  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
   507
  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
   508
  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
   509
  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
   510
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   511
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   512
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
   513
{
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
   514
  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
   515
  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
   516
  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
   517
  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
   518
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   519
void 
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   520
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
   521
{
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
   522
  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
   523
  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
   524
  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
   525
  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
   526
}
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
   527
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
   528
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
   529
{
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
  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
   531
  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
   532
  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
   533
  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
   534
}
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
   535
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
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
   537
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
   538
{
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
   539
  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
   540
  class LookupMatchesResolver : public Resolver 
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   541
  {
7784
549a235e73a1 Handle the case where '*' is used against the name of an attribute in a configuration path
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7412
diff changeset
   542
  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
   543
    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
   544
      : 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
   545
    {}
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
   546
    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
   547
      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
   548
      m_contexts.push_back (path);
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   549
    }
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
   550
    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
   551
    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
   552
  } resolver = LookupMatchesResolver (path);
2531
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   553
  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
   554
    {
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   555
      resolver.Resolve (*i);
b451b5fc8b57 implement context-based trace connection
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2504
diff changeset
   556
    }
4139
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   557
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   558
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   559
  // 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
   560
  // 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
   561
  // 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
   562
  //
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   563
  resolver.Resolve (0);
d45e62c78504 add an object name service
Craig Dowell <craigdo@ee.washington.edu>
parents: 3787
diff changeset
   564
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
   565
  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
   566
}
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
   567
2569
d5cff2968984 make Disconnect work with trace contexts.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2532
diff changeset
   568
void 
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   569
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
   570
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   571
  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
   572
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   573
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   574
void 
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   575
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
   576
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   577
  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
   578
    {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   579
      if (*i == obj)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   580
        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   581
          m_roots.erase (i);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   582
          return;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7003
diff changeset
   583
        }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   584
    }
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   585
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   586
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   587
uint32_t 
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   588
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
   589
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   590
  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
   591
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   592
Ptr<Object> 
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   593
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
   594
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   595
  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
   596
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   597
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   598
namespace Config {
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   599
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   600
void Reset (void)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   601
{
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   602
  // First, let's reset the initial value of every attribute
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   603
  for (uint32_t i = 0; i < TypeId::GetRegisteredN (); i++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   604
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   605
      TypeId tid = TypeId::GetRegistered (i);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   606
      for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   607
        {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   608
          struct TypeId::AttributeInformation info = tid.GetAttribute (j);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   609
          tid.SetAttributeInitialValue (j, info.originalInitialValue);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   610
        }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   611
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   612
  // 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
   613
  for (GlobalValue::Iterator i = GlobalValue::Begin (); i != GlobalValue::End (); ++i)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   614
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   615
      (*i)->ResetInitialValue ();
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   616
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   617
}
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   618
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   619
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
   620
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   621
  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
   622
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   623
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
   624
{
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   625
  if (!SetDefaultFailSafe(name, value))
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   626
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   627
      NS_FATAL_ERROR ("Could not set default value for " << name);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   628
    }
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   629
}
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   630
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
   631
{
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   632
  std::string::size_type pos = fullName.rfind ("::");
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   633
  if (pos == std::string::npos)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   634
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   635
      return false;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   636
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   637
  std::string tidName = fullName.substr (0, pos);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   638
  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
   639
  TypeId tid;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   640
  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   641
  if (!ok)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   642
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   643
      return false;
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
  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   646
    {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   647
      struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   648
      if (tmp.name == paramName)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   649
        {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   650
          Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   651
          if (v == 0)
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   652
            {
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   653
              return false;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   654
            }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   655
          tid.SetAttributeInitialValue (j, v);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   656
          return true;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   657
        }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   658
    }
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   659
  return false;
2570
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   660
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   661
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
   662
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   663
  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
   664
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2941
diff changeset
   665
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
   666
{
15d5421022a1 add FailSafe versions of setters which could fail.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2569
diff changeset
   667
  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
   668
}
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   669
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
   670
{
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   671
  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
   672
}
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   673
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
   674
{
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   675
  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
   676
}
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   677
void 
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   678
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
   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 ()->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
   681
}
2594
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   682
void 
a8f89acd17a1 Config::Connect -> Config::ConnectWithoutContext && Config::ConnectWithContext -> Config::Connect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2593
diff changeset
   683
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
   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 ()->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
   686
}
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
   687
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
   688
{
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
   689
  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
   690
}
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   691
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   692
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
   693
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   694
  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
   695
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   696
2532
86a40c7cbfe9 register and unregister the NodeList as a config root namespace
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2531
diff changeset
   697
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
   698
{
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   699
  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
   700
}
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   701
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   702
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
   703
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   704
  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
   705
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   706
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   707
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
   708
{
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   709
  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
   710
}
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   711
5257
fc9fd5cbc007 Remove and replace config unit test (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4158
diff changeset
   712
} // namespace Config
2941
e1ff74674f87 add functions to access list of root namespace objects
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2933
diff changeset
   713
2474
1d1f77782138 A Config class which hooks into the Object Attribute/Tracing system.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   714
} // namespace ns3