blob: c142fd9b6ebe7c27f48352391f84d1c9f3ba3b3f (
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 Yahoo. 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
|