diff options
Diffstat (limited to 'searchlib/src/vespa/searchcommon/attribute/basictype.cpp')
-rw-r--r-- | searchlib/src/vespa/searchcommon/attribute/basictype.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchcommon/attribute/basictype.cpp b/searchlib/src/vespa/searchcommon/attribute/basictype.cpp new file mode 100644 index 00000000000..5bab2fc06d2 --- /dev/null +++ b/searchlib/src/vespa/searchcommon/attribute/basictype.cpp @@ -0,0 +1,37 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/searchcommon/attribute/basictype.h> +#include <vespa/vespalib/util/exceptions.h> + +namespace search::attribute { + +const BasicType::TypeInfo BasicType::_typeTable[BasicType::MAX_TYPE] = { + { BasicType::NONE, 0, "none" }, + { BasicType::STRING, 0, "string" }, + { BasicType::BOOL, sizeof(int8_t), "bool" }, + { BasicType::UINT2, sizeof(int8_t), "uint2" }, + { BasicType::UINT4, sizeof(int8_t), "uint4" }, + { BasicType::INT8, sizeof(int8_t), "int8" }, + { BasicType::INT16, sizeof(int16_t), "int16" }, + { BasicType::INT32, sizeof(int32_t), "int32" }, + { BasicType::INT64, sizeof(int64_t), "int64" }, + { BasicType::FLOAT, sizeof(float), "float" }, + { BasicType::DOUBLE, sizeof(double), "double" }, + { BasicType::PREDICATE, 0, "predicate" }, + { BasicType::TENSOR, 0, "tensor" }, + { BasicType::REFERENCE, 12, "reference" } +}; + +BasicType::Type +BasicType::asType(const vespalib::string &t) +{ + for (size_t i(0); i < sizeof(_typeTable)/sizeof(_typeTable[0]); i++) { + if (t == _typeTable[i]._name) { + return _typeTable[i]._type; + } + } + throw vespalib::IllegalStateException(t + " not recognized as valid attribute data type"); + return NONE; +} + +} |