Realm C++ SDK Version v2.2.0

property.hpp

1
2//
3// Copyright 2024 Realm Inc.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#ifndef CPPREALM_BRIDGE_PROPERTY_HPP
20#define CPPREALM_BRIDGE_PROPERTY_HPP
21
22#include <functional>
23#include <string>
24#include <cpprealm/internal/bridge/utils.hpp>
25
26namespace realm {
27 struct Property;
28}
29
30namespace realm::internal::bridge {
31 struct col_key;
32
33 struct property {
34 enum class type : unsigned short {
35 Int = 0,
36 Bool = 1,
37 String = 2,
38 Data = 3,
39 Date = 4,
40 Float = 5,
41 Double = 6,
42 Object = 7, // currently must be either Array xor Nullable
43 LinkingObjects = 8, // currently must be Array and not Nullable
44
45 Mixed = 9,
46 ObjectId = 10,
47 Decimal = 11,
48 UUID = 12,
49
50 // Flags which can be combined with any of the above types except as noted
51 Required = 0,
52 Nullable = 64,
53 Array = 128,
54 Set = 256,
55 Dictionary = 512,
56
57 Collection = Array | Set | Dictionary,
58 Flags = Nullable | Collection
59 };
60
61 property();
62 property(const property& other) ;
63 property& operator=(const property& other);
64 property(property&& other) noexcept;
65 property &operator=(property &&other) noexcept;
66 ~property();
67 property(const Property&); //NOLINT(google-explicit-constructor)
68 property(const std::string& name,
69 type type,
70 bool is_primary_key);
71 property(const std::string& name,
72 type type,
73 const std::string& object_name);
74 operator Property() const; //NOLINT(google-explicit-constructor)
75 void set_object_link(const std::string&);
76 void set_origin_property_name(const std::string&);
77 void set_type(type);
78 void set_primary_key(bool);
79 bool is_primary() const;
80 std::string name() const;
81 [[nodiscard]] col_key column_key() const;
82 private:
83#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
84 storage::Property m_property[1];
85#else
86 std::shared_ptr<Property> m_property;
87#endif
88 };
89
90 namespace {
91 template <typename E>
92 constexpr auto to_underlying(E e)
93 {
94 return static_cast<typename std::underlying_type<E>::type>(e);
95 }
96 }
97 inline constexpr property::type operator|(property::type a, property::type b)
98 {
99 return static_cast<property::type>(to_underlying(a) | to_underlying(b));
100 }
101 inline constexpr property::type operator&(property::type a, property::type b)
102 {
103 return static_cast<property::type>(to_underlying(a) & to_underlying(b));
104 }
105
106 inline constexpr bool property_has_flag(property::type property, property::type flag) {
107 return static_cast<bool>(property & flag);
108 }
109}
110
111#endif //CPPREALM_BRIDGE_PROPERTY_HPP
Definition: col_key.hpp:28
Definition: property.hpp:33