Пример #1
0
/**
  * Create the simple API
  * @param nrhs :: The number of parameters in the Matlab function call
  * @param prhs :: The data from the Matlab function call
  * @returns An integer indicating success/failure
  */
int CreateSimpleAPI(int, mxArray **, int nrhs, const mxArray *prhs[]) {

    // Ensure all libraries are loaded
    FrameworkManager::Instance();

    // Create directory to store mfiles
    std::string mpath("");
    if (nrhs == 0) {
        mpath = "MantidSimpleAPI";
    } else if (nrhs == 1) {
        char buffer[256];
        mxGetString(prhs[0], buffer, sizeof(buffer));
        mpath = std::string(buffer) + "/MantidSimpleAPI";
    } else {
        mexErrMsgTxt("SimpleAPI_Create takes either 0 or 1 arguments.");
    }

    Poco::File simpleAPI(mpath);
    if (simpleAPI.exists()) {
        simpleAPI.remove(true);
    }
    try {
        simpleAPI.createDirectory();
    } catch (std::exception &) {
        mexErrMsgTxt(
            "An error occurred while creating the directory for the simple API.");
    }

    std::vector<std::string> algKeys = AlgorithmFactory::Instance().getKeys();
    std::vector<std::string>::const_iterator sIter = algKeys.begin();
    typedef std::map<std::string, unsigned int> VersionMap;
    VersionMap vMap;
    for (; sIter != algKeys.end(); ++sIter) {
        std::string key = (*sIter);
        std::string name = key.substr(0, key.find("|"));
        VersionMap::iterator vIter = vMap.find(name);
        if (vIter == vMap.end())
            vMap.insert(make_pair(name, 1));
        else
            ++(vIter->second);
    }

    std::string contents_path = simpleAPI.path() + "/Contents.m";
    std::ofstream contents(contents_path.c_str());
    contents << "%A simpler API for Mantid\n%\n%The algorithms available are:\n";
    VersionMap::const_iterator vIter = vMap.begin();
    for (; vIter != vMap.end(); ++vIter) {
        contents << "% " << vIter->first << "\n";
        CreateSimpleAPIHelper(vIter->first, mpath + std::string("/"));
    }
    contents
            << "% For help with an individual command type \"help algorithm_name\"\n";
    contents.close();
    return 0;
}
Пример #2
0
void VersionInfo::AddVersion(VersionMap& versions, const SceneVersion& version)
{
    DVASSERT(versions.find(version.version) == versions.end());
    versions.insert(VersionMap::value_type(version.version, version));
}