Gokulakannan Somasundaram escribió:
Hi Joaquín ,
I am extremely sorry, i missed your mail. First of all thanks
a lot for replying.
No problem. Please don't top-post:
http://www.boost.org/community/policy.html#quoting
I have fixed the issue for now. But i am actually explaining the issue
i had. Please take a shot at it.
Say i have an object and i have created multi index on some
members of the object. Now since,
this is being used in a multi-threaded code, i will acquire a mutex on
the whole multi-index, only if i have
updated those attributes involved in the multi-index build. Else i
won't take the mutex.
Now my problem is, i have multi-indexed many such classes.
what is the best way to check whether
the updated attribute is part of multi-index. Currently we have
written a python code which scans the C++
files and creates a list of attribute numbers ( each member attribute
has a number associated with it ).
Whenever there is an update, we check against the list produced by the
python code in C++.
My question was if there is a way to do this within C++ itself.
If we had the following metafunction to check whether a particular
key extractor is used with a multi_index_container or not:
template
struct is_key_extractor_of{};
then it is easy to know at compile time if a particular member of a class is
referenced by a member<...> key extractor (composite keys are harder and
left as an exercise to the reader):
struct A
{
int a,b,c,d,e,f;
};
typedef multi_index_container<
int,
indexed_by<
ordered_unique >,
sequenced<>,
>
multi_t;
BOOST_MPL_ASSERT ((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT_NOT((is_key_extractor_of,multi_t>));
Full code provided in the attachment. Does this help to implement your
scenario?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at.
http://www.tid.es/ES/PAGINAS/disclaimer.aspx
#include
#include
#include
#include
struct no_key_extractor{};
template
struct key_extractor
{
typedef no_key_extractor type;
};
template<
typename Arg1,typename Arg2,typename Arg3,
typename Index>
struct key_extractor<
boost::multi_index::ordered_unique,Index>
{
typedef typename Index::key_from_value type;
};
template<
typename Arg1,typename Arg2,typename Arg3,
typename Index>
struct key_extractor<
boost::multi_index::ordered_non_unique,Index>
{
typedef typename Index::key_from_value type;
};
template<
typename Arg1,typename Arg2,typename Arg3,typename Arg4,
typename Index>
struct key_extractor<
boost::multi_index::hashed_unique,Index>
{
typedef typename Index::key_from_value type;
};
template<
typename Arg1,typename Arg2,typename Arg3,typename Arg4,
typename Index>
struct key_extractor<
boost::multi_index::hashed_non_unique,Index>
{
typedef typename Index::key_from_value type;
};
template<typename MultiIndexContainer>
struct key_extractor_list:
boost::mpl::transform<
typename MultiIndexContainer::index_specifier_type_list,
typename MultiIndexContainer::index_type_list,
key_extractorboost::mpl::_,boost::mpl::_
{};
template
struct is_key_extractor_of:
boost::mpl::contains<
typename key_extractor_list<MultiIndexContainer>::type,
KeyExtractor
{};
/* testing */
#include
#include
#include
#include
#include
#include
#include
using namespace boost::multi_index;
struct A
{
int a,b,c,d,e,f;
};
typedef multi_index_container<
int,
indexed_by<
ordered_unique >,
ordered_non_unique >,
hashed_unique >,
hashed_non_unique >,
sequenced<>,
random_access<>
multi_t;
BOOST_MPL_ASSERT ((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT ((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT ((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT ((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT_NOT((is_key_extractor_of,multi_t>));
BOOST_MPL_ASSERT_NOT((is_key_extractor_of,multi_t>));
int main(){}