// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "integerbase.h" #include #include #include namespace search { using largeint_t = attribute::IAttributeVector::largeint_t; template IntegerAttributeTemplate::IntegerAttributeTemplate(const vespalib::string & name) : IntegerAttributeTemplate(name, BasicType::fromType(T())) { } template IntegerAttributeTemplate::IntegerAttributeTemplate(const vespalib::string & name, const Config & c) : IntegerAttribute(name, c), _defaultValue(ChangeBase::UPDATE, 0, defaultValue()) { assert(c.basicType() == BasicType::fromType(T())); } template IntegerAttributeTemplate::IntegerAttributeTemplate(const vespalib::string & name, const Config & c, const BasicType &realType) : IntegerAttribute(name, c), _defaultValue(ChangeBase::UPDATE, 0, 0u) { assert(c.basicType() == realType); (void) realType; assert(BasicType::fromType(T()) == BasicType::INT8); } template IntegerAttributeTemplate::~IntegerAttributeTemplate() = default; template bool IntegerAttributeTemplate::findEnum(const char *value, EnumHandle &e) const { vespalib::asciistream iss(value); int64_t ivalue = 0; try { iss >> ivalue; } catch (const vespalib::IllegalArgumentException &) { } return findEnum(ivalue, e); } template std::vector IntegerAttributeTemplate::findFoldedEnums(const char *value) const { std::vector result; EnumHandle h; if (findEnum(value, h)) { result.push_back(h); } return result; } template long IntegerAttributeTemplate::onSerializeForAscendingSort(DocId doc, void * serTo, long available, const common::BlobConverter *) const { T origValue(get(doc)); return vespalib::serializeForSort< vespalib::convertForSort >(origValue, serTo, available); } template long IntegerAttributeTemplate::onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter *) const { T origValue(get(doc)); return vespalib::serializeForSort< vespalib::convertForSort >(origValue, serTo, available); } }