src/core/default-value.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 24 May 2007 09:34:43 +0200
changeset 683 12f6158f0bc8
parent 624 11cc5c692eb4
child 959 bc215f926abd
child 1549 19967b5f92d7
permissions -rw-r--r--
add EnumDefaultValue::SetValue
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
599
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     2
/*
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     3
 * Copyright (c) 2007 INRIA
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     4
 *
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     7
 * published by the Free Software Foundation;
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     8
 *
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    12
 * GNU General Public License for more details.
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    13
 *
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    15
 * along with this program; if not, write to the Free Software
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    17
 *
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7b7012218291 add license header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 538
diff changeset
    19
 */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    20
#ifndef DEFAULT_VALUE_H
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    21
#define DEFAULT_VALUE_H
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    22
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    23
#include <string>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    24
#include <list>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    25
#include "callback.h"
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    26
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    27
/**
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    28
 * \defgroup config Simulation configuration
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    29
 *
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    30
 */
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    31
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    32
namespace ns3 {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    33
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    34
class DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    35
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    36
public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    37
  virtual ~DefaultValueBase ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    38
  std::string GetName (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    39
  std::string GetHelp (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    40
  // parse a matching parameter
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    41
  // return true in case of success, false otherwise.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    42
  bool ParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    43
  std::string GetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    44
  std::string GetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    45
protected:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    46
  DefaultValueBase (const std::string &name, 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    47
		    const std::string &help);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    48
private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    49
  virtual bool DoParseValue (const std::string &value) = 0;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    50
  virtual std::string DoGetType (void) const = 0;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    51
  virtual std::string DoGetDefaultValue (void) const = 0;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    52
  std::string m_name;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    53
  std::string m_help;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    54
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    55
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    56
class DefaultValueList
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    57
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    58
 public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    59
  typedef std::list<DefaultValueBase *>::iterator Iterator;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    60
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    61
  static Iterator Begin (void);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    62
  static Iterator End (void);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    63
  static void Remove (const std::string &name);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    64
  static void Add (DefaultValueBase *defaultValue);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    65
 private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    66
  typedef std::list<DefaultValueBase *> List;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    67
  static List *GetList (void);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    68
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    69
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    70
/**
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    71
 * \ingroup config
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    72
 * \param name name of variable to bind
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    73
 * \param value value to bind to the specified variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    74
 *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    75
 * If the variable name does not match any existing
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    76
 * variable or if the value is not compatible with
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    77
 * the variable type, this function will abort
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    78
 * at runtime and print an error message detailing
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    79
 * which variable or value triggered the problem.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    80
 */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    81
void Bind (std::string name, std::string value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    82
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    83
/**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    84
 * \brief A Boolean variable for ns3::Bind
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
    85
 * \ingroup config
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    86
 *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    87
 * Every instance of this type is automatically 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    88
 * registered in the variable pool which is used
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    89
 * by ns3::Bind. 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    90
 */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    91
class BooleanDefaultValue : public DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    92
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    93
public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    94
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    95
   * \param name name of variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    96
   * \param help help text which explains the purpose
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    97
   *        and the semantics of this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    98
   * \param defaultValue the default value to assign
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    99
   *        to this variable.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   100
   *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   101
   * Unless the user invokes ns3::Bind with the right arguments,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   102
   * the GetValue method will return the default value. Otherwise,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   103
   * it will return the user-specified value.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   104
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   105
  BooleanDefaultValue (std::string name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   106
		       std::string help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   107
		       bool defaultValue);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   108
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   109
   * \returns the default value for this variable or a
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   110
   *          user-provided overriden variable.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   111
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   112
  bool GetValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   113
private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   114
  virtual bool DoParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   115
  virtual std::string DoGetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   116
  virtual std::string DoGetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   117
  bool m_defaultValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   118
  bool m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   119
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   120
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   121
/**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   122
 * \brief An Integer variable for ns3::Bind
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   123
 * \ingroup config
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   124
 *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   125
 * Every instance of this type is automatically 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   126
 * registered in the variable pool which is used
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   127
 * by ns3::Bind. 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   128
 */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   129
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   130
class IntegerDefaultValue : public DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   131
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   132
public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   133
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   134
   * \param name the name of the variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   135
   * \param help help text which explains the purpose
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   136
   *        and the semantics of this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   137
   * \param defaultValue the default value assigned
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   138
   *        to this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   139
   *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   140
   * By default, the set of allowed values is the entire range
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   141
   * of values which can be stored and retrieved from the underlying
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   142
   * type.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   143
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   144
  IntegerDefaultValue (std::string name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   145
		       std::string help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   146
		       T defaultValue);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   147
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   148
   * \param name the name of the variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   149
   * \param help help text which explains the purpose
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   150
   *        and the semantics of this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   151
   * \param defaultValue the default value assigned to this
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   152
   *        variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   153
   * \param minValue the minimum value which can be set
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   154
   *        in this variable
612
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   155
   */
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   156
  IntegerDefaultValue (std::string name,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   157
		       std::string help,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   158
		       T defaultValue,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   159
		       T minValue);
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   160
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   161
  /**
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   162
   * \param name the name of the variable
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   163
   * \param help help text which explains the purpose
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   164
   *        and the semantics of this variable
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   165
   * \param defaultValue the default value assigned to this
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   166
   *        variable
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   167
   * \param minValue the minimum value which can be set
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   168
   *        in this variable
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   169
   * \param maxValue the maximum value which can be set in this
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   170
   *        variable.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   171
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   172
  IntegerDefaultValue (std::string name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   173
		       std::string help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   174
		       T defaultValue,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   175
		       T minValue,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   176
		       T maxValue);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   177
612
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   178
  void SetValue (T v);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   179
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   180
  T GetValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   181
private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   182
  virtual bool DoParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   183
  virtual std::string DoGetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   184
  virtual std::string DoGetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   185
  T m_defaultValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   186
  T m_minValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   187
  T m_maxValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   188
  T m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   189
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   190
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   191
/**
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   192
 * \brief Named enumeration defaults
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   193
 * \ingroup config
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   194
 *
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   195
 * Every instance of this type is automatically 
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   196
 * registered in the variable pool which is used
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   197
 * by ns3::Bind. 
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   198
 */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   199
class StringEnumDefaultValue : public DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   200
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   201
public:
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   202
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   203
   * \param name The name of the variable
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   204
   * \param help The help string
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   205
   */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   206
  StringEnumDefaultValue (const std::string &name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   207
                          const std::string &help);
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   208
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   209
   * \brief Add a default value to this enumeration of strings
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   210
   * \param value The string to make the default for this
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   211
   */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   212
  void AddDefaultValue (const std::string &value);
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   213
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   214
   * \brief Add a possible value to accept for this default value
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   215
   */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   216
  void AddPossibleValue (const std::string &value);
624
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   217
  /**
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   218
   * \brief Get the value of this default value.
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   219
   * \return The string that has been assigned to this default value, either by
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   220
   * Bind() or by a command line setting
11cc5c692eb4 datarate, packet, defaultvalue, object dox
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 612
diff changeset
   221
   */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   222
  std::string GetValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   223
private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   224
  virtual bool DoParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   225
  virtual std::string DoGetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   226
  virtual std::string DoGetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   227
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   228
  bool m_oneDefault;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   229
  std::list<std::string> m_possibleValues;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   230
  std::string m_defaultValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   231
  std::string m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   232
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   233
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   234
/**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   235
 * \brief An enum variable for ns3::Bind
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   236
 * \ingroup config
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   237
 *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   238
 * Every instance of this type is automatically 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   239
 * registered in the variable pool which is used
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   240
 * by ns3::Bind. 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   241
 */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   242
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   243
class EnumDefaultValue : public DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   244
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   245
public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   246
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   247
   * \param name the name of this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   248
   * \param help help text which explains the purpose
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   249
   *        and the semantics of this variable
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   250
   * \param defaultValue the default value assigned to this
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   251
   *        variable unless it is overriden with ns3::Bind
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   252
   * \param defaultValueString the string which represents
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   253
   *        the default value which should be used by ns3::Bind
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   254
   *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   255
   * This method takes a variable number of arguments. The list of
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   256
   * arguments is terminated by the pair of values 0 and (void *)0.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   257
   * Each pair of extra argument is assumed to be of the form 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   258
   * (enum value, string representing enum value). If ns3::Bind
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   259
   * is invoked on this variable, it will check that the user-provided
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   260
   * values are within the set of values specified in this constructor.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   261
   *
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   262
   * Typical useage of this method will look like this:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   263
   * \code
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   264
   * enum MyEnum {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   265
   *   MY_ENUM_A,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   266
   *   MY_ENUM_B,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   267
   *   MY_ENUM_C,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   268
   * };
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   269
   * // set default value to be "B".
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   270
   * static EnumDefaultValue<enum MyEnum> 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   271
   *  g_myDefaultValue ("my", "my help",
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   272
   *                    MY_ENUM_B, "B",
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   273
   *                    MY_ENUM_A, "A",
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   274
   *                    MY_ENUM_C, "C",);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   275
   *                    0, (void*)0);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   276
   * \endcode
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   277
   * Note that to ensure portability to 64 bit systems, make sure that
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   278
   * the last element in the variable list of arguments is (void *)0.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   279
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   280
  EnumDefaultValue (const std::string &name, const std::string &help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   281
		    T defaultValue, const char *defaultValueString, 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   282
		    ...);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   283
  void AddPossibleValue (T value, const std::string &valueString);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   284
  /**
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   285
   * \returns the default value or any other value specified by the 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   286
   *          user with ns3::Bind
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   287
   */
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   288
  T GetValue (void);
683
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   289
  /**
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   290
   * \param value the new default value.
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   291
   */
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   292
  void SetValue (T value);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   293
 private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   294
  virtual bool DoParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   295
  virtual std::string DoGetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   296
  virtual std::string DoGetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   297
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   298
  typedef std::list<std::pair<T,std::string> > PossibleValues;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   299
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   300
  T m_defaultValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   301
  PossibleValues m_possibleValues;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   302
  T m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   303
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   304
538
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   305
/**
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   306
 * \brief Class used to call a certain function during the configuration of the
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   307
 * simulation
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   308
 * \ingroup config
3cc417842b5f Added/fixed some doxygen
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 439
diff changeset
   309
 */
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   310
class CommandDefaultValue : public DefaultValueBase
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   311
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   312
public:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   313
  CommandDefaultValue (const std::string &name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   314
		       const std::string &help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   315
		       Callback<void> cb);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   316
private:
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   317
  virtual bool DoParseValue (const std::string &value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   318
  virtual std::string DoGetType (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   319
  virtual std::string DoGetDefaultValue (void) const;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   320
  Callback<void> m_cb;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   321
};
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   322
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   323
}//namespace ns3
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   324
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   325
#include "type-name.h"
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   326
#include "assert.h"
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   327
#include <sstream>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   328
#include <stdarg.h>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   329
#include <limits>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   330
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   331
namespace ns3 {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   332
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   333
/**************************************************************
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   334
 **************************************************************/
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   335
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   336
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   337
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   338
IntegerDefaultValue<T>::IntegerDefaultValue (std::string name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   339
					     std::string help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   340
					     T defaultValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   341
  : DefaultValueBase (name, help),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   342
    m_defaultValue (defaultValue),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   343
    m_minValue (std::numeric_limits<T>::min ()),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   344
    m_maxValue (std::numeric_limits<T>::max ()),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   345
    m_value (defaultValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   346
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   347
  DefaultValueList::Add (this);
612
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   348
  NS_ASSERT (m_minValue < m_maxValue);
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   349
}
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   350
template <typename T>
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   351
IntegerDefaultValue<T>::IntegerDefaultValue (std::string name,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   352
					     std::string help,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   353
					     T defaultValue,
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   354
					     T minValue)
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   355
  : DefaultValueBase (name, help),
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   356
    m_defaultValue (defaultValue),
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   357
    m_minValue (minValue),
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   358
    m_maxValue (std::numeric_limits<T>::max ()),
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   359
    m_value (defaultValue)
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   360
{
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   361
  DefaultValueList::Add (this);
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   362
  NS_ASSERT (m_minValue < m_maxValue);
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   363
  NS_ASSERT (m_defaultValue <= m_maxValue &&
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   364
	     m_defaultValue >= m_minValue);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   365
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   366
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   367
IntegerDefaultValue<T>::IntegerDefaultValue (std::string name,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   368
					     std::string help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   369
					     T defaultValue,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   370
					     T minValue,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   371
					     T maxValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   372
  : DefaultValueBase (name, help),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   373
    m_defaultValue (defaultValue),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   374
    m_minValue (minValue),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   375
    m_maxValue (maxValue),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   376
    m_value (defaultValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   377
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   378
  DefaultValueList::Add (this);
612
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   379
  NS_ASSERT (m_minValue < m_maxValue);
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   380
  NS_ASSERT (m_defaultValue <= m_maxValue &&
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   381
	     m_defaultValue >= m_minValue);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   382
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   383
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   384
template <typename T>
612
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   385
void 
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   386
IntegerDefaultValue<T>::SetValue (T v)
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   387
{
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   388
  NS_ASSERT (v <= m_maxValue &&
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   389
	     v >= m_minValue);
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   390
  m_value = v;
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   391
}
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   392
ffba29d7bdb2 add a few features to IntegerDefaultValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 599
diff changeset
   393
template <typename T>
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   394
T
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   395
IntegerDefaultValue<T>::GetValue (void) const
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   396
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   397
  return m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   398
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   399
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   400
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   401
bool
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   402
IntegerDefaultValue<T>::DoParseValue (const std::string &value)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   403
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   404
  std::istringstream iss;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   405
  iss.str (value);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   406
  iss >> m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   407
  if (m_value > m_maxValue ||
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   408
      m_value < m_minValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   409
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   410
      return false;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   411
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   412
  return !iss.bad () && !iss.fail ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   413
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   414
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   415
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   416
std::string
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   417
IntegerDefaultValue<T>::DoGetType (void) const
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   418
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   419
  std::ostringstream oss;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   420
  oss << TypeNameGet<T> () << "("
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   421
      << m_minValue << ":" 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   422
      << m_maxValue << ")";
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   423
  return oss.str ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   424
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   425
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   426
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   427
std::string
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   428
IntegerDefaultValue<T>::DoGetDefaultValue (void) const
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   429
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   430
  std::ostringstream oss;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   431
  oss << m_defaultValue;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   432
  return oss.str ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   433
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   434
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   435
/**************************************************************
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   436
 **************************************************************/
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   437
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   438
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   439
EnumDefaultValue<T>::EnumDefaultValue (const std::string &name, const std::string &help,
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   440
				       T defaultValue, const char *defaultValueString, 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   441
				       ...)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   442
  : DefaultValueBase (name, help),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   443
    m_defaultValue (defaultValue),
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   444
    m_value (defaultValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   445
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   446
  AddPossibleValue (defaultValue, defaultValueString);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   447
  va_list list;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   448
  va_start (list, defaultValueString);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   449
  while (true)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   450
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   451
      T v = (T) va_arg (list, int);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   452
      const char *str = va_arg (list, const char *);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   453
      if (v == 0 && str == 0)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   454
	{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   455
	  break;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   456
	}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   457
      AddPossibleValue (v, str);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   458
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   459
  DefaultValueList::Add (this);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   460
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   461
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   462
void 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   463
EnumDefaultValue<T>::AddPossibleValue (T value, const std::string &valueString)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   464
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   465
  m_possibleValues.push_back (std::make_pair (value, valueString));
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   466
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   467
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   468
T 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   469
EnumDefaultValue<T>::GetValue (void)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   470
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   471
  return m_value;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   472
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   473
template <typename T>
683
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   474
void
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   475
EnumDefaultValue<T>::SetValue (T value)
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   476
{
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   477
  m_value = value;
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   478
}
12f6158f0bc8 add EnumDefaultValue::SetValue
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 624
diff changeset
   479
template <typename T>
439
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   480
bool 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   481
EnumDefaultValue<T>::DoParseValue (const std::string &value)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   482
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   483
  for (typename PossibleValues::iterator i = m_possibleValues.begin ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   484
       i != m_possibleValues.end (); i++)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   485
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   486
      if (value == i->second)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   487
	{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   488
	  m_value = i->first;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   489
	  return true;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   490
	}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   491
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   492
  return false;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   493
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   494
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   495
std::string 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   496
EnumDefaultValue<T>::DoGetType (void) const
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   497
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   498
  std::string retval;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   499
  retval += "(";
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   500
  for (typename PossibleValues::const_iterator i = m_possibleValues.begin ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   501
       i != m_possibleValues.end (); i++)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   502
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   503
      if (i != m_possibleValues.begin ())
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   504
	{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   505
	  retval += "|";
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   506
	}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   507
      retval += i->second;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   508
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   509
  retval += ")";
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   510
  return retval;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   511
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   512
template <typename T>
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   513
std::string 
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   514
EnumDefaultValue<T>::DoGetDefaultValue (void) const
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   515
{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   516
  for (typename PossibleValues::const_iterator i = m_possibleValues.begin ();
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   517
       i != m_possibleValues.end (); i++)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   518
    {
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   519
      if (i->first == m_defaultValue)
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   520
	{
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   521
	  return i->second;
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   522
	}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   523
    }
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   524
  // cannot happen theoretically.
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   525
  NS_ASSERT (false);
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   526
  return ""; // quiet compiler
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   527
}
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   528
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   529
}//namespace ns3
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   530
fed13fb45eef Incorporated defaults and command-line arguments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   531
#endif /* DEFAULT_VALUE_H */