Skip to content

Commit

Permalink
[lib] syntax and add missing api
Browse files Browse the repository at this point in the history
  • Loading branch information
tangxifan committed Sep 16, 2023
1 parent 6366479 commit 74b9f67
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions libs/libnamemanager/src/base/module_name_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
* |
Expand All @@ -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 */
3 changes: 3 additions & 0 deletions libs/libnamemanager/src/base/module_name_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Include header files required by the data structure definition
*******************************************************************/
#include <string>
#include <vector>
#include <map>

/* Begin namespace openfpga */
Expand All @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions libs/libnamemanager/src/io/read_xml_module_name_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 74b9f67

Please sign in to comment.