| 960 | } |
| 961 | |
| 962 | void Database::readFlexshelfLayout(std::string const &layout_file) { |
| 963 | // ==================== Read Layout ==================== |
| 964 | |
| 965 | pugi::xml_document doc; |
| 966 | pugi::xml_parse_result result = doc.load_file(layout_file.c_str()); |
| 967 | if (!result) { |
| 968 | openparfPrint(kError, "failed to open file %s for read\n", layout_file.c_str()); |
| 969 | return; |
| 970 | } |
| 971 | pugi::xml_node arch = doc.child("arch"); |
| 972 | pugi::xml_node core = arch.child("core"); |
| 973 | BookshelfDatabaseCallbacks cbk(*this); |
| 974 | openparfPrint(kInfo, "read layout from %s\n", layout_file.c_str()); |
| 975 | |
| 976 | // ------------------- read sites ------------------- |
| 977 | struct SiteSize { |
| 978 | int32_t width; |
| 979 | int32_t height; |
| 980 | int32_t offset_x; |
| 981 | int32_t offset_y; |
| 982 | }; |
| 983 | |
| 984 | int32_t num_tile = 0; |
| 985 | std::unordered_map<std::string, std::pair<int32_t, int32_t>> tile_sizes; |
| 986 | std::unordered_map<std::string, std::vector<SiteSize>> site_sizes; |
| 987 | for (pugi::xml_node tile : arch.child("tile_blocks").children("tile")) { |
| 988 | std::string type = tile.attribute("type").as_string(); |
| 989 | int32_t tile_width = tile.attribute("width").as_int(); |
| 990 | int32_t tile_height = tile.attribute("height").as_int(); |
| 991 | num_tile += 1; |
| 992 | tile_sizes[type] = {tile_width, tile_height}; |
| 993 | |
| 994 | if (tile.children("sub_tiles").empty()) { |
| 995 | // read site size |
| 996 | site_sizes[type].push_back({tile_width, tile_height, 0, 0}); |
| 997 | openparfPrint(kInfo, "tile %s size: %d %d\n", type.c_str(), tile_width, tile_height); |
| 998 | |
| 999 | // read resource capacity |
| 1000 | std::vector<std::pair<std::string, uint32_t>> resource_caps; |
| 1001 | for (pugi::xml_node resource : tile.children("resource")) { |
| 1002 | std::string resource_name = resource.attribute("name").as_string(); |
| 1003 | int32_t cap = resource.attribute("num").as_int(); |
| 1004 | resource_caps.emplace_back(resource_name, cap); |
| 1005 | openparfPrint(kInfo, "tile %s resource %s capacity %d\n", type.c_str(), resource_name.c_str(), cap); |
| 1006 | } |
| 1007 | cbk.setSiteResources(type, resource_caps); |
| 1008 | } else { |
| 1009 | // read sub tile size |
| 1010 | for (pugi::xml_node sub_tile : tile.child("sub_tiles").children("sub_tile")) { |
| 1011 | int32_t width = sub_tile.attribute("width").as_int(); |
| 1012 | int32_t height = sub_tile.attribute("height").as_int(); |
| 1013 | int32_t offset_x = sub_tile.attribute("offset_x").as_int(); |
| 1014 | int32_t offset_y = sub_tile.attribute("offset_y").as_int(); |
| 1015 | site_sizes[type].push_back({width, height, offset_x, offset_y}); |
| 1016 | openparfPrint(kInfo, "tile %s sub site size: %d %d offset: %d %d\n", type.c_str(), width, height, offset_x, |
| 1017 | offset_y); |
| 1018 | } |
| 1019 |
nothing calls this directly
no test coverage detected