0

I'm attempting to generate a class than can read any type of serialized XSD/XML code. Since I have about 1000 different data defintions, I would love to make the XmlLoader class generic.

However, in the auto-generated serialized code, the way to obtain a pointer to the in-memory data is difficult for me to grasp.

The code:

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;
};

The problem lies with this line: xmlInstance = std::auto_ptr<XmlType > (XmlType_(filename, 0, props));

If I were to do this by hand, it would look something like:

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

Notice the _ for the function on XmlType.

When I try to template this, the compiler states that XmlType_ isn't a type, nor was it included in the argument template.

Since XmlType_ isn't a type, it's a function generated by the XSD serializer, how can I pass this through the template? I've never encountered anything like this before.

Any ideas?

Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47

0 Answers0