src/core/model/object-base.cc
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Fri, 11 Sep 2015 10:52:44 +0200
changeset 11666 e8634b0101f7
parent 11131 6a448ac28669
child 12701 4a05435b2208
permissions -rw-r--r--
Missing SetGroupName in two classes
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"
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
    23
#include "attribute-construction-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
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7399
diff changeset
    27
#include <cstdlib>
4216
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
11096
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    30
/**
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    31
 * \file
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    32
 * \ingroup object
11131
6a448ac28669 [Doxygen] Various in src/core
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11096
diff changeset
    33
 * ns3::ObjectBase class implementation.
11096
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    34
 */
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    35
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10710
diff changeset
    36
namespace ns3 {
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    37
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10710
diff changeset
    38
NS_LOG_COMPONENT_DEFINE ("ObjectBase");
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    39
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10410
diff changeset
    40
NS_OBJECT_ENSURE_REGISTERED (ObjectBase);
6393
f7e1f9dfa08d ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents: 4216
diff changeset
    41
11096
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    42
/**
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    43
 * Ensure the TypeId for ObjectBase gets fully configured
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    44
 * to anchor the inheritance tree properly.
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    45
 *
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    46
 * \relates ns3::ObjectBase
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    47
 *
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    48
 * \return The TypeId for ObjectBase.
e57bfdb4f12c [Doxygen] Objects
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
    49
 */
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    50
static TypeId
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    51
GetObjectIid (void)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    52
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    53
  NS_LOG_FUNCTION_NOARGS ();
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    54
  TypeId tid = TypeId ("ns3::ObjectBase");
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    55
  tid.SetParent (tid);
11666
e8634b0101f7 Missing SetGroupName in two classes
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11131
diff changeset
    56
  tid.SetGroupName ("Core");
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    57
  return tid;
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
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    60
TypeId 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    61
ObjectBase::GetTypeId (void)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    62
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    63
  NS_LOG_FUNCTION_NOARGS ();
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    64
  static TypeId tid = GetObjectIid ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    65
  return tid;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    66
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    67
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    68
ObjectBase::~ObjectBase () 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    69
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    70
  NS_LOG_FUNCTION (this);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    71
}
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    72
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    73
void
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    74
ObjectBase::NotifyConstructionCompleted (void)
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    75
{
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    76
  NS_LOG_FUNCTION (this);
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    77
}
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    78
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    79
void
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
    80
ObjectBase::ConstructSelf (const AttributeConstructionList &attributes)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    81
{
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    82
  // loop over the inheritance tree back to the Object base class.
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    83
  NS_LOG_FUNCTION (this << &attributes);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    84
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
    85
  do {
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    86
      // loop over all attributes in object type
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    87
      NS_LOG_DEBUG ("construct tid="<<tid.GetName ()<<", params="<<tid.GetAttributeN ());
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    88
      for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    89
        {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    90
          struct TypeId::AttributeInformation info = tid.GetAttribute(i);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    91
          NS_LOG_DEBUG ("try to construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    92
                        info.name <<"\"");
10710
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
    93
          // is this attribute stored in this AttributeConstructionList instance ?
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
    94
          Ptr<AttributeValue> value = attributes.Find(info.checker);
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
    95
          // See if this attribute should not be set here in the
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
    96
          // constructor.
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
    97
          if (!(info.flags & TypeId::ATTR_CONSTRUCT))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    98
            {
10710
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
    99
              // Handle this attribute if it should not be 
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   100
              // set here.
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   101
              if (value == 0)
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   102
                {
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   103
                  // Skip this attribute if it's not in the
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   104
                  // AttributeConstructionList.
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   105
                  continue;
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   106
                }              
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   107
              else
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   108
                {
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   109
                  // This is an error because this attribute is not
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   110
                  // settable in its constructor but is present in
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   111
                  // the AttributeConstructionList.
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   112
                  NS_FATAL_ERROR ("Attribute name="<<info.name<<" tid="<<tid.GetName () << ": initial value cannot be set using attributes");
1c733dcc50b2 Bug 1717 - Detect unsettable attributes
Mitch Watrous <watrous@u.washington.edu>
parents: 10652
diff changeset
   113
                }
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   114
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   115
          bool found = false;
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   116
          if (value != 0)
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   117
            {
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   118
              // We have a matching attribute value.
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   119
              if (DoSet (info.accessor, info.checker, *value))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   120
                {
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   121
                  NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   122
                                info.name<<"\"");
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   123
                  found = true;
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   124
                  continue;
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   125
                }
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   126
            }              
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   127
          if (!found)
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
              // 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
   130
#ifdef HAVE_GETENV
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   131
              char *envVar = getenv ("NS_ATTRIBUTE_DEFAULT");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   132
              if (envVar != 0)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   133
                {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   134
                  std::string env = std::string (envVar);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   135
                  std::string::size_type cur = 0;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   136
                  std::string::size_type next = 0;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   137
                  while (next != std::string::npos)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   138
                    {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   139
                      next = env.find (";", cur);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   140
                      std::string tmp = std::string (env, cur, next-cur);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   141
                      std::string::size_type equal = tmp.find ("=");
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   142
                      if (equal != std::string::npos)
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
                          std::string name = tmp.substr (0, equal);
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   145
                          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
   146
                          if (name == tid.GetAttributeFullName (i))
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   147
                            {
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   148
                              if (DoSet (info.accessor, info.checker, StringValue (value)))
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   149
                                {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   150
                                  NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   151
                                                info.name <<"\" from env var");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   152
                                  found = true;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   153
                                  break;
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
                            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   156
                        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   157
                      cur = next + 1;
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   158
                    }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   159
                }
4216
621e2ef9e7b8 add support for NS_ATTRIBUTE_DEFAULT
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2965
diff changeset
   160
#endif /* HAVE_GETENV */
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   161
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   162
          if (!found)
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   163
            {
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   164
              // 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
   165
              DoSet (info.accessor, info.checker, *info.initialValue);
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   166
              NS_LOG_DEBUG ("construct \""<< tid.GetName ()<<"::"<<
7392
88230da4bb1a use new API
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7169
diff changeset
   167
                            info.name <<"\" from initial value.");
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   168
            }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   169
        }
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   170
      tid = tid.GetParent ();
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   171
    } while (tid != ObjectBase::GetTypeId ());
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   172
  NotifyConstructionCompleted ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   173
}
2370
5f7ad186b798 introduce ObjectBase
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   175
bool
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7392
diff changeset
   176
ObjectBase::DoSet (Ptr<const AttributeAccessor> accessor, 
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
   177
                   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
   178
                   const AttributeValue &value)
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   179
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   180
  NS_LOG_FUNCTION (this << accessor << checker << &value);
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   181
  Ptr<AttributeValue> v = checker->CreateValidValue (value);
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   182
  if (v == 0)
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   183
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   184
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   185
    }
