Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
FieldDefinition.hpp
Go to the documentation of this file.
1#pragma once
3#include <string>
4#include <variant>
5#include "FieldType.hpp"
7
8// Forward-Declaration needed for testing
9template<fishnet::FieldValueType T>
11
12namespace fishnet {
13
15private:
16 static inline int id = 0;
17 FieldCounter()= default;
18public:
19 [[nodiscard]] static int operator()() noexcept {
20 return id++;
21 }
22};
23
29template<class T>
30concept IFieldDefinition = FieldValueType<typename T::value_type> && std::equality_comparable<T> && requires(const T & fieldDef){
31 typename T::value_type;
32 {fieldDef.getFieldName()} -> std::convertible_to<std::string_view>;
33 {fieldDef.getFieldID()} -> std::integral;
34};
35
42template<FieldValueType T>
44private:
45 friend class FieldDefinitionTestFactory<T>;
46
47 template<geometry::AnyGeometry G>
48 friend class VectorLayer;
49
50 std::string fieldName;
51 int fieldID;
52
53 constexpr explicit FieldDefinition(std::string fieldName) : fieldName(std::move(fieldName)), fieldID(FieldCounter::operator()()) {}
54 constexpr explicit FieldDefinition(std::string fieldName,int id) : fieldName(std::move(fieldName)), fieldID(id) {}
55
56public:
57 using value_type = T;
58
59 [[nodiscard]] constexpr const std::string &getFieldName() const noexcept {
60 return this->fieldName;
61 }
62
63 [[nodiscard]] constexpr int getFieldID() const noexcept {
64 return this->fieldID;
65 }
66
67 template<FieldValueType U>
68 constexpr bool inline operator==(const FieldDefinition<U> & other )const noexcept {
69 return this->fieldID == other.getFieldID();
70 }
71};
72}
73
74namespace fishnet::__impl {
75template<typename Variant>
76struct FieldDefinitionTypes;
77
78template<typename... Types>
79struct FieldDefinitionTypes<std::variant<Types...>> {
80 using type = std::variant<FieldDefinition<Types>...>; // Construct FieldDefinitionVariant from FieldValueVariant
81};
82}
83
84namespace fishnet{
85using FieldDefinitionVariant = fishnet::__impl::FieldDefinitionTypes<FieldType>::type;
86}
Definition FieldDefinition.hpp:10
Definition FieldDefinition.hpp:14
static int operator()() noexcept
Definition FieldDefinition.hpp:19
Field definition implementation. Defines name, id and data type of a field.
Definition FieldDefinition.hpp:43
constexpr bool operator==(const FieldDefinition< U > &other) const noexcept
Definition FieldDefinition.hpp:68
constexpr int getFieldID() const noexcept
Definition FieldDefinition.hpp:63
constexpr const std::string & getFieldName() const noexcept
Definition FieldDefinition.hpp:59
T value_type
Definition FieldDefinition.hpp:57
Stores the geometries, wrapped in features (which hold the field values / attributes) Keeps track of ...
Definition VectorLayer.hpp:28
Definition FieldType.hpp:10
Defines an Interface for FieldDefinitions, which can be used as generic parameter.
Definition FieldDefinition.hpp:30
Definition BFSClustering.hpp:5
fishnet::__impl::FieldDefinitionTypes< FieldType >::type FieldDefinitionVariant
Definition FieldDefinition.hpp:85
STL namespace.