blob: dd3122c44cd9fd7db4d4c7ad447a7fd25e6e1b23 (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "structuredfieldvalue.h"
#include <vespa/document/datatype/datatype.h>
#include <vespa/vespalib/util/exceptions.h>
namespace document {
template <typename T>
std::unique_ptr<T>
StructuredFieldValue::getAs(const Field &field) const {
FieldValue::UP val = getValue(field);
T *t = dynamic_cast<T *>(val.get());
if (val.get() && !t) {
throw vespalib::IllegalStateException("Field " + field.toString() + " has unexpected type.", VESPA_STRLOC);
}
val.release();
return std::unique_ptr<T>(t);
}
} // document
|