0

我正在尝试生成一个可以读取任何类型的序列化 XSD/XML 代码的类。因为我有大约 1000 种不同的数据定义,所以我很想让这个XmlLoader类通用。

但是,在自动生成的序列化代码中,获取指向内存数据的指针的方法我很难掌握。

编码:

template <class XmlType>
class XmlLoader {
public:

    XmlLoader(const std::string &filename, const std::string &xsd) :
    filename(filename),
    xsd(xsd) {
        try {
            this->initialize();
        } catch (const xml_schema::exception &e) {
            ERROR("Unable to parse [%s], aborting\n", filename.c_str());
        } catch (const std::invalid_argument &e) {
            ERROR("Unable to locate [%s], aborting\n",
                    std::string(Component::getJarssXSDDirectory() + xsd).c_str());
        }
    }

    std::auto_ptr<XmlType> xmlInstance;

private:

    void initialize() {

        std::string schema = Component::getJarssXSDDirectory() + xsd;
        if (!Application::validatePath(schema)) {
            throw std::invalid_argument("XSD cannot be found");
        }

        xml_schema::properties props;
        props.no_namespace_schema_location(schema);
        xmlInstance = std::auto_ptr<XmlType > (XmlType_(filename, 0, props));
    }

    std::string filename;
    std::string xsd;
};

问题在于这一行:xmlInstance = std::auto_ptr<XmlType > (XmlType_(filename, 0, props));

如果我要手动执行此操作,它看起来像:

xmlInstance = std::auto_ptr<XmlType>(XmlType_(filename, 0, props));

注意_XmlType 上的函数。

当我尝试对此进行模板化时,编译器指出它XmlType_不是类型,也没有包含在参数模板中。

由于XmlType_不是类型,它是 XSD 序列化程序生成的函数,我如何通过模板传递它?我以前从未遇到过这样的事情。

有任何想法吗?

4

0 回答 0