|
Boost : |
From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2004-09-20 07:09:07
> Peter Dimov <pdimov_at_[hidden]> wrote:
>
> How would you use such a thing? :-)
>
Here's a concrete example below. Though, as has been pointed out
previously, boost::call_traits are probably not the most appropriate
to use here. It assumes some other concepts not encapsulated here.
matt.
/*_____________________________________________________________________
created: 2004-6-8 12:06
filename: helpers.hpp
author: Matt Hurd
_______________________________________________________________________*/
#ifndef HELPERS_HPP_200468
#define HELPERS_HPP_200468
#define SYNCH_SIMPLE_ATTRIBUTE( VAR_NAME, VAR_TYPE ) \
\
public: \
template< bool > \
void \
VAR_NAME \
( \
boost::call_traits< VAR_TYPE >::param_type new_ ## VAR_NAME \
) \
{ \
if ( boost::needs_lock<VAR_TYPE>::value ) { \
lock lk(guard_ ); \
VAR_NAME<false>( new_ ## VAR_NAME); \
} else { \
VAR_NAME<false>( new_ ## VAR_NAME); \
} \
} \
\
void \
VAR_NAME \
( \
boost::call_traits< VAR_TYPE >::param_type new_ ## VAR_NAME \
) \
{ \
VAR_NAME < true > ( new_ ## VAR_NAME ); \
} \
\
template< > \
void \
VAR_NAME<false> \
( \
boost::call_traits<VAR_TYPE>::param_type new_ ## VAR_NAME \
) \
{ \
VAR_NAME ## _ = new_ ## VAR_NAME; \
} \
\
template< bool > \
VAR_TYPE \
VAR_NAME( ) const \
{ \
if ( boost::needs_lock< VAR_TYPE >::value ) { \
lock lk(guard_, synch::lock_status::shared ); \
return VAR_NAME<false>( ); \
} else { \
return VAR_NAME<false>( ); \
} \
} \
\
VAR_TYPE \
VAR_NAME( ) const \
{ \
return VAR_NAME<true>( ); \
} \
\
template< > \
VAR_TYPE \
VAR_NAME <false>() const \
{ \
return VAR_NAME ## _; \
} \
\
boost::call_traits<VAR_TYPE>::const_reference \
VAR_NAME ## _ref( ) const \
{ \
return VAR_NAME ## _; \
} \
\
private: \
VAR_TYPE VAR_NAME ## _; \
#endif
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk