summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-14 14:56:03 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-14 14:56:03 +0000
commit80835efd5c385b6f8e19212a7c032e57af1fd73d (patch)
tree8dc193f8ef1db5ac6f41d3b3266c8f87dc06cfd7 /document
parenta772cb05a682fd05fabd0d571417ec7976d0165d (diff)
Remove virtuality of DocumentId.
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/documentidtest.cpp12
-rw-r--r--document/src/tests/documenttestcase.cpp2
-rw-r--r--document/src/tests/fieldvalue/referencefieldvalue_test.cpp4
-rw-r--r--document/src/vespa/document/base/documentid.cpp34
-rw-r--r--document/src/vespa/document/base/documentid.h13
-rw-r--r--document/src/vespa/document/fieldvalue/document.cpp4
-rw-r--r--document/src/vespa/document/fieldvalue/referencefieldvalue.cpp7
-rw-r--r--document/src/vespa/document/select/valuenodes.cpp6
8 files changed, 25 insertions, 57 deletions
diff --git a/document/src/tests/documentidtest.cpp b/document/src/tests/documentidtest.cpp
index a6255cc148a..d3f6e8a8fcd 100644
--- a/document/src/tests/documentidtest.cpp
+++ b/document/src/tests/documentidtest.cpp
@@ -44,16 +44,8 @@ TEST(DocumentIdTest, generateJavaComplianceFile)
TEST(DocumentIdTest, testOutput)
{
DocumentId id("id:ns:news::crawler:http://www.yahoo.com");
-
- std::ostringstream ost;
- ost << id;
- std::string expected("id:ns:news::crawler:http://www.yahoo.com");
- EXPECT_EQ(expected, ost.str());
-
- EXPECT_EQ(vespalib::string(expected), id.toString());
-
- expected = "DocumentId(id = id:ns:news::crawler:http://www.yahoo.com, gid(0xa516a5abd7c7fa26944b72f7))";
- EXPECT_EQ(expected, static_cast<Printable&>(id).toString(true));
+ vespalib::string expected("id:ns:news::crawler:http://www.yahoo.com");
+ EXPECT_EQ(expected, id.toString());
}
namespace {
diff --git a/document/src/tests/documenttestcase.cpp b/document/src/tests/documenttestcase.cpp
index fa59358f6d3..b460d318099 100644
--- a/document/src/tests/documenttestcase.cpp
+++ b/document/src/tests/documenttestcase.cpp
@@ -28,7 +28,7 @@ using namespace fieldvalue;
TEST(DocumentTest, testSizeOf)
{
- EXPECT_EQ(136ul, sizeof(Document));
+ EXPECT_EQ(128ul, sizeof(Document));
EXPECT_EQ(72ul, sizeof(StructFieldValue));
EXPECT_EQ(24ul, sizeof(StructuredFieldValue));
EXPECT_EQ(64ul, sizeof(SerializableArray));
diff --git a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
index 17fb5ac74e6..b42e2d9cd7a 100644
--- a/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
+++ b/document/src/tests/fieldvalue/referencefieldvalue_test.cpp
@@ -122,7 +122,7 @@ TEST_F("clone()ing creates new instance with same ID and type", Fixture) {
ReferenceFieldValue src(f.refType, DocumentId("id:ns:foo::yoshi"));
std::unique_ptr<ReferenceFieldValue> cloned(src.clone());
- ASSERT_TRUE(cloned.get() != nullptr);
+ ASSERT_TRUE(cloned);
ASSERT_TRUE(cloned->hasValidDocumentId());
EXPECT_EQUAL(src.getDocumentId(), cloned->getDocumentId());
EXPECT_EQUAL(src.getDataType(), cloned->getDataType());
@@ -133,7 +133,7 @@ TEST_F("Can clone() value without document ID", Fixture) {
ReferenceFieldValue src(f.refType);
std::unique_ptr<ReferenceFieldValue> cloned(src.clone());
- ASSERT_TRUE(cloned.get() != nullptr);
+ ASSERT_TRUE(cloned);
EXPECT_FALSE(cloned->hasValidDocumentId());
EXPECT_EQUAL(src.getDataType(), cloned->getDataType());
EXPECT_TRUE(cloned->hasChanged());
diff --git a/document/src/vespa/document/base/documentid.cpp b/document/src/vespa/document/base/documentid.cpp
index 3d5657d093c..69e2aacd073 100644
--- a/document/src/vespa/document/base/documentid.cpp
+++ b/document/src/vespa/document/base/documentid.cpp
@@ -9,30 +9,26 @@ using vespalib::nbostream;
namespace document {
DocumentId::DocumentId()
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(new NullIdString())
{
}
DocumentId::DocumentId(vespalib::stringref id)
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(IdString::createIdString(id.data(), id.size()).release())
{
}
DocumentId::DocumentId(vespalib::nbostream & is)
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(IdString::createIdString(is.peek(), strlen(is.peek())).release())
{
is.adjustReadPos(strlen(is.peek()) + 1);
}
DocumentId::DocumentId(const IdString& id)
- : Printable(),
- _globalId(),
+ : _globalId(),
_id(id.clone())
{
}
@@ -51,30 +47,12 @@ void DocumentId::set(vespalib::stringref id) {
_globalId.first = false;
}
-void
-DocumentId::print(std::ostream& out, bool verbose, const std::string& indent) const
-{
- (void) indent;
- if (verbose) {
- out << "DocumentId(id = ";
- }
- out << _id->toString().c_str();
- if (verbose) {
- out << ", " << getGlobalId().toString() << ")";
- }
-}
-
size_t
DocumentId::getSerializedSize() const
{
return _id->toString().size() + 1;
}
-void DocumentId::swap(DocumentId & rhs) {
- _id.swap(rhs._id);
- std::swap(_globalId, rhs._globalId);
-}
-
void
DocumentId::calculateGlobalId() const
{
@@ -90,5 +68,9 @@ DocumentId::calculateGlobalId() const
_globalId.second.set(key);
}
+std::ostream &
+operator << (std::ostream & os, const DocumentId & id) {
+ return os << id.toString();
+}
} // document
diff --git a/document/src/vespa/document/base/documentid.h b/document/src/vespa/document/base/documentid.h
index d395b751011..b69097e52fd 100644
--- a/document/src/vespa/document/base/documentid.h
+++ b/document/src/vespa/document/base/documentid.h
@@ -21,7 +21,6 @@
#include "idstring.h"
#include "globalid.h"
-#include <vespa/document/util/printable.h>
namespace vespalib { class nbostream; }
@@ -29,7 +28,7 @@ namespace document {
class DocumentType;
-class DocumentId : public Printable
+class DocumentId
{
public:
typedef std::unique_ptr<DocumentId> UP;
@@ -41,7 +40,7 @@ public:
DocumentId & operator = (DocumentId && rhs) = default;
DocumentId(const DocumentId & rhs);
DocumentId & operator = (const DocumentId & rhs);
- ~DocumentId() override;
+ ~DocumentId();
/**
* Parse the given document identifier given as string, and create an
* identifier object from it.
@@ -62,8 +61,6 @@ public:
*/
vespalib::string toString() const;
- void print(std::ostream& out, bool verbose, const std::string& indent) const override;
-
bool operator==(const DocumentId& other) const { return *_id == *other._id; }
bool operator!=(const DocumentId& other) const { return ! (*_id == *other._id); }
@@ -76,9 +73,7 @@ public:
return _globalId.second;
}
- DocumentId* clone() const { return new DocumentId(*this); }
- virtual size_t getSerializedSize() const;
- void swap(DocumentId & rhs);
+ size_t getSerializedSize() const;
private:
mutable std::pair<bool, GlobalId> _globalId;
vespalib::CloneablePtr<IdString> _id;
@@ -86,5 +81,7 @@ private:
void calculateGlobalId() const;
};
+std::ostream & operator << (std::ostream & os, const DocumentId & id);
+
} // document
diff --git a/document/src/vespa/document/fieldvalue/document.cpp b/document/src/vespa/document/fieldvalue/document.cpp
index 29414c901f8..ae0cd5ed9eb 100644
--- a/document/src/vespa/document/fieldvalue/document.cpp
+++ b/document/src/vespa/document/fieldvalue/document.cpp
@@ -226,9 +226,9 @@ Document::print(std::ostream& out, bool verbose,
const std::string& indent) const
{
if (!verbose) {
- out << "Document(" << getId() << ", " << getType() << ")";
+ out << "Document(" << getId().toString() << ", " << getType() << ")";
} else {
- out << "Document(" << getId() << "\n" << indent << " ";
+ out << "Document(" << getId().toString() << "\n" << indent << " ";
getType().print(out, true, indent + " ");
for (const_iterator it = begin(); it != end(); ++it) {
out << "\n" << indent << " " << it.field().getName() << ": ";
diff --git a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
index 281161fccbf..b642ebdc775 100644
--- a/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
+++ b/document/src/vespa/document/fieldvalue/referencefieldvalue.cpp
@@ -37,8 +37,7 @@ ReferenceFieldValue::ReferenceFieldValue(
requireIdOfMatchingType(_documentId, _dataType->getTargetType());
}
-ReferenceFieldValue::~ReferenceFieldValue() {
-}
+ReferenceFieldValue::~ReferenceFieldValue() = default;
void ReferenceFieldValue::requireIdOfMatchingType(
const DocumentId& id, const DocumentType& type)
@@ -105,9 +104,7 @@ int ReferenceFieldValue::compare(const FieldValue& rhs) const {
void ReferenceFieldValue::print(std::ostream& os, bool verbose, const std::string& indent) const {
(void) verbose;
assert(_dataType != nullptr);
- os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId(";
- _documentId.print(os, false, "");
- os << "))";
+ os << indent << "ReferenceFieldValue(" << *_dataType << ", DocumentId(" << _documentId.toString() << "))";
}
bool ReferenceFieldValue::hasChanged() const {
diff --git a/document/src/vespa/document/select/valuenodes.cpp b/document/src/vespa/document/select/valuenodes.cpp
index 9cfdae14de1..70cdbc10e8b 100644
--- a/document/src/vespa/document/select/valuenodes.cpp
+++ b/document/src/vespa/document/select/valuenodes.cpp
@@ -571,7 +571,7 @@ IdValueNode::traceValue(const DocumentId& id, std::ostream& out) const
value = id.getScheme().getDocType();
out << "Resolved id.type to value\"" << value << "\".\n";
} else {
- out << "Could not resolve type of doc " << id << ".\n";
+ out << "Could not resolve type of doc " << id.toString() << ".\n";
return std::make_unique<InvalidValue>();
}
break;
@@ -589,7 +589,7 @@ IdValueNode::traceValue(const DocumentId& id, std::ostream& out) const
out << "Resolved group of doc (type " << id.getScheme().getType()
<< ") to \"" << value << "\".\n";
} else {
- out << "Can't resolve group of doc \"" << id << "\".\n";
+ out << "Can't resolve group of doc \"" << id.toString() << "\".\n";
return std::make_unique<InvalidValue>();
}
break;
@@ -604,7 +604,7 @@ IdValueNode::traceValue(const DocumentId& id, std::ostream& out) const
<< " to " << *result << ".\n";
return result;
} else {
- out << "Could not resolve user of doc " << id << ".\n";
+ out << "Could not resolve user of doc " << id.toString() << ".\n";
return std::make_unique<InvalidValue>();
}
}