src/core/model/object-base.cc
author Mathieu Lacage <mathieu.lacage@gmail.com>
Wed, 03 Aug 2011 09:42:10 -0400
changeset 7392 88230da4bb1a
parent 7169 358f71a624d8
child 7393 8c3dfe0be54d
permissions -rw-r--r--
use new API
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2718
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     2
/*
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     3
 * Copyright (c) 2008 INRIA
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     4
 *
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     7
 * published by the Free Software Foundation;
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     8
 *
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    12
 * GNU General Public License for more details.
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    13
 *
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    14
 * You should have received a copy of the GNU General Public License
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    15
 * along with this program; if not, write to the Free Software
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    17
 *
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
    19
 */
2370
5f7ad186b798 introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "object-base.h"
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    21
#include "log.h"
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    22
#include "trace-source-accessor.h"
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
    23
#include "attribute-list.h"
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    24
#include "string.h"
4216
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    25
#include "ns3/core-config.h"
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    26
#ifdef HAVE_STDLIB_H
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    27
#include <stdlib.h>
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
    28
#endif
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    29
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    30
NS_LOG_COMPONENT_DEFINE ("ObjectBase");
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    31
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    32
namespace ns3 {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    33
6393
f7e1f9dfa08d ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents: 4216
diff changeset
    34
NS_OBJECT_ENSURE_REGISTERED (ObjectBase);
f7e1f9dfa08d ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents: 4216
diff changeset
    35
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    36
static TypeId
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    37
GetObjectIid (void)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    38
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    39
  TypeId tid = TypeId ("ns3::ObjectBase");
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    40
  tid.SetParent (tid);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    41
  return tid;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    42
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    43
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    44
TypeId 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    45
ObjectBase::GetTypeId (void)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    46
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    47
  static TypeId tid = GetObjectIid ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    48
  return tid;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    49
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    50
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    51
ObjectBase::~ObjectBase () 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    52
{
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    53
}
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    54
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    55
void
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    56
ObjectBase::NotifyConstructionCompleted (void)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    57
{}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    58
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    59
void
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    60
ObjectBase::ConstructSelf (const AttributeList &attributes)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    61
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    62
  // loop over the inheritance tree back to the Object base class.
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    63
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    64
  do {
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    65
      // loop over all attributes in object type
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    66
      NS_LOG_DEBUG ("construct tid="<<tid.GetName ()<<", params="<<tid.GetAttributeN ());
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    67
      for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    68
        {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    69
          struct TypeId::AttributeInformation info = tid.GetAttribute(i);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    70
          NS_LOG_DEBUG ("try to construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    71
                        info.name <<"\"");
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    72
          if (!(info.flags & TypeId::ATTR_CONSTRUCT))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    73
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    74
              continue;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    75
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    76
          bool found = false;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    77
          // is this attribute stored in this AttributeList instance ?
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    78
          for (AttributeList::Attrs::const_iterator j = attributes.m_attributes.begin ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    79
               j != attributes.m_attributes.end (); j++)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    80
            {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    81
              if (j->checker == info.checker)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    82
                {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    83
                  // We have a matching attribute value.
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    84
                  if (DoSet (info.accessor, info.checker, *j->value))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    85
                    {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    86
                      NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    87
                                    info.name<<"\"");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    88
                      found = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    89
                      break;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    90
                    }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    91
                }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    92
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    93
          if (!found)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    94
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    95
              // is this attribute stored in the global instance ?
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    96
              for (AttributeList::Attrs::const_iterator j = AttributeList::GetGlobal ()->m_attributes.begin ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    97
                   j != AttributeList::GetGlobal ()->m_attributes.end (); j++)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    98
                {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    99
                  if (j->checker == info.checker)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   100
                    {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   101
                      // We have a matching attribute value.
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   102
                      if (DoSet (info.accessor, info.checker, *j->value))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   103
                        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   104
                          NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   105
                                        info.name <<"\" from global");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   106
                          found = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   107
                          break;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   108
                        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   109
                    }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   110
                }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   111
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   112
          if (!found)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   113
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   114
              // No matching attribute value so we try to look at the env var.
4216
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
   115
#ifdef HAVE_GETENV
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   116
              char *envVar = getenv ("NS_ATTRIBUTE_DEFAULT");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   117
              if (envVar != 0)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   118
                {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   119
                  std::string env = std::string (envVar);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   120
                  std::string::size_type cur = 0;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   121
                  std::string::size_type next = 0;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   122
                  while (next != std::string::npos)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   123
                    {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   124
                      next = env.find (";", cur);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   125
                      std::string tmp = std::string (env, cur, next-cur);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   126
                      std::string::size_type equal = tmp.find ("=");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   127
                      if (equal != std::string::npos)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   128
                        {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   129
                          std::string name = tmp.substr (0, equal);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   130
                          std::string value = tmp.substr (equal+1, tmp.size () - equal - 1);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   131
                          if (name == tid.GetAttributeFullName (i))
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   132
                            {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   133
                              if (DoSet (info.accessor, info.checker, StringValue (value)))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   134
                                {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   135
                                  NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   136
                                                info.name <<"\" from env var");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   137
                                  found = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   138
                                  break;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   139
                                }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   140
                            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   141
                        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   142
                      cur = next + 1;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   143
                    }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   144
                }
4216
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
   145
#endif /* HAVE_GETENV */
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   146
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   147
          if (!found)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   148
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   149
              // No matching attribute value so we try to set the default value.
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   150
              DoSet (info.accessor, info.checker, *info.initialValue);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   151
              NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   152
                            info.name <<"\" from initial value.");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   153
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   154
        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   155
      tid = tid.GetParent ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   156
    } while (tid != ObjectBase::GetTypeId ());
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   157
  NotifyConstructionCompleted ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   158
}
2370
5f7ad186b798 introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   160
bool
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   161
ObjectBase::DoSet (Ptr<const AttributeAccessor> spec, 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   162
                   Ptr<const AttributeChecker> checker,
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   163
                   const AttributeValue &value)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   164
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   165
  bool ok = checker->Check (value);
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   166
  if (ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   167
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   168
      ok = spec->Set (this, value);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   169
      return ok;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   170
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   171
  // attempt to convert to string
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   172
  const StringValue *str = dynamic_cast<const StringValue *> (&value);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   173
  if (str == 0)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   174
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   175
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   176
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   177
  // attempt to convert back from string.
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   178
  Ptr<AttributeValue> v = checker->Create ();
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   179
  ok = v->DeserializeFromString (str->Get (), checker);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   180
  if (!ok)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   181
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   182
      return false;
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   183
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   184
  ok = checker->Check (*v);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   185
  if (!ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   186
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   187
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   188
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   189
  ok = spec->Set (this, *v);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   190
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   191
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   192
void
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   193
ObjectBase::SetAttribute (std::string name, const AttributeValue &value)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   194
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   195
  struct TypeId::AttributeInfo info;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   196
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   197
  if (!tid.LookupAttributeByName (name, &info))
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   198
    {
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   199
      NS_FATAL_ERROR ("Attribute name="<<name<<" does not exist for this object: tid="<<tid.GetName ());
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   200
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   201
  if (!(info.flags & TypeId::ATTR_SET) ||
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   202
      !info.accessor->HasSetter ())
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   203
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   204
      NS_FATAL_ERROR ("Attribute name="<<name<<" is not settable for this object: tid="<<tid.GetName ());
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   205
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   206
  if (!DoSet (info.accessor, info.checker, value))
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   207
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   208
      NS_FATAL_ERROR ("Attribute name="<<name<<" could not be set for this object: tid="<<tid.GetName ());
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   209
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   210
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   211
bool 
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   212
ObjectBase::SetAttributeFailSafe (std::string name, const AttributeValue &value)
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   213
{
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   214
  struct TypeId::AttributeInfo info;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   215
  TypeId tid = GetInstanceTypeId ();
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   216
  if (!tid.LookupAttributeByName (name, &info))
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   217
    {
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   218
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   219
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   220
  if (!(info.flags & TypeId::ATTR_SET) ||
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   221
      !info.accessor->HasSetter ())
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   222
    {
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   223
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   224
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   225
  return DoSet (info.accessor, info.checker, value);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   226
}
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   227
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   228
void
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   229
ObjectBase::GetAttribute (std::string name, AttributeValue &value) const
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   230
{
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   231
  struct TypeId::AttributeInfo info;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   232
  TypeId tid = GetInstanceTypeId ();
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   233
  if (!tid.LookupAttributeByName (name, &info))
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   234
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   235
      NS_FATAL_ERROR ("Attribute name="<<name<<" does not exist for this object: tid="<<tid.GetName ());
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   236
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   237
  if (!(info.flags & TypeId::ATTR_GET) || 
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   238
      !info.accessor->HasGetter ())
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   239
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   240
      NS_FATAL_ERROR ("Attribute name="<<name<<" is not gettable for this object: tid="<<tid.GetName ());
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   241
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   242
  bool ok = info.accessor->Get (this, value);
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   243
  if (ok)
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   244
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   245
      return;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   246
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   247
  StringValue *str = dynamic_cast<StringValue *> (&value);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   248
  if (str == 0)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   249
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   250
      NS_FATAL_ERROR ("Attribute name="<<name<<" tid="<<tid.GetName () << ": input value is not a string");
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   251
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   252
  Ptr<AttributeValue> v = info.checker->Create ();
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   253
  ok = info.accessor->Get (this, *PeekPointer (v));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   254
  if (!ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   255
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   256
      NS_FATAL_ERROR ("Attribute name="<<name<<" tid="<<tid.GetName () << ": could not get value");
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   257
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   258
  str->Set (v->SerializeToString (info.checker));
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   259
}
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   260
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   261
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   262
bool
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   263
ObjectBase::GetAttributeFailSafe (std::string name, AttributeValue &value) const
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   264
{
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   265
  struct TypeId::AttributeInfo info;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   266
  TypeId tid = GetInstanceTypeId ();
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   267
  if (!tid.LookupAttributeByName (name, &info))
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   268
    {
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   269
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   270
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   271
  if (!(info.flags & TypeId::ATTR_GET) ||
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   272
      !info.accessor->HasGetter ())
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   273
    {
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   274
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   275
    }
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   276
  bool ok = info.accessor->Get (this, value);
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   277
  if (ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   278
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   279
      return true;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   280
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   281
  StringValue *str = dynamic_cast<StringValue *> (&value);
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   282
  if (str == 0)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   283
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   284
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   285
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   286
  Ptr<AttributeValue> v = info.checker->Create ();
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   287
  ok = info.accessor->Get (this, *PeekPointer (v));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   288
  if (!ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   289
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   290
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   291
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   292
  str->Set (v->SerializeToString (info.checker));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   293
  return true;
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   294
}
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   295
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   296
bool 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   297
ObjectBase::TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   298
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   299
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   300
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   301
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   302
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   303
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   304
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   305
  bool ok = accessor->ConnectWithoutContext (this, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   306
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   307
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   308
bool 
2718
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   309
ObjectBase::TraceConnect (std::string name, std::string context, const CallbackBase &cb)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   310
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   311
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   312
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   313
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   314
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   315
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   316
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   317
  bool ok = accessor->Connect (this, context, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   318
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   319
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   320
bool 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   321
ObjectBase::TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   322
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   323
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   324
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   325
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   326
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   327
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   328
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   329
  bool ok = accessor->DisconnectWithoutContext (this, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   330
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   331
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   332
bool 
2718
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   333
ObjectBase::TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   334
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   335
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   336
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   337
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   338
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   339
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   340
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   341
  bool ok = accessor->Disconnect (this, context, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   342
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   343
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   344
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   345
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   346
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   347
} // namespace ns3