|
Boost : |
From: ÃÓ °ê«T (kctan_tw_at_[hidden])
Date: 2003-10-28 20:06:21
I have written a tool to adapt old properties class, for example:
typedef BOOL int;
struct OldProperties
{
BOOL bFoo;
};
and we can adapt it like this:
class new_properties
{
public:
new_properties() : foo(old_prop.bFoo) {}
boost::property_adapter<bool, BOOL> foo;
private:
OldProperties old_prop;
};
new_properties new_prop;
then we can set and get property as follow:
new_prop.foo = true;
bool foo = new_prop.foo;
We can decide the read/write policy like this:
boost::property_adapter<bool, BOOL, boost::read_only_tag> read_only_foo;
boost::property_adapter<bool, BOOL, boost::write_only_tag> write_only_foo;
default the policy tag is read_write_tag.
We also can decide what the get and set operation are:
struct bool_to_BOOL
{
BOOL operator()(bool src) const
{
return src ? 1 : 0;
}
};
struct BOOL_to_bool
{
bool operator()(BOOL src) const
{
return !!src;
}
};
boost::property_adapter<bool, BOOL, boost::read_write_tag, bool_to_BOOL,
BOOL_to_bool> foo;
If we cannot decide what type the source is, we can write as follow:
boost::any_property_adapter<BOOL> foo;
and we can use all features of property_adapter like this:
boost::property_adapter<BOOL, boost::read_write_tag, bool_to_BOOL,
BOOL_to_bool> foo;
_________________________________________________________________
¤U¸ü³Ì·sª©¥»ªº MSN Messenger¡G»PªB¤Í¦b½u¤W²á¤Ñ¡AÀH®É´x´¤ªÑ¥«°]¸g¡B¤u§@¾÷·|µ¥
³Ì·s¸ê°T http://messenger.msn.com.tw/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk