⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 database.cxx

📁 移植到WLIT项目的redboot源代码
💻 CXX
📖 第 1 页 / 共 5 页
字号:
        CYG_REPORT_RETURN();        return template_i->second.versions;    }        CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_versions()");    static std::vector<std::string> dummy;    return dummy;}std::stringCdlPackagesDatabaseBody::get_template_filename(std::string template_name, std::string version_name) const{    CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_filename");    CYG_REPORT_FUNCARG1XV(this);    CYG_PRECONDITION_THISC();    // Given the way templates are identified, the filename can be determined    // easily by concatenating a few strings. The only complication is that    // version_name may be an empty string, indicating that the most recent    // version should be used.    std::map<std::string,template_data>::const_iterator template_i = templates.find(template_name);    if (template_i == templates.end()) {        CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_filename");        CYG_REPORT_RETURN();        return "";    }    if ("" == version_name) {        CYG_ASSERTC(0 != template_i->second.versions.size());        version_name = template_i->second.versions[0];    } else {        std::vector<std::string>::const_iterator vsn_i = std::find(template_i->second.versions.begin(),                                                                   template_i->second.versions.end(), version_name);        if (vsn_i == template_i->second.versions.end()) {            CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_template_filename");            CYG_REPORT_RETURN();            return "";        }    }    std::string result = component_repository + "/templates/" + template_name + "/" + version_name + ".ect";    CYG_REPORT_RETURN();    return result;}// ----------------------------------------------------------------------------// The descriptions now live in an eCos savefile, i.e. a Tcl script, so// extracting them can be relatively expensive and needs to happen on// a just-in-time basis.const std::stringCdlPackagesDatabaseBody::get_template_description(std::string template_name, std::string version_name){    CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_description");    CYG_REPORT_FUNCARG1XV(this);    CYG_PRECONDITION_THISC();    // Is this a known template?    std::map<std::string, struct template_data>::iterator template_i = templates.find(template_name);    if (template_i == templates.end()) {        CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_description");        CYG_REPORT_RETURN();        return "";    }    // Is it a known version of the template?    if ("" == version_name) {        CYG_ASSERTC(0 != template_i->second.versions.size());        version_name = template_i->second.versions[0];    } else {        if (std::find(template_i->second.versions.begin(), template_i->second.versions.end(), version_name) ==            template_i->second.versions.end()) {            CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_template_description");            CYG_REPORT_RETURN();            return "";        }    }    // We have a valid template and version. Has the version file in    // question been read in yet?    std::map<std::string, struct template_version_data>::iterator version_i;    version_i = template_i->second.version_details.find(version_name);    if (version_i != template_i->second.version_details.end()) {        CYG_REPORT_RETURN();        return version_i->second.description;    }        std::string filename = this->get_template_filename(template_name, version_name);    if ("" == filename) {        CYG_REPORT_RETURN();        return "";    }     extract_template_details(filename, template_i->second.version_details[version_name].description,                             template_i->second.version_details[version_name].packages);    CYG_REPORT_RETURN();    return template_i->second.version_details[version_name].description;}// ----------------------------------------------------------------------------// Similarly extracting package information needs to happen on a// just-in-time basis.const std::vector<std::string>&CdlPackagesDatabaseBody::get_template_packages(std::string template_name, std::string version_name){    CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_template_packages");    CYG_REPORT_FUNCARG1XV(this);    CYG_PRECONDITION_THISC();    static std::vector<std::string> dummy;        // Is this a known template?    std::map<std::string, struct template_data>::iterator template_i = templates.find(template_name);    if (template_i == templates.end()) {        CYG_FAIL("Invalid template name passed to CdlPackagesDatabase::get_template_packages");        CYG_REPORT_RETURN();        return dummy;    }    // Is it a known version of the template?    if ("" == version_name) {        CYG_ASSERTC(0 != template_i->second.versions.size());        version_name = template_i->second.versions[0];    } else {        if (std::find(template_i->second.versions.begin(), template_i->second.versions.end(), version_name) ==            template_i->second.versions.end()) {            CYG_FAIL("Invalid template version passed to CdlPackagesDatabase::get_packages");            CYG_REPORT_RETURN();            return dummy;        }    }    // We have a valid template and version. Has the version file in    // question been read in yet?    std::map<std::string, struct template_version_data>::iterator version_i;    version_i = template_i->second.version_details.find(version_name);    if (version_i != template_i->second.version_details.end()) {        CYG_REPORT_RETURN();        return version_i->second.packages;    }        std::string filename = this->get_template_filename(template_name, version_name);    if ("" == filename) {        CYG_REPORT_RETURN();        return dummy;    }     extract_template_details(filename, template_i->second.version_details[version_name].description,                             template_i->second.version_details[version_name].packages);    CYG_REPORT_RETURN();    return template_i->second.version_details[version_name].packages;}// ----------------------------------------------------------------------------// Extracting the description and package information involves running// the script through a Tcl interpreter extended with the appropriate// commands. Most of the savefile information is irrelevant and is handled// by extract_ignore(). The commands of interest are cdl_configuration and// its sub-commands description and package.static intextract_ignore(CdlInterpreter interp, int argc, char** argv){    return TCL_OK;}static intextract_cdl_configuration(CdlInterpreter interp, int argc, char** argv){    CYG_REPORT_FUNCNAMETYPE("extract_cdl_configuration", "result %d");    CYG_REPORT_FUNCARG2XV(interp, argc);    CYG_PRECONDITION_CLASSC(interp);    int result = TCL_OK;        // usage: cdl_configuration <name> <body>    if (3 != argc) {        interp->set_result("Invalid cdl_configuration command in template, expecting two arguments");        result = TCL_ERROR;    } else {        // Ignore the first argument for now.        std::string tmp;        result = interp->eval(argv[2], tmp);                // After processing the cdl_configuration command the description and        // package information should be known. There is no point in processing        // the rest of the file.        if (TCL_OK == result) {            interp->set_result("OK");            result = TCL_ERROR;        }    }    CYG_REPORT_RETVAL(result);    return result;}static intextract_cdl_description(CdlInterpreter interp, int argc, char** argv){    CYG_REPORT_FUNCNAMETYPE("extract_cdl_description", "result %d");    CYG_REPORT_FUNCARG2XV(interp, argc);    CYG_PRECONDITION_CLASSC(interp);    int result = TCL_OK;        // usage: package <name>    if (2 != argc) {        interp->set_result("Invalid description command in template, expecting just one argument");        result = TCL_ERROR;    } else {        ClientData client_data = interp->get_assoc_data(template_description_key);        CYG_ASSERTC(0 != client_data);        std::string* result_ptr = static_cast<std::string*>(client_data);        *result_ptr = argv[1];    }    CYG_REPORT_RETVAL(result);    return result;}static intextract_cdl_package(CdlInterpreter interp, int argc, char** argv){    CYG_REPORT_FUNCNAMETYPE("extract_cdl_package", "result %d");    CYG_REPORT_FUNCARG2XV(interp, argc);    CYG_PRECONDITION_CLASSC(interp);    int result = TCL_OK;        // usage: package <name> <version>    if (2 > argc) {        interp->set_result("Invalid package command in template, expecting two arguments");        result = TCL_ERROR;    } else {        ClientData client_data = interp->get_assoc_data(template_packages_key);        CYG_ASSERTC(0 != client_data);        std::vector<std::string>* result_ptr = static_cast<std::vector<std::string>*>(client_data);        result_ptr->push_back(argv[1]);    }    CYG_REPORT_RETVAL(result);    return result;}voidCdlPackagesDatabaseBody::extract_template_details(std::string filename, std::string& description,                                                      std::vector<std::string>& packages){    CYG_REPORT_FUNCNAME("CdlPackagesDatabase::extract_template_description");    CdlInterpreter interp = CdlInterpreterBody::make();    interp->set_assoc_data(template_description_key, static_cast<ClientData>(&description));    interp->set_assoc_data(template_packages_key,    static_cast<ClientData>(&packages));    static CdlInterpreterCommandEntry extract_commands[] =    {        CdlInterpreterCommandEntry("cdl_savefile_version",  &extract_ignore                 ),        CdlInterpreterCommandEntry("cdl_savefile_command",  &extract_ignore                 ),        CdlInterpreterCommandEntry("cdl_configuration",     &extract_cdl_configuration      ),        CdlInterpreterCommandEntry("hardware",              &extract_ignore                 ),        CdlInterpreterCommandEntry("template",              &extract_ignore                 ),        CdlInterpreterCommandEntry("description",           &extract_cdl_description        ),        CdlInterpreterCommandEntry("package",               &extract_cdl_package            ),        CdlInterpreterCommandEntry("unknown",               &extract_ignore                 ),        CdlInterpreterCommandEntry("",                      0                               )    };    std::vector<CdlInterpreterCommandEntry> new_commands;    for (int i = 0; 0 != extract_commands[i].command; i++) {        new_commands.push_back(extract_commands[i]);    }    interp->push_commands(new_commands);    std::string tmp;    int result = interp->eval_file(filename, tmp);    // Special escape mechanism, see extract_cdl_configuration() above    if ((TCL_ERROR == result) && ("OK" == tmp)) {        result = TCL_OK;    }#if 0        if (TCL_OK != result) {        // No obvious way of recovering just yet    }#endif    delete interp;                               CYG_REPORT_RETURN();}//}}}//{{{  CdlPackagesDatabase:: get_valid_cflags()                 // ----------------------------------------------------------------------------const std::vector<std::string>&CdlPackagesDatabaseBody::get_valid_cflags(){    CYG_REPORT_FUNCNAME("CdlPackagesDatabase::get_valid_compiler_flags");    static std::vector<std::string> result_vec;    static const char* valid_flags[] = {        "ARCHFLAGS",  "CARCHFLAGS",  "CXXARCHFLAGS",  "LDARCHFLAGS",        "ERRFLAGS",   "CERRFLAGS",   "CXXERRFLAGS",   "LDERRFLAGS",        "LANGFLAGS",  "CLANGFLAGS",  "CXXLANGFLAGS",  "LDLANGFLAGS",        "DBGFLAGS",   "CDBGFLAGS",   "CXXDBGFLAGS",   "LDDBGFLAGS",        "EXTRAFLAGS", "CEXTRAFLAGS", "CXXEXTRAFLAGS", "LDEXTRAFLAGS",        0    };    if (0 == result_vec.size()) {        for (int i = 0; 0 != valid_flags[i]; i++) {            result_vec.push_back(valid_flags[i]);        }    }    CYG_REPORT_RETURN();    return result_vec;}//}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -