src/core/attribute-accessor-helper.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 11 Apr 2008 11:25:21 -0700
changeset 2950 9e20fb862cd8
parent 2724 62557689f8f9
child 2965 4b28e9740e3b
permissions -rw-r--r--
add AttributeAccessor::HasGetter/HasSetter and implement it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2581
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
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: 2513
diff changeset
     2
/*
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
     3
 * Copyright (c) 2008 INRIA
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
     4
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
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: 2513
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: 2513
diff changeset
     7
 * published by the Free Software Foundation;
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
     8
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
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: 2513
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: 2513
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: 2513
diff changeset
    12
 * GNU General Public License for more details.
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
    13
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
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: 2513
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: 2513
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: 2513
diff changeset
    17
 *
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
    18
 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
31d4960dc31b add missing copyright statements.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2513
diff changeset
    19
 */
2449
30127bc12056 param-spec-helper.h -> attribute-accessor-helper.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    20
#ifndef ATTRIBUTE_ACCESSOR_HELPER_H
30127bc12056 param-spec-helper.h -> attribute-accessor-helper.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
    21
#define ATTRIBUTE_ACCESSOR_HELPER_H
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
2724
62557689f8f9 add missing include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    23
#include "attribute.h"
62557689f8f9 add missing include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2581
diff changeset
    24
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
namespace ns3 {
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    27
template <typename V, typename T1>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
    28
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    29
MakeAccessorHelper (T1 a1);
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
    30
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    31
template <typename V, typename T1, typename T2>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
    32
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    33
MakeAccessorHelper (T1 a1, T2 a2);
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    34
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    35
} // namespace ns3
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    36
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
    37
/***************************************************************
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
    38
 *        The implementation of the above functions.
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
    39
 ***************************************************************/
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    40
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
    41
#include "type-traits.h"
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    42
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    43
namespace ns3 {
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    44
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    45
template <typename T, typename U>
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    46
class AccessorHelper : public AttributeAccessor
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
{
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
public:
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    49
  AccessorHelper () {}
2410
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    50
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    51
  virtual bool Set (ObjectBase * object, Attribute val) const {
2410
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    52
    const U *value = val.DynCast<const U*> ();
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    53
    if (value == 0)
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    54
      {
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    55
	return false;
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    56
      }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    57
    T *obj = dynamic_cast<T *> (object);
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    58
    if (obj == 0)
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    59
      {
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    60
	return false;
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    61
      }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    62
    return DoSet (obj, value);
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    63
  }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    64
2433
3a98e1db7f80 PValue -> Attribute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2427
diff changeset
    65
  virtual bool Get (const ObjectBase * object, Attribute val) const {
2410
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    66
    U *value = val.DynCast<U*> ();
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    67
    if (value == 0)
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    68
      {
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    69
	return false;
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    70
      }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    71
    const T *obj = dynamic_cast<const T *> (object);
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    72
    if (obj == 0)
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    73
      {
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    74
	return false;
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    75
      }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    76
    return DoGet (obj, value);
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    77
  }
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    78
88dc7d4a6731 introduce top-level ParamSpec for bindings.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2408
diff changeset
    79
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
private:
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
    81
  virtual bool DoSet (T *object, const U *v) const = 0;
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
    82
  virtual bool DoGet (const T *object, U *v) const = 0;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    83
};
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    84
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    85
template <typename V, typename T, typename U>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
    86
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
    87
DoMakeAccessorHelperOne (U T::*memberVariable)
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    88
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    89
  class MemberVariable : public AccessorHelper<T,V>
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    90
    {
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    91
    public:
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    92
      MemberVariable (U T::*memberVariable)
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
    93
	: AccessorHelper<T,V> (),
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    94
	m_memberVariable (memberVariable)
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    95
	{}
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
    96
    private:
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
    97
      virtual bool DoSet (T *object, const V *v) const {
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
    98
	(object->*m_memberVariable) = U (v->Get ());
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
    99
	return true;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   100
      }
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   101
      virtual bool DoGet (const T *object, V *v) const {
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   102
	v->Set (object->*m_memberVariable);
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   103
	return true;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   104
      }
2950
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   105
      virtual bool HasGetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   106
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   107
      }
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   108
      virtual bool HasSetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   109
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   110
      }
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   111
      
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   112
      U T::*m_memberVariable;
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   113
    };
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   114
  return Ptr<const AttributeAccessor> (new MemberVariable (memberVariable), false);
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   115
}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   116
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   117
template <typename V, typename T, typename U>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   118
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   119
DoMakeAccessorHelperOne (U (T::*getter) (void) const)
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   120
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   121
  class MemberMethod : public AccessorHelper<T,V>
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   122
    {
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   123
    public:
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   124
      MemberMethod (U (T::*getter) (void) const)
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   125
	: AccessorHelper<T,V> (),
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   126
	m_getter (getter)
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   127
	{}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   128
    private:
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   129
      virtual bool DoSet (T *object, const V *v) const {
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   130
	return false;
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   131
      }
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   132
      virtual bool DoGet (const T *object, V *v) const {
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   133
	v->Set ((object->*m_getter) ());
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   134
	return true;
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   135
      }
2950
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   136
      virtual bool HasGetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   137
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   138
      }
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   139
      virtual bool HasSetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   140
        return false;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   141
      }
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   142
      U (T::*m_getter) (void) const;
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   143
    };
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   144
  return Ptr<const AttributeAccessor> (new MemberMethod (getter), false);
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   145
}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   146
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   147
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   148
template <typename V, typename T, typename U>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   149
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   150
DoMakeAccessorHelperOne (void (T::*setter) (U))
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   151
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   152
  class MemberMethod : public AccessorHelper<T,V>
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   153
    {
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   154
    public:
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   155
      MemberMethod (void (T::*setter) (U))
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   156
	: AccessorHelper<T,V> (),
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   157
	m_setter (setter)
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   158
	{}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   159
    private:
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   160
      virtual bool DoSet (T *object, const V *v) const {
2513
a00e97e256ea typos in untested code path.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2461
diff changeset
   161
	(object->*m_setter) (U (v->Get ()));
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   162
	return true;
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   163
      }
2513
a00e97e256ea typos in untested code path.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2461
diff changeset
   164
      virtual bool DoGet (const T *object, V *v) const {
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   165
	return false;
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   166
      }
2950
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   167
      virtual bool HasGetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   168
        return false;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   169
      }
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   170
      virtual bool HasSetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   171
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   172
      }
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   173
      void (T::*m_setter) (U);
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   174
    };
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   175
  return Ptr<const AttributeAccessor> (new MemberMethod (setter), false);
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   176
}
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   177
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   178
template <typename W, typename T, typename U, typename V>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   179
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   180
DoMakeAccessorHelperTwo (void (T::*setter) (U), 
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   181
			  V (T::*getter) (void) const)
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   182
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   183
  class MemberMethod : public AccessorHelper<T,W>
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   184
    {
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   185
    public:
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   186
      MemberMethod (void (T::*setter) (U), 
2427
9245ec163111 split checker from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2424
diff changeset
   187
		    V (T::*getter) (void) const)
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   188
	: AccessorHelper<T,W> (),
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   189
	m_setter (setter),
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   190
	m_getter (getter)
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   191
	{}
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   192
    private:
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   193
      virtual bool DoSet (T *object, const W *v) const {
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   194
	(object->*m_setter) (v->Get ());
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   195
	return true;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   196
      }
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   197
      virtual bool DoGet (const T *object, W *v) const {
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   198
	v->Set ((object->*m_getter) ());
2403
759adf2fdf98 report more get/set errors
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2398
diff changeset
   199
	return true;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   200
      }
2950
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   201
      virtual bool HasGetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   202
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   203
      }
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   204
      virtual bool HasSetter (void) const {
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   205
        return true;
9e20fb862cd8 add AttributeAccessor::HasGetter/HasSetter and implement it.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2724
diff changeset
   206
      }
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   207
      void (T::*m_setter) (U);
