diff --git a/src/impl/winmd_reader/cache.h b/src/impl/winmd_reader/cache.h index b6d0f4c..6d113e5 100644 --- a/src/impl/winmd_reader/cache.h +++ b/src/impl/winmd_reader/cache.h @@ -158,12 +158,13 @@ namespace winmd::reader // This won't invalidate any existing database or row_base (e.g. TypeDef) instances // However, it may invalidate iterators and references to namespace_members, because those are stored in std::vector - void add_database(std::string_view const& file) + template + void add_database(std::string_view const& file, TypeFilter filter) { auto& db = m_databases.emplace_back(file, this); for (auto&& type : db.TypeDef) { - if (type.Flags().value == 0 || is_nested(type)) + if (type.Flags().value == 0 || is_nested(type) || !filter(type)) { continue; } @@ -182,6 +183,11 @@ namespace winmd::reader } } + void add_database(std::string_view const& file) + { + add_database(file, default_type_filter{}); + } + std::vector const& nested_types(TypeDef const& enclosing_type) const { auto it = m_nested_types.find(enclosing_type); diff --git a/test/cache.cpp b/test/cache.cpp index a464a81..f589dce 100644 --- a/test/cache.cpp +++ b/test/cache.cpp @@ -60,6 +60,32 @@ TEST_CASE("cache_add") REQUIRE(JsonValue.TypeNamespace() == "Windows.Data.Json"); } +TEST_CASE("cache_add_filter") +{ + std::filesystem::path winmd_dir = get_local_winmd_path(); + auto file_path = winmd_dir; + file_path.append("Windows.Foundation.winmd"); + + cache c(file_path.string()); + + TypeDef JsonValue = c.find("Windows.Data.Json", "JsonValue"); + REQUIRE(!JsonValue); + + file_path = winmd_dir; + file_path.append("Windows.Data.winmd"); + c.add_database(file_path.string(), [](TypeDef const& type) + { + return !(type.TypeNamespace() == "Windows.Data.Json" && type.TypeName() == "JsonArray"); + }); + + JsonValue = c.find("Windows.Data.Json", "JsonValue"); + REQUIRE(!!JsonValue); + REQUIRE(JsonValue.TypeName() == "JsonValue"); + REQUIRE(JsonValue.TypeNamespace() == "Windows.Data.Json"); + + REQUIRE(!c.find("Windows.Data.Json", "JsonArray")); +} + TEST_CASE("cache_add_duplicate") { std::filesystem::path winmd_dir = get_local_winmd_path();