$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] make member functions (in)accessible
From: dhruva (dhruva_at_[hidden])
Date: 2009-02-26 09:08:56
Though I have not used it myself, there is enable_if or disable_if in BOOST. That might help.
-dhruva
----- Original Message ----
> From: Stefan Funck <stefanfunck_at_[hidden]>
> To: boost-users_at_[hidden]
> Sent: Thursday, 26 February, 2009 7:34:01 PM
> Subject: [Boost-users] make member functions (in)accessible
> 
> Dear all,
> 
> I'm trying to find some magic that makes a member function of some object x
> accessible if and only if it were called from within a class that has object x
> as a member. Is there a (boost)-way of doing this?
> 
> As this may seem a bit obscure, I'm trying to give an example:
> 
> template 
> class Property
> {
> public:
>     T get() const;
>     void set(const T& val);
> private:
>     T  m_val;
> };
> is a simple class holding a value of T.
> 
> I have some classes holding potentially many Properties. I'd like to have these
> properties publically available, some as only readable, others writable as well,
> so that others (e.g. gui-classes) can access them:
> 
> class A
> {
> public:
>     Property  propA;
>     Property  propB;
> };
> 
> so I may do:
> 
> A  a;
> a.propA.get();
> a.propA.set(0.5);
> a.propB.get();
> 
> but NOT:
> 
> a.propB.set(1);
> 
> because propB was defined with Writable=false. BUT, from within class A, I would
> like to do
> 
> propB.set(1);
> 
> because otherwise this property is useless. (How) can this be achieved (with 
> boost)?
> 
> I could make set() private in the Writable=false - specialisation of Property
> and declare A as a friend, but that's prohibitive since Property shouldn't know
> about A and it won't work for derived classes of A. Another option would be
> 
> class A
> {
> public:
>     A() : propA(propA_priv), propB(propB_priv) {}
> 
>     PropertyWrapper  propA;
>     PropertyWrapper  propB;
> private:
>     Property  propA_priv;
>     Property  propB_priv;
> };
> 
> so the actual properties are private and the wrapper provides the actual
> interface to the outside world. But as there may be many properties I'd like to
> get away without the wrapper objects ...
> 
> Thanks for any ideas!
> Stefan
> 
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://listarchives.boost.org/mailman/listinfo.cgi/boost-users
      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/