diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-11-28 13:58:51 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-12-12 02:55:39 +0100 |
commit | af3f0048f62e84e36bee3a69396d0e26894a51f0 (patch) | |
tree | 95b4a6beb3dfa5f165818753dd80b6b7e43093b5 | |
parent | 390ab5ab4e529746f33732e4f07d9ab581dbc5bd (diff) |
Reduce unneccessary code incluscion.
54 files changed, 640 insertions, 526 deletions
diff --git a/document/src/vespa/document/base/fieldpath.cpp b/document/src/vespa/document/base/fieldpath.cpp index 68944fda91c..bf978bf21cb 100644 --- a/document/src/vespa/document/base/fieldpath.cpp +++ b/document/src/vespa/document/base/fieldpath.cpp @@ -6,9 +6,9 @@ #include <vespa/document/datatype/mapdatatype.h> #include <vespa/document/datatype/weightedsetdatatype.h> #include <vespa/document/datatype/primitivedatatype.h> -#include <vespa/vespalib/objects/visit.h> #include <vespa/vespalib/util/exceptions.h> #include <vespa/document/fieldvalue/fieldvalue.h> +#include <vespa/vespalib/objects/visit.hpp> using vespalib::IllegalArgumentException; using vespalib::make_string; diff --git a/document/src/vespa/document/datatype/annotationtype.cpp b/document/src/vespa/document/datatype/annotationtype.cpp index 57d5e38db31..f34d20c348e 100644 --- a/document/src/vespa/document/datatype/annotationtype.cpp +++ b/document/src/vespa/document/datatype/annotationtype.cpp @@ -1,14 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".annotationtype"); - #include "annotationtype.h" - #include "numericdatatype.h" #include "primitivedatatype.h" #include <vespa/vespalib/stllike/string.h> +#include <vespa/vespalib/stllike/asciistream.h> using std::vector; using vespalib::string; diff --git a/document/src/vespa/document/datatype/annotationtype.h b/document/src/vespa/document/datatype/annotationtype.h index 74f2ea030c4..e70580786d6 100644 --- a/document/src/vespa/document/datatype/annotationtype.h +++ b/document/src/vespa/document/datatype/annotationtype.h @@ -4,9 +4,10 @@ #include "datatype.h" #include <memory> -#include <string> #include <vector> +namespace vespalib { class asciistream; } + namespace document { class AnnotationType { diff --git a/document/src/vespa/document/datatype/numericdatatype.cpp b/document/src/vespa/document/datatype/numericdatatype.cpp index 46a2a4e6b7b..5e7579871a9 100644 --- a/document/src/vespa/document/datatype/numericdatatype.cpp +++ b/document/src/vespa/document/datatype/numericdatatype.cpp @@ -2,6 +2,7 @@ #include <vespa/fastos/fastos.h> #include <vespa/document/datatype/numericdatatype.h> +#include <ostream> namespace document { diff --git a/document/src/vespa/document/fieldvalue/literalfieldvalue.h b/document/src/vespa/document/fieldvalue/literalfieldvalue.h index 14f0d199543..b5c8ace6e9c 100644 --- a/document/src/vespa/document/fieldvalue/literalfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/literalfieldvalue.h @@ -16,8 +16,7 @@ #include <vespa/document/datatype/primitivedatatype.h> #include <vespa/document/fieldvalue/fieldvalue.h> -#include <vespa/document/util/bytebuffer.h> -#include <vespa/document/util/stringutil.h> +#include <vespa/vespalib/stllike/hash_fun.h> namespace document { diff --git a/document/src/vespa/document/fieldvalue/numericfieldvalue.h b/document/src/vespa/document/fieldvalue/numericfieldvalue.h index 8636d015816..5464c064997 100644 --- a/document/src/vespa/document/fieldvalue/numericfieldvalue.h +++ b/document/src/vespa/document/fieldvalue/numericfieldvalue.h @@ -17,6 +17,7 @@ #include <vespa/document/util/bytebuffer.h> #include <vespa/vespalib/stllike/asciistream.h> #include <vespa/vespalib/stllike/lexical_cast.h> +#include <vespa/vespalib/stllike/hash_fun.h> namespace document { @@ -41,27 +42,25 @@ public: value_type getValue() const { return _value; } void setValue(Number newValue) { _value = newValue; } - // FieldValue implementation. - virtual FieldValue& assign(const FieldValue&); - virtual int compare(const FieldValue& other) const; - - virtual FieldValue& operator=(const vespalib::stringref &); - virtual FieldValue& operator=(int32_t); - virtual FieldValue& operator=(int64_t); - virtual FieldValue& operator=(float); - virtual FieldValue& operator=(double); - virtual size_t hash() const { return vespalib::hash<Number>()(_value); } - - virtual char getAsByte() const; - virtual int32_t getAsInt() const; - virtual int64_t getAsLong() const; - virtual float getAsFloat() const; - virtual double getAsDouble() const; - virtual vespalib::string getAsString() const; - - virtual void print(std::ostream& out, bool verbose, - const std::string& indent) const; - virtual bool hasChanged() const { return _altered; } + FieldValue& assign(const FieldValue&) override ; + int compare(const FieldValue& other) const override; + + FieldValue& operator=(const vespalib::stringref &) override; + FieldValue& operator=(int32_t) override; + FieldValue& operator=(int64_t) override; + FieldValue& operator=(float) override; + FieldValue& operator=(double) override; + size_t hash() const { return vespalib::hash<Number>()(_value); } + + char getAsByte() const override; + int32_t getAsInt() const override; + int64_t getAsLong() const override; + float getAsFloat() const override; + double getAsDouble() const override; + vespalib::string getAsString() const override; + + void print(std::ostream& out, bool verbose, const std::string& indent) const override; + virtual bool hasChanged() const override { return _altered; } }; template<typename Number> diff --git a/persistence/src/vespa/persistence/spi/clusterstate.cpp b/persistence/src/vespa/persistence/spi/clusterstate.cpp index 4c1d2606a9a..731344ce7cd 100644 --- a/persistence/src/vespa/persistence/spi/clusterstate.cpp +++ b/persistence/src/vespa/persistence/spi/clusterstate.cpp @@ -3,6 +3,7 @@ #include <vespa/persistence/spi/clusterstate.h> #include <vespa/vdslib/state/clusterstate.h> #include <vespa/vdslib/distribution/distribution.h> +#include <vespa/vespalib/objects/nbostream.h> namespace storage { namespace spi { diff --git a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp index 53a2a4d59ea..ad96184cb57 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.cpp @@ -4,6 +4,7 @@ #include <vespa/vespalib/util/closuretask.h> #include <vespa/searchlib/fef/matchdatalayout.h> #include <vespa/searchlib/query/tree/termnodes.h> +#include <vespa/vespalib/stllike/hash_set.h> #include <vespa/log/log.h> LOG_SETUP(".searchcorespi.index.warmupindexcollection"); @@ -20,6 +21,12 @@ using vespalib::makeClosure; using index::IDiskIndex; using fastos::TimeStamp; using fastos::ClockSystem; +using TermMap = vespalib::hash_set<vespalib::string>; + +class FieldTermMap : public vespalib::hash_map<uint32_t, TermMap> +{ + +}; WarmupIndexCollection::WarmupIndexCollection(const WarmupConfig & warmupConfig, ISearchableIndexCollection::SP prev, @@ -34,7 +41,7 @@ WarmupIndexCollection::WarmupIndexCollection(const WarmupConfig & warmupConfig, _executor(executor), _warmupDone(warmupDone), _warmupEndTime(ClockSystem::now() + TimeStamp::Seconds(warmupConfig.getDuration())), - _handledTerms() + _handledTerms(std::make_unique<FieldTermMap>()) { if (next->valid()) { setCurrentIndex(next->getCurrentIndex()); @@ -126,7 +133,7 @@ WarmupIndexCollection::handledBefore(uint32_t fieldId, const Node &term) if (sb != NULL) { const vespalib::string & s = sb->getTerm(); vespalib::LockGuard guard(_lock); - TermMap::insert_result found = _handledTerms[fieldId].insert(s); + TermMap::insert_result found = (*_handledTerms)[fieldId].insert(s); return ! found.second; } return true; diff --git a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h index be25b81d498..21a96e2bcff 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h +++ b/searchcorespi/src/vespa/searchcorespi/index/warmupindexcollection.h @@ -9,6 +9,8 @@ namespace searchcorespi { +class FieldTermMap; + class IWarmupDone { public: virtual ~IWarmupDone() { } @@ -108,9 +110,7 @@ private: IWarmupDone & _warmupDone; fastos::TimeStamp _warmupEndTime; vespalib::Lock _lock; - typedef vespalib::hash_set<vespalib::string> TermMap; - typedef vespalib::hash_map<uint32_t, TermMap> FieldTermMap; - FieldTermMap _handledTerms; + std::unique_ptr<FieldTermMap> _handledTerms; }; } // namespace searchcorespi diff --git a/searchlib/src/vespa/searchlib/aggregation/aggregation.cpp b/searchlib/src/vespa/searchlib/aggregation/aggregation.cpp index 07c21137b1d..01a9f9920cc 100644 --- a/searchlib/src/vespa/searchlib/aggregation/aggregation.cpp +++ b/searchlib/src/vespa/searchlib/aggregation/aggregation.cpp @@ -3,7 +3,7 @@ #include "expressioncountaggregationresult.h" #include <vespa/searchlib/aggregation/aggregation.h> #include <stdexcept> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <vespa/vespalib/xxhash/xxhash.h> namespace search { diff --git a/searchlib/src/vespa/searchlib/aggregation/grouping.cpp b/searchlib/src/vespa/searchlib/aggregation/grouping.cpp index 22b438cd539..70fae8fea5d 100644 --- a/searchlib/src/vespa/searchlib/aggregation/grouping.cpp +++ b/searchlib/src/vespa/searchlib/aggregation/grouping.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.aggregation.grouping"); #include <vespa/searchlib/aggregation/grouping.h> #include <vespa/searchlib/aggregation/hitsaggregationresult.h> #include <stdexcept> @@ -9,6 +7,10 @@ LOG_SETUP(".searchlib.aggregation.grouping"); #include <vespa/vespalib/objects/objectpredicate.h> #include <vespa/vespalib/objects/objectoperation.h> #include <vespa/searchlib/attribute/stringbase.h> +#include <vespa/vespalib/objects/serializer.hpp> +#include <vespa/vespalib/objects/deserializer.hpp> +#include <vespa/log/log.h> +LOG_SETUP(".searchlib.aggregation.grouping"); using namespace search::expression; using vespalib::FieldBase; diff --git a/searchlib/src/vespa/searchlib/aggregation/hit.h b/searchlib/src/vespa/searchlib/aggregation/hit.h index 2fbed2510f2..2f628c3003c 100644 --- a/searchlib/src/vespa/searchlib/aggregation/hit.h +++ b/searchlib/src/vespa/searchlib/aggregation/hit.h @@ -18,7 +18,6 @@ private: public: DECLARE_IDENTIFIABLE_ABSTRACT_NS2(search, aggregation, Hit); DECLARE_NBO_SERIALIZE; - typedef vespalib::IdentifiablePtr<Hit> CP; typedef std::unique_ptr<Hit> UP; Hit() : _rank() {} diff --git a/searchlib/src/vespa/searchlib/aggregation/hitlist.cpp b/searchlib/src/vespa/searchlib/aggregation/hitlist.cpp index 7994856ec46..8dacf74d9d4 100644 --- a/searchlib/src/vespa/searchlib/aggregation/hitlist.cpp +++ b/searchlib/src/vespa/searchlib/aggregation/hitlist.cpp @@ -8,6 +8,9 @@ #include <algorithm> #include <vespa/vespalib/objects/objectpredicate.h> #include <vespa/vespalib/objects/objectoperation.h> +#include <vespa/vespalib/objects/identifiable.hpp> + + namespace search { namespace aggregation { @@ -15,6 +18,7 @@ namespace aggregation { using vespalib::FieldBase; using vespalib::Serializer; using vespalib::Deserializer; +using HitCP = vespalib::IdentifiablePtr<Hit>; IMPLEMENT_IDENTIFIABLE_NS2(search, aggregation, HitList, ResultNode); @@ -83,12 +87,12 @@ HitList::onSerialize(Serializer & os) const { os << (uint32_t)(_fs4hits.size() + _vdshits.size()); for (uint32_t i(0); i < _fs4hits.size(); i++) { - Hit::CP hit(const_cast<FS4Hit *>(&_fs4hits[i])); + HitCP hit(const_cast<FS4Hit *>(&_fs4hits[i])); os << hit; hit.release(); } for (uint32_t i(0); i < _vdshits.size(); i++) { - Hit::CP hit(const_cast<VdsHit *>(&_vdshits[i])); + HitCP hit(const_cast<VdsHit *>(&_vdshits[i])); os << hit; hit.release(); } @@ -102,7 +106,7 @@ HitList::onDeserialize(Deserializer & is) is >> count; for (uint32_t i(0); i < count; i++) { - Hit::CP hit; + HitCP hit; is >> hit; if (hit->inherits(FS4Hit::classId)) { _fs4hits.push_back(static_cast<const FS4Hit &>(*hit)); diff --git a/searchlib/src/vespa/searchlib/aggregation/vdshit.cpp b/searchlib/src/vespa/searchlib/aggregation/vdshit.cpp index a1df9646ebd..916e933f731 100644 --- a/searchlib/src/vespa/searchlib/aggregation/vdshit.cpp +++ b/searchlib/src/vespa/searchlib/aggregation/vdshit.cpp @@ -2,6 +2,8 @@ #include <vespa/fastos/fastos.h> #include "vdshit.h" #include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/serializer.hpp> +#include <vespa/vespalib/objects/deserializer.hpp> namespace search { namespace aggregation { diff --git a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp index 6d693bb6f42..c0f89e54b23 100644 --- a/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp +++ b/searchlib/src/vespa/searchlib/diskindex/diskindex.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".diskindex.diskindex"); #include "diskindex.h" #include "disktermblueprint.h" #include <vespa/searchlib/index/schemautil.h> @@ -12,9 +10,12 @@ LOG_SETUP(".diskindex.diskindex"); #include <vespa/searchlib/queryeval/termasstring.h> #include <vespa/searchlib/util/dirtraverse.h> #include <vespa/searchlib/query/tree/simplequery.h> +#include <vespa/vespalib/stllike/hash_set.h> #include "pagedict4randread.h" #include "fileheader.h" #include "bitvectorkeyscope.h" +#include <vespa/log/log.h> +LOG_SETUP(".diskindex.diskindex"); using namespace search::index; using namespace search::query; diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp index 7cdf65fd57b..038e16bf872 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp @@ -1,16 +1,14 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".seach.docstore"); - #include "cachestats.h" #include "documentstore.h" +#include "visitcache.h" #include <vespa/vespalib/objects/nbostream.h> #include <vespa/vespalib/util/atomic.h> +#include <vespa/vespalib/stllike/cache.h> -namespace search -{ +namespace search { namespace { @@ -40,17 +38,96 @@ DocumentVisitorAdapter::visit(uint32_t lid, vespalib::ConstBufferRef buf) { using vespalib::nbostream; +namespace docstore { + +class Value { +public: + using Alloc = vespalib::alloc::Alloc; + typedef std::unique_ptr<Value> UP; + + Value() : _compressedSize(0), _uncompressedSize(0), _compression(document::CompressionConfig::NONE) {} + + Value(Value &&rhs) : + _compressedSize(rhs._compressedSize), + _uncompressedSize(rhs._uncompressedSize), + _compression(rhs._compression), + _buf(std::move(rhs._buf)) {} + + Value(const Value &rhs) : + _compressedSize(rhs._compressedSize), + _uncompressedSize(rhs._uncompressedSize), + _compression(rhs._compression), + _buf(Alloc::alloc(rhs.size())) { + memcpy(get(), rhs.get(), size()); + } + + Value &operator=(Value &&rhs) { + _buf = std::move(rhs._buf); + _compressedSize = rhs._compressedSize; + _uncompressedSize = rhs._uncompressedSize; + _compression = rhs._compression; + return *this; + } + + void setCompression(document::CompressionConfig::Type comp, size_t uncompressedSize) { + _compression = comp; + _uncompressedSize = uncompressedSize; + } + + document::CompressionConfig::Type getCompression() const { return _compression; } + + size_t getUncompressedSize() const { return _uncompressedSize; } + + /** + * Compress buffer into temporary buffer and copy temporary buffer to + * value along with compression config. + */ + void set(vespalib::DataBuffer &&buf, ssize_t len, const document::CompressionConfig &compression); + + /** + * Decompress value into temporary buffer and deserialize document from + * the temporary buffer. + */ + document::Document::UP deserializeDocument(const document::DocumentTypeRepo &repo); + + size_t size() const { return _compressedSize; } + bool empty() const { return size() == 0; } + operator const void *() const { return _buf.get(); } + const void *get() const { return _buf.get(); } + void *get() { return _buf.get(); } +private: + size_t _compressedSize; + size_t _uncompressedSize; + document::CompressionConfig::Type _compression; + Alloc _buf; +}; + +class BackingStore { +public: + BackingStore(IDataStore &store, const document::CompressionConfig &compression) : + _backingStore(store), + _compression(compression) { } + + bool read(DocumentIdT key, Value &value) const; + void visit(const IDocumentStore::LidVector &lids, const document::DocumentTypeRepo &repo, IDocumentVisitor &visitor) const; + void write(DocumentIdT, const Value &) {} + void erase(DocumentIdT) {} + const document::CompressionConfig &getCompression(void) const { return _compression; } +private: + IDataStore &_backingStore; + const document::CompressionConfig _compression; +}; + void -DocumentStore::Value::set(vespalib::DataBuffer && buf, +Value::set(vespalib::DataBuffer &&buf, ssize_t len, - const document::CompressionConfig & compression) -{ + const document::CompressionConfig &compression) { //Underlying buffer must be identical to allow swap. vespalib::DataBuffer compressed(buf.getData(), 0u); document::CompressionConfig::Type type = - document::compress(compression, - vespalib::ConstBufferRef(buf.getData(), len), - compressed, true); + document::compress(compression, + vespalib::ConstBufferRef(buf.getData(), len), + compressed, true); _compressedSize = compressed.getDataLen(); if (buf.getData() == compressed.getData()) { // Uncompressed so we can just steal the underlying buffer. @@ -67,9 +144,8 @@ DocumentStore::Value::set(vespalib::DataBuffer && buf, document::Document::UP -DocumentStore::Value::deserializeDocument(const document::DocumentTypeRepo & repo) -{ - vespalib::DataBuffer uncompressed((char *)_buf.get(), (size_t)0); +Value::deserializeDocument(const document::DocumentTypeRepo &repo) { + vespalib::DataBuffer uncompressed((char *) _buf.get(), (size_t) 0); document::decompress(getCompression(), getUncompressedSize(), vespalib::ConstBufferRef(*this, size()), @@ -79,13 +155,14 @@ DocumentStore::Value::deserializeDocument(const document::DocumentTypeRepo & rep } -void DocumentStore::BackingStore::visit(const LidVector & lids, const document::DocumentTypeRepo &repo, IDocumentVisitor & visitor) const { +void BackingStore::visit(const IDocumentStore::LidVector &lids, const document::DocumentTypeRepo &repo, + IDocumentVisitor &visitor) const { DocumentVisitorAdapter adapter(repo, visitor); _backingStore.read(lids, adapter); } bool -DocumentStore::BackingStore::read(DocumentIdT key, Value & value) const { +BackingStore::read(DocumentIdT key, Value &value) const { bool found(false); vespalib::DataBuffer buf(4096); ssize_t len = _backingStore.read(key, buf); @@ -96,12 +173,29 @@ DocumentStore::BackingStore::read(DocumentIdT key, Value & value) const { return found; } +} + +using CacheParams = vespalib::CacheParam< + vespalib::LruParam<DocumentIdT, docstore::Value>, + docstore::BackingStore, + vespalib::zero<DocumentIdT>, + vespalib::size<docstore::Value> +>; + +class Cache : public vespalib::cache<CacheParams> { +public: + Cache(BackingStore & b, size_t maxBytes) : vespalib::cache<CacheParams>(b, maxBytes) { } +}; + +using VisitCache = docstore::VisitCache; +using docstore::Value; + DocumentStore::DocumentStore(const Config & config, IDataStore & store) : IDocumentStore(), _config(config), _backingStore(store), - _store(_backingStore, config.getCompression()), - _cache(new Cache(_store, config.getMaxCacheBytes())), + _store(new docstore::BackingStore(_backingStore, config.getCompression())), + _cache(new Cache(*_store, config.getMaxCacheBytes())), _visitCache(new VisitCache(store, config.getMaxCacheBytes(), config.getCompression())), _uncached_lookups(0) { @@ -112,6 +206,10 @@ DocumentStore::~DocumentStore() { } +bool +DocumentStore::useCache() const { + return (_cache->capacityBytes() != 0) && (_cache->capacity() != 0); +} void DocumentStore::visit(const LidVector & lids, const document::DocumentTypeRepo &repo, IDocumentVisitor & visitor) const @@ -123,7 +221,7 @@ DocumentStore::visit(const LidVector & lids, const document::DocumentTypeRepo &r adapter.visit(lid, blobSet.get(lid)); } } else { - _store.visit(lids, repo, visitor); + _store->visit(lids, repo, visitor); } } @@ -136,7 +234,7 @@ DocumentStore::read(DocumentIdT lid, const document::DocumentTypeRepo &repo) con value = _cache->read(lid); } else { vespalib::Atomic::add(&_uncached_lookups, 1UL); - _store.read(lid, value); + _store->read(lid, value); } if ( ! value.empty() ) { retval = value.deserializeDocument(repo); @@ -352,7 +450,7 @@ DocumentStore::accept(IDocumentStoreReadVisitor &visitor, const document::DocumentTypeRepo &repo) { WrapVisitor<IDocumentStoreReadVisitor> wrap(visitor, repo, - _store.getCompression(), + _store->getCompression(), *this, _backingStore. tentativeLastSyncToken()); @@ -368,7 +466,7 @@ DocumentStore::accept(IDocumentStoreRewriteVisitor &visitor, { WrapVisitor<IDocumentStoreRewriteVisitor> wrap(visitor, repo, - _store.getCompression(), + _store->getCompression(), *this, _backingStore. tentativeLastSyncToken()); diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.h b/searchlib/src/vespa/searchlib/docstore/documentstore.h index 43006b18e90..edd7f8e9387 100644 --- a/searchlib/src/vespa/searchlib/docstore/documentstore.h +++ b/searchlib/src/vespa/searchlib/docstore/documentstore.h @@ -4,10 +4,18 @@ #include "idocumentstore.h" #include "idatastore.h" -#include "visitcache.h" namespace search { +namespace docstore { + class VisitCache; + class BackingStore; + class Cache; +} +using docstore::VisitCache; +using docstore::BackingStore; +using docstore::Cache; + /** * Simple document store that contains serialized Document instances. * updates will be held in memory until flush() is called. @@ -155,96 +163,13 @@ public: getFileChunkStats() const override; private: + bool useCache() const; + template <class> class WrapVisitor; class WrapVisitorProgress; - class Value { - public: - using Alloc = vespalib::alloc::Alloc; - typedef std::unique_ptr<Value> UP; - Value() : _compressedSize(0), _uncompressedSize(0), _compression(document::CompressionConfig::NONE) { } - - Value(Value && rhs) : - _compressedSize(rhs._compressedSize), - _uncompressedSize(rhs._uncompressedSize), - _compression(rhs._compression), - _buf(std::move(rhs._buf)) - { } - - Value(const Value & rhs) : - _compressedSize(rhs._compressedSize), - _uncompressedSize(rhs._uncompressedSize), - _compression(rhs._compression), - _buf(Alloc::alloc(rhs.size())) - { - memcpy(get(), rhs.get(), size()); - } - Value & operator = (Value && rhs) { - _buf = std::move(rhs._buf); - _compressedSize = rhs._compressedSize; - _uncompressedSize = rhs._uncompressedSize; - _compression = rhs._compression; - return *this; - } - void setCompression(document::CompressionConfig::Type comp, size_t uncompressedSize) { - _compression = comp; - _uncompressedSize = uncompressedSize; - } - document::CompressionConfig::Type getCompression() const { return _compression; } - size_t getUncompressedSize() const { return _uncompressedSize; } - - /** - * Compress buffer into temporary buffer and copy temporary buffer to - * value along with compression config. - */ - void set(vespalib::DataBuffer && buf, ssize_t len, const document::CompressionConfig &compression); - - /** - * Decompress value into temporary buffer and deserialize document from - * the temporary buffer. - */ - document::Document::UP deserializeDocument(const document::DocumentTypeRepo &repo); - - size_t size() const { return _compressedSize; } - bool empty() const { return size() == 0; } - operator const void * () const { return _buf.get(); } - const void * get() const { return _buf.get(); } - void * get() { return _buf.get(); } - - private: - size_t _compressedSize; - size_t _uncompressedSize; - document::CompressionConfig::Type _compression; - Alloc _buf; - }; - class BackingStore { - public: - BackingStore(IDataStore & store, const document::CompressionConfig & compression) : - _backingStore(store), - _compression(compression) - { } - bool read(DocumentIdT key, Value & value) const; - void visit(const LidVector & lids, const document::DocumentTypeRepo &repo, IDocumentVisitor & visitor) const; - void write(DocumentIdT, const Value &) { } - void erase(DocumentIdT ) { } - - const document::CompressionConfig & getCompression(void) const { return _compression; } - private: - IDataStore & _backingStore; - const document::CompressionConfig _compression; - }; - bool useCache() const { return (_cache->capacityBytes() != 0) && (_cache->capacity() != 0); } - using CacheParams = vespalib::CacheParam< - vespalib::LruParam<DocumentIdT, Value>, - BackingStore, - vespalib::zero<DocumentIdT>, - vespalib::size<Value> - >; - using Cache = vespalib::cache<CacheParams>; - using VisitCache = docstore::VisitCache; - Config _config; IDataStore & _backingStore; - BackingStore _store; + std::unique_ptr<BackingStore> _store; std::shared_ptr<Cache> _cache; std::shared_ptr<VisitCache> _visitCache; mutable volatile uint64_t _uncached_lookups; diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h index 518280bcc09..0602574058d 100644 --- a/searchlib/src/vespa/searchlib/docstore/visitcache.h +++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h @@ -5,6 +5,7 @@ #include "idocumentstore.h" #include "cachestats.h" #include <vespa/vespalib/stllike/cache.h> +#include <vespa/vespalib/stllike/hash_set.h> #include <vespa/vespalib/util/alloc.h> namespace search { diff --git a/searchlib/src/vespa/searchlib/expression/arrayatlookupfunctionnode.h b/searchlib/src/vespa/searchlib/expression/arrayatlookupfunctionnode.h index 271543126da..692f2d36764 100644 --- a/searchlib/src/vespa/searchlib/expression/arrayatlookupfunctionnode.h +++ b/searchlib/src/vespa/searchlib/expression/arrayatlookupfunctionnode.h @@ -4,6 +4,10 @@ #include <vespa/searchlib/expression/unaryfunctionnode.h> namespace search { + namespace attribute { + class IAttributeVector; + class IAttributeContext; + } namespace expression { class ArrayAtLookup : public UnaryFunctionNode diff --git a/searchlib/src/vespa/searchlib/expression/expressionnode.h b/searchlib/src/vespa/searchlib/expression/expressionnode.h index d5c388f18e5..69b7f430193 100644 --- a/searchlib/src/vespa/searchlib/expression/expressionnode.h +++ b/searchlib/src/vespa/searchlib/expression/expressionnode.h @@ -3,10 +3,13 @@ #include <vespa/fastos/fastos.h> #include <vespa/searchlib/common/identifiable.h> -#include <vespa/searchcommon/attribute/iattributecontext.h> +#include <vespa/vespalib/objects/identifiable.hpp> #include <vespa/vespalib/objects/visit.h> namespace search { + +namespace attribute { class IAttributeContext; } + namespace expression { typedef uint32_t DocId; diff --git a/searchlib/src/vespa/searchlib/expression/functionnodes.cpp b/searchlib/src/vespa/searchlib/expression/functionnodes.cpp index fff019767d4..fc46761270a 100644 --- a/searchlib/src/vespa/searchlib/expression/functionnodes.cpp +++ b/searchlib/src/vespa/searchlib/expression/functionnodes.cpp @@ -37,12 +37,11 @@ #include <vespa/searchlib/expression/strcatserializer.h> #include <vespa/searchlib/expression/normalizesubjectfunctionnode.h> #include <vespa/searchlib/expression/arrayoperationnode.h> +#include <vespa/vespalib/objects/serializer.hpp> +#include <vespa/vespalib/objects/deserializer.hpp> #include <map> #include <vespa/vespalib/util/md5.h> -#include <vespa/log/log.h> - -LOG_SETUP(".searchlib.documentexpressions"); namespace search { namespace expression { @@ -201,7 +200,6 @@ namespace { void MultiArgFunctionNode::onPrepare(bool preserveAccurateTypes) { - LOG(debug, "MultiArgFunctionNode::onPrepare(this=%p) Actual class = %s", this, getClass().name()); for(size_t i(0), m(_args.size()); i < m; i++) { _args[i]->prepare(preserveAccurateTypes); } diff --git a/searchlib/src/vespa/searchlib/expression/interpolatedlookupfunctionnode.h b/searchlib/src/vespa/searchlib/expression/interpolatedlookupfunctionnode.h index d81acb929f1..73d84b27dca 100644 --- a/searchlib/src/vespa/searchlib/expression/interpolatedlookupfunctionnode.h +++ b/searchlib/src/vespa/searchlib/expression/interpolatedlookupfunctionnode.h @@ -4,6 +4,8 @@ #include <vespa/searchlib/expression/unaryfunctionnode.h> namespace search { + namespace attribute { class IAttributeVector; } + namespace expression { class InterpolatedLookup : public UnaryFunctionNode diff --git a/searchlib/src/vespa/searchlib/expression/rawbucketresultnode.cpp b/searchlib/src/vespa/searchlib/expression/rawbucketresultnode.cpp index df0d7384e35..27a187addb6 100644 --- a/searchlib/src/vespa/searchlib/expression/rawbucketresultnode.cpp +++ b/searchlib/src/vespa/searchlib/expression/rawbucketresultnode.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include "rawbucketresultnode.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace expression { diff --git a/searchlib/src/vespa/searchlib/expression/resultnode.h b/searchlib/src/vespa/searchlib/expression/resultnode.h index caf01a5fb5d..b30ff68c51c 100644 --- a/searchlib/src/vespa/searchlib/expression/resultnode.h +++ b/searchlib/src/vespa/searchlib/expression/resultnode.h @@ -4,6 +4,7 @@ #include <vespa/searchlib/expression/expressionnode.h> #include <vespa/searchlib/expression/serializer.h> #include <vespa/vespalib/util/exception.h> +#include <vespa/vespalib/util/buffer.h> namespace search { namespace expression { diff --git a/searchlib/src/vespa/searchlib/expression/resultnodes.cpp b/searchlib/src/vespa/searchlib/expression/resultnodes.cpp index 2a1e3ea1981..e812de071f5 100644 --- a/searchlib/src/vespa/searchlib/expression/resultnodes.cpp +++ b/searchlib/src/vespa/searchlib/expression/resultnodes.cpp @@ -8,9 +8,9 @@ #include <vespa/searchlib/expression/nullresultnode.h> #include <vespa/searchlib/expression/positiveinfinityresultnode.h> #include <cmath> -#include <vespa/log/log.h> - -LOG_SETUP(".searchlib.documentexpressions"); +#include <vespa/vespalib/objects/visit.hpp> +#include <vespa/vespalib/objects/serializer.hpp> +#include <vespa/vespalib/objects/deserializer.hpp> namespace search { namespace expression { diff --git a/searchlib/src/vespa/searchlib/expression/resultvector.h b/searchlib/src/vespa/searchlib/expression/resultvector.h index fc3d9037d45..019a9d694a8 100644 --- a/searchlib/src/vespa/searchlib/expression/resultvector.h +++ b/searchlib/src/vespa/searchlib/expression/resultvector.h @@ -10,7 +10,7 @@ #include "floatbucketresultnode.h" #include "stringbucketresultnode.h" #include "rawbucketresultnode.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <algorithm> namespace search { diff --git a/searchlib/src/vespa/searchlib/expression/stringbucketresultnode.cpp b/searchlib/src/vespa/searchlib/expression/stringbucketresultnode.cpp index 2b7b4f096ff..d348fbb849d 100644 --- a/searchlib/src/vespa/searchlib/expression/stringbucketresultnode.cpp +++ b/searchlib/src/vespa/searchlib/expression/stringbucketresultnode.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include "stringbucketresultnode.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace expression { diff --git a/searchlib/src/vespa/searchlib/query/query.cpp b/searchlib/src/vespa/searchlib/query/query.cpp index 861b0258dc1..188ac1584d4 100644 --- a/searchlib/src/vespa/searchlib/query/query.cpp +++ b/searchlib/src/vespa/searchlib/query/query.cpp @@ -1,12 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include <vespa/searchlib/query/query.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> using vespalib::Identifiable; -namespace search -{ +namespace search { IMPLEMENT_IDENTIFIABLE_ABSTRACT_NS(search, QueryConnector, QueryNode); IMPLEMENT_IDENTIFIABLE_NS(search, Query, Identifiable); diff --git a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp index 73a7c3d7b84..9e324a5f260 100644 --- a/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/blueprint.cpp @@ -3,7 +3,7 @@ #include <vespa/fastos/fastos.h> #include <vespa/log/log.h> #include "blueprint.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <vespa/vespalib/objects/objectdumper.h> #include <vespa/vespalib/util/stringfmt.h> #include "leaf_blueprints.h" diff --git a/searchlib/src/vespa/searchlib/queryeval/booleanmatchiteratorwrapper.cpp b/searchlib/src/vespa/searchlib/queryeval/booleanmatchiteratorwrapper.cpp index 1510716a84b..9c3dec5c1b2 100644 --- a/searchlib/src/vespa/searchlib/queryeval/booleanmatchiteratorwrapper.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/booleanmatchiteratorwrapper.cpp @@ -1,12 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".booleanmatchiteratorwrapper"); #include "booleanmatchiteratorwrapper.h" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/fef/termfieldmatchdataarray.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp index 62efcab7c4c..015b3f25499 100644 --- a/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/dot_product_blueprint.cpp @@ -1,14 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".queryeval.dot_product_blueprint"); - #include "dot_product_blueprint.h" #include "dot_product_search.h" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <algorithm> namespace search { diff --git a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp index e61fd77918c..30ae5e023ef 100644 --- a/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/equiv_blueprint.cpp @@ -3,6 +3,7 @@ #include <vespa/fastos/fastos.h> #include "equiv_blueprint.h" #include "equivsearch.h" +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/multisearch.cpp b/searchlib/src/vespa/searchlib/queryeval/multisearch.cpp index 60a2d373e75..35dea4f1b63 100644 --- a/searchlib/src/vespa/searchlib/queryeval/multisearch.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/multisearch.cpp @@ -2,7 +2,7 @@ #include <vespa/fastos/fastos.h> #include "multisearch.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp index ec5c7d49910..cce2f22797b 100644 --- a/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/simple_phrase_blueprint.cpp @@ -1,14 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".simple_phrase_blueprint"); - #include "simple_phrase_blueprint.h" #include "simple_phrase_search.h" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <algorithm> #include <map> diff --git a/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp b/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp index 1482ec21fed..34388a11af2 100644 --- a/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/sourceblendersearch.cpp @@ -1,9 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> #include "sourceblendersearch.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp index b57694fc07d..d92ed9007bd 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_blueprint.cpp @@ -1,14 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".queryeval.parallel_weak_and_blueprint"); - #include "wand_parts.h" #include "parallel_weak_and_blueprint.h" #include "parallel_weak_and_search.h" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <algorithm> namespace search { diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.cpp index c021557a0f5..00bb4eda04d 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.cpp @@ -1,7 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "wand_parts.h" -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp index 988be3f6ba9..fd07bcfef40 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp @@ -6,7 +6,7 @@ #include <vespa/searchlib/queryeval/orsearch.h> #include <vespa/vespalib/util/left_right_heap.h> #include <vespa/vespalib/util/priority_queue.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> namespace search { namespace queryeval { diff --git a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp index d572fd5f48b..8c73601c312 100644 --- a/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/weighted_set_term_blueprint.cpp @@ -1,14 +1,11 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include <vespa/log/log.h> -LOG_SETUP(".queryeval.weighted_set_term.blueprint"); - #include "weighted_set_term_blueprint.h" #include "weighted_set_term_search.h" #include <vespa/searchlib/fef/termfieldmatchdata.h> #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/vespalib/objects/visit.h> +#include <vespa/vespalib/objects/visit.hpp> #include <algorithm> namespace search { diff --git a/staging_vespalib/src/vespa/vespalib/objects/deserializer.h b/staging_vespalib/src/vespa/vespalib/objects/deserializer.h index 3e3eb3cc526..e25e08e67c9 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/deserializer.h +++ b/staging_vespalib/src/vespa/vespalib/objects/deserializer.h @@ -6,8 +6,7 @@ #include <vector> #include <stdint.h> -namespace vespalib -{ +namespace vespalib { class Identifiable; @@ -57,25 +56,9 @@ public: Deserializer & operator >> (double & value) { return get(_unspecifiedField, value); } Deserializer & operator >> (string & value) { return get(_unspecifiedField, value); } template <typename T> - Deserializer & operator >> (vespalib::Array<T> & v) { - uint32_t sz; - get(_sizeField, sz); - v.resize(sz); - for(size_t i(0); i < sz; i++) { - (*this) >> v[i]; - } - return *this; - } + Deserializer & operator >> (vespalib::Array<T> & v); template <typename T> - Deserializer & operator >> (std::vector<T> & v) { - uint32_t sz; - get(_sizeField, sz); - v.resize(sz); - for(size_t i(0); i < sz; i++) { - (*this) >> v[i]; - } - return *this; - } + Deserializer & operator >> (std::vector<T> & v); }; diff --git a/staging_vespalib/src/vespa/vespalib/objects/deserializer.hpp b/staging_vespalib/src/vespa/vespalib/objects/deserializer.hpp new file mode 100644 index 00000000000..4d01994461a --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/deserializer.hpp @@ -0,0 +1,33 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "deserializer.h" + +namespace vespalib { + +template <typename T> +Deserializer & +Deserializer::operator >> (vespalib::Array<T> & v) { + uint32_t sz; + get(_sizeField, sz); + v.resize(sz); + for(size_t i(0); i < sz; i++) { + (*this) >> v[i]; + } + return *this; +} + +template <typename T> +Deserializer & +Deserializer::operator >> (std::vector<T> & v) { + uint32_t sz; + get(_sizeField, sz); + v.resize(sz); + for(size_t i(0); i < sz; i++) { + (*this) >> v[i]; + } + return *this; +} + +} + diff --git a/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h b/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h index 9592566b7d4..e3f55161b77 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h +++ b/staging_vespalib/src/vespa/vespalib/objects/fieldbase.h @@ -3,8 +3,7 @@ #include <vespa/vespalib/stllike/string.h> -namespace vespalib -{ +namespace vespalib { class IFieldBase { diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp index c6459219fc4..f142fedade5 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp +++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.cpp @@ -1,20 +1,89 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> +#include "identifiable.hpp" #include <cassert> #include <vespa/vespalib/util/stringfmt.h> #include <stdexcept> #include <algorithm> -#include <vespa/vespalib/objects/identifiable.h> +#include <vespa/vespalib/objects/nbostream.h> #include "objectdumper.h" #include "visit.h" #include "objectpredicate.h" #include "objectoperation.h" #include <vespa/vespalib/util/classname.h> +#include <vespa/vespalib/stllike/hash_set.h> + namespace vespalib { -Identifiable::Register * Identifiable::_register = NULL; -Identifiable::ILoader * Identifiable::_classLoader = NULL; +namespace { + +class Register { +public: + using RuntimeClass = Identifiable::RuntimeClass; + Register(); + ~Register(); + bool append(RuntimeClass * c); + bool erase(RuntimeClass * c); + const RuntimeClass * classFromId(unsigned id) const; + const RuntimeClass * classFromName(const char * name) const; + const char * id2Name(unsigned id) const; + unsigned name2Id(const char * name) const; + bool empty() const { return _listById.empty(); } +private: + struct GetId { uint32_t operator() (const RuntimeClass * f) const { return f->id(); } }; + struct HashId { size_t operator() (const RuntimeClass * f) const { return f->id(); } }; + struct EqualId { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return a->id() == b->id(); } }; + struct GetName { const char * operator() (const RuntimeClass * f) const { return f->name(); } }; + struct HashName { size_t operator() (const RuntimeClass * f) const { return hashValue(f->name()); } }; + struct EqualName { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return strcmp(a->name(), b->name()) == 0; } }; + typedef hash_set<RuntimeClass *, HashId, EqualId> IdList; + typedef hash_set<RuntimeClass *, HashName, EqualName> NameList; + IdList _listById; + NameList _listByName; +}; + +Register::Register() : + _listById(), + _listByName() +{ } + +Register::~Register() { } + +bool Register::erase(Identifiable::RuntimeClass * c) +{ + _listById.erase(c); + _listByName.erase(c); + return true; +} + +bool Register::append(Identifiable::RuntimeClass * c) +{ + bool ok((_listById.find(c) == _listById.end()) && ((_listByName.find(c) == _listByName.end()))); + if (ok) { + _listById.insert(c); + _listByName.insert(c); + } + return ok; +} + +const Identifiable::RuntimeClass * Register::classFromId(unsigned id) const +{ + IdList::const_iterator it(_listById.find<uint32_t, GetId, hash<uint32_t>, std::equal_to<uint32_t> >(id)); + return (it != _listById.end()) ? *it : NULL; +} + +const Identifiable::RuntimeClass * Register::classFromName(const char *name) const +{ + NameList::const_iterator it(_listByName.find<const char *, GetName, hash<const char *>, std::equal_to<const char *> >(name)); + return (it != _listByName.end()) ? *it : NULL; +} + +Register * _register = nullptr; + +} + +Identifiable::ILoader * Identifiable::_classLoader = nullptr; FieldBase Identifiable::hasObjectField("hasObject"); FieldBase Identifiable::sizeField("size"); FieldBase Identifiable::classIdField("classId"); @@ -22,6 +91,16 @@ FieldBase Identifiable::objectField("object"); IMPLEMENT_IDENTIFIABLE(Identifiable, Identifiable); +const Identifiable::RuntimeClass * +Identifiable::classFromId(unsigned id) { + return _register->classFromId(id); +} + +const Identifiable::RuntimeClass * +Identifiable::classFromName(const char * name) { + return _register->classFromName(name); +} + Identifiable::RuntimeClass::RuntimeClass(RuntimeInfo * info_) : _rt(info_) { @@ -36,23 +115,23 @@ Identifiable::RuntimeClass::RuntimeClass(RuntimeInfo * info_) : } } } - if (Identifiable::_register == NULL) { - Identifiable::_register = new Register(); + if (_register == NULL) { + _register = new Register(); } - if (! Identifiable::_register->append(this)) { - const RuntimeClass * old = Identifiable::_register->classFromId(id()); + if (! _register->append(this)) { + const RuntimeClass * old = _register->classFromId(id()); throw std::runtime_error(make_string("Duplicate Identifiable object(%s, %s, %d) being registered. Choose a unique id. Object (%s, %s, %d) is using it.", name(), info(), id(), old->name(), old->info(), old->id())); } } Identifiable::RuntimeClass::~RuntimeClass() { - if ( ! Identifiable::_register->erase(this) ) { + if ( ! _register->erase(this) ) { assert(0); } - if (Identifiable::_register->empty()) { - delete Identifiable::_register; - Identifiable::_register = NULL; + if (_register->empty()) { + delete _register; + _register = NULL; } } @@ -63,23 +142,6 @@ bool Identifiable::RuntimeClass::inherits(unsigned cid) const return (cid == cur->_id); } -Identifiable::Register::Register() : - _listById(), - _listByName() -{ -} - -Identifiable::Register::~Register() -{ -} - -bool Identifiable::Register::erase(Identifiable::RuntimeClass * c) -{ - _listById.erase(c); - _listByName.erase(c); - return true; -} - class SortById : public std::binary_function<const Identifiable::RuntimeClass *, const Identifiable::RuntimeClass *, bool> { public: bool operator() (const Identifiable::RuntimeClass * x, const Identifiable::RuntimeClass * y) const { @@ -94,28 +156,6 @@ public: } }; -bool Identifiable::Register::append(Identifiable::RuntimeClass * c) -{ - bool ok((_listById.find(c) == _listById.end()) && ((_listByName.find(c) == _listByName.end()))); - if (ok) { - _listById.insert(c); - _listByName.insert(c); - } - return ok; -} - -const Identifiable::RuntimeClass * Identifiable::Register::classFromId(unsigned id) const -{ - IdList::const_iterator it(_listById.find<uint32_t, GetId, hash<uint32_t>, std::equal_to<uint32_t> >(id)); - return (it != _listById.end()) ? *it : NULL; -} - -const Identifiable::RuntimeClass * Identifiable::Register::classFromName(const char *name) const -{ - NameList::const_iterator it(_listByName.find<const char *, GetName, hash<const char *>, std::equal_to<const char *> >(name)); - return (it != _listByName.end()) ? *it : NULL; -} - Serializer & operator << (Serializer & os, const Identifiable & obj) { os.put(Identifiable::classIdField, obj.getClass().id()); diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.h b/staging_vespalib/src/vespa/vespalib/objects/identifiable.h index 67f5917c68d..33c936afbd4 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/identifiable.h +++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.h @@ -28,8 +28,6 @@ #include "objectvisitor.h" #include <vespa/vespalib/util/memory.h> -#include <vespa/vespalib/util/linkedptr.h> -#include <vespa/vespalib/stllike/hash_set.h> #define IDENTIFIABLE_CLASSID(cclass) CID_##cclass #define IDENTIFIABLE_CLASSID_NS(ns, cclass) CID_##ns##_##cclass @@ -124,8 +122,7 @@ virtual vespalib::Deserializer & onDeserialize(vespalib::Deserializer & is); -namespace vespalib -{ +namespace vespalib { class ObjectPredicate; class ObjectOperation; @@ -233,12 +230,12 @@ public: * Given the unique registered id of a class it will look up the object describing it. * @return object describing the class. */ - static const RuntimeClass * classFromId(unsigned id) { return _register->classFromId(id); } + static const RuntimeClass * classFromId(unsigned id); /** * Given the unique registered name of a class it will look up the object describing it. * @return object describing the class. */ - static const RuntimeClass * classFromName(const char * name) { return _register->classFromName(name); } + static const RuntimeClass * classFromName(const char * name); /** * Here you can provide an optional classloader. */ @@ -402,165 +399,8 @@ private: virtual Serializer & onSerialize(Serializer & os) const; virtual Deserializer & onDeserialize(Deserializer & is); - class Register { - public: - Register(); - ~Register(); - bool append(RuntimeClass * c); - bool erase(RuntimeClass * c); - const RuntimeClass * classFromId(unsigned id) const; - const RuntimeClass * classFromName(const char * name) const; - const char * id2Name(unsigned id) const; - unsigned name2Id(const char * name) const; - bool empty() const { return _listById.empty(); } - private: - struct GetId { uint32_t operator() (const RuntimeClass * f) const { return f->id(); } }; - struct HashId { size_t operator() (const RuntimeClass * f) const { return f->id(); } }; - struct EqualId { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return a->id() == b->id(); } }; - struct GetName { const char * operator() (const RuntimeClass * f) const { return f->name(); } }; - struct HashName { size_t operator() (const RuntimeClass * f) const { return hashValue(f->name()); } }; - struct EqualName { bool operator() (const RuntimeClass * a, const RuntimeClass * b) const { return strcmp(a->name(), b->name()) == 0; } }; - typedef hash_set<RuntimeClass *, HashId, EqualId> IdList; - typedef hash_set<RuntimeClass *, HashName, EqualName> NameList; - IdList _listById; - NameList _listByName; - }; - static Register * _register; static ILoader * _classLoader; }; -template <typename T> -Serializer & Identifiable::serialize(const T & v, Serializer & os) { - uint32_t sz(v.size()); - os.put(sizeField, sz); - for(size_t i(0); i < sz; i++) { - v[i].serialize(os); - } - return os; -} - -template <typename T> -Deserializer & Identifiable::deserialize(T & v, Deserializer & is) { - uint32_t sz(0); - is.get(sizeField, sz); - v.resize(sz); - for(size_t i(0); i < sz; i++) { - v[i].deserialize(is); - } - return is; -} - -template <typename T> -class IdentifiablePtr : public CloneablePtr<T> -{ -public: - IdentifiablePtr(const T &t) : CloneablePtr<T>(t.clone()) {} - IdentifiablePtr(T * p=NULL) : CloneablePtr<T>(p) { } - int cmp(const IdentifiablePtr<T> &rhs) const { - const T *a = this->get(); - const T *b = rhs.get(); - if (a == 0) { - return (b == 0) ? 0 : -1; - } - return (b == 0) ? 1 : a->cmp(*b); - } - bool operator < (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) < 0); } - bool operator > (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) > 0); } - bool operator == (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) == 0); } - bool operator != (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) != 0); } - Serializer & serialize(Serializer & os) const { - if (this->get()) { - os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); - } else { - os.put(Identifiable::hasObjectField, uint8_t(0)); - } - return os; - } - Deserializer & deserialize(Deserializer & is) { - uint8_t hasObject; - is.get(Identifiable::hasObjectField, hasObject); - if (hasObject) { - this->reset(static_cast<T *>(Identifiable::create(is).release())); - } - return is; - } - friend Serializer & operator << (Serializer & os, const IdentifiablePtr<T> & agg) { return agg.serialize(os); } - friend Deserializer & operator >> (Deserializer & is, IdentifiablePtr<T> & agg) { return agg.deserialize(is); } -}; - -template <typename T> -class IdentifiableSharedPtr : public std::shared_ptr<T> -{ -public: - IdentifiableSharedPtr(const T &t) : std::shared_ptr<T>(t.clone()) {} - IdentifiableSharedPtr(T * p=NULL) : std::shared_ptr<T>(p) { } - int cmp(const IdentifiableSharedPtr<T> &rhs) const { - const T *a = this->get(); - const T *b = rhs.get(); - if (a == 0) { - return (b == 0) ? 0 : -1; - } - return (b == 0) ? 1 : a->cmp(*b); - } - bool operator < (const IdentifiableSharedPtr<T> &rhs) const { - return (cmp(rhs) < 0); - } - Serializer & serialize(Serializer & os) const { - if (this->get()) { - os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); - } else { - os.put(Identifiable::hasObjectField, uint8_t(0)); - } - return os; - } - Deserializer & deserialize(Deserializer & is) { - uint8_t hasObject; - is.get(Identifiable::hasObjectField, hasObject); - if (hasObject) { - reset(static_cast<T *>(Identifiable::create(is).release())); - } - return is; - } - friend Serializer & operator << (Serializer & os, const IdentifiableSharedPtr<T> & agg) { return agg.serialize(os); } - friend Deserializer & operator >> (Deserializer & is, IdentifiableSharedPtr<T> & agg) { return agg.deserialize(is); } -}; - -template <typename T> -class IdentifiableLinkedPtr : public LinkedPtr<T> -{ -public: - IdentifiableLinkedPtr(const T &t) : LinkedPtr<T>(t.clone()) {} - IdentifiableLinkedPtr(T * p=NULL) : LinkedPtr<T>(p) { } - int cmp(const IdentifiableLinkedPtr<T> &rhs) const { - const T *a = this->get(); - const T *b = rhs.get(); - if (a == 0) { - return (b == 0) ? 0 : -1; - } - return (b == 0) ? 1 : a->cmp(*b); - } - bool operator < (const IdentifiableLinkedPtr<T> &rhs) const { - return (cmp(rhs) < 0); - } - Serializer & serialize(Serializer & os) const { - if (this->get()) { - os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); - } else { - os.put(Identifiable::hasObjectField, uint8_t(0)); - } - return os; - } - Deserializer & deserialize(Deserializer & is) { - uint8_t hasObject; - is.get(Identifiable::hasObjectField, hasObject); - if (hasObject) { - this->reset(static_cast<T *>(Identifiable::create(is).release())); - } - return is; - } - friend Serializer & operator << (Serializer & os, const IdentifiableLinkedPtr<T> & agg) { return agg.serialize(os); } - friend Deserializer & operator >> (Deserializer & is, IdentifiableLinkedPtr<T> & agg) { return agg.deserialize(is); } -}; - } diff --git a/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp b/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp new file mode 100644 index 00000000000..617d631328b --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/identifiable.hpp @@ -0,0 +1,157 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once +/** + * \class vespalib::Identifiable + * \ingroup util + * + * \brief Superclass for objects adding some runtime type information. + * + * This class is a superclass used by many other classes to add some runtime + * information. + * + * This can be used to verify type to be able to do cheap static casts + * instead of dynamic casts. It can be used to identify type of object, and + * it can also be used to generate an object of the given type (If it's not + * an identifiable abstract type). + * + */ + +#include "identifiable.h" +#include <vespa/vespalib/util/linkedptr.h> + +namespace vespalib { + +template <typename T> +Serializer & Identifiable::serialize(const T & v, Serializer & os) { + uint32_t sz(v.size()); + os.put(sizeField, sz); + for(size_t i(0); i < sz; i++) { + v[i].serialize(os); + } + return os; +} + +template <typename T> +Deserializer & Identifiable::deserialize(T & v, Deserializer & is) { + uint32_t sz(0); + is.get(sizeField, sz); + v.resize(sz); + for(size_t i(0); i < sz; i++) { + v[i].deserialize(is); + } + return is; +} + +template <typename T> +class IdentifiablePtr : public CloneablePtr<T> +{ +public: + IdentifiablePtr(const T &t) : CloneablePtr<T>(t.clone()) {} + IdentifiablePtr(T * p=NULL) : CloneablePtr<T>(p) { } + int cmp(const IdentifiablePtr<T> &rhs) const { + const T *a = this->get(); + const T *b = rhs.get(); + if (a == 0) { + return (b == 0) ? 0 : -1; + } + return (b == 0) ? 1 : a->cmp(*b); + } + bool operator < (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) < 0); } + bool operator > (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) > 0); } + bool operator == (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) == 0); } + bool operator != (const IdentifiablePtr<T> &rhs) const { return (cmp(rhs) != 0); } + Serializer & serialize(Serializer & os) const { + if (this->get()) { + os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); + } else { + os.put(Identifiable::hasObjectField, uint8_t(0)); + } + return os; + } + Deserializer & deserialize(Deserializer & is) { + uint8_t hasObject; + is.get(Identifiable::hasObjectField, hasObject); + if (hasObject) { + this->reset(static_cast<T *>(Identifiable::create(is).release())); + } + return is; + } + friend Serializer & operator << (Serializer & os, const IdentifiablePtr<T> & agg) { return agg.serialize(os); } + friend Deserializer & operator >> (Deserializer & is, IdentifiablePtr<T> & agg) { return agg.deserialize(is); } +}; + +template <typename T> +class IdentifiableSharedPtr : public std::shared_ptr<T> +{ +public: + IdentifiableSharedPtr(const T &t) : std::shared_ptr<T>(t.clone()) {} + IdentifiableSharedPtr(T * p=NULL) : std::shared_ptr<T>(p) { } + int cmp(const IdentifiableSharedPtr<T> &rhs) const { + const T *a = this->get(); + const T *b = rhs.get(); + if (a == 0) { + return (b == 0) ? 0 : -1; + } + return (b == 0) ? 1 : a->cmp(*b); + } + bool operator < (const IdentifiableSharedPtr<T> &rhs) const { + return (cmp(rhs) < 0); + } + Serializer & serialize(Serializer & os) const { + if (this->get()) { + os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); + } else { + os.put(Identifiable::hasObjectField, uint8_t(0)); + } + return os; + } + Deserializer & deserialize(Deserializer & is) { + uint8_t hasObject; + is.get(Identifiable::hasObjectField, hasObject); + if (hasObject) { + reset(static_cast<T *>(Identifiable::create(is).release())); + } + return is; + } + friend Serializer & operator << (Serializer & os, const IdentifiableSharedPtr<T> & agg) { return agg.serialize(os); } + friend Deserializer & operator >> (Deserializer & is, IdentifiableSharedPtr<T> & agg) { return agg.deserialize(is); } +}; + +template <typename T> +class IdentifiableLinkedPtr : public LinkedPtr<T> +{ +public: + IdentifiableLinkedPtr(const T &t) : LinkedPtr<T>(t.clone()) {} + IdentifiableLinkedPtr(T * p=NULL) : LinkedPtr<T>(p) { } + int cmp(const IdentifiableLinkedPtr<T> &rhs) const { + const T *a = this->get(); + const T *b = rhs.get(); + if (a == 0) { + return (b == 0) ? 0 : -1; + } + return (b == 0) ? 1 : a->cmp(*b); + } + bool operator < (const IdentifiableLinkedPtr<T> &rhs) const { + return (cmp(rhs) < 0); + } + Serializer & serialize(Serializer & os) const { + if (this->get()) { + os.put(Identifiable::hasObjectField, uint8_t(1)) << *this->get(); + } else { + os.put(Identifiable::hasObjectField, uint8_t(0)); + } + return os; + } + Deserializer & deserialize(Deserializer & is) { + uint8_t hasObject; + is.get(Identifiable::hasObjectField, hasObject); + if (hasObject) { + this->reset(static_cast<T *>(Identifiable::create(is).release())); + } + return is; + } + friend Serializer & operator << (Serializer & os, const IdentifiableLinkedPtr<T> & agg) { return agg.serialize(os); } + friend Deserializer & operator >> (Deserializer & is, IdentifiableLinkedPtr<T> & agg) { return agg.deserialize(is); } +}; + +} diff --git a/staging_vespalib/src/vespa/vespalib/objects/nboserializer.cpp b/staging_vespalib/src/vespa/vespalib/objects/nboserializer.cpp index 00e7a9c7edd..38dca76a0cd 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/nboserializer.cpp +++ b/staging_vespalib/src/vespa/vespalib/objects/nboserializer.cpp @@ -1,9 +1,14 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> #include "nboserializer.h" +#include <vespa/vespalib/objects/nbostream.h> namespace vespalib { +const char * NBOSerializer::peek() const { + return _stream.peek(); +} + NBOSerializer &NBOSerializer::put(const IFieldBase &, bool value) { _stream << value; return *this; diff --git a/staging_vespalib/src/vespa/vespalib/objects/nboserializer.h b/staging_vespalib/src/vespa/vespalib/objects/nboserializer.h index bac768fec2c..9288757508e 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/nboserializer.h +++ b/staging_vespalib/src/vespa/vespalib/objects/nboserializer.h @@ -3,9 +3,11 @@ #include <vespa/vespalib/objects/serializer.h> #include <vespa/vespalib/objects/deserializer.h> -#include <vespa/vespalib/objects/nbostream.h> namespace vespalib { + +class nbostream; + class NBOSerializer : public Serializer, public Deserializer { public: NBOSerializer(nbostream &stream) : _stream(stream) { } @@ -27,7 +29,7 @@ public: virtual NBOSerializer &get(const IFieldBase &field, float &value); virtual NBOSerializer &get(const IFieldBase &field, string &value); - const char *peek() const { return _stream.peek(); } + const char *peek() const; const nbostream &getStream() const { return _stream; } nbostream &getStream() { return _stream; } diff --git a/staging_vespalib/src/vespa/vespalib/objects/serializer.h b/staging_vespalib/src/vespa/vespalib/objects/serializer.h index c846123ce45..5e67b968946 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/serializer.h +++ b/staging_vespalib/src/vespa/vespalib/objects/serializer.h @@ -6,8 +6,7 @@ #include <vector> #include <stdint.h> -namespace vespalib -{ +namespace vespalib { class Identifiable; @@ -43,23 +42,9 @@ public: Serializer & operator << (double value) { return put(_unspecifiedField, value); } Serializer & operator << (const stringref & value) { return put(_unspecifiedField, value); } template <typename T> - Serializer & operator << (const vespalib::Array<T> & v) { - uint32_t sz(v.size()); - put(_sizeField, sz); - for(size_t i(0); i < sz; i++) { - (*this) << v[i]; - } - return *this; - } + Serializer & operator << (const vespalib::Array<T> & v); template <typename T> - Serializer & operator << (const std::vector<T> & v) { - uint32_t sz(v.size()); - put(_sizeField, sz); - for(size_t i(0); i < sz; i++) { - (*this) << v[i]; - } - return *this; - } + Serializer & operator << (const std::vector<T> & v); }; } diff --git a/staging_vespalib/src/vespa/vespalib/objects/serializer.hpp b/staging_vespalib/src/vespa/vespalib/objects/serializer.hpp new file mode 100644 index 00000000000..4b632249679 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/serializer.hpp @@ -0,0 +1,33 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/objects/fieldbase.h> +#include <vespa/vespalib/util/array.h> +#include <vector> +#include <stdint.h> + +namespace vespalib { + +template <typename T> +Serializer & +Serializer::operator << (const vespalib::Array<T> & v) { + uint32_t sz(v.size()); + put(_sizeField, sz); + for(size_t i(0); i < sz; i++) { + (*this) << v[i]; + } + return *this; +} +template <typename T> +Serializer & +Serializer::operator << (const std::vector<T> & v) { + uint32_t sz(v.size()); + put(_sizeField, sz); + for(size_t i(0); i < sz; i++) { + (*this) << v[i]; + } + return *this; +} + +} + diff --git a/staging_vespalib/src/vespa/vespalib/objects/visit.cpp b/staging_vespalib/src/vespa/vespalib/objects/visit.cpp index 3b160961a01..fc266d5130d 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/visit.cpp +++ b/staging_vespalib/src/vespa/vespalib/objects/visit.cpp @@ -1,6 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include <vespa/fastos/fastos.h> -#include "visit.h" +#include "visit.hpp" void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable *obj) { if (obj != 0) { diff --git a/staging_vespalib/src/vespa/vespalib/objects/visit.h b/staging_vespalib/src/vespa/vespalib/objects/visit.h index 42826c7ff74..fa5bd8f177d 100644 --- a/staging_vespalib/src/vespa/vespalib/objects/visit.h +++ b/staging_vespalib/src/vespa/vespalib/objects/visit.h @@ -1,11 +1,12 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <string> -#include <vector> -#include <vespa/vespalib/util/stringfmt.h> -#include "objectvisitor.h" -#include "identifiable.h" +#include <vespa/vespalib/stllike/string.h> + +namespace vespalib { + class Identifiable; + class ObjectVisitor; +} void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable *obj); void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Identifiable &obj); @@ -21,75 +22,5 @@ void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, uint64_t void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, float value); void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, double value); void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::string &value); -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::string &value); +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::stringref &value); void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const char *value); - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::CloneablePtr<T> &ptr) { - if (ptr.get()) { - visit(self, name, *ptr); - } else { - self.visitNull(name); - } -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::shared_ptr<T> &ptr) { - if (ptr.get()) { - visit(self, name, *ptr); - } else { - self.visitNull(name); - } -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::unique_ptr<T> &ptr) { - if (ptr.get()) { - visit(self, name, *ptr); - } else { - self.visitNull(name); - } -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::LinkedPtr<T> &ptr) { - if (ptr.get()) { - visit(self, name, *ptr); - } else { - self.visitNull(name); - } -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiablePtr<T> &ptr) { - visit(self, name, ptr.get()); -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableLinkedPtr<T> &ptr) { - visit(self, name, ptr.get()); -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableSharedPtr<T> &ptr) { - visit(self, name, ptr.get()); -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::vector<T> &list) { - self.openStruct(name, "std::vector"); - for (uint32_t i = 0; i < list.size(); ++i) { - visit(self, vespalib::make_string("[%u]", i), list[i]); - } - self.closeStruct(); -} - -template<typename T> -void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Array<T> &list) { - self.openStruct(name, "vespalib::Array"); - for (uint32_t i = 0; i < list.size(); ++i) { - visit(self, vespalib::make_string("[%u]", i), list[i]); - } - self.closeStruct(); -} - diff --git a/staging_vespalib/src/vespa/vespalib/objects/visit.hpp b/staging_vespalib/src/vespa/vespalib/objects/visit.hpp new file mode 100644 index 00000000000..ca4cd5972bd --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/objects/visit.hpp @@ -0,0 +1,78 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "visit.h" +#include <vector> +#include <vespa/vespalib/util/stringfmt.h> +#include "objectvisitor.h" +#include "identifiable.hpp" + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::CloneablePtr<T> &ptr) { + if (ptr.get()) { + visit(self, name, *ptr); + } else { + self.visitNull(name); + } +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::shared_ptr<T> &ptr) { + if (ptr.get()) { + visit(self, name, *ptr); + } else { + self.visitNull(name); + } +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::unique_ptr<T> &ptr) { + if (ptr.get()) { + visit(self, name, *ptr); + } else { + self.visitNull(name); + } +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::LinkedPtr<T> &ptr) { + if (ptr.get()) { + visit(self, name, *ptr); + } else { + self.visitNull(name); + } +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiablePtr<T> &ptr) { + visit(self, name, ptr.get()); +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableLinkedPtr<T> &ptr) { + visit(self, name, ptr.get()); +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableSharedPtr<T> &ptr) { + visit(self, name, ptr.get()); +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::vector<T> &list) { + self.openStruct(name, "std::vector"); + for (uint32_t i = 0; i < list.size(); ++i) { + visit(self, vespalib::make_string("[%u]", i), list[i]); + } + self.closeStruct(); +} + +template<typename T> +void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Array<T> &list) { + self.openStruct(name, "vespalib::Array"); + for (uint32_t i = 0; i < list.size(); ++i) { + visit(self, vespalib::make_string("[%u]", i), list[i]); + } + self.closeStruct(); +} + diff --git a/vdslib/src/vespa/vdslib/container/parameters.cpp b/vdslib/src/vespa/vdslib/container/parameters.cpp index 83907ed6960..cbf5e3a9979 100644 --- a/vdslib/src/vespa/vdslib/container/parameters.cpp +++ b/vdslib/src/vespa/vdslib/container/parameters.cpp @@ -2,8 +2,7 @@ #include <vespa/fastos/fastos.h> #include <vespa/vdslib/container/parameters.h> - -#include <sstream> +#include <vespa/vespalib/objects/nbostream.h> using namespace vdslib; diff --git a/vespalib/src/vespa/vespalib/stllike/hash_fun.h b/vespalib/src/vespa/vespalib/stllike/hash_fun.h index 6a7533f8298..6dc22214005 100644 --- a/vespalib/src/vespa/vespalib/stllike/hash_fun.h +++ b/vespalib/src/vespa/vespalib/stllike/hash_fun.h @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include <string> #include <stdint.h> #include <vespa/vespalib/stllike/string.h> |