v0.2.47..v0.2.48 changeset ApiEntityDisplayInfo.cpp
Garret Voltz edited this page Sep 27, 2019
·
1 revision
diff --git a/hoot-core/src/main/cpp/hoot/core/info/ApiEntityDisplayInfo.cpp b/hoot-core/src/main/cpp/hoot/core/info/ApiEntityDisplayInfo.cpp
index 8fd564b..8021cb3 100644
--- a/hoot-core/src/main/cpp/hoot/core/info/ApiEntityDisplayInfo.cpp
+++ b/hoot-core/src/main/cpp/hoot/core/info/ApiEntityDisplayInfo.cpp
@@ -46,7 +46,8 @@
#include <hoot/core/algorithms/subline-matching/SublineStringMatcher.h>
#include <hoot/core/conflate/matching/Match.h>
#include <hoot/core/conflate/merging/Merger.h>
-
+#include <hoot/core/algorithms/WayJoiner.h>
+#include <hoot/core/criterion/ConflatableElementCriterion.h>
// Qt
#include <QTextStream>
@@ -71,139 +72,6 @@ public:
static const int MAX_NAME_SIZE = 45;
static const int MAX_TYPE_SIZE = 18;
-template<typename ApiEntity>
-QString getApiEntities(const std::string& apiEntityBaseClassName, const QString& apiEntityType,
- const bool displayType,
- //the size of the longest names plus a 3 space buffer; the value passed in
- //here by callers may have to be adjusted over time for some entity types
- const int maxNameSize)
-{
- LOG_VARD(apiEntityBaseClassName);
- std::vector<std::string> classNames =
- Factory::getInstance().getObjectNamesByBase(apiEntityBaseClassName);
- LOG_VARD(classNames);
- ApiEntityNameComparator<ApiEntity> apiEntityNameComparator;
- std::sort(classNames.begin(), classNames.end(), apiEntityNameComparator);
- QString buffer;
- QTextStream ts(&buffer);
-
- for (size_t i = 0; i < classNames.size(); i++)
- {
- const std::string className = classNames[i];
- LOG_VARD(className);
-
- std::shared_ptr<ApiEntity> apiEntity(
- Factory::getInstance().constructObject<ApiEntity>(className));
-
- std::shared_ptr<ApiEntityInfo> apiEntityInfo =
- std::dynamic_pointer_cast<ApiEntityInfo>(apiEntity);
- if (!apiEntityInfo.get())
- {
- throw HootException(
- "Calls to printApiEntities must be made with classes that implement ApiEntityInfo.");
- }
-
- LOG_VARD(apiEntityInfo->getDescription());
- if (!apiEntityInfo->getDescription().isEmpty())
- {
- bool supportsSingleStat = false;
- std::shared_ptr<SingleStatistic> singleStat =
- std::dynamic_pointer_cast<SingleStatistic>(apiEntity);
- if (singleStat.get())
- {
- supportsSingleStat = true;
- }
-
- QString name = QString::fromStdString(className).replace("hoot::", "");
- //append '*' to the names of visitors that support the SingleStatistic interface
- if (supportsSingleStat)
- {
- name += "*";
- }
- const int indentAfterName = maxNameSize - name.size();
- const int indentAfterType = MAX_TYPE_SIZE - apiEntityType.size();
- QString line_buffer;
- QTextStream line(&line_buffer);
- line << " " << name << QString(indentAfterName, ' ');
- if (displayType)
- {
- line << apiEntityType << QString(indentAfterType, ' ');
- }
- line << apiEntityInfo->getDescription();
- LOG_VARD(line.readAll());
- ts << line.readAll() << endl;
- }
- }
- return ts.readAll();
-}
-
-// match/merger creators have a more roundabout way to get at the description, so we'll create a new
-// display method for them
-template<typename ApiEntity>
-QString getApiEntities2(const std::string& apiEntityClassName)
-{
- //the size of the longest names plus a 3 space buffer
- const int maxNameSize = 48;
-
- std::vector<std::string> names =
- Factory::getInstance().getObjectNamesByBase(apiEntityClassName);
- ApiEntityNameComparator<ApiEntity> apiEntityNameComparator;
- std::sort(names.begin(), names.end(), apiEntityNameComparator);
- LOG_VARD(names);
- QStringList output;
- for (size_t i = 0; i < names.size(); i++)
- {
- // get all names known by this creator
- std::shared_ptr<ApiEntity> mc(
- Factory::getInstance().constructObject<ApiEntity>(names[i]));
- std::vector<CreatorDescription> creators = mc->getAllCreators();
- LOG_VARD(creators.size());
-
- for (std::vector<CreatorDescription>::const_iterator itr = creators.begin();
- itr != creators.end(); ++itr)
- {
- CreatorDescription description = *itr;
- LOG_VARD(description);
- const QString name = QString::fromStdString(description.className).replace("hoot::", "");
- LOG_VARD(name);
- //this suppresses test and auxiliary rules files
- if (!name.endsWith("Test.js") && !name.endsWith("Rules.js"))
- {
- const int indentAfterName = maxNameSize - name.size();
- QString line = " " + name + QString(indentAfterName, ' ');
- line += description.description;
- if (description.experimental)
- line += " (experimental)";
- LOG_VARD(line);
- output.append(line);
- }
- }
- }
- output.sort();
-
- QString buffer;
- QTextStream ts(&buffer);
- for (int i = 0; i < output.size(); i++)
- ts << output.at(i) << endl;
-
- return ts.readAll();
-}
-
-QString ApiEntityDisplayInfo::_apiEntityTypeForBaseClass(const QString& className)
-{
- LOG_VARD(className);
- if (className.toStdString() == OsmMapOperation::className() ||
- Factory::getInstance().hasBase<OsmMapOperation>(className.toStdString()))
- {
- return "operation";
- }
- else if (className.toStdString() == ElementVisitor::className() ||
- Factory::getInstance().hasBase<ElementVisitor>(className.toStdString()))
- {
- return "visitor";
- }
- return "";
-}
QString ApiEntityDisplayInfo::getDisplayInfoOps(const QString& optName)
{
@@ -227,7 +95,7 @@ QString ApiEntityDisplayInfo::getDisplayInfoOps(const QString& optName)
QString buffer;
QTextStream ts(&buffer);
for (int i = 0; i < operations.size(); i++)
- {
+ {
QString className = operations[i];
LOG_VARD(className);
@@ -287,19 +155,20 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "; * = implements SingleStatistic):";
msg.prepend("Operators");
ts << msg << endl;
- ts << getApiEntities<ElementCriterion>(
+ ts << _getApiEntities<ElementCriterion, ElementCriterion>(
ElementCriterion::className(), "criterion", true, MAX_NAME_SIZE);
- ts << getApiEntities<OsmMapOperation>(
+ ts << _getApiEntities<OsmMapOperation, OsmMapOperation>(
OsmMapOperation::className(), "operation", true, MAX_NAME_SIZE);
- ts << getApiEntities<ElementVisitor>(ElementVisitor::className(), "visitor", true, MAX_NAME_SIZE);
+ ts << _getApiEntities<ElementVisitor, ElementVisitor>(
+ ElementVisitor::className(), "visitor", true, MAX_NAME_SIZE);
}
- // this is pretty repetitive :-(
+ // All of this from here on down is pretty repetitive :-(
else if (apiEntityType == "feature-extractors")
{
msg += "):";
msg.prepend("Feature Extractors");
ts << msg << endl;
- ts << getApiEntities<FeatureExtractor>(
+ ts << _getApiEntities<FeatureExtractor, FeatureExtractor>(
FeatureExtractor::className(), "feature extractor", false, MAX_NAME_SIZE);
}
else if (apiEntityType == "matchers")
@@ -307,15 +176,14 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "):";
msg.prepend("Matchers");
ts << msg << endl;
- ts << getApiEntities<Match>(
- Match::className(), "matcher", false, MAX_NAME_SIZE);
+ ts << _getApiEntities<Match, Match>(Match::className(), "matcher", false, MAX_NAME_SIZE);
}
else if (apiEntityType == "mergers")
{
msg += "):";
msg.prepend("Mergers");
ts << msg << endl;
- ts << getApiEntities<Merger>(
+ ts << _getApiEntities<Merger, Merger>(
Merger::className(), "merger", false, MAX_NAME_SIZE);
}
else if (apiEntityType == "match-creators")
@@ -323,28 +191,29 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "):";
msg.prepend("Conflate Match Creators");
ts << msg << endl;
- ts << getApiEntities2<MatchCreator>(MatchCreator::className());
+ ts << _getApiEntitiesForMatchMergerCreators<MatchCreator>(MatchCreator::className());
}
else if (apiEntityType == "merger-creators")
{
msg += "):";
msg.prepend("Conflate Merger Creators");
ts << msg << endl;
- ts << getApiEntities2<MergerCreator>(MergerCreator::className());
+ ts << _getApiEntitiesForMatchMergerCreators<MergerCreator>(MergerCreator::className());
}
else if (apiEntityType == "tag-mergers")
{
msg += "):";
msg.prepend("Tag Mergers");
ts << msg << endl;
- ts << getApiEntities<TagMerger>(TagMerger::className(), "tag merger", false, MAX_NAME_SIZE - 10);
+ ts << _getApiEntities<TagMerger, TagMerger>(
+ TagMerger::className(), "tag merger", false, MAX_NAME_SIZE - 10);
}
else if (apiEntityType == "string-comparators")
{
msg += "):";
msg.prepend("String Comparators");
ts << msg << endl;
- ts << getApiEntities<StringDistance>(
+ ts << _getApiEntities<StringDistance, StringDistance>(
StringDistance::className(), "string comparator", false, MAX_NAME_SIZE - 15);
}
else if (apiEntityType == "subline-matchers")
@@ -352,7 +221,7 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "):";
msg.prepend("Subline Matchers");
ts << msg << endl;
- ts << getApiEntities<SublineMatcher>(
+ ts << _getApiEntities<SublineMatcher, SublineMatcher>(
SublineMatcher::className(), "subline matcher", false, MAX_NAME_SIZE - 15);
}
else if (apiEntityType == "subline-string-matchers")
@@ -360,7 +229,7 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "):";
msg.prepend("Subline Matchers");
ts << msg << endl;
- ts << getApiEntities<SublineStringMatcher>(
+ ts << _getApiEntities<SublineStringMatcher, SublineStringMatcher>(
SublineStringMatcher::className(), "subline string matcher", false, MAX_NAME_SIZE - 15);
}
else if (apiEntityType == "value-aggregators")
@@ -368,10 +237,171 @@ QString ApiEntityDisplayInfo::getDisplayInfo(const QString& apiEntityType)
msg += "):";
msg.prepend("Value Aggregators");
ts << msg << endl;
- ts << getApiEntities<ValueAggregator>(
+ ts << _getApiEntities<ValueAggregator, ValueAggregator>(
ValueAggregator::className(), "value aggregator", false, MAX_NAME_SIZE - 10);
}
+ else if (apiEntityType == "way-joiners")
+ {
+ msg += "):";
+ msg.prepend("Way Joiners");
+ ts << msg << endl;
+ ts << _getApiEntities<WayJoiner, WayJoiner>(
+ WayJoiner::className(), "way joiner", false, MAX_NAME_SIZE - 10);
+ }
+ else if (apiEntityType == "conflatable-criteria")
+ {
+ msg += "):";
+ msg.prepend("Conflatable Criteria");
+ ts << msg << endl;
+ ts << _getApiEntities<ElementCriterion, ConflatableElementCriterion>(
+ ElementCriterion::className(), "conflatable criteria", false, MAX_NAME_SIZE - 10);
+ }
+ return ts.readAll();
+}
+
+template<typename ApiEntity, typename ApiEntityChild>
+QString ApiEntityDisplayInfo::_getApiEntities(
+ const std::string& apiEntityBaseClassName, const QString& apiEntityType,
+ const bool displayType,
+ //the size of the longest names plus a 3 space buffer; the value passed in
+ //here by callers may have to be adjusted over time for some entity types
+ const int maxNameSize)
+{
+ LOG_VARD(apiEntityBaseClassName);
+ std::vector<std::string> classNames =
+ Factory::getInstance().getObjectNamesByBase(apiEntityBaseClassName);
+ LOG_VARD(classNames);
+ ApiEntityNameComparator<ApiEntity> apiEntityNameComparator;
+ std::sort(classNames.begin(), classNames.end(), apiEntityNameComparator);
+ QString buffer;
+ QTextStream ts(&buffer);
+
+ for (size_t i = 0; i < classNames.size(); i++)
+ {
+ const std::string className = classNames[i];
+ LOG_VARD(className);
+
+ std::shared_ptr<ApiEntity> apiEntity(
+ Factory::getInstance().constructObject<ApiEntity>(className));
+
+ std::shared_ptr<ApiEntityInfo> apiEntityInfo =
+ std::dynamic_pointer_cast<ApiEntityInfo>(apiEntity);
+ if (!apiEntityInfo.get())
+ {
+ throw IllegalArgumentException(
+ "Calls to printApiEntities must be made with classes that implement ApiEntityInfo.");
+ }
+
+ if (ApiEntity::className() != ApiEntityChild::className())
+ {
+ std::shared_ptr<ApiEntityChild> child = std::dynamic_pointer_cast<ApiEntityChild>(apiEntity);
+ if (!child)
+ {
+ continue;
+ }
+ }
+
+ LOG_VARD(apiEntityInfo->getDescription());
+ if (!apiEntityInfo->getDescription().isEmpty())
+ {
+ bool supportsSingleStat = false;
+ std::shared_ptr<SingleStatistic> singleStat =
+ std::dynamic_pointer_cast<SingleStatistic>(apiEntity);
+ if (singleStat.get())
+ {
+ supportsSingleStat = true;
+ }
+
+ QString name = QString::fromStdString(className).replace("hoot::", "");
+ //append '*' to the names of visitors that support the SingleStatistic interface
+ if (supportsSingleStat)
+ {
+ name += "*";
+ }
+ const int indentAfterName = maxNameSize - name.size();
+ const int indentAfterType = MAX_TYPE_SIZE - apiEntityType.size();
+ QString line_buffer;
+ QTextStream line(&line_buffer);
+ line << " " << name << QString(indentAfterName, ' ');
+ if (displayType)
+ {
+ line << apiEntityType << QString(indentAfterType, ' ');
+ }
+ line << apiEntityInfo->getDescription();
+ LOG_VARD(line.readAll());
+ ts << line.readAll() << endl;
+ }
+ }
return ts.readAll();
}
+// match/merger creators have a more roundabout way to get at the description, so we'll create a new
+// display method for them
+template<typename ApiEntity>
+QString ApiEntityDisplayInfo::_getApiEntitiesForMatchMergerCreators(
+ const std::string& apiEntityClassName)
+{
+ //the size of the longest names plus a 3 space buffer
+ const int maxNameSize = 48;
+
+ std::vector<std::string> names =
+ Factory::getInstance().getObjectNamesByBase(apiEntityClassName);
+ ApiEntityNameComparator<ApiEntity> apiEntityNameComparator;
+ std::sort(names.begin(), names.end(), apiEntityNameComparator);
+ LOG_VARD(names);
+ QStringList output;
+ for (size_t i = 0; i < names.size(); i++)
+ {
+ // get all names known by this creator
+ std::shared_ptr<ApiEntity> mc(
+ Factory::getInstance().constructObject<ApiEntity>(names[i]));
+ std::vector<CreatorDescription> creators = mc->getAllCreators();
+ LOG_VARD(creators.size());
+
+ for (std::vector<CreatorDescription>::const_iterator itr = creators.begin();
+ itr != creators.end(); ++itr)
+ {
+ CreatorDescription description = *itr;
+ LOG_VARD(description);
+ const QString name = QString::fromStdString(description.className).replace("hoot::", "");
+ LOG_VARD(name);
+ //this suppresses test and auxiliary rules files
+ if (!name.endsWith("Test.js") && !name.endsWith("Rules.js"))
+ {
+ const int indentAfterName = maxNameSize - name.size();
+ QString line = " " + name + QString(indentAfterName, ' ');
+ line += description.description;
+ if (description.experimental)
+ line += " (experimental)";
+ LOG_VARD(line);
+ output.append(line);
+ }
+ }
+ }
+ output.sort();
+
+ QString buffer;
+ QTextStream ts(&buffer);
+ for (int i = 0; i < output.size(); i++)
+ ts << output.at(i) << endl;
+
+ return ts.readAll();
+}
+
+QString ApiEntityDisplayInfo::_apiEntityTypeForBaseClass(const QString& className)
+{
+ LOG_VARD(className);
+ if (className.toStdString() == OsmMapOperation::className() ||
+ Factory::getInstance().hasBase<OsmMapOperation>(className.toStdString()))
+ {
+ return "operation";
+ }
+ else if (className.toStdString() == ElementVisitor::className() ||
+ Factory::getInstance().hasBase<ElementVisitor>(className.toStdString()))
+ {
+ return "visitor";
+ }
+ return "";
+}
+
}