7399
520706f801e8 introduce Config::Reset
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7393
diff changeset
   186
  bool ok = accessor->Set (this, *v);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   187
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   188
}
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   189
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   190
void
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   191
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
   192
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   193
  NS_LOG_FUNCTION (this << name << &value);
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7392
diff changeset
   194
  struct TypeId::AttributeInformation info;
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   195
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   196
  if (!tid.LookupAttributeByName (name, &info))
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   197
    {
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   198
      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
   199
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   200
  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
   201
      !info.accessor->HasSetter ())
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   202
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   203
      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
   204
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   205
  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
   206
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   207
      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
   208
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   209
}
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   210
bool 
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   211
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
   212
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   213
  NS_LOG_FUNCTION (this << name << &value);
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7392
diff changeset
   214
  struct TypeId::AttributeInformation info;
2716
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
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   231
  NS_LOG_FUNCTION (this << name << &value);
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7392
diff changeset
   232
  struct TypeId::AttributeInformation info;
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   233
  TypeId tid = GetInstanceTypeId ();
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   234
  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
   235
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   236
      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
   237
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   238
  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
   239
      !info.accessor->HasGetter ())
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   240
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   241
      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
   242
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   243
  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
   244
  if (ok)
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   245
    {
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   246
      return;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   247
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   248
  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
   249
  if (str == 0)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   250
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   251
      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
   252
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   253
  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
   254
  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
   255
  if (!ok)
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   256
    {
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   257
      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
   258
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   259
  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
   260
}
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   261
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   262
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   263
bool
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   264
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
   265
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   266
  NS_LOG_FUNCTION (this << name << &value);
7393
8c3dfe0be54d use new API. kill old one.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7392
diff changeset
   267
  struct TypeId::AttributeInformation info;
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   268
  TypeId tid = GetInstanceTypeId ();
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   269
  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
   270
    {
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   271
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   272
    }
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   273
  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
   274
      !info.accessor->HasGetter ())
2716
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
      return false;
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   277
    }
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   278
  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
   279
  if (ok)
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
      return true;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   282
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   283
  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
   284
  if (str == 0)
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
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   287
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   288
  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
   289
  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
   290
  if (!ok)
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
      return false;
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   293
    }
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2718
diff changeset
   294
  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
   295
  return true;
2716
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   296
}
2319c4bde708 use FailSafe postfix in a more rigorous way.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2693
diff changeset
   297
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   298
bool 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   299
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
   300
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   301
  NS_LOG_FUNCTION (this << name << &cb);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   302
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   303
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   304
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   305
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   306
      return false;
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 ok = accessor->ConnectWithoutContext (this, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   309
  return ok;
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
bool 
2718
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   312
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
   313
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   314
  NS_LOG_FUNCTION (this << name << context << &cb);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   315
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   316
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   317
  if (accessor == 0)
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   318
    {
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   319
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   320
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   321
  bool ok = accessor->Connect (this, context, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   322
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   323
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   324
bool 
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   325
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
   326
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   327
  NS_LOG_FUNCTION (this << name << &cb);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   328
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   329
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   330
  if (accessor == 0)
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
      return false;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   333
    }
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   334
  bool ok = accessor->DisconnectWithoutContext (this, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   335
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   336
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   337
bool 
2718
9fe723baa16b cleanup.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2716
diff changeset
   338
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
   339
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   340
  NS_LOG_FUNCTION (this << name << context << &cb);
2637
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   341
  TypeId tid = GetInstanceTypeId ();
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   342
  Ptr<const TraceSourceAccessor> accessor = tid.LookupTraceSourceByName (name);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   343
  if (accessor == 0)
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
      return false;
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
  bool ok = accessor->Disconnect (this, context, cb);
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   348
  return ok;
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   349
}
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   350
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   351
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   352
ac94e4889027 move attribute code to ObjectBase.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2370
diff changeset
   353
} // namespace ns3