allow attribute setters to fail.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue Aug 12 12:55:11 2008 -0700 (18 months ago)
changeset 35431548d7e3604f
parent 3542 076ae3766f27
child 3544 10c667a90efa
allow attribute setters to fail.
src/core/attribute-accessor-helper.h
src/core/attribute-test.cc
     1.1 --- a/src/core/attribute-accessor-helper.h	Mon Aug 11 15:18:40 2008 -0700
     1.2 +++ b/src/core/attribute-accessor-helper.h	Tue Aug 12 12:55:11 2008 -0700
     1.3 @@ -223,6 +223,49 @@
     1.4    return DoMakeAccessorHelperTwo<W> (setter, getter);
     1.5  }
     1.6  
     1.7 +template <typename W, typename T, typename U, typename V>
     1.8 +Ptr<const AttributeAccessor>
     1.9 +DoMakeAccessorHelperTwo (bool (T::*setter) (U), 
    1.10 +                         V (T::*getter) (void) const)
    1.11 +{
    1.12 +  class MemberMethod : public AccessorHelper<T,W>
    1.13 +    {
    1.14 +    public:
    1.15 +      MemberMethod (bool (T::*setter) (U), 
    1.16 +		    V (T::*getter) (void) const)
    1.17 +	: AccessorHelper<T,W> (),
    1.18 +	m_setter (setter),
    1.19 +	m_getter (getter)
    1.20 +	{}
    1.21 +    private:
    1.22 +      virtual bool DoSet (T *object, const W *v) const {
    1.23 +	bool ok = (object->*m_setter) (v->Get ());
    1.24 +        return ok;
    1.25 +      }
    1.26 +      virtual bool DoGet (const T *object, W *v) const {
    1.27 +	v->Set ((object->*m_getter) ());
    1.28 +	return true;
    1.29 +      }
    1.30 +      virtual bool HasGetter (void) const {
    1.31 +        return true;
    1.32 +      }
    1.33 +      virtual bool HasSetter (void) const {
    1.34 +        return true;
    1.35 +      }
    1.36 +      bool (T::*m_setter) (U);
    1.37 +      V (T::*m_getter) (void) const;
    1.38 +    };
    1.39 +  return Ptr<const AttributeAccessor> (new MemberMethod (setter, getter), false);
    1.40 +}
    1.41 +
    1.42 +template <typename W, typename T, typename U, typename V>
    1.43 +Ptr<const AttributeAccessor>
    1.44 +DoMakeAccessorHelperTwo (bool (T::*getter) (void) const, 
    1.45 +                         void (T::*setter) (U))
    1.46 +{
    1.47 +  return DoMakeAccessorHelperTwo<W> (setter, getter);
    1.48 +}
    1.49 +
    1.50  template <typename V, typename T1>
    1.51  Ptr<const AttributeAccessor>
    1.52  MakeAccessorHelper (T1 a1)
     2.1 --- a/src/core/attribute-test.cc	Mon Aug 11 15:18:40 2008 -0700
     2.2 +++ b/src/core/attribute-test.cc	Tue Aug 12 12:55:11 2008 -0700
     2.3 @@ -206,8 +206,9 @@
     2.4    Ptr<Derived> DoGetVector (uint32_t i) const {
     2.5      return m_vector2[i];
     2.6    }
     2.7 -  void DoSetIntSrc (int8_t v) {
     2.8 +  bool DoSetIntSrc (int8_t v) {
     2.9      m_intSrc2 = v;
    2.10 +    return true;
    2.11    }
    2.12    int8_t DoGetIntSrc (void) const {
    2.13      return m_intSrc2;