added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / object_schema.hpp
1 ////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright 2015 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 //
17 ////////////////////////////////////////////////////////////////////////////
18
19 #ifndef REALM_OBJECT_SCHEMA_HPP
20 #define REALM_OBJECT_SCHEMA_HPP
21
22 #include <realm/string_data.hpp>
23
24 #include <string>
25 #include <vector>
26
27 namespace realm {
28 class Descriptor;
29 class Group;
30 class Schema;
31 enum class PropertyType: unsigned char;
32 struct ObjectSchemaValidationException;
33 struct Property;
34
35 class ObjectSchema {
36 public:
37     ObjectSchema();
38     ObjectSchema(std::string name, std::initializer_list<Property> persisted_properties);
39     ObjectSchema(std::string name, std::initializer_list<Property> persisted_properties,
40                  std::initializer_list<Property> computed_properties);
41     ~ObjectSchema();
42
43     // create object schema from existing table
44     // if no table is provided it is looked up in the group
45     ObjectSchema(Group const& group, StringData name, size_t index=-1);
46
47     std::string name;
48     std::vector<Property> persisted_properties;
49     std::vector<Property> computed_properties;
50     std::string primary_key;
51
52     Property *property_for_name(StringData name);
53     const Property *property_for_name(StringData name) const;
54     Property *primary_key_property() {
55         return property_for_name(primary_key);
56     }
57     const Property *primary_key_property() const {
58         return property_for_name(primary_key);
59     }
60     bool property_is_computed(Property const& property) const;
61
62     void validate(Schema const& schema, std::vector<ObjectSchemaValidationException>& exceptions) const;
63
64     friend bool operator==(ObjectSchema const& a, ObjectSchema const& b);
65
66     static PropertyType from_core_type(Descriptor const& table, size_t col);
67
68 private:
69     void set_primary_key_property();
70 };
71 }
72
73 #endif /* defined(REALM_OBJECT_SCHEMA_HPP) */