move List class to its own file

This commit is contained in:
Ari Lazier 2015-10-13 14:44:31 -07:00
parent 9cb9960af5
commit 77359f14e3
5 changed files with 101 additions and 45 deletions

View File

@ -54,6 +54,8 @@
0270BCD11B7D067300010E03 /* RealmReactModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReactModule.m */; }; 0270BCD11B7D067300010E03 /* RealmReactModule.m in Sources */ = {isa = PBXBuildFile; fileRef = 0270BCD01B7D067300010E03 /* RealmReactModule.m */; };
02B29A311B7CF86D008A7E6B /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; }; 02B29A311B7CF86D008A7E6B /* RealmJS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CB11AE99CEC009B348C /* RealmJS.framework */; };
02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; 02B58CCE1AE99D4D009B348C /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
02C0864E1BCDB27000942F9C /* list.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02C0864C1BCDB27000942F9C /* list.cpp */; settings = {ASSET_TAGS = (); }; };
02C0864F1BCDB27000942F9C /* list.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 02C0864D1BCDB27000942F9C /* list.hpp */; settings = {ASSET_TAGS = (); }; };
02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; }; 02D456DA1B7E59A500EE1299 /* ArrayTests.js in Resources */ = {isa = PBXBuildFile; fileRef = 02D456D91B7E59A500EE1299 /* ArrayTests.js */; };
02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; }; 02D8D1F71B601984006DB49D /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -183,6 +185,8 @@
02B58CB11AE99CEC009B348C /* RealmJS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RealmJS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 02B58CB11AE99CEC009B348C /* RealmJS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RealmJS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 02B58CBC1AE99CEC009B348C /* RealmJSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RealmJSTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 02B58CCD1AE99D4D009B348C /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
02C0864C1BCDB27000942F9C /* list.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = list.cpp; path = "src/object-store/list.cpp"; sourceTree = "<group>"; };
02C0864D1BCDB27000942F9C /* list.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = list.hpp; path = "src/object-store/list.hpp"; sourceTree = "<group>"; };
02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; }; 02D456D91B7E59A500EE1299 /* ArrayTests.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = ArrayTests.js; path = tests/ArrayTests.js; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -234,6 +238,8 @@
02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */, 02601F021BA0F0C4007C91FF /* external_commit_helper.hpp */,
02601F051BA0F0CD007C91FF /* index_set.cpp */, 02601F051BA0F0CD007C91FF /* index_set.cpp */,
02601F061BA0F0CD007C91FF /* index_set.hpp */, 02601F061BA0F0CD007C91FF /* index_set.hpp */,
02C0864C1BCDB27000942F9C /* list.cpp */,
02C0864D1BCDB27000942F9C /* list.hpp */,
02601F0B1BA0F3A7007C91FF /* schema.cpp */, 02601F0B1BA0F3A7007C91FF /* schema.cpp */,
02601F0C1BA0F3A7007C91FF /* schema.hpp */, 02601F0C1BA0F3A7007C91FF /* schema.hpp */,
02601F0F1BA10228007C91FF /* transact_log_handler.cpp */, 02601F0F1BA10228007C91FF /* transact_log_handler.cpp */,
@ -353,6 +359,7 @@
02601F041BA0F0C4007C91FF /* external_commit_helper.hpp in Headers */, 02601F041BA0F0C4007C91FF /* external_commit_helper.hpp in Headers */,
02601F091BA0F0CD007C91FF /* index_set.hpp in Headers */, 02601F091BA0F0CD007C91FF /* index_set.hpp in Headers */,
0270BC6D1B7CFC1C00010E03 /* property.hpp in Headers */, 0270BC6D1B7CFC1C00010E03 /* property.hpp in Headers */,
02C0864F1BCDB27000942F9C /* list.hpp in Headers */,
0270BC6F1B7CFC1C00010E03 /* results.hpp in Headers */, 0270BC6F1B7CFC1C00010E03 /* results.hpp in Headers */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -563,6 +570,7 @@
02601F111BA10228007C91FF /* transact_log_handler.cpp in Sources */, 02601F111BA10228007C91FF /* transact_log_handler.cpp in Sources */,
0270BC591B7CFC0D00010E03 /* RJSUtil.mm in Sources */, 0270BC591B7CFC0D00010E03 /* RJSUtil.mm in Sources */,
0270BC551B7CFC0D00010E03 /* RJSResults.mm in Sources */, 0270BC551B7CFC0D00010E03 /* RJSResults.mm in Sources */,
02C0864E1BCDB27000942F9C /* list.cpp in Sources */,
02601F031BA0F0C4007C91FF /* external_commit_helper.cpp in Sources */, 02601F031BA0F0C4007C91FF /* external_commit_helper.cpp in Sources */,
0270BC6B1B7CFC1C00010E03 /* object_store.cpp in Sources */, 0270BC6B1B7CFC1C00010E03 /* object_store.cpp in Sources */,
0270BC701B7CFC1C00010E03 /* shared_realm.cpp in Sources */, 0270BC701B7CFC1C00010E03 /* shared_realm.cpp in Sources */,

