diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-06 15:56:27 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-02-08 12:51:37 +0000 |
commit | 474da0ab05ba58999f4d4840d62902b81f5378a9 (patch) | |
tree | c241825051e5b22b1bb4dcd41a12d24a43dd0e16 /searchcommon | |
parent | fdae546b833532aac0a2f49400ccf15071549c6b (diff) |
- Generate mode modern c++ code.
- Use existing predefined types.
- Allow for better management by allowing large string vectors to be mmapped.
Diffstat (limited to 'searchcommon')
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schema.cpp | 26 | ||||
-rw-r--r-- | searchcommon/src/vespa/searchcommon/common/schema.h | 15 |
2 files changed, 19 insertions, 22 deletions
diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index 0127f727069..c6a2a4532a3 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -48,7 +48,7 @@ writeFieldSets(vespalib::asciistream &os, struct FieldName { vespalib::string name; - FieldName(const std::vector<vespalib::string> & lines) + FieldName(const config::StringVector & lines) : name(ConfigParser::parse<vespalib::string>("name", lines)) { } @@ -64,8 +64,7 @@ getFieldId(vespalib::stringref name, const T &map) } // namespace -namespace search { -namespace index { +namespace search::index { const uint32_t Schema::UNKNOWN_FIELD_ID(std::numeric_limits<uint32_t>::max()); @@ -88,7 +87,7 @@ Schema::Field::Field(vespalib::stringref n, DataType dt, CollectionType ct, vesp } // XXX: Resource leak if exception is thrown. -Schema::Field::Field(const std::vector<vespalib::string> & lines) +Schema::Field::Field(const config::StringVector & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), _dataType(schema::dataTypeFromName(ConfigParser::parse<vespalib::string>("datatype", lines))), _collectionType(schema::collectionTypeFromName(ConfigParser::parse<vespalib::string>("collectiontype", lines))) @@ -140,7 +139,7 @@ Schema::IndexField::IndexField(vespalib::stringref name, DataType dt, { } -Schema::IndexField::IndexField(const std::vector<vespalib::string> &lines) +Schema::IndexField::IndexField(const config::StringVector &lines) : Field(lines), _avgElemLen(ConfigParser::parse<int32_t>("averageelementlen", lines, 512)), _interleaved_features(ConfigParser::parse<bool>("interleavedfeatures", lines, false)) @@ -181,11 +180,11 @@ Schema::IndexField::operator!=(const IndexField &rhs) const _interleaved_features != rhs._interleaved_features; } -Schema::FieldSet::FieldSet(const std::vector<vespalib::string> & lines) : +Schema::FieldSet::FieldSet(const config::StringVector & lines) : _name(ConfigParser::parse<vespalib::string>("name", lines)), _fields() { - std::vector<FieldName> fn = ConfigParser::parseArray<FieldName>("field", lines); + std::vector<FieldName> fn = ConfigParser::parseArray<std::vector<FieldName>>("field", lines); for (size_t i = 0; i < fn.size(); ++i) { _fields.push_back(fn[i].name); } @@ -238,16 +237,16 @@ Schema::loadFromFile(const vespalib::string & fileName) LOG(warning, "Could not open input file '%s' as part of loadFromFile()", fileName.c_str()); return false; } - std::vector<vespalib::string> lines; + config::StringVector lines; std::string tmpLine; while (file) { getline(file, tmpLine); lines.push_back(tmpLine); } - _indexFields = ConfigParser::parseArray<IndexField>("indexfield", lines); - _attributeFields = ConfigParser::parseArray<AttributeField>("attributefield", lines); - _summaryFields = ConfigParser::parseArray<SummaryField>("summaryfield", lines); - _fieldSets = ConfigParser::parseArray<FieldSet>("fieldset", lines); + _indexFields = ConfigParser::parseArray<std::vector<IndexField>>("indexfield", lines); + _attributeFields = ConfigParser::parseArray<std::vector<AttributeField>>("attributefield", lines); + _summaryFields = ConfigParser::parseArray<std::vector<SummaryField>>("summaryfield", lines); + _fieldSets = ConfigParser::parseArray<std::vector<FieldSet>>("fieldset", lines); _importedAttributeFields.clear(); // NOTE: these are not persisted to disk _indexIds.clear(); for (size_t i(0), m(_indexFields.size()); i < m; i++) { @@ -579,5 +578,4 @@ Schema::empty() const _importedAttributeFields.empty(); } -} // namespace search::index -} // namespace search +} diff --git a/searchcommon/src/vespa/searchcommon/common/schema.h b/searchcommon/src/vespa/searchcommon/common/schema.h index f86bb3068c5..3a9bcbdd904 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.h +++ b/searchcommon/src/vespa/searchcommon/common/schema.h @@ -3,10 +3,9 @@ #pragma once #include "datatype.h" -#include <vespa/vespalib/stllike/string.h> +#include <vespa/config/common/types.h> #include <vespa/vespalib/stllike/hash_map.h> #include <vespa/vespalib/util/ptrholder.h> -#include <vector> namespace vespalib { class asciistream; } namespace search::index { @@ -20,7 +19,6 @@ class Schema public: using UP = std::unique_ptr<Schema>; using SP = std::shared_ptr<Schema>; - using PH = vespalib::PtrHolder<Schema>; using DataType = schema::DataType; using CollectionType = schema::CollectionType; @@ -45,7 +43,7 @@ public: /** * Create this field based on the given config lines. **/ - Field(const std::vector<vespalib::string> & lines); + Field(const config::StringVector & lines); Field(const Field &) noexcept; Field & operator = (const Field &) noexcept; Field(Field &&) noexcept; @@ -92,7 +90,7 @@ public: /** * Create this index field based on the given config lines. **/ - IndexField(const std::vector<vespalib::string> &lines); + IndexField(const config::StringVector &lines); IndexField &setAvgElemLen(uint32_t avgElemLen) { _avgElemLen = avgElemLen; return *this; } IndexField &set_interleaved_features(bool value) { @@ -133,7 +131,7 @@ public: /** * Create this field collection based on the given config lines. **/ - FieldSet(const std::vector<vespalib::string> & lines); + FieldSet(const config::StringVector & lines); ~FieldSet(); @@ -143,8 +141,9 @@ public: } const vespalib::string &getName() const { return _name; } - const std::vector<vespalib::string> &getFields() const - { return _fields; } + const std::vector<vespalib::string> &getFields() const { + return _fields; + } bool operator==(const FieldSet &rhs) const; bool operator!=(const FieldSet &rhs) const; |