src/core/attribute.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 09 Apr 2008 12:15:24 -0700
changeset 2927 73b47ce1d805
parent 2633 a0639de8cd8b
child 2947 b0fec3381418
permissions -rw-r--r--
get rid of implicit conversion of Attribute to/from Ptr<>. Replace this with an explicit Pointer class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     2
/*
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     3
 * Copyright (c) 2008 INRIA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     4
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     7
 * published by the Free Software Foundation;
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     8
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    12
 * GNU General Public License for more details.
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    13
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    14
 * You should have received a copy of the GNU General Public License
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    15
 * along with this program; if not, write to the Free Software
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    17
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2550
diff changeset
    19
 */
2438
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2437
diff changeset
    20
#ifndef ATTRIBUTE_H
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2437
diff changeset
    21
#define ATTRIBUTE_H
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include <string>
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <stdint.h>
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    25
#include "ptr.h"
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
namespace ns3 {
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
    29
class AttributeAccessor;
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    30
class AttributeChecker;
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    31
class Attribute;
2633
a0639de8cd8b split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2619
diff changeset
    32
class ObjectBase;
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    34
/**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    35
 * \brief Hold a value for an Attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    36
 *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    37
 * Instances of this class are usually created by Attribute::Create<> and
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    38
 * should always be wrapped into an Attribute object.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    39
 * Most subclasses of this base class are implemented by the 
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    40
 * ATTRIBUTE_HELPER_* macros.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    41
 */
2437
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    42
class AttributeValue
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
{
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
public:
2437
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    45
  AttributeValue ();
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    46
  AttributeValue (const AttributeValue &o);
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    47
  AttributeValue &operator = (const AttributeValue &o);
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    48
  virtual ~AttributeValue ();
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    50
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    51
   * \returns a deep copy of this class, wrapped into an Attribute object.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    52
   */
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    53
  virtual Attribute Copy (void) const = 0;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    54
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    55
   * \param checker the checker associated to the attribute
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    56
   * \returns a string representation of this value.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    57
   *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    58
   * In most cases, this method will not make any use of the checker argument.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    59
   * However, in a very limited set of cases, the checker argument is needed to
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    60
   * perform proper serialization. A nice example of code which needs it is
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    61
   * the EnumValue::SerializeToString code.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    62
   */
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    63
  virtual std::string SerializeToString (Ptr<const AttributeChecker> checker) const = 0;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    64
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    65
   * \param value a string representation of the value
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    66
   * \param checker a pointer to the checker associated to the attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    67
   * \returns true if the input string was correctly-formatted and could be
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    68
   *          successfully deserialized, false otherwise.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    69
   *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    70
   * Upon return of this function, this AttributeValue instance contains
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    71
   * the deserialized value.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    72
   * In most cases, this method will not make any use of the checker argument.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    73
   * However, in a very limited set of cases, the checker argument is needed to
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    74
   * perform proper serialization. A nice example of code which needs it is
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    75
   * the EnumValue::SerializeToString code.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    76
   */
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    77
  virtual bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker) = 0;
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
private:
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    79
  friend class Attribute;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    80
  uint32_t m_count;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    81
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    82
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    83
/**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    84
 * \brief an opaque wrapper around a value to set or retrieved
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    85
 *        from an attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    86
 *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    87
 * This class is really a smart pointer to an instance of AttributeValue.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    88
 * Of course, the question is "why not use a Ptr<AttributeValue>" ?. The 
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    89
 * answer is long and complicated but the crux of the issue is that if we
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    90
 * do not reproduce the smart pointer code in this class, we cannot provide
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    91
 * transparent handling of Ptr<T> values through the attribute system.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    92
 */
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    93
class Attribute
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    94
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
    95
public:
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    96
  Attribute ();
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    97
  Attribute (const Attribute &o);
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    98
  Attribute &operator = (const Attribute &o);
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    99
  ~Attribute ();
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   100
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   101
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   102
   * Forward to AttributeValue::Copy
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   103
   */
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   104
  Attribute Copy (void) const;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   105
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   106
   * Forward to AttributeValue::SerializeToString
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   107
   */
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   108
  std::string SerializeToString (Ptr<const AttributeChecker> checker) const;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   109
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   110
   * Forward to AttributeValue::DeserializeFromString
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   111
   */
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   112
  bool DeserializeFromString (std::string value, Ptr<const AttributeChecker> checker);
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   113
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   114
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   115
   * \returns a new Attribute object which wraps an instance of the requested
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   116
   * subclass of AttributeValue.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   117
   */
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   118
  template <typename T>
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   119
  static Attribute Create (void);
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   120
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   121
   * \param a1 a value to pass through to the constructor of the class T.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   122
   * \returns a new Attribute object which wraps an instance of the requested
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   123
   * subclass of AttributeValue.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   124
   */
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   125
  template <typename T, typename T1>
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   126
  static Attribute Create (T1 a1);
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   127
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   128
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   129
   * This method performs a dynamic_cast on the underlying AttributeValue.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   130
   * This method is typically used to implement conversion operators
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   131
   * from the type Attribute. In most cases, these conversion operators
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   132
   * will be generated for you by the ATTRIBUTE_HELPER_* macros.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   133
   * \returns the casted pointer.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   134
   */
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   135
  template <typename T>
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   136
  T DynCast (void) const;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   137
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   138
private:
2437
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   139
  Attribute (AttributeValue *value);
44e34ffee8e3 Value -> AttributeValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   140
  AttributeValue *m_value;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   141
};
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   142
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   143
/**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   144
 * \brief allow setting and getting the value of an attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   145
 *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   146
 * The goal of this class is to hide from the user how an attribute
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   147
 * is actually set or get to or from a class instance. Implementations
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   148
 * of this base class are usually provided through the MakeAccessorHelper
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   149
 * template functions, hidden behind an ATTRIBUTE_HELPER_* macro.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   150
 */
2633
a0639de8cd8b split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2619
diff changeset
   151
class AttributeAccessor
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   152
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   153
public:
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   154
  AttributeAccessor ();
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   155
  void Ref (void) const;
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   156
  void Unref (void) const;
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   157
  virtual ~AttributeAccessor ();
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   158
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   159
  /**
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   160
   * \param object the object instance to set the value in
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   161
   * \param value the value to set
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   162
   * \returns true if the value could be set successfully, false otherwise.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   163
   *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   164
   * This method expects that the caller has checked that the input value is
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   165
   * valid with AttributeChecker::Check.
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   166
   */
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   167
  virtual bool Set (ObjectBase * object, Attribute value) const = 0;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   168
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   169
   * \param object the object instance to get the value from
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   170
   * \param attribute a pointer to where the value should be set.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   171
   * \returns true if the value could be read successfully, and
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   172
   *          stored in the input value, false otherwise.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   173
   *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   174
   * This method expects that the caller has checked that the input value is
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   175
   * valid with AttributeChecker::Check.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   176
   */
2595
b504951bcca8 fix doxygen errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2583
diff changeset
   177
  virtual bool Get (const ObjectBase * object, Attribute attribute) const = 0;
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   178
private:
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   179
  mutable uint32_t m_count;
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   180
};
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   181
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   182
/**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   183
 * \brief Represent the type of an attribute
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   184
 *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   185
 * Each type of attribute has an associated unique AttributeChecker
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   186
 * subclass. The type of the subclass can be safely used by users
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   187
 * to infer the type of the associated attribute. i.e., we expect
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   188
 * binding authors to use the checker associated to an attribute
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   189
 * to detect the type of the associated attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   190
 *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   191
 * Most subclasses of this base class are implemented by the 
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   192
 * ATTRIBUTE_HELPER_* macros.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   193
 */
2633
a0639de8cd8b split code from object.h/object.cc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2619
diff changeset
   194
class AttributeChecker
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   195
{
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   196
public:
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   197
  AttributeChecker ();
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   198
  void Ref (void) const;
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   199
  void Unref (void) const;
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   200
  virtual ~AttributeChecker ();
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   201
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   202
   * \param value a pointer to the value to check
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   203
   * \returns true if the input value is both of the right type
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   204
   *          and if its value is within the requested range. Returns
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   205
   *          false otherwise.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   206
   */
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   207
  virtual bool Check (Attribute value) const = 0;
2599
fcc1728eb669 Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
   208
  virtual std::string GetType (void) const = 0;
fcc1728eb669 Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
   209
  virtual bool HasTypeConstraints (void) const = 0;
fcc1728eb669 Add sufficient information to AttributeChecker to generate nice-looking doxygen documentation.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2595
diff changeset
   210
  virtual std::string GetTypeConstraints (void) const = 0;
2583
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   211
  /**
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   212
   * \returns a new instance of an AttributeValue (wrapper in an Attribute 
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   213
   *          instance) which matches the type of the underlying attribute.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   214
   *
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   215
   * This method is typically used to create a temporary variable prior
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   216
   * to calling Attribute::DeserializeFromString.
c09faa6c90bf doxygen doc
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
   217
   */
2520
a4896ebf6e1d introduce AttributeChecker::Create and use it instead of AttributeValue::Copy.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2506
diff changeset
   218
  virtual Attribute Create (void) const = 0;
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   219
private:
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
  mutable uint32_t m_count;
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
};
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   223
} // namespace ns3
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   224
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   225
namespace ns3 {
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   226
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   227
/********************************************************
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   228
 *        The implementation of the Attribute 
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   229
 *          class template methods.
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   230
 ********************************************************/
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   231
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   232
template <typename T>
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   233
Attribute 
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   234
Attribute::Create (void)
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   235
{
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   236
  return Attribute (new T ());
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   237
}
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   238
template <typename T, typename T1>
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   239
Attribute 
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   240
Attribute::Create (T1 a1)
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   241
{
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   242
  return Attribute (new T (a1));
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   243
}
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   244
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   245
template <typename T>
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   246
T
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
   247
Attribute::DynCast (void) const
2374
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   248
{
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   249
  return dynamic_cast<T> (m_value);
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   250
}
570f3c6c6142 make Ptr<T> convertible to a Value.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2371
diff changeset
   251
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
} // namespace ns3
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
2438
e2ac9f9aeeb9 value.h -> attribute.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2437
diff changeset
   254
#endif /* ATTRIBUTE_H */