1 ////////////////////////////////////////////////////////////////////////////
 
   3 // Copyright 2015 Realm Inc.
 
   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
 
   9 // http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  17 ////////////////////////////////////////////////////////////////////////////
 
  19 #ifndef REALM_OBJECT_SCHEMA_HPP
 
  20 #define REALM_OBJECT_SCHEMA_HPP
 
  22 #include <realm/string_data.hpp>
 
  31 enum class PropertyType: unsigned char;
 
  32 struct ObjectSchemaValidationException;
 
  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);
 
  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);
 
  48     std::vector<Property> persisted_properties;
 
  49     std::vector<Property> computed_properties;
 
  50     std::string primary_key;
 
  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);
 
  57     const Property *primary_key_property() const {
 
  58         return property_for_name(primary_key);
 
  60     bool property_is_computed(Property const& property) const;
 
  62     void validate(Schema const& schema, std::vector<ObjectSchemaValidationException>& exceptions) const;
 
  64     friend bool operator==(ObjectSchema const& a, ObjectSchema const& b);
 
  66     static PropertyType from_core_type(Descriptor const& table, size_t col);
 
  69     void set_primary_key_property();
 
  73 #endif /* defined(REALM_OBJECT_SCHEMA_HPP) */