aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/attribute/attribute_manager_explorer.cpp
blob: 0b48afe4ab812d5a770f207fadd685a50987a65b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attribute_manager_explorer.h"
#include "attribute_executor.h"
#include "attribute_vector_explorer.h"
#include <vespa/searchlib/attribute/attributevector.h>

using search::AttributeVector;
using vespalib::slime::Inserter;

namespace proton {

AttributeManagerExplorer::AttributeManagerExplorer(const proton::IAttributeManager::SP &mgr)
    : _mgr(mgr)
{
}

AttributeManagerExplorer::~AttributeManagerExplorer() {}

void
AttributeManagerExplorer::get_state(const Inserter &inserter, bool full) const
{
    (void) full;
    inserter.insertObject();
}

std::vector<vespalib::string>
AttributeManagerExplorer::get_children_names() const
{
    auto& attributes = _mgr->getWritableAttributes();
    std::vector<vespalib::string> names;
    for (const auto &attr : attributes) {
        names.push_back(attr->getName());
    }
    return names;
}

std::unique_ptr<vespalib::StateExplorer>
AttributeManagerExplorer::get_child(vespalib::stringref name) const
{
    auto guard = _mgr->getAttribute(name);
    auto attr = guard ? guard->getSP() : std::shared_ptr<AttributeVector>();
    if (attr && _mgr->getWritableAttribute(name) != nullptr) {
        auto executor = std::make_unique<AttributeExecutor>(_mgr, std::move(attr));
        return std::make_unique<AttributeVectorExplorer>(std::move(executor));
    }
    return {};
}

} // namespace proton