summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-07-30 13:49:42 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-07-31 17:40:51 +0200
commit2dc16fd1eeaff16d6a3fc615480127d94b9049e8 (patch)
tree257108b9b526460f44110429cc68f3928d7e5812 /document
parent5868461e6c629ee86c6a1f64752e2f14290f2aa1 (diff)
Avoid including more than you need.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/serialization/vespadocumentserializer_test.cpp2
-rw-r--r--document/src/tests/weightedsetfieldvaluetest.cpp1
-rw-r--r--document/src/vespa/document/datatype/weightedsetdatatype.cpp2
-rw-r--r--document/src/vespa/document/fieldvalue/mapfieldvalue.cpp10
-rw-r--r--document/src/vespa/document/fieldvalue/mapfieldvalue.h12
-rw-r--r--document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp38
-rw-r--r--document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h1
-rw-r--r--document/src/vespa/document/serialization/vespadocumentserializer.cpp1
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.cpp1
9 files changed, 35 insertions, 33 deletions
diff --git a/document/src/tests/serialization/vespadocumentserializer_test.cpp b/document/src/tests/serialization/vespadocumentserializer_test.cpp
index 45920cb10fd..d09012a4e4b 100644
--- a/document/src/tests/serialization/vespadocumentserializer_test.cpp
+++ b/document/src/tests/serialization/vespadocumentserializer_test.cpp
@@ -8,6 +8,8 @@
#include <vespa/document/datatype/annotationreferencedatatype.h>
#include <vespa/document/datatype/arraydatatype.h>
#include <vespa/document/datatype/documenttype.h>
+#include <vespa/document/datatype/weightedsetdatatype.h>
+#include <vespa/document/datatype/mapdatatype.h>
#include <vespa/document/fieldvalue/annotationreferencefieldvalue.h>
#include <vespa/document/fieldvalue/arrayfieldvalue.h>
#include <vespa/document/fieldvalue/bytefieldvalue.h>
diff --git a/document/src/tests/weightedsetfieldvaluetest.cpp b/document/src/tests/weightedsetfieldvaluetest.cpp
index cf8857904cc..745bc2dfa67 100644
--- a/document/src/tests/weightedsetfieldvaluetest.cpp
+++ b/document/src/tests/weightedsetfieldvaluetest.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/document/fieldvalue/fieldvalues.h>
+#include <vespa/document/datatype/weightedsetdatatype.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/vespalib/objects/nbostream.h>
diff --git a/document/src/vespa/document/datatype/weightedsetdatatype.cpp b/document/src/vespa/document/datatype/weightedsetdatatype.cpp
index 7f607caec1e..c2726ec6f5a 100644
--- a/document/src/vespa/document/datatype/weightedsetdatatype.cpp
+++ b/document/src/vespa/document/datatype/weightedsetdatatype.cpp
@@ -1,7 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "weightedsetdatatype.h"
-#include "primitivedatatype.h"
+#include "mapdatatype.h"
#include <vespa/document/fieldvalue/weightedsetfieldvalue.h>
#include <vespa/vespalib/stllike/asciistream.h>
#include <ostream>
diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp
index af5b5242ef6..f4b4c72661c 100644
--- a/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.cpp
@@ -4,6 +4,7 @@
#include "weightedsetfieldvalue.h"
#include "iteratorhandler.h"
#include <vespa/document/base/exceptions.h>
+#include <vespa/document/datatype/mapdatatype.h>
#include <vespa/vespalib/util/xmlstream.h>
#include <ostream>
@@ -286,6 +287,15 @@ MapFieldValue::hasChanged() const
// referred to externally, and should thus not need to be checked.
return _altered;
}
+const DataType *
+MapFieldValue::getDataType() const {
+ return _type;
+}
+
+FieldValue::UP
+MapFieldValue::createValue() const {
+ return getMapType().getValueType().createFieldValue();
+}
MapFieldValue::const_iterator
MapFieldValue::find(const FieldValue& key) const
diff --git a/document/src/vespa/document/fieldvalue/mapfieldvalue.h b/document/src/vespa/document/fieldvalue/mapfieldvalue.h
index 3a900cf60d7..b6eef78794b 100644
--- a/document/src/vespa/document/fieldvalue/mapfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/mapfieldvalue.h
@@ -8,8 +8,7 @@
#pragma once
#include "fieldvalue.h"
-#include <vespa/document/datatype/mapdatatype.h>
-#include <vespa/vespalib/util/polymorphicarrays.h>
+#include <vespa/vespalib/util/polymorphicarray.h>
namespace document {
@@ -124,7 +123,7 @@ public:
int compare(const FieldValue&) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
bool hasChanged() const override;
- const DataType *getDataType() const override { return _type; }
+ const DataType *getDataType() const override;
void printXml(XmlOutputStream& out) const override;
const_iterator begin() const { return const_iterator(*this, nextPresent(0)); }
@@ -136,12 +135,7 @@ public:
const_iterator find(const FieldValue& fv) const;
iterator find(const FieldValue& fv);
- FieldValue::UP createKey() const {
- return getMapType().getKeyType().createFieldValue();
- }
- FieldValue::UP createValue() const {
- return getMapType().getValueType().createFieldValue();
- }
+ FieldValue::UP createValue() const;
DECLARE_IDENTIFIABLE_ABSTRACT(MapFieldValue);
};
diff --git a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp
index 64680c15a6f..d47f1a4ae76 100644
--- a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.cpp
@@ -1,6 +1,8 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "weightedsetfieldvalue.h"
+#include <vespa/document/datatype/weightedsetdatatype.h>
+#include <vespa/document/datatype/mapdatatype.h>
#include <vespa/document/base/exceptions.h>
#include <vespa/vespalib/util/xmlstream.h>
#include <ostream>
@@ -20,8 +22,7 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(WeightedSetFieldValue, CollectionFieldValue);
namespace {
const DataType &getKeyType(const DataType &type) {
- const WeightedSetDataType *wtype =
- Identifiable::cast<const WeightedSetDataType *>(&type);
+ const WeightedSetDataType *wtype = Identifiable::cast<const WeightedSetDataType *>(&type);
if (!wtype) {
throw IllegalArgumentException("Cannot generate a weighted set value with non-weighted set "
"type " + type.toString() + ".", VESPA_STRLOC);
@@ -58,24 +59,22 @@ WeightedSetFieldValue::add(const FieldValue& key, int weight)
_map.erase(key);
return false;
}
- return _map.insert(FieldValue::UP(key.clone()), FieldValue::UP(new IntFieldValue(weight)));
+ return _map.insert(FieldValue::UP(key.clone()), std::make_unique<IntFieldValue>(weight));
}
bool
-WeightedSetFieldValue::addIgnoreZeroWeight(const FieldValue& key,
- int32_t weight)
+WeightedSetFieldValue::addIgnoreZeroWeight(const FieldValue& key, int32_t weight)
{
verifyKey(key);
_altered = true;
- return _map.insert(FieldValue::UP(key.clone()),
- FieldValue::UP(new IntFieldValue(weight)));
+ return _map.insert(FieldValue::UP(key.clone()), std::make_unique<IntFieldValue>(weight));
}
void
WeightedSetFieldValue::push_back(FieldValue::UP key, int weight)
{
_altered = true;
- _map.push_back(std::move(key), FieldValue::UP(new IntFieldValue(weight)));
+ _map.push_back(std::move(key), std::make_unique<IntFieldValue>(weight));
}
void
@@ -145,40 +144,35 @@ WeightedSetFieldValue::compare(const FieldValue& other) const
int diff = CollectionFieldValue::compare(other);
if (diff != 0) return diff;
- const WeightedSetFieldValue& wset(
- dynamic_cast<const WeightedSetFieldValue&>(other));
+ const WeightedSetFieldValue& wset(dynamic_cast<const WeightedSetFieldValue&>(other));
return _map.compare(wset._map);
}
void
WeightedSetFieldValue::printXml(XmlOutputStream& xos) const
{
- for (WeightedFieldValueMap::const_iterator it = _map.begin();
- it != _map.end(); ++it)
- {
- const IntFieldValue& fv = static_cast<const IntFieldValue&>(*it->second);
+ for (const auto & entry : _map) {
+
+ const IntFieldValue& fv = static_cast<const IntFieldValue&>(*entry.second);
xos << XmlTag("item") << XmlAttribute("weight", fv.getValue())
- << *it->first
+ << *entry.first
<< XmlEndTag();
}
}
void
-WeightedSetFieldValue::print(std::ostream& out, bool verbose,
- const std::string& indent) const
+WeightedSetFieldValue::print(std::ostream& out, bool verbose, const std::string& indent) const
{
out << getDataType()->getName() << "(";
int count = 0;
- for (WeightedFieldValueMap::const_iterator it = _map.begin();
- it != _map.end(); ++it)
- {
+ for (const auto & entry : _map) {
if (count++ != 0) {
out << ",";
}
out << "\n" << indent << " ";
- it->first->print(out, verbose, indent + " ");
- const IntFieldValue& fv = static_cast<const IntFieldValue&>(*it->second);
+ entry.first->print(out, verbose, indent + " ");
+ const IntFieldValue& fv = static_cast<const IntFieldValue&>(*entry.second);
out << " - weight " << fv.getValue();
}
if (_map.size() > 0) out << "\n" << indent;
diff --git a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h
index 431569a6e66..0f73e2602d3 100644
--- a/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h
+++ b/document/src/vespa/document/fieldvalue/weightedsetfieldvalue.h
@@ -10,7 +10,6 @@
#include "collectionfieldvalue.h"
#include "mapfieldvalue.h"
#include "intfieldvalue.h"
-#include <vespa/document/datatype/weightedsetdatatype.h>
#include <map>
namespace document {
diff --git a/document/src/vespa/document/serialization/vespadocumentserializer.cpp b/document/src/vespa/document/serialization/vespadocumentserializer.cpp
index 2b6fe0833e7..2534690b014 100644
--- a/document/src/vespa/document/serialization/vespadocumentserializer.cpp
+++ b/document/src/vespa/document/serialization/vespadocumentserializer.cpp
@@ -20,6 +20,7 @@
#include <vespa/document/fieldvalue/weightedsetfieldvalue.h>
#include <vespa/document/fieldvalue/tensorfieldvalue.h>
#include <vespa/document/fieldvalue/referencefieldvalue.h>
+#include <vespa/document/datatype/weightedsetdatatype.h>
#include <vespa/document/update/updates.h>
#include <vespa/document/update/fieldpathupdates.h>
#include <vespa/vespalib/data/slime/binary_format.h>
diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp
index 2b1b7b5e9f3..cf7f48c4367 100644
--- a/document/src/vespa/document/update/mapvalueupdate.cpp
+++ b/document/src/vespa/document/update/mapvalueupdate.cpp
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "mapvalueupdate.h"
+#include <vespa/document/datatype/weightedsetdatatype.h>
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/vespalib/objects/nbostream.h>