예제 #1
0
파일: Help.cpp 프로젝트: SylerWang/RevBayes
/** Initialize the help from an XML file */
void Help::initializeHelp(std::string helpDir)
{

    // find the path to the directory containing the help files
    RevBayesCore::RbFileManager fMngr = RevBayesCore::RbFileManager();
    //pathToHelpDir = fMngr.getCurrentDirectory();

   
    fMngr.setFilePath(this->helpDir);
    if (fMngr.testDirectory() == false)
    {
        RBOUT("Warning: Cannot find directory containing help files. User help is unavailable. Path = " + this->helpDir);
        return;
    }
    
    
}
/** Format the error exception string for problems specifying the file/path name */
void Func_readCharacterDataUniversal::formatError(RevBayesCore::RbFileManager& fm, std::string& errorStr) {
    
    bool fileNameProvided    = fm.isFileNamePresent();
    bool isFileNameGood      = fm.testFile();
    bool isDirectoryNameGood = fm.testDirectory();
    
    if ( fileNameProvided == false && isDirectoryNameGood == false )
        errorStr += "Could not read contents of directory \"" + fm.getFilePath() + "\" because the directory does not exist";
    else if (fileNameProvided == true && (isFileNameGood == false || isDirectoryNameGood == false))
        {
        errorStr += "Could not read file named \"" + fm.getFileName() + "\" in directory named \"" + fm.getFilePath() + "\" ";
        if (isFileNameGood == false && isDirectoryNameGood == true)
            errorStr += "because the file does not exist";
        else if (isFileNameGood == true && isDirectoryNameGood == false)
            errorStr += "because the directory does not exist";
        else
            errorStr += "because neither the directory nor the file exist";
        }
}
예제 #3
0
/** Initialize the help from an XML file */
void RbHelpSystem::initializeHelp(const std::string &helpDir)
{
    
    // find the path to the directory containing the help files
    RevBayesCore::RbFileManager fMngr = RevBayesCore::RbFileManager();
    
    fMngr.setFilePath(helpDir);
    if (fMngr.testDirectory() == false)
    {
        throw RbException("Warning: Cannot find directory containing help files. User help is unavailable. Path = " + helpDir);
    }
    
    // get a help parser instance
    RbHelpParser parser = RbHelpParser();
    
    // get the files contained in the directory

    // gather all xml files in help dir, filtered by '.ext'
    std::string ext = "xml";
    std::vector<std::string> files;
    std::vector<std::string> fileNames;
    fMngr.setStringWithNamesOfFilesInDirectory( files );
    for (std::vector<std::string>::iterator it = files.begin(); it != files.end(); ++it)
    {
        RevBayesCore::RbFileManager tmpFM = RevBayesCore::RbFileManager( *it );
        if ( tmpFM.getFileExtension() == ext)
        {
            fileNames.push_back( *it );
        }
    }

    for (std::vector<std::string>::iterator it = fileNames.begin(); it != fileNames.end(); ++it)
    {
        
        if ( parser.testHelpEntry( *it ) == RbHelpParser::FUNCTION )
        {
            
            RbHelpFunction h = parser.parseHelpFunction( *it );
            helpForFunctions.insert( std::pair<std::string,RbHelpFunction>( h.getName() , h) );
            helpFunctionNames.insert( h.getName() );
            
            
            // also add all aliases
            const std::vector<std::string>& aliases = h.getAliases();
            for (std::vector<std::string>::const_iterator alias = aliases.begin(); alias != aliases.end(); ++alias)
            {
                helpForFunctions.insert( std::pair<std::string,RbHelpFunction>( *alias , h) );
            }
            
        }
        
        
        
        if ( parser.testHelpEntry( *it ) == RbHelpParser::TYPE || parser.testHelpEntry( *it ) == RbHelpParser::DISTRIBUTION || parser.testHelpEntry( *it ) == RbHelpParser::MONITOR || parser.testHelpEntry( *it ) == RbHelpParser::MOVE )
        {
            
            RbHelpType* h = NULL;
            if ( parser.testHelpEntry( *it ) == RbHelpParser::TYPE )
            {
                h = parser.parseHelpType( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::DISTRIBUTION )
            {
                h = parser.parseHelpDistribution( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::MONITOR )
            {
                h = parser.parseHelpMonitor( *it );
            }
            else if ( parser.testHelpEntry( *it ) == RbHelpParser::MOVE )
            {
                h = parser.parseHelpMove( *it );
            }

            helpForTypes.insert( std::pair<std::string,RbHelpType*>( h->getName() , h) );
            helpTypeNames.insert( h->getName() );
            
            
            // create a map for all methods for this type
            std::map<std::string, RbHelpFunction> methodsHelp;
            const std::vector<RbHelpFunction>& method = h->getMethods();
            for (std::vector<RbHelpFunction>::const_iterator m = method.begin(); m != method.end(); ++m)
            {
                methodsHelp.insert( std::pair<std::string,RbHelpFunction>( m->getName() , *m) );
            }
            
            // add the methods to our global map
            helpForMethods.insert( std::pair<std::string, std::map<std::string,RbHelpFunction> >(h->getName(),methodsHelp) );
            
            
            // also add all aliases
            const std::vector<std::string>& aliases = h->getAliases();
            for (std::vector<std::string>::const_iterator alias = aliases.begin(); alias != aliases.end(); ++alias)
            {
                helpForTypes.insert( std::pair<std::string,RbHelpType*>( *alias , h->clone() ) );
                helpForMethods.insert( std::pair<std::string, std::map<std::string,RbHelpFunction> >(*alias,methodsHelp) );
            }
        }
        
        
    }
    
    
}