2393
025986c8b400 untested templates rarely work.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2380
diff changeset
   208
      V (T::*m_getter) (void) const;
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   209
    };
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   210
  return Ptr<const AttributeAccessor> (new MemberMethod (setter, getter), false);
2375
6f8733409b3b add back IntValue support
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2374
diff changeset
   211
}
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   213
template <typename W, typename T, typename U, typename V>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   214
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   215
DoMakeAccessorHelperTwo (V (T::*getter) (void) const, 
2424
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
   216
			  void (T::*setter) (U))
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   217
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   218
  return DoMakeAccessorHelperTwo<W> (setter, getter);
2424
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
   219
}
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
   220
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   221
template <typename V, typename T1>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   222
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   223
MakeAccessorHelper (T1 a1)
2424
217a447122a6 split initial value from ParamSpec.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2423
diff changeset
   224
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   225
  return DoMakeAccessorHelperOne<V> (a1);
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   226
}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   227
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   228
template <typename V, typename T1, typename T2>
2436
23415bac7eaf Accessor -> AttributeAccessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2435
diff changeset
   229
Ptr<const AttributeAccessor>
2435
3128175f5866 ParamSpec -> Accessor
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2433
diff changeset
   230
MakeAccessorHelper (T1 a1, T2 a2)
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   231
{
2461
a48106d6f3b4 remove accessor BASE arg to MakeAccessorHelper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2449
diff changeset
   232
  return DoMakeAccessorHelperTwo<V> (a1, a2);
2408
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   233
}
04fe819b3ad1 rework param-spec-helper code to avoid having to deal with pointers to member functions et al.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2403
diff changeset
   234
2371
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   235
} // namespace ns3
2118204a86e6 initial work on Value code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
2449
30127bc12056 param-spec-helper.h -> attribute-accessor-helper.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   237
#endif /* ATTRIBUTE_ACCESSOR_HELPER_H */