[lib] syntax and add missing api

This commit is contained in:
tangxifan 2023-09-15 17:00:02 -07:00
parent 636647902e
commit 74b9f673ec
3 changed files with 14 additions and 2 deletions

View File

@ -26,6 +26,14 @@ std::string ModuleNameMap::name(const std::string& tag) const {
return result->second;
}
std::vector<std::string> ModuleNameMap::tags() const {
std::vector<std::string> keys;
for (auto const& element : tag2names_) {
keys.push_back(element.first);
}
return keys;
}
int ModuleNameMap::set_tag_to_name_pair(const std::string& tag, const std::string& name) {
/* tagA <--x--> nameA
* |
@ -45,6 +53,7 @@ int ModuleNameMap::set_tag_to_name_pair(const std::string& tag, const std::strin
tag2names_[tag] = name;
/* Clean up */
name2tags_.erase(name);
return CMD_EXEC_SUCCESS;
}
} /* end namespace openfpga */

View File

@ -5,6 +5,7 @@
* Include header files required by the data structure definition
*******************************************************************/
#include <string>
#include <vector>
#include <map>
/* Begin namespace openfpga */
@ -17,6 +18,8 @@ class ModuleNameMap {
public: /* Public accessors */
/** @brief Get customized name with a given tag */
std::string name(const std::string& tag) const;
/** @brief return a list of all the current keys */
std::vector<std::string> tags() const;
public: /* Public mutators */
/** @brief Create the one-on-one mapping between an built-in name and a customized name. Return 0 for success, return 1 for fail */

View File

@ -30,10 +30,10 @@ static int read_xml_module_name_binding(pugi::xml_node& xml_binding,
const pugiutil::loc_data& loc_data,
ModuleNameMap& module_name_map) {
std::string default_name =
get_attribute(xml_port, XML_MODULE_NAME_ATTRIBUTE_DEFAULT, loc_data)
get_attribute(xml_binding, XML_MODULE_NAME_ATTRIBUTE_DEFAULT, loc_data)
.as_string();
std::string given_name =
get_attribute(xml_port, XML_MODULE_NAME_ATTRIBUTE_GIVEN, loc_data)
get_attribute(xml_binding, XML_MODULE_NAME_ATTRIBUTE_GIVEN, loc_data)
.as_string();
return module_name_map.set_tag_to_name_pair(default_name, given_name);