Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/impl/winmd_reader/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename TypeFilter>
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;
}
Expand All @@ -182,6 +183,11 @@ namespace winmd::reader
}
}

void add_database(std::string_view const& file)
{
add_database(file, default_type_filter{});
}

std::vector<TypeDef> const& nested_types(TypeDef const& enclosing_type) const
{
auto it = m_nested_types.find(enclosing_type);
Expand Down
26 changes: 26 additions & 0 deletions test/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down