示例#1
0
XML_Node* Application::get_XML_File(const std::string& file, int debug)
{
    std::unique_lock<std::mutex> xmlLock(xml_mutex);
    std::string path = "";
    path = findInputFile(file);
    int mtime = get_modified_time(path);

    if (xmlfiles.find(path) != xmlfiles.end()) {
        // Already have a parsed XML tree for this file cached. Check the
        // last-modified time.
        std::pair<XML_Node*, int> cache = xmlfiles[path];
        if (cache.second == mtime) {
            return cache.first;
        }
    }
    /*
     * Check whether or not the file is XML (based on the file extension). If
     * not, it will be first processed with the preprocessor.
     */
    string::size_type idot = path.rfind('.');
    string ext;
    if (idot != string::npos) {
        ext = path.substr(idot, path.size());
    } else {
        ext = "";
    }
    XML_Node* x = new XML_Node("doc");
    if (ext != ".xml" && ext != ".ctml") {
        // Assume that we are trying to open a cti file. Do the conversion to XML.
        std::stringstream phase_xml(ct2ctml_string(path));
        x->build(phase_xml);
    } else {
        std::ifstream s(path.c_str());
        if (s) {
            x->build(s);
        } else {
            throw CanteraError("get_XML_File",
                "cannot open "+file+" for reading.\n"
                "Note, this error indicates a possible configuration problem.");
        }
    }
    x->lock();
    xmlfiles[path] = {x, mtime};
    return x;
}
示例#2
0
void ct2ctml(const char* file, const int debug)
{
    string xml = ct2ctml_string(file);
    string out_name = file;
#ifdef _WIN32
    // For Windows, make the path POSIX compliant so code looking for directory
    // separators is simpler.  Just look for '/' not both '/' and '\\'
    std::replace_if(out_name.begin(), out_name.end(),
                    std::bind2nd(std::equal_to<char>(), '\\'), '/');
#endif
    size_t idir = out_name.rfind('/');
    if (idir != npos) {
        out_name = out_name.substr(idir+1, out_name.size());
    }
    size_t idot = out_name.rfind('.');
    if (idot != npos) {
        out_name = out_name.substr(0, idot) + ".xml";
    } else {
        out_name += ".xml";
    }
    std::ofstream out(out_name);
    out << xml;
}