aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/datatype/positiondatatype.cpp
blob: 67c18b943f5c6a80cf322d7843592d3e70a354af (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
51
52
53
54
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "positiondatatype.h"

namespace document {

namespace {

const vespalib::string ZCURVE("_zcurve");

}

const vespalib::string PositionDataType::STRUCT_NAME("position");
const vespalib::string PositionDataType::FIELD_X("x");
const vespalib::string PositionDataType::FIELD_Y("y");

StructDataType::UP
PositionDataType::createInstance()
{
    auto type = std::make_unique<StructDataType>(PositionDataType::STRUCT_NAME);
    type->addField(Field(PositionDataType::FIELD_X, *DataType::INT));
    type->addField(Field(PositionDataType::FIELD_Y, *DataType::INT));
    return type;
}

const StructDataType &
PositionDataType::getInstance()
{
    static StructDataType::UP instance = createInstance();
    return *instance;
}

vespalib::string
PositionDataType::getZCurveFieldName(const vespalib::string & fieldName)
{
    return fieldName + ZCURVE;
}

vespalib::stringref
PositionDataType::cutZCurveFieldName(vespalib::stringref name)
{
    return name.substr(0, name.size() - 7);
}

bool
PositionDataType::isZCurveFieldName(vespalib::stringref name)
{
    if (name.size() > ZCURVE.size()) {
        return ZCURVE == name.substr(name.size() - ZCURVE.size());
    }
    return false;
}

} // document