|
Boost Users : |
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2008-05-15 14:32:35
Christian Holmquist wrote:
> Hi,
>
> I have a class X : public intrusive::list_base_hook<> and would like
> to embed an additional member bool using the pointer_plus_bit.
>
> Can this be achieved using the value_traits somehow, and have the list
> working 'appropriately'?
It can be achieved using value_traits. Just repeat the following example:
but instead of defining this value_traits:
//Define the node traits. A single node_traits will be enough.
struct simple_node_traits
{
typedef simple_node node;
typedef node * node_ptr;
typedef const node * const_node_ptr;
static node *get_next(const node *n)
{ return n->next_; }
static void set_next(node *n, node *next)
{ n->next_ = next; }
// ...
};
Use this (supposing you want to embed the bit in the next pointer):
struct simple_node_traits
{
// ...
static node *get_next(const node *n)
{ return pointer_plus_bit<node*>::get_pointer(n->next_); }
static void set_next(node *n, node *next)
{ return pointer_plus_bit<node*>::set_pointer(n->next_, next); }
//...
};
I haven't compiled it, so it might contain errors. To access to the set
bit you should define a function that accesses next pointer and extracts
the bit, something like:
pointer_plus_bit<node*>::set_bit(x.next_, true);
bool ret = pointer_plus_bit<node*>::get_bit(x.next_);
Take in care that you should make sure that
has_pointer_plus_bit<void *, boost::alignment_of<node>::value>::value;
is true, otherwise, you won't have space to store the bit, because the
pointed type has not even alignment.
FYI, I've just erased pointer_plus_bit.hpp and substituted it with a
more generic pointer_plus_bits.hpp in Trunk. Now that I see that it's
being used, I will need to provide backwards compatibility.
I hope it works,
Ion
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net