// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "floatbase.h" #include #include #include namespace search { template FloatingPointAttributeTemplate::FloatingPointAttributeTemplate(const vespalib::string & name) : FloatingPointAttributeTemplate(name, BasicType::fromType(T())) { } template FloatingPointAttributeTemplate::FloatingPointAttributeTemplate(const vespalib::string & name, const Config & c) : FloatingPointAttribute(name, c), _defaultValue(ChangeBase::UPDATE, 0, defaultValue()) { assert(c.basicType() == BasicType::fromType(T())); } template FloatingPointAttributeTemplate::~FloatingPointAttributeTemplate() = default; template bool FloatingPointAttributeTemplate::findEnum(const char *value, EnumHandle &e) const { vespalib::asciistream iss(value); T fvalue = 0; try { iss >> fvalue; } catch (const vespalib::IllegalArgumentException &) { } return findEnum(fvalue, e); } template std::vector FloatingPointAttributeTemplate::findFoldedEnums(const char *value) const { std::vector result; EnumHandle h; if (findEnum(value, h)) { result.push_back(h); } return result; } template long FloatingPointAttributeTemplate::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 FloatingPointAttributeTemplate::onSerializeForDescendingSort(DocId doc, void * serTo, long available, const common::BlobConverter *) const { T origValue(get(doc)); return vespalib::serializeForSort< vespalib::convertForSort >(origValue, serTo, available); } }