Refactor template class arg_filter into string_arg_filter instead, support for IfcProxy.Tag (untested, did not find suitable test input yet).

This commit is contained in:
Stinkfist0
2017-02-17 09:27:37 +02:00
committed by Thomas Krijnen
parent 1b7d38a56d
commit 7101ac22c8
2 changed files with 26 additions and 30 deletions
+8 -7
View File
@@ -436,7 +436,7 @@ int main(int argc, char** argv)
}
// IfcRoot.GlobalId
IfcGeom::arg_filter<IfcSchema::IfcRoot, 0, std::string> guid_filter;
IfcGeom::string_arg_filter guid_filter(IfcSchema::Type::IfcRoot, 0);
guid_filter.traverse = traverse;
if (include_filter.arg == GUID_ARG) {
guid_filter.include = true;
@@ -452,7 +452,7 @@ int main(int argc, char** argv)
// Note: skipping IfcRoot OwnerHistory, argument index 1
// IfcRoot.Name
IfcGeom::arg_filter<IfcSchema::IfcRoot, 2, std::string> name_filter;
IfcGeom::string_arg_filter name_filter(IfcSchema::Type::IfcRoot, 2);
name_filter.traverse = traverse;
if (include_filter.arg == NAME_ARG) {
name_filter.include = true;
@@ -466,7 +466,7 @@ int main(int argc, char** argv)
}
// IfcRoot.Description
IfcGeom::arg_filter<IfcSchema::IfcRoot, 3, std::string> desc_filter;
IfcGeom::string_arg_filter desc_filter(IfcSchema::Type::IfcRoot, 3);
desc_filter.traverse = traverse;
if (include_filter.arg == DESC_ARG) {
desc_filter.include = true;
@@ -479,10 +479,11 @@ int main(int argc, char** argv)
filters.push_back(boost::ref(desc_filter));
}
/// @todo IfcProxy.Tag
//IfcGeom::arg_filter<IfcSchema::IfcProxy, 8, std::string> tag_filter;
// IfcElement.Tag
IfcGeom::arg_filter<IfcSchema::IfcElement, 7, std::string> tag_filter;
// IfcProxy.Tag & IfcElement.Tag
IfcGeom::string_arg_filter::arg_map_t tag_args;
tag_args[IfcSchema::Type::IfcProxy] = 8;
tag_args[IfcSchema::Type::IfcElement] = 7;
IfcGeom::string_arg_filter tag_filter(tag_args);
tag_filter.traverse = traverse;
if (include_filter.arg == TAG_ARG) {
tag_filter.include = true;
+18 -23
View File
@@ -102,32 +102,27 @@ namespace IfcGeom
}
};
/// @todo Maybe not use template class for this after all. Attribute name would be better
/// than index, but IfcBaseClass doesn't have getArgument(name) (IfcLateBoundEntity would have though).
template<class IfcType, unsigned short ArgIndex, typename ArgType>
struct arg_filter : public wildcard_filter
struct string_arg_filter : public wildcard_filter
{
arg_filter()
{
#ifndef NDEBUG
IfcType dummy(0);
assert(ArgIndex < dummy.getArgumentCount());
#endif
}
arg_filter(bool include, bool traverse, const std::set<std::string>& patterns)
: wildcard_filter(include, traverse, patterns)
{
#ifndef NDEBUG
IfcType dummy(0);
assert(ArgIndex < dummy.getArgumentCount());
#endif
populate(patterns);
}
// Using this for now in order to overcome the fact that different classes have the argument at different indices.
typedef std::map<IfcSchema::Type::Enum, unsigned short> arg_map_t;
arg_map_t args;
ArgType value(IfcSchema::IfcProduct* prod) const
/// @todo Take only attribute name when IfcBaseClass and IfcLateBoundEntity are merged.
string_arg_filter(arg_map_t args) : args(args) {}
string_arg_filter(IfcSchema::Type::Enum type, unsigned short index) { args[type] = index; }
std::string value(IfcSchema::IfcProduct* prod) const
{
Argument *arg = prod->is(IfcType::Class()) ? prod->entity->getArgument(ArgIndex) : 0;
return arg && !arg->isNull() ? *arg : ArgType();
for (arg_map_t::const_iterator it = args.begin(); it != args.end(); ++it) {
if (prod->is(it->first)) {
Argument *arg = (it->second <= prod->entity->getArgumentCount() ? prod->entity->getArgument(it->second) : 0);
if (arg && !arg->isNull()) {
return *arg;
}
}
}
return "";
}
bool operator()(IfcSchema::IfcProduct* prod) const