File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -158,12 +158,13 @@ namespace winmd::reader
158158
159159 // This won't invalidate any existing database or row_base (e.g. TypeDef) instances
160160 // However, it may invalidate iterators and references to namespace_members, because those are stored in std::vector
161- void add_database (std::string_view const & file)
161+ template <typename TypeFilter>
162+ void add_database (std::string_view const & file, TypeFilter filter)
162163 {
163164 auto & db = m_databases.emplace_back (file, this );
164165 for (auto && type : db.TypeDef )
165166 {
166- if (type.Flags ().value == 0 || is_nested (type))
167+ if (type.Flags ().value == 0 || is_nested (type) || ! filter (type) )
167168 {
168169 continue ;
169170 }
@@ -182,6 +183,11 @@ namespace winmd::reader
182183 }
183184 }
184185
186+ void add_database (std::string_view const & file)
187+ {
188+ add_database (file, default_type_filter{});
189+ }
190+
185191 std::vector<TypeDef> const & nested_types (TypeDef const & enclosing_type) const
186192 {
187193 auto it = m_nested_types.find (enclosing_type);
Original file line number Diff line number Diff line change @@ -60,6 +60,32 @@ TEST_CASE("cache_add")
6060 REQUIRE (JsonValue.TypeNamespace () == " Windows.Data.Json" );
6161}
6262
63+ TEST_CASE (" cache_add_filter" )
64+ {
65+ std::filesystem::path winmd_dir = get_local_winmd_path ();
66+ auto file_path = winmd_dir;
67+ file_path.append (" Windows.Foundation.winmd" );
68+
69+ cache c (file_path.string ());
70+
71+ TypeDef JsonValue = c.find (" Windows.Data.Json" , " JsonValue" );
72+ REQUIRE (!JsonValue);
73+
74+ file_path = winmd_dir;
75+ file_path.append (" Windows.Data.winmd" );
76+ c.add_database (file_path.string (), [](TypeDef const & type)
77+ {
78+ return !(type.TypeNamespace () == " Windows.Data.Json" && type.TypeName () == " JsonArray" );
79+ });
80+
81+ JsonValue = c.find (" Windows.Data.Json" , " JsonValue" );
82+ REQUIRE (!!JsonValue);
83+ REQUIRE (JsonValue.TypeName () == " JsonValue" );
84+ REQUIRE (JsonValue.TypeNamespace () == " Windows.Data.Json" );
85+
86+ REQUIRE (!c.find (" Windows.Data.Json" , " JsonArray" ));
87+ }
88+
6389TEST_CASE (" cache_add_duplicate" )
6490{
6591 std::filesystem::path winmd_dir = get_local_winmd_path ();
You can’t perform that action at this time.
0 commit comments