コード例 #1
0
ファイル: helptopic.cpp プロジェクト: mpharrigan/gromacs
bool
AbstractCompositeHelpTopic::writeSubTopicList(const HelpWriterContext &context,
        const std::string       &title) const
{
    if (context.outputFormat() != eHelpOutputFormat_Console)
    {
        Impl::SubTopicList::const_iterator topic;
        for (topic = impl_->subTopics_.begin(); topic != impl_->subTopics_.end(); ++topic)
        {
            const char *const title = (*topic)->title();
            if (!isNullOrEmpty(title))
            {
                context.outputFile().writeLine();
                HelpWriterContext subContext(context);
                subContext.enterSubSection(title);
                (*topic)->writeHelp(subContext);
            }
        }
        return true;
    }
    int maxNameLength = 0;
    Impl::SubTopicMap::const_iterator topic;
    for (topic = impl_->subTopicMap_.begin(); topic != impl_->subTopicMap_.end(); ++topic)
    {
        const char *const title = topic->second->title();
        if (!isNullOrEmpty(title))
        {
            int nameLength = static_cast<int>(topic->first.length());
            if (nameLength > maxNameLength)
            {
                maxNameLength = nameLength;
            }
        }
    }
    if (maxNameLength == 0)
    {
        return false;
    }
    TextWriter        &file = context.outputFile();
    TextTableFormatter formatter;
    formatter.addColumn(NULL, maxNameLength + 1, false);
    formatter.addColumn(NULL, 72 - maxNameLength, true);
    formatter.setFirstColumnIndent(4);
    file.writeLine(title);
    for (topic = impl_->subTopicMap_.begin(); topic != impl_->subTopicMap_.end(); ++topic)
    {
        const char *const name  = topic->first.c_str();
        const char *const title = topic->second->title();
        if (!isNullOrEmpty(title))
        {
            formatter.clear();
            formatter.addColumnLine(0, name);
            formatter.addColumnLine(1, title);
            file.writeString(formatter.formatRow());
        }
    }
    return true;
}
コード例 #2
0
ファイル: datafilefinder.cpp プロジェクト: friforever/gromacs
void DataFileFinder::setSearchPathFromEnv(const char *envVarName)
{
    if (!impl_)
    {
        impl_.reset(new Impl());
    }
    impl_->envName_ = envVarName;
    const char *const lib = getenv(envVarName);
    if (!isNullOrEmpty(lib))
    {
        std::vector<std::string>   &path        = impl_->searchPath_; // convenience
        const std::string           defaultPath = impl_->getDefaultPath();
        std::vector<std::string>    tmpPath;
        Path::splitPathEnvironment(lib, &tmpPath);
        std::set<std::string>       pathsSeen;
        pathsSeen.insert(defaultPath);
        for (auto &d : tmpPath)
        {
            if (!pathsSeen.count(d))
            {
                path.push_back(d);
                pathsSeen.insert(d);
            }
        }
        impl_->bEnvIsSet_ = true;
    }
}
コード例 #3
0
ファイル: stringutil.cpp プロジェクト: friforever/gromacs
bool endsWith(const char *str, const char *suffix)
{
    if (isNullOrEmpty(suffix))
    {
        return true;
    }
    const size_t strLength    = std::strlen(str);
    const size_t suffixLength = std::strlen(suffix);
    return (strLength >= suffixLength
            && std::strcmp(&str[strLength - suffixLength], suffix) == 0);
}
コード例 #4
0
ファイル: datafilefinder.cpp プロジェクト: friforever/gromacs
std::string DataFileFinder::Impl::getDefaultPath()
{
    const InstallationPrefixInfo installPrefix
        = getProgramContext().installationPrefix();
    if (!isNullOrEmpty(installPrefix.path))
    {
        const char *const dataPath
            = installPrefix.bSourceLayout ? "share" : GMX_INSTALL_GMXDATADIR;
        return Path::join(installPrefix.path, dataPath, "top");
    }
    return std::string();
}
コード例 #5
0
void DataFileFinder::setSearchPathFromEnv(const char *envVarName)
{
    if (!impl_.get())
    {
        impl_.reset(new Impl());
    }
    impl_->envName_ = envVarName;
    const char *const lib = getenv(envVarName);
    if (!isNullOrEmpty(lib))
    {
        impl_->bEnvIsSet_ = true;
        Path::splitPathEnvironment(lib, &impl_->searchPath_);
    }
}
コード例 #6
0
const IR::StructInitializerExpression* StructTypeReplacement::explode(
    const IR::Expression *root, cstring prefix) {
    auto vec = new IR::IndexedVector<IR::NamedExpression>();
    auto fieldType = ::get(structFieldMap, prefix);
    BUG_CHECK(fieldType, "No field for %1%", prefix);
    for (auto f : fieldType->fields) {
        cstring fieldName = prefix + "." + f->name.name;
        auto newFieldname = ::get(fieldNameRemap, fieldName);
        const IR::Expression* expr;
        if (!newFieldname.isNullOrEmpty()) {
            expr = new IR::Member(root, newFieldname);
        } else {
            expr = explode(root, fieldName);
        }
        vec->push_back(new IR::NamedExpression(f->name, expr));
    }
    return new IR::StructInitializerExpression(fieldType->name, *vec, false);
}
コード例 #7
0
const IR::Node* ReplaceStructs::postorder(IR::Member* expression) {
    // Find out if this applies to one of the parameters that are being replaced.
    const IR::Expression* e = expression;
    cstring prefix = "";
    while (auto mem = e->to<IR::Member>()) {
        e = mem->expr;
        prefix = cstring(".") + mem->member + prefix;
    }
    auto pe = e->to<IR::PathExpression>();
    if (pe == nullptr)
        return expression;
    // At this point we know that pe is an expression of the form
    // param.field1.etc.fieldN, where param has a type that needs to be replaced.
    auto decl = replacementMap->refMap->getDeclaration(pe->path, true);
    auto param = decl->to<IR::Parameter>();
    if (param == nullptr)
        return expression;
    auto repl = ::get(toReplace, param);
    if (repl == nullptr)
        return expression;
    auto newFieldName = ::get(repl->fieldNameRemap, prefix);
    const IR::Expression* result;
    if (newFieldName.isNullOrEmpty()) {
        auto type = replacementMap->typeMap->getType(getOriginal(), true);
        // This could be, for example, a method like setValid.
        if (!type->is<IR::Type_Struct>())
            return expression;
        if (getParent<IR::Member>() != nullptr)
            // We only want to process the outermost Member
            return expression;
        // Prefix is a reference to a field of the original struct whose
        // type is actually a struct itself.  We need to replace the field
        // with a struct initializer expression.  (This won't work if the
        // field is being used as a left-value.  Hopefully, all such uses
        // of a struct-valued field as a left-value have been already
        // replaced by the NestedStructs pass.)
        result = repl->explode(pe, prefix);
    } else {
        result = new IR::Member(pe, newFieldName);
    }
    LOG3("Replacing " << expression << " with " << result);
    return result;
}