src/core/attribute-list.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 3190 51fe9001a679
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
mathieu@2671
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@2671
     2
/*
mathieu@2671
     3
 * Copyright (c) 2008 INRIA
mathieu@2671
     4
 *
mathieu@2671
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@2671
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@2671
     7
 * published by the Free Software Foundation;
mathieu@2671
     8
 *
mathieu@2671
     9
 * This program is distributed in the hope that it will be useful,
mathieu@2671
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@2671
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@2671
    12
 * GNU General Public License for more details.
mathieu@2671
    13
 *
mathieu@2671
    14
 * You should have received a copy of the GNU General Public License
mathieu@2671
    15
 * along with this program; if not, write to the Free Software
mathieu@2671
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@2671
    17
 *
mathieu@2671
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
mathieu@2671
    19
 */
mathieu@2633
    20
#ifndef ATTRIBUTE_LIST_H
mathieu@2633
    21
#define ATTRIBUTE_LIST_H
mathieu@2633
    22
mathieu@2633
    23
#include <string>
mathieu@2633
    24
#include <vector>
mathieu@2633
    25
#include "attribute.h"
mathieu@2633
    26
#include "type-id.h"
mathieu@2633
    27
mathieu@2633
    28
namespace ns3 {
mathieu@2633
    29
mathieu@2633
    30
/**
tomh@3182
    31
 * \ingroup attribute
tomh@3182
    32
 *
mathieu@2633
    33
 * \brief a container of attributes to be used during object's construction
mathieu@2633
    34
 *        and in ns3::Object::Set.
mathieu@2633
    35
 *
mathieu@2633
    36
 */
mathieu@2633
    37
class AttributeList
mathieu@2633
    38
{
mathieu@2633
    39
public:
mathieu@2633
    40
  AttributeList ();
mathieu@2633
    41
  AttributeList (const AttributeList &o);
mathieu@2633
    42
  AttributeList &operator = (const AttributeList &o);
mathieu@2633
    43
  ~AttributeList ();
mathieu@2633
    44
  /**
mathieu@2633
    45
   * \param name the full name of the attribute to set
mathieu@2633
    46
   * \param value the value to set
mathieu@2633
    47
   *
mathieu@2633
    48
   * This method checks that a attribute with the requested
mathieu@2633
    49
   * name exists and that the value specified is an acceptable
mathieu@2633
    50
   * value of that attribute. If any of these checks fails,
mathieu@2633
    51
   * the program terminates with a message.
mathieu@2633
    52
   */
mathieu@2965
    53
  void Set (std::string name, const AttributeValue &value);
mathieu@2633
    54
  /**
mathieu@2633
    55
   * \param name the full name of the attribute to set
mathieu@2633
    56
   * \param value the value to set
mathieu@2633
    57
   * \returns true if the requested attribute exists and could be
mathieu@2633
    58
   *          stored, false otherwise.
mathieu@2633
    59
   */
mathieu@2965
    60
  bool SetFailSafe (std::string name, const AttributeValue &value);
mathieu@2633
    61
  /**
mathieu@2633
    62
   * \param tid the TypeId associated to this attribute
mathieu@2633
    63
   * \param name the name (not full!) of the attribute
mathieu@2633
    64
   * \param value the value to set
mathieu@2633
    65
   *
mathieu@2633
    66
   * This method checks that a attribute with the requested
mathieu@2633
    67
   * name exists and that the value specified is an acceptable
mathieu@2633
    68
   * value of that attribute. If any of these checks fails,
mathieu@2633
    69
   * the program terminates with a message.
mathieu@2633
    70
   */
mathieu@2965
    71
  void SetWithTid (TypeId tid, std::string name, const AttributeValue &value);
mathieu@2633
    72
mathieu@2633
    73
  /**
mathieu@2633
    74
   * Clear the content of this instance.
mathieu@2633
    75
   */
mathieu@2633
    76
  void Reset (void);
mathieu@2633
    77
mathieu@2633
    78
  /**
mathieu@2633
    79
   * \returns the global attribute container
mathieu@2633
    80
   *
mathieu@2633
    81
   * The global attribute container can be used to specify
mathieu@2633
    82
   * a set of attribute values without having to re-specify
mathieu@2633
    83
   * them for each object when it is created. This container
mathieu@2633
    84
   * is checked only during object construction and 
mathieu@2633
    85
   * it is always checked last, after any per-object
mathieu@2633
    86
   * container is checked.
mathieu@2633
    87
   */
mathieu@2633
    88
  static AttributeList *GetGlobal (void);
mathieu@2633
    89
mathieu@2633
    90
  std::string SerializeToString (void) const;
mathieu@2633
    91
  bool DeserializeFromString (std::string value);
mathieu@2633
    92
private:
mathieu@2637
    93
  friend class ObjectBase;
mathieu@2633
    94
  struct Attr {
mathieu@2633
    95
    Ptr<const AttributeChecker> checker;
mathieu@2965
    96
    Ptr<const AttributeValue> value;
mathieu@2633
    97
  };
mathieu@2633
    98
  typedef std::vector<struct Attr> Attrs;
mathieu@2633
    99
  typedef Attrs::iterator Iterator;
mathieu@2633
   100
  typedef Attrs::const_iterator CIterator;
mathieu@2633
   101
mathieu@2633
   102
mathieu@2633
   103
mathieu@2965
   104
  bool DoSet (struct TypeId::AttributeInfo *info, const AttributeValue &param);
mathieu@2965
   105
  void DoSetOne (Ptr<const AttributeChecker> checker, const AttributeValue &param);
mathieu@2633
   106
  std::string LookupAttributeFullNameByChecker (Ptr<const AttributeChecker> checker) const;
mathieu@2633
   107
mathieu@2633
   108
  Attrs m_attributes;
mathieu@2633
   109
};
mathieu@2633
   110
mathieu@3892
   111
class UnsafeAttributeList
mathieu@3892
   112
{
mathieu@3892
   113
public:
mathieu@3892
   114
  UnsafeAttributeList ();
mathieu@3892
   115
  UnsafeAttributeList (const UnsafeAttributeList &o);
mathieu@3892
   116
  UnsafeAttributeList &operator = (const UnsafeAttributeList &o);
mathieu@3892
   117
  ~UnsafeAttributeList ();
mathieu@3892
   118
  
mathieu@3892
   119
  void Set (std::string name, const AttributeValue &param);
mathieu@3892
   120
mathieu@3892
   121
  AttributeList GetSafe (std::string name) const;
mathieu@3892
   122
private:
mathieu@3892
   123
  std::vector<std::pair<std::string,Ptr<AttributeValue> > > m_attributes;
mathieu@3892
   124
};
mathieu@3892
   125
mathieu@2633
   126
} // namespace ns3
mathieu@2633
   127
mathieu@2633
   128
#endif /* ATTRIBUTE_LIST_H */