summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2018-08-30 14:47:39 +0200
committerGitHub <noreply@github.com>2018-08-30 14:47:39 +0200
commitcef4c0f9d7c084f320e77abb2a93522acd7f3f53 (patch)
treea557b37dcd5038bc122ee6f412cbc03c8fcaae17 /searchlib
parent2aab85e0c1f25cd272e456861cc5b5c7821ff5ea (diff)
parentbf165e376dcd6d742b60351e056e46b1bf0f7ee3 (diff)
Merge pull request #6736 from vespa-engine/toregge/use-proper-variant-of-attribute-node-integer-handler
Make AttributeNode::IntegerHandler a templated class.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/expression/attributenode.cpp14
-rw-r--r--searchlib/src/vespa/searchlib/expression/attributenode.h2
2 files changed, 11 insertions, 5 deletions
diff --git a/searchlib/src/vespa/searchlib/expression/attributenode.cpp b/searchlib/src/vespa/searchlib/expression/attributenode.cpp
index 2cf9c57f5de..0d8f68c1f3e 100644
--- a/searchlib/src/vespa/searchlib/expression/attributenode.cpp
+++ b/searchlib/src/vespa/searchlib/expression/attributenode.cpp
@@ -13,17 +13,18 @@ using search::attribute::BasicType;
IMPLEMENT_EXPRESSIONNODE(AttributeNode, FunctionNode);
+template <typename V>
class AttributeNode::IntegerHandler : public AttributeNode::Handler
{
public:
IntegerHandler(ResultNode & result) :
Handler(),
- _vector(((IntegerResultNodeVector &)result).getVector()),
+ _vector(((V &)result).getVector()),
_wVector()
{ }
void handle(const AttributeResult & r) override;
private:
- IntegerResultNodeVector::Vector & _vector;
+ typename V::Vector & _vector;
std::vector<search::attribute::IAttributeVector::WeightedInt> _wVector;
};
@@ -143,15 +144,19 @@ void AttributeNode::onPrepare(bool preserveAccurateTypes)
switch (basicType) {
case BasicType::INT8:
setResultType(std::make_unique<Int8ResultNodeVector>());
+ _handler = std::make_unique<IntegerHandler<Int8ResultNodeVector>>(updateResult());
break;
case BasicType::INT16:
setResultType(std::make_unique<Int16ResultNodeVector>());
+ _handler = std::make_unique<IntegerHandler<Int16ResultNodeVector>>(updateResult());
break;
case BasicType::INT32:
setResultType(std::make_unique<Int32ResultNodeVector>());
+ _handler = std::make_unique<IntegerHandler<Int32ResultNodeVector>>(updateResult());
break;
case BasicType::INT64:
setResultType(std::make_unique<Int64ResultNodeVector>());
+ _handler = std::make_unique<IntegerHandler<Int64ResultNodeVector>>(updateResult());
break;
default:
throw std::runtime_error("This is no valid integer attribute " + attribute->getName());
@@ -159,8 +164,8 @@ void AttributeNode::onPrepare(bool preserveAccurateTypes)
}
} else {
setResultType(std::make_unique<IntegerResultNodeVector>());
+ _handler = std::make_unique<IntegerHandler<IntegerResultNodeVector>>(updateResult());
}
- _handler = std::make_unique<IntegerHandler>(updateResult());
} else {
if (preserveAccurateTypes) {
switch (basicType) {
@@ -214,7 +219,8 @@ void AttributeNode::onPrepare(bool preserveAccurateTypes)
}
}
-void AttributeNode::IntegerHandler::handle(const AttributeResult & r)
+template <typename V>
+void AttributeNode::IntegerHandler<V>::handle(const AttributeResult & r)
{
size_t numValues = r.getAttribute()->getValueCount(r.getDocId());
_vector.resize(numValues);
diff --git a/searchlib/src/vespa/searchlib/expression/attributenode.h b/searchlib/src/vespa/searchlib/expression/attributenode.h
index a99cc49eb30..3cbccd32e60 100644
--- a/searchlib/src/vespa/searchlib/expression/attributenode.h
+++ b/searchlib/src/vespa/searchlib/expression/attributenode.h
@@ -63,7 +63,7 @@ protected:
virtual void handle(const AttributeResult & r) = 0;
};
private:
- class IntegerHandler;
+ template <typename V> class IntegerHandler;
class FloatHandler;
class StringHandler;
class EnumHandler;