diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-03 08:39:54 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-06 09:12:38 +0200 |
commit | fdfc2ee5b03c00caa4c655a4ba3dab5554ba354a (patch) | |
tree | c1be9b153b2bf4ce5bdf2661a452c2250a2f9e98 /document | |
parent | 02a2201dbce24db2586d94f37a6093192a0da691 (diff) |
Hide the implementation details.
Diffstat (limited to 'document')
25 files changed, 153 insertions, 123 deletions
diff --git a/document/src/tests/arrayfieldvaluetest.cpp b/document/src/tests/arrayfieldvaluetest.cpp index 7f31e0c3b3a..0535edc495b 100644 --- a/document/src/tests/arrayfieldvaluetest.cpp +++ b/document/src/tests/arrayfieldvaluetest.cpp @@ -4,6 +4,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/util/bytebuffer.h> using vespalib::nbostream; diff --git a/document/src/tests/documentcalculatortestcase.cpp b/document/src/tests/documentcalculatortestcase.cpp index a292302ad61..bc112c80a8c 100644 --- a/document/src/tests/documentcalculatortestcase.cpp +++ b/document/src/tests/documentcalculatortestcase.cpp @@ -9,6 +9,7 @@ #include <vespa/document/fieldvalue/intfieldvalue.h> #include <vespa/document/fieldvalue/longfieldvalue.h> #include <vespa/document/fieldvalue/floatfieldvalue.h> +#include <vespa/document/select/variablemap.h> #include <vespa/vespalib/util/exceptions.h> namespace document { @@ -52,46 +53,42 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DocumentCalculatorTest); void DocumentCalculatorTest::testConstant() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "4.0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables))); } void DocumentCalculatorTest::testSimple() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) / 2"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables))); } void DocumentCalculatorTest::testVariables() { - DocumentCalculator::VariableMap variables; - variables["x"] = 3.0; - variables["y"] = 5.0; + auto variables = std::make_unique<select::VariableMap>(); + (*variables)["x"] = 3.0; + (*variables)["y"] = 5.0; DocumentCalculator calc(getRepo(), "($x + $y) / 2"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); CPPUNIT_ASSERT_EQUAL(4.0, calc.evaluate(doc, std::move(variables))); } void DocumentCalculatorTest::testFields() { - DocumentCalculator::VariableMap variables; - variables["x"] = 3.0; - variables["y"] = 5.0; + auto variables = std::make_unique<select::VariableMap>(); + (*variables)["x"] = 3.0; + (*variables)["y"] = 5.0; DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); doc.setValue(doc.getField("headerval"), IntFieldValue(5)); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); @@ -100,14 +97,13 @@ DocumentCalculatorTest::testFields() { void DocumentCalculatorTest::testFieldsDivZero() { - DocumentCalculator::VariableMap variables; - variables["x"] = 3.0; - variables["y"] = 5.0; + auto variables = std::make_unique<select::VariableMap>(); + (*variables)["x"] = 3.0; + (*variables)["y"] = 5.0; DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); doc.setValue(doc.getField("headerval"), IntFieldValue(5)); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(0)); @@ -121,11 +117,10 @@ DocumentCalculatorTest::testFieldsDivZero() { void DocumentCalculatorTest::testDivideByZero() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) / 0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); try { calc.evaluate(doc, std::move(variables)); CPPUNIT_ASSERT(false); @@ -136,11 +131,10 @@ DocumentCalculatorTest::testDivideByZero() { void DocumentCalculatorTest::testModByZero() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(3 + 5) % 0"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); try { calc.evaluate(doc, std::move(variables)); CPPUNIT_ASSERT(false); @@ -151,12 +145,11 @@ DocumentCalculatorTest::testModByZero() { void DocumentCalculatorTest::testFieldNotSet() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(testdoctype1.headerval + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); try { @@ -169,13 +162,12 @@ DocumentCalculatorTest::testFieldNotSet() { void DocumentCalculatorTest::testFieldNotFound() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "(testdoctype1.mynotfoundfield + testdoctype1" ".hfloatval) / testdoctype1.headerlongval"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); doc.setValue(doc.getField("hfloatval"), FloatFieldValue(3.0)); doc.setValue(doc.getField("headerlongval"), LongFieldValue(2)); try { @@ -188,11 +180,10 @@ DocumentCalculatorTest::testFieldNotFound() { void DocumentCalculatorTest::testByteSubtractionZeroResult() { - DocumentCalculator::VariableMap variables; + auto variables = std::make_unique<select::VariableMap>(); DocumentCalculator calc(getRepo(), "testdoctype1.byteval - 3"); - Document doc(*_testRepo.getDocumentType("testdoctype1"), - DocumentId("doc:test:foo")); + Document doc(*_testRepo.getDocumentType("testdoctype1"), DocumentId("doc:test:foo")); doc.setValue(doc.getField("byteval"), ByteFieldValue(3)); CPPUNIT_ASSERT_EQUAL(0.0, calc.evaluate(doc, std::move(variables))); } diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp index b100487a94e..c844f2cf5a2 100644 --- a/document/src/tests/documenttestcase.cpp +++ b/document/src/tests/documenttestcase.cpp @@ -11,6 +11,7 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/testkit/test_kit.h> #include <vespa/document/util/serializableexceptions.h> +#include <vespa/document/util/bytebuffer.h> using vespalib::nbostream; diff --git a/document/src/tests/primitivefieldvaluetest.cpp b/document/src/tests/primitivefieldvaluetest.cpp index 15fd6e00959..018408a2d02 100644 --- a/document/src/tests/primitivefieldvaluetest.cpp +++ b/document/src/tests/primitivefieldvaluetest.cpp @@ -4,6 +4,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/util/bytebuffer.h> using vespalib::nbostream; diff --git a/document/src/tests/structfieldvaluetest.cpp b/document/src/tests/structfieldvaluetest.cpp index 9940f2de5b3..1b2fa17a79a 100644 --- a/document/src/tests/structfieldvaluetest.cpp +++ b/document/src/tests/structfieldvaluetest.cpp @@ -6,6 +6,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/util/bytebuffer.h> using vespalib::nbostream; using document::config_builder::Struct; diff --git a/document/src/tests/weightedsetfieldvaluetest.cpp b/document/src/tests/weightedsetfieldvaluetest.cpp index 81b98da297f..68b94cd2f16 100644 --- a/document/src/tests/weightedsetfieldvaluetest.cpp +++ b/document/src/tests/weightedsetfieldvaluetest.cpp @@ -4,6 +4,7 @@ #include <vespa/document/serialization/vespadocumentdeserializer.h> #include <vespa/vdstestlib/cppunit/macros.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/util/bytebuffer.h> using vespalib::nbostream; diff --git a/document/src/vespa/document/base/documentcalculator.cpp b/document/src/vespa/document/base/documentcalculator.cpp index 7a83d80764c..24afdee3bd1 100644 --- a/document/src/vespa/document/base/documentcalculator.cpp +++ b/document/src/vespa/document/base/documentcalculator.cpp @@ -5,6 +5,7 @@ #include <vespa/document/select/compare.h> #include <vespa/document/select/parser.h> #include <vespa/document/select/valuenode.h> +#include <vespa/document/select/variablemap.h> #include <vespa/vespalib/util/exceptions.h> namespace document { @@ -21,13 +22,13 @@ DocumentCalculator::DocumentCalculator( DocumentCalculator::~DocumentCalculator() { } double -DocumentCalculator::evaluate(const Document& doc, VariableMap && variables) +DocumentCalculator::evaluate(const Document& doc, std::unique_ptr<select::VariableMap> variables) { select::Compare& compare(static_cast<select::Compare&>(*_selectionNode)); const select::ValueNode& left = compare.getLeft(); select::Context context(doc); - context._variables = std::move(variables); + context.setVariableMap(std::move(variables)); std::unique_ptr<select::Value> value = left.getValue(context); select::NumberValue* num = dynamic_cast<select::NumberValue*>(value.get()); diff --git a/document/src/vespa/document/base/documentcalculator.h b/document/src/vespa/document/base/documentcalculator.h index 7e1feaf5688..fc9eb73dea2 100644 --- a/document/src/vespa/document/base/documentcalculator.h +++ b/document/src/vespa/document/base/documentcalculator.h @@ -2,18 +2,18 @@ #pragma once #include <vespa/document/select/node.h> -#include <vespa/vespalib/stllike/hash_map.h> namespace document { + +namespace select { class VariableMap; } + class DocumentTypeRepo; class DocumentCalculator { public: - using VariableMap = vespalib::hash_map<vespalib::string, double>; - DocumentCalculator(const DocumentTypeRepo& repo, const vespalib::string& expression); ~DocumentCalculator(); - double evaluate(const Document& doc, VariableMap && variables); + double evaluate(const Document& doc, std::unique_ptr<select::VariableMap> variables); private: std::unique_ptr<select::Node> _selectionNode; diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp index 8e8f6ab52d8..29f487df989 100644 --- a/document/src/vespa/document/fieldvalue/document.cpp +++ b/document/src/vespa/document/fieldvalue/document.cpp @@ -9,6 +9,7 @@ #include <vespa/vespalib/objects/nbostream.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/base/exceptions.h> +#include <vespa/document/util/bytebuffer.h> #include <sstream> @@ -17,7 +18,6 @@ using vespalib::make_string; using vespalib::IllegalArgumentException; using vespalib::IllegalStateException; - namespace document { namespace { diff --git a/document/src/vespa/document/fieldvalue/serializablearray.cpp b/document/src/vespa/document/fieldvalue/serializablearray.cpp index 77204490dc0..f5aa25d4d0c 100644 --- a/document/src/vespa/document/fieldvalue/serializablearray.cpp +++ b/document/src/vespa/document/fieldvalue/serializablearray.cpp @@ -3,6 +3,8 @@ #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/util/bytebuffer.h> #include <vespa/vespalib/stllike/hash_map.hpp> +#include <vespa/vespalib/data/databuffer.h> +#include <vespa/document/util/compressor.h> #include <vespa/log/log.h> LOG_SETUP(".document.serializable-array"); diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp index d3cbcb77ba2..74805ce3f10 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.cpp +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.cpp @@ -10,6 +10,7 @@ #include <vespa/document/datatype/positiondatatype.h> #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/base/exceptions.h> +#include <vespa/document/util/bytebuffer.h> #include <vespa/log/log.h> LOG_SETUP(".document.structfieldvalue"); @@ -42,6 +43,26 @@ StructFieldValue::~StructFieldValue() { } StructFieldValue::Chunks::~Chunks() { } void +StructFieldValue::Chunks::push_back(SerializableArray::UP item) { + assert(_sz < 2); + _chunks[_sz++].reset(item.release()); +} + +void +StructFieldValue::Chunks::clear() { + _chunks[0].reset(); + _chunks[1].reset(); + _sz = 0; +} + +void +StructFieldValue::Chunks::swap(Chunks & rhs) { + _chunks[0].swap(rhs._chunks[0]); + _chunks[1].swap(rhs._chunks[1]); + std::swap(_sz, rhs._sz); +} + +void StructFieldValue::swap(StructFieldValue & rhs) { StructuredFieldValue::swap(rhs); diff --git a/document/src/vespa/document/fieldvalue/structfieldvalue.h b/document/src/vespa/document/fieldvalue/structfieldvalue.h index d57c8b965f7..01a0e732e43 100644 --- a/document/src/vespa/document/fieldvalue/structfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/structfieldvalue.h @@ -11,8 +11,6 @@ #include "structuredfieldvalue.h" #include "serializablearray.h" -#include <vespa/document/util/compressionconfig.h> -#include <vector> namespace document { @@ -33,24 +31,13 @@ public: ~Chunks(); SerializableArray & operator [] (size_t i) { return *_chunks[i]; } const SerializableArray & operator [] (size_t i) const { return *_chunks[i]; } - void push_back(SerializableArray::UP item) { - assert(_sz < 2); - _chunks[_sz++].reset(item.release()); - } + VESPA_DLL_LOCAL void push_back(SerializableArray::UP item); SerializableArray & back() { return *_chunks[_sz-1]; } const SerializableArray & back() const { return *_chunks[_sz-1]; } size_t size() const { return _sz; } bool empty() const { return _sz == 0; } - void clear() { - _chunks[0].reset(); - _chunks[1].reset(); - _sz = 0; - } - void swap(Chunks & rhs) { - _chunks[0].swap(rhs._chunks[0]); - _chunks[1].swap(rhs._chunks[1]); - std::swap(_sz, rhs._sz); - } + VESPA_DLL_LOCAL void clear(); + VESPA_DLL_LOCAL void swap(Chunks & rhs); private: SerializableArray::CP _chunks[2]; size_t _sz; @@ -79,7 +66,7 @@ public: void lazyDeserialize(const FixedTypeRepo &repo, uint16_t version, SerializableArray::EntryMap && fields, - ByteBuffer::UP buffer, + std::unique_ptr<ByteBuffer> buffer, CompressionConfig::Type comp_type, int32_t uncompressed_length); diff --git a/document/src/vespa/document/select/branch.cpp b/document/src/vespa/document/select/branch.cpp index 85e42dd74b5..ea0d0ef5646 100644 --- a/document/src/vespa/document/select/branch.cpp +++ b/document/src/vespa/document/select/branch.cpp @@ -3,6 +3,7 @@ #include "branch.h" #include "visitor.h" #include <cassert> +#include <ostream> namespace document { namespace select { diff --git a/document/src/vespa/document/select/constant.cpp b/document/src/vespa/document/select/constant.cpp index a48492685f3..0e2fdc2ecec 100644 --- a/document/src/vespa/document/select/constant.cpp +++ b/document/src/vespa/document/select/constant.cpp @@ -3,6 +3,7 @@ #include "constant.h" #include "visitor.h" #include <cassert> +#include <ostream> namespace document::select { @@ -46,8 +47,7 @@ Constant::visit(Visitor &v) const void -Constant::print(std::ostream& out, bool, - const std::string&) const +Constant::print(std::ostream& out, bool, const std::string&) const { if (_parentheses) out << '('; out << _name; diff --git a/document/src/vespa/document/select/context.cpp b/document/src/vespa/document/select/context.cpp index 44d005e9db2..ef29770ddc8 100644 --- a/document/src/vespa/document/select/context.cpp +++ b/document/src/vespa/document/select/context.cpp @@ -1,11 +1,12 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "context.h" +#include "variablemap.h" +#include <vespa/document/select/value.h> -namespace document { -namespace select { +namespace document::select { -Context::Context(void) +Context::Context() : _doc(NULL), _docId(NULL), _docUpdate(NULL), @@ -35,5 +36,20 @@ Context::Context(const DocumentUpdate& docUpdate) Context::~Context() { } -} // select -} // document +std::unique_ptr<Value> +Context::getValue(const vespalib::string & value) const { + VariableMap::const_iterator iter = _variables->find(value); + + if (iter != _variables->end()) { + return std::make_unique<FloatValue>(iter->second); + } else { + return std::make_unique<FloatValue>(0.0); + } +} + +void +Context::setVariableMap(std::unique_ptr<VariableMap> map) { + _variables = std::move(map); +} + +} diff --git a/document/src/vespa/document/select/context.h b/document/src/vespa/document/select/context.h index 11a3a2be51c..0e347e22bb5 100644 --- a/document/src/vespa/document/select/context.h +++ b/document/src/vespa/document/select/context.h @@ -2,9 +2,9 @@ #pragma once #include <vespa/vespalib/stllike/string.h> -#include <vespa/vespalib/stllike/hash_map.h> +#include <memory> -namespace document{ +namespace document { class Document; class DocumentId; @@ -12,24 +12,26 @@ class DocumentUpdate; namespace select { -class Context -{ -public: - typedef vespalib::hash_map<vespalib::string, double> VariableMap; +class Value; +class VariableMap; +class Context { +public: Context(); - Context(const Document& doc); - Context(const DocumentId& docId); - Context(const DocumentUpdate& docUpdate); + Context(const Document & doc); + Context(const DocumentId & docId); + Context(const DocumentUpdate & docUpdate); virtual ~Context(); - const Document * _doc; - const DocumentId * _docId; - const DocumentUpdate * _docUpdate; - VariableMap _variables; -}; - -} // select -} // document + void setVariableMap(std::unique_ptr<VariableMap> map); + std::unique_ptr<Value> getValue(const vespalib::string & value) const; + const Document *_doc; + const DocumentId *_docId; + const DocumentUpdate *_docUpdate; +private: + std::unique_ptr<VariableMap> _variables; +}; +} +} diff --git a/document/src/vespa/document/select/invalidconstant.cpp b/document/src/vespa/document/select/invalidconstant.cpp index 793e34c7bc5..53e3a6e1647 100644 --- a/document/src/vespa/document/select/invalidconstant.cpp +++ b/document/src/vespa/document/select/invalidconstant.cpp @@ -2,9 +2,9 @@ #include "invalidconstant.h" #include "visitor.h" +#include <ostream> -namespace document { -namespace select { +namespace document::select { InvalidConstant::InvalidConstant(const vespalib::stringref & value) : Node(value) @@ -26,13 +26,11 @@ InvalidConstant::visit(Visitor &v) const void -InvalidConstant::print(std::ostream& out, bool, - const std::string&) const +InvalidConstant::print(std::ostream& out, bool, const std::string&) const { if (_parentheses) out << '('; out << _name; if (_parentheses) out << ')'; } -} // select -} // document +} diff --git a/document/src/vespa/document/select/value.cpp b/document/src/vespa/document/select/value.cpp index 7638ba3c36e..7a453fe5cf3 100644 --- a/document/src/vespa/document/select/value.cpp +++ b/document/src/vespa/document/select/value.cpp @@ -2,7 +2,6 @@ #include "value.h" #include "operator.h" -#include <cstdint> namespace document { namespace select { diff --git a/document/src/vespa/document/select/valuenode.cpp b/document/src/vespa/document/select/valuenode.cpp index 49eab9d75ff..96bc46bd54e 100644 --- a/document/src/vespa/document/select/valuenode.cpp +++ b/document/src/vespa/document/select/valuenode.cpp @@ -36,6 +36,13 @@ namespace { } } +std::unique_ptr<Value> +ValueNode::defaultTrace(std::unique_ptr<Value> val, std::ostream& out) const +{ + out << "Returning value " << *val << ".\n"; + return std::move(val); +} + InvalidValueNode::InvalidValueNode(const vespalib::stringref & name) : _name(name) { } @@ -147,13 +154,7 @@ CurrentTimeValueNode::print(std::ostream& out, bool verbose, std::unique_ptr<Value> VariableValueNode::getValue(const Context& context) const { - VariableMap::const_iterator iter = context._variables.find(_value); - - if (iter != context._variables.end()) { - return std::unique_ptr<Value>(new FloatValue(iter->second)); - } else { - return std::unique_ptr<Value>(new FloatValue(0.0)); - } + return context.getValue(_value); } diff --git a/document/src/vespa/document/select/valuenode.h b/document/src/vespa/document/select/valuenode.h index e3f0b4c4a94..d56b1468508 100644 --- a/document/src/vespa/document/select/valuenode.h +++ b/document/src/vespa/document/select/valuenode.h @@ -29,34 +29,25 @@ namespace select { class ValueNode : public Printable { public: - typedef std::unique_ptr<ValueNode> UP; - typedef Context::VariableMap VariableMap; + using UP = std::unique_ptr<ValueNode>; ValueNode() : _parentheses(false) {} virtual ~ValueNode() {} void setParentheses() { _parentheses = true; } - - void clearParentheses() - { - _parentheses = false; - } - + void clearParentheses() { _parentheses = false; } bool hadParentheses() const { return _parentheses; } virtual std::unique_ptr<Value> getValue(const Context& context) const = 0; virtual std::unique_ptr<Value> - traceValue(const Context &context, - std::ostream &out) const { + traceValue(const Context &context, std::ostream &out) const { return defaultTrace(getValue(context), out); } virtual void print(std::ostream& out, bool verbose, const std::string& indent) const override = 0; - virtual void visit(Visitor&) const = 0; - virtual ValueNode::UP clone() const = 0; private: bool _parentheses; // Set to true if parentheses was used around this part @@ -70,12 +61,7 @@ protected: return ret; } - std::unique_ptr<Value> defaultTrace(std::unique_ptr<Value> val, - std::ostream& out) const - { - out << "Returning value " << *val << ".\n"; - return std::move(val); - } + std::unique_ptr<Value> defaultTrace(std::unique_ptr<Value> val, std::ostream& out) const; }; class InvalidValueNode : public ValueNode diff --git a/document/src/vespa/document/select/variablemap.h b/document/src/vespa/document/select/variablemap.h new file mode 100644 index 00000000000..86a1cb85e63 --- /dev/null +++ b/document/src/vespa/document/select/variablemap.h @@ -0,0 +1,15 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/vespalib/stllike/hash_map.h> +#include <vespa/vespalib/stllike/string.h> + +namespace document::select { + +using VariableMapT = vespalib::hash_map<vespalib::string, double>; + +class VariableMap : public VariableMapT { +public: + using VariableMapT::VariableMapT; +}; + +} diff --git a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp index 93856b376aa..b2a2bd098a6 100644 --- a/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentdeserializer.cpp @@ -27,6 +27,7 @@ #include <vespa/document/util/serializableexceptions.h> #include <vespa/document/base/exceptions.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/document/util/bytebuffer.h> #include <vespa/log/log.h> LOG_SETUP(".vespadocumentdeserializer"); diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp index 11317f2ff0a..1f6a4a4f0b0 100644 --- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp +++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp @@ -24,7 +24,9 @@ #include <vespa/document/update/fieldpathupdates.h> #include <vespa/vespalib/data/slime/binary_format.h> #include <vespa/vespalib/objects/nbostream.h> +#include <vespa/vespalib/data/databuffer.h> #include <vespa/eval/tensor/serialization/typed_binary_format.h> +#include <vespa/document/util/compressor.h> using std::make_pair; using std::pair; diff --git a/document/src/vespa/document/update/assignfieldpathupdate.cpp b/document/src/vespa/document/update/assignfieldpathupdate.cpp index 0a676c88df2..4b8ee510576 100644 --- a/document/src/vespa/document/update/assignfieldpathupdate.cpp +++ b/document/src/vespa/document/update/assignfieldpathupdate.cpp @@ -1,9 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "assignfieldpathupdate.h" #include <vespa/document/fieldvalue/fieldvalues.h> -#include <vespa/document/repo/fixedtyperepo.h> #include <vespa/document/select/parser.h> +#include <vespa/document/select/variablemap.h> #include <vespa/document/serialization/vespadocumentdeserializer.h> -#include <vespa/document/update/assignfieldpathupdate.h> #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/exceptions.h> #include <boost/numeric/conversion/cast.hpp> @@ -108,7 +109,8 @@ FieldValue::IteratorHandler::ModificationStatus AssignFieldPathUpdate::AssignExpressionIteratorHandler::doModify(FieldValue& fv) { LOG(spam, "fv = %s", fv.toString().c_str()); if (fv.inherits(NumericFieldValueBase::classId)) { - DocumentCalculator::VariableMap vars; + std::unique_ptr<select::VariableMap> varHolder = std::make_unique<select::VariableMap>(); + select::VariableMap & vars = *varHolder; for (VariableMap::const_iterator i(getVariables().begin()), e(getVariables().end()); i != e; ++i) { @@ -122,7 +124,7 @@ AssignFieldPathUpdate::AssignExpressionIteratorHandler::doModify(FieldValue& fv) vars["value"] = fv.getAsDouble(); try { - double res = _calc.evaluate(_doc, std::move(vars)); + double res = _calc.evaluate(_doc, std::move(varHolder)); if (_removeIfZero && static_cast<uint64_t>(res) == 0) { return REMOVED; } else { diff --git a/document/src/vespa/document/update/clearvalueupdate.cpp b/document/src/vespa/document/update/clearvalueupdate.cpp index 13143e004ee..cb526852299 100644 --- a/document/src/vespa/document/update/clearvalueupdate.cpp +++ b/document/src/vespa/document/update/clearvalueupdate.cpp @@ -1,15 +1,15 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "clearvalueupdate.h" #include <vespa/document/base/field.h> -#include <vespa/document/update/clearvalueupdate.h> #include <vespa/document/fieldvalue/document.h> #include <vespa/vespalib/util/exceptions.h> +#include <ostream> using vespalib::IllegalArgumentException; using vespalib::IllegalStateException; -namespace document -{ +namespace document { IMPLEMENT_IDENTIFIABLE(ClearValueUpdate, ValueUpdate); |