从SAX解析器事件填充c++ POD结构

时间:2021-12-02 01:09:12

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.

我正在尝试使用在你的指针对成员和成员函数的最好的使用下给出的StructSerlialiser代码?在填充了FieldBinderList之后,我如何使用基类列表访问指向成员的指针?如果我想用一个从XML文件中读取的值来设置字段,就需要这样做。

1 个解决方案

#1


1  

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

当一个StructSeriliser被创建时,它被传递一个对象实例,它对应于并且为每个字段创建序列化器:

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.

然后,当serialiser被传递一个start元素时,它将它传递给下一个适当的字段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.

老实说,最初的代码片段并不是想要使用它本身的权利。这个类的完整代码超过了500行,对于原语、选项和选项也有序列化器。

#1


1  

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

当一个StructSeriliser被创建时,它被传递一个对象实例,它对应于并且为每个字段创建序列化器:

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.

然后,当serialiser被传递一个start元素时,它将它传递给下一个适当的字段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.

老实说,最初的代码片段并不是想要使用它本身的权利。这个类的完整代码超过了500行,对于原语、选项和选项也有序列化器。