Beispiel #1
0
bool
OptionsCont::processMetaOptions(bool missingOptions) {
    if (missingOptions) {
        // no options are given
        std::cout << myFullName << std::endl;
        std::cout << " Build features: " << HAVE_ENABLED << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        std::cout << " License GPLv3+: GNU GPL Version 3 or later <http://gnu.org/licenses/gpl.html>\n";
        std::cout << " Use --help to get the list of options." << std::endl;
        return true;
    }

    // check whether the help shall be printed
    if (getBool("help")) {
        std::cout << myFullName << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        printHelp(std::cout);
        return true;
    }
    // check whether the help shall be printed
    if (getBool("version")) {
        std::cout << myFullName << std::endl;
        std::cout << " Build features: " << HAVE_ENABLED << std::endl;
        for (std::vector<std::string>::const_iterator it =
                    myCopyrightNotices.begin(); it != myCopyrightNotices.end(); ++it) {
            std::cout << " " << *it << std::endl;
        }
        std::cout << "\n" << myFullName << " is part of SUMO.\n";
        std::cout << "SUMO is free software: you can redistribute it and/or modify\n";
        std::cout << "it under the terms of the GNU General Public License as published by\n";
        std::cout << "the Free Software Foundation, either version 3 of the License, or\n";
        std::cout << "(at your option) any later version.\n\n";
        std::cout << "This program is distributed in the hope that it will be useful,\n";
        std::cout << "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
        std::cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
        std::cout << "GNU General Public License for more details.\n\n";
        std::cout << "You should have received a copy of the GNU General Public License\n";
        std::cout << "along with this program. If not, see http://www.gnu.org/licenses/gpl.html" << std::endl;
        return true;
    }
    // check whether the settings shall be printed
    if (exists("print-options") && getBool("print-options")) {
        std::cout << (*this);
    }
    // check whether something has to be done with options
    // whether the current options shall be saved
    if (isSet("save-configuration", false)) { // sumo-gui does not register these
        if (getString("save-configuration") == "-" || getString("save-configuration") == "stdout") {
            writeConfiguration(std::cout, true, false, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-configuration").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save configuration to '" + getString("save-configuration") + "'");
        } else {
            writeConfiguration(out, true, false, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written configuration to '" + getString("save-configuration") + "'");
            }
            return true;
        }
    }
    // whether the template shall be saved
    if (isSet("save-template", false)) { // sumo-gui does not register these
        if (getString("save-template") == "-" || getString("save-template") == "stdout") {
            writeConfiguration(std::cout, false, true, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-template").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save template to '" + getString("save-template") + "'");
        } else {
            writeConfiguration(out, false, true, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written template to '" + getString("save-template") + "'");
            }
            return true;
        }
    }
    if (isSet("save-schema", false)) { // sumo-gui does not register these
        if (getString("save-schema") == "-" || getString("save-schema") == "stdout") {
            writeSchema(std::cout, getBool("save-commented"));
            return true;
        }
        std::ofstream out(getString("save-schema").c_str());
        if (!out.good()) {
            throw ProcessError("Could not save schema to '" + getString("save-schema") + "'");
        } else {
            writeSchema(out, getBool("save-commented"));
            if (getBool("verbose")) {
                WRITE_MESSAGE("Written schema to '" + getString("save-schema") + "'");
            }
            return true;
        }
    }
    return false;
}
Beispiel #2
0
void Index::open(FileSystemPtr& pFileSys, AccessMode am,
                 const DocumentSchema* pDocSchema)
{
    FIRTEX_ASSERT2(m_pFileSys.isNull());
    m_pFileSys = pFileSys;
    m_accessMode = am;
	
    BarrelsInfoPtr pBarrelsInfo(new BarrelsInfo());
    pBarrelsInfo->read(pFileSys);//read barrels Info

    if (am == WRITE)
    {
        if (!pDocSchema)
        {
            FIRTEX_THROW(InvalidConfigException, "Schema is empty in write mode.");
        }

        m_pDocSchema = new DocumentSchema(*pDocSchema);
        writeSchema(m_pDocSchema, pFileSys);

        pBarrelsInfo->remove(m_pFileSys);

        m_pComponentBuilder = new ComponentBuilder();
        m_pComponentBuilder->init(m_pDocSchema);
        initAnalyzerMapper();

        m_pIndexBarrelKeeper = new IndexBarrelKeeper(m_pFileSys, m_pDocSchema.get(),
                m_pComponentBuilder.get(), m_pAnalyzerMapper.get());
        m_pIndexBarrelKeeper->init(pBarrelsInfo, IndexBarrelKeeper::WRITE);

        openWriter();
    }
    else // READ, APPEND or RDWR mode
    {
        if (pBarrelsInfo->getIndexVersion() != FX_INDEX_VERSION)
        {
            FIRTEX_THROW(VersionException, "Incompatible index version.");
        }
        if (pBarrelsInfo->getBarrelCount() > 0)
        {
            DocumentSchemaPtr pSchemaExist = readSchema(m_pFileSys);
            if (pSchemaExist.isNull())
            {
                FIRTEX_THROW(IndexCollapseException, "Read schema FAILED.");
            }
            if (pDocSchema && !pSchemaExist->isEqual(*pDocSchema))
            {
                FIRTEX_THROW(IllegalArgumentException,
                        "The given document schema is not equal to the existing schema.");
            }
            m_pDocSchema = pSchemaExist;
        }
        else
        {
            if (!pDocSchema)
            {
                FIRTEX_THROW(IllegalArgumentException,
                        "No document schema is specified.");
            }
            m_pDocSchema = new DocumentSchema(*pDocSchema);
        }

        m_pComponentBuilder = new ComponentBuilder();
        m_pComponentBuilder->init(m_pDocSchema);
        initAnalyzerMapper();

        m_pIndexBarrelKeeper = new IndexBarrelKeeper(m_pFileSys, m_pDocSchema.get(),
                m_pComponentBuilder.get(), m_pAnalyzerMapper.get());

        if (am == READ || am == RDWR)
        {
            m_pIndexBarrelKeeper->init(pBarrelsInfo, (am == READ) ?
                    IndexBarrelKeeper::READ : IndexBarrelKeeper::RDWR);

            openReader();
            if (am == RDWR)
            {
                openWriter();
            }
        }
        else if (am == APPEND)
        {
            m_pIndexBarrelKeeper->init(pBarrelsInfo, IndexBarrelKeeper::WRITE);
            openWriter();
        }
    }
}