View File

@ -24,34 +24,6 @@
using RJSAccessor = realm::NativeAccessor<JSValueRef, JSContextRef>; using RJSAccessor = realm::NativeAccessor<JSValueRef, JSContextRef>;
using namespace realm; using namespace realm;
size_t List::size() {
return link_view->size();
}
Row List::get(std::size_t row_ndx) {
verify_valid_row(row_ndx);
return link_view->get(row_ndx);
}
void List::set(std::size_t row_ndx, std::size_t target_row_ndx) {
verify_valid_row(row_ndx);
link_view->set(row_ndx, target_row_ndx);
}
void List::verify_valid_row(std::size_t row_ndx) {
size_t size = link_view->size();
if (row_ndx >= size) {
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
}
}
void List::verify_attached() {
if (!link_view->is_attached()) {
throw std::runtime_error("Tableview is not attached");
}
link_view->sync_if_needed();
}
static inline List * RJSVerifiedArray(JSObjectRef object) { static inline List * RJSVerifiedArray(JSObjectRef object) {
List *list = RJSGetInternal<List *>(object); List *list = RJSGetInternal<List *>(object);
list->verify_attached(); list->verify_attached();

View File

@ -18,23 +18,7 @@
#import "RJSUtil.hpp" #import "RJSUtil.hpp"
#import "shared_realm.hpp" #import "shared_realm.hpp"
#import <realm/link_view.hpp> #import "list.hpp"
namespace realm {
struct List {
List(SharedRealm &r, ObjectSchema &s, LinkViewRef l) : realm(r), object_schema(s), link_view(l) {}
// FIXME - all should be const
SharedRealm realm;
ObjectSchema &object_schema;
LinkViewRef link_view;
size_t size();
Row get(std::size_t row_ndx);
void set(std::size_t row_ndx, std::size_t target_row_ndx);
void verify_valid_row(std::size_t row_ndx);
void verify_attached();
};
}
extern const JSStaticFunction RJSArrayFuncs[]; extern const JSStaticFunction RJSArrayFuncs[];
JSClassRef RJSArrayClass(); JSClassRef RJSArrayClass();

50
src/object-store/list.cpp Normal file
View File

@ -0,0 +1,50 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#include "list.hpp"
#import <stdexcept>
using namespace realm;
size_t List::size() {
return link_view->size();
}
Row List::get(std::size_t row_ndx) {
verify_valid_row(row_ndx);
return link_view->get(row_ndx);
}
void List::set(std::size_t row_ndx, std::size_t target_row_ndx) {
verify_valid_row(row_ndx);
link_view->set(row_ndx, target_row_ndx);
}
void List::verify_valid_row(std::size_t row_ndx) {
size_t size = link_view->size();
if (row_ndx >= size) {
throw std::out_of_range(std::string("Index ") + std::to_string(row_ndx) + " is outside of range 0..." + std::to_string(size) + ".");
}
}
void List::verify_attached() {
if (!link_view->is_attached()) {
throw std::runtime_error("Tableview is not attached");
}
link_view->sync_if_needed();
}

42
src/object-store/list.hpp Normal file
View File

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2015 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
#ifndef REALM_LIST_HPP
#define REALM_LIST_HPP
#import "shared_realm.hpp"
#import <realm/link_view.hpp>
namespace realm {
struct List {
List(SharedRealm &r, ObjectSchema &s, LinkViewRef l) : realm(r), object_schema(s), link_view(l) {}
// FIXME - all should be const
SharedRealm realm;
ObjectSchema &object_schema;
LinkViewRef link_view;
size_t size();
Row get(std::size_t row_ndx);
void set(std::size_t row_ndx, std::size_t target_row_ndx);
void verify_valid_row(std::size_t row_ndx);
void verify_attached();
};
}
#endif /* REALM_LIST_HPP */