Boost logo

Boost :

From: Reece Dunn (msclrhd_at_[hidden])
Date: 2004-11-07 19:29:36


Hi All,

I have been working on an implementation of a library that allows you to
define properties, based on the wg21 N1615 paper by Lois Goldthwaite.
The code is committed to the sandbox (under the property directory) with
tests and preliminary documentation.

I have seperated the properties into two. The boilerplate code for
operator overloads, organised by rank, where rank is the number of
indices (the term is borrowed from Tensor algebra) provides one group.

The other group is the property storage that implements the get and set
functions that the boilerplate classes use to implement the operator
overloads.

: Scalar Properties

A scalar property is a single-element property. You can have simple
properties that either store their values internally or reference an
external data member:

class object
{
    int val;
    public:
       scalar_property< aliased_property< int > > Val;
       object(): Val( val ){}
};

int main()
{
    scalar_property< value_property< int > > ival( 0 );
    ival = 7;
    ival += 3;

    int j;
    scalar_property< aliased_property< int > > jval( j );
    jval = 2;
    assert( j == 2 );
}

You can also define more complex properties that use class methods to
control them:

class object
{
    int val;
    public:
       int get_Val() const{ return val; }
       void set_Val( const int &amp; v ){ val = v; }
       scalar_property&lt; object_property
       &lt;
          int, object,
          &amp;object::get_Val, &amp;object::set_Val
       &gt; &gt; Val;
       object(): Val( this ){}
};

: Rank 1 Properties

A rank 1 property is a 1-dimensional property. For example:

class result_set
{
    public: // property record index[];
       record get_record( int i ) const;
       void set_record( int i, record r );
       boost::rank1_property< boost::rank1_object_property
       <
          record, int, result_set,
          &result_set::get_record,
          &result_set::set_record
> > record;
    public:
       result_set(): record( this )
       {
       }
};

Regards,
Reece


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