tags:

views:

85

answers:

1

I am trying to use the StructSerlialiser code given under What’s the best use you’ve had with pointer to members and member functions? After populating the FieldBinderList, how do I access the pointer to member with the base class list? I need to do this if I want to set that field with a value read off an XML file.

+1  A: 

When a StructSeriliser is created it is passed an instance of the object is corresponds to and it creates Serialisers for each Field:

StructSerialiser (T* data)
    : SerialiserData (data)
{
    if (fieldBinderList_.empty ())
        Serialiser<T>::initialise ();

    typedef FieldBinderList::const_iterator Iter;
    for ( Iter iter = fieldBinderList_.begin ()
        ; iter != fieldBinderList_.end ()
        ; ++iter
        )
    {
        serialisers_.push_back
            ( SerialiserEntry
                ( (*iter)->tags_
                , (*iter)->createSerialiser (*data)
                )
            );
    }
}

Then when the serialiser is passed a start element it passes it to the next appropriate Field serialiser.

To be honest, the original code snippet wasn't intended to be usable in it's own right. The full code for just that class is over 500 lines, and there are serialisers for primitives, optionals and choices as well.

jon hanson