Boost logo

Boost :

From: Gary Powell (powellg_at_[hidden])
Date: 2002-02-13 11:09:57


I wrote one 2 years ago and it was fun to play with but it never made it
into production code. Why? Because it was so unfamiliar to all the other
programmers on the team. I was thinking it would be useful as I could put
break points on the get/set fns and then in non DEBUG code just remove the
whole thing.

void fooFn(MYclass &my)
{

    my.value = 0; // is this calling a function? Can't tell unless I go look
it up.
}

The other issue was that the alignment of the variables changed.

 struct foo {
     char a;
     char b;
};

sizeof(foo) with byte alignment could be as small as 2 bytes.

template<typename T, class EnclosingClass>
class readonly
{
public:
    friend class EnclosingClass;

....
   every dang operator and its brother.
};

 struct goo {
     readonly<char,goo> a;
     readonly<char,goo> b;
};
sizeof(goo) on the same machine ended up 8 bytes.

// I included the enclosing class to be the friend, after all someone has to
be able to write to it.

So then I figured I'd #ifdef DEBUG the class into nothing using MACRO's, but
I ran into problems with the test files having written binary data for the
class's (that turned out bad for other reasons as well) and not being able
to read it back in with production code.

So I abandoned the whole idea. It was fun to play with though.

  Yours,
 -gary-

-----Original Message-----
From: Geurt Vos [mailto:G.Vos_at_[hidden]]
Sent: Wednesday, February 13, 2002 1:01 AM
To: boost_at_[hidden]
Subject: [boost] properties in C++

Hi,
I was wondering if there's interest in "properties
for C++". Properties in the sense of: assigning
to a data member will call a user-defined 'set'
function, reading from the data member will call
a user-defined 'get' function.

Example:

class A {
private:
    void set_it(int);
    int get_it() const;
public:
    [...] value;
};

A a;
a.value = 100;
-> a.set_it(100);
int i = a.value
-> int i = a.get_it();
int i = a.value = 100;
-> a.set_it(100);
-> int i = a.get_it();

For the declaration I'm thinking of something like:

    boost::property<
        boost::read<int,A,&A::get_it>,
        boost::write<int,A,&A::set_it>
> value;

* it doesn't matter whether read<> or write<> comes first
* if write<> is missing, the property is read-only
* if read<> is missing, the property is write-only

Is there any interest in this? I do have an implementation
lying around. I can have it uploaded within a few days
(have to boostify the thing...).

Geurt

Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk