// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "intermediate_blueprint_factory.h" #include #include #include namespace search::queryeval::test { template char IntermediateBlueprintFactory::child_name(void* blueprint) const { auto itr = _child_names.find(blueprint); if (itr != _child_names.end()) { return itr->second; } return '?'; } template IntermediateBlueprintFactory::IntermediateBlueprintFactory(vespalib::stringref name) : _name(name), _children(), _child_names() { } template IntermediateBlueprintFactory::~IntermediateBlueprintFactory() = default; template std::unique_ptr IntermediateBlueprintFactory::make_blueprint() { auto res = std::make_unique(); _child_names.clear(); char name = 'A'; for (const auto& factory : _children) { auto child = factory->make_blueprint(); _child_names[child.get()] = name++; res->addChild(std::move(child)); } return res; } template vespalib::string IntermediateBlueprintFactory::get_name(Blueprint& blueprint) const { auto* intermediate = blueprint.asIntermediate(); if (intermediate != nullptr) { std::ostringstream oss; bool first = true; oss << _name << "["; for (size_t i = 0; i < intermediate->childCnt(); ++i) { auto* child = &intermediate->getChild(i); oss << (first ? "" : ",") << child_name(child) << "."; if (child->strict()) { oss << "s(" << std::setw(6) << std::setprecision(3) << child->strict_cost() << ")"; } else { oss << "n(" << std::setw(6) << std::setprecision(3) << child->cost() << ")"; } first = false; } oss << "]"; return oss.str(); } return get_class_name(blueprint); } template class IntermediateBlueprintFactory; AndBlueprintFactory::AndBlueprintFactory() : IntermediateBlueprintFactory("AND") {} }