|
| 1 | +//////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright 2023 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_OS_CLASS_HPP |
| 20 | +#define REALM_OS_CLASS_HPP |
| 21 | + |
| 22 | +#include <realm/obj.hpp> |
| 23 | +#include "realm/parser/keypath_mapping.hpp" |
| 24 | +#include "realm/parser/query_parser.hpp" |
| 25 | +#include <memory> |
| 26 | + |
| 27 | +namespace realm { |
| 28 | + |
| 29 | +class ObjectSchema; |
| 30 | +class Realm; |
| 31 | +class Query; |
| 32 | + |
| 33 | +class Class { |
| 34 | +public: |
| 35 | + Class(std::shared_ptr<Realm> r, const ObjectSchema* object_schema); |
| 36 | + |
| 37 | + size_t num_objects() const |
| 38 | + { |
| 39 | + return m_table->size(); |
| 40 | + } |
| 41 | + bool is_embedded() |
| 42 | + { |
| 43 | + return m_table->is_embedded(); |
| 44 | + } |
| 45 | + TableKey get_key() const |
| 46 | + { |
| 47 | + return m_table->get_key(); |
| 48 | + } |
| 49 | + ColKey get_column_key(StringData name) const |
| 50 | + { |
| 51 | + return m_table->get_column_key(name); |
| 52 | + } |
| 53 | + std::shared_ptr<Realm> get_realm() const noexcept |
| 54 | + { |
| 55 | + return m_realm; |
| 56 | + } |
| 57 | + TableRef get_table() const noexcept |
| 58 | + { |
| 59 | + return m_table; |
| 60 | + } |
| 61 | + const ObjectSchema& get_schema() const noexcept |
| 62 | + { |
| 63 | + return *m_object_schema; |
| 64 | + } |
| 65 | + |
| 66 | + Query get_query(const std::string& query_string, query_parser::Arguments& args, |
| 67 | + const query_parser::KeyPathMapping& mapping) const |
| 68 | + { |
| 69 | + return m_table->query(query_string, args, mapping); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + std::pair<Obj, bool> create_object(Mixed primary_value); |
| 74 | + Obj create_object(); |
| 75 | + Obj get_object(Mixed primary_value); |
| 76 | + |
| 77 | +private: |
| 78 | + std::shared_ptr<Realm> m_realm; |
| 79 | + const ObjectSchema* m_object_schema; |
| 80 | + TableRef m_table; |
| 81 | +}; |
| 82 | + |
| 83 | +} // namespace realm |
| 84 | + |
| 85 | +#endif // REALM_OS_CLASS_HPP |
0 commit comments