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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "visit.h"
#include "objectvisitor.h"
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/array.h>
#include "identifiable.hpp"
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::CloneablePtr<T> &ptr) {
if (ptr.get()) {
visit(self, name, *ptr);
} else {
self.visitNull(name);
}
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::shared_ptr<T> &ptr) {
if (ptr.get()) {
visit(self, name, *ptr);
} else {
self.visitNull(name);
}
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::unique_ptr<T> &ptr) {
if (ptr.get()) {
visit(self, name, *ptr);
} else {
self.visitNull(name);
}
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiablePtr<T> &ptr) {
visit(self, name, ptr.get());
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::IdentifiableSharedPtr<T> &ptr) {
visit(self, name, ptr.get());
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const std::vector<T> &list) {
self.openStruct(name, "std::vector");
for (uint32_t i = 0; i < list.size(); ++i) {
::visit(self, vespalib::make_string("[%u]", i), list[i]);
}
self.closeStruct();
}
template<typename T>
void visit(vespalib::ObjectVisitor &self, const vespalib::string &name, const vespalib::Array<T> &list) {
self.openStruct(name, "vespalib::Array");
for (uint32_t i = 0; i < list.size(); ++i) {
::visit(self, vespalib::make_string("[%u]", i), list[i]);
}
self.closeStruct();
}
|