Skip to content

Commit

Permalink
ObjectiveC++ refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
automactic committed Jun 29, 2020
1 parent 4021b01 commit 459cd86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Model/Operations/SearchOperation/SearchOperation.h
Expand Up @@ -12,8 +12,8 @@ NS_ASSUME_NONNULL_BEGIN

@interface SearchOperation : NSOperation

@property (nonatomic, strong) NSArray *results NS_REFINED_FOR_SWIFT;
@property (nonatomic, strong) NSString *searchText;
@property (nonatomic, strong) NSArray *results NS_REFINED_FOR_SWIFT;

- (id)initWithSearchText:(NSString *)searchText zimFileIDs:(NSSet *)identifiers;
- (void)performSearch:(BOOL)withFullTextSnippet;
Expand Down
6 changes: 3 additions & 3 deletions Model/Operations/SearchOperation/SearchOperation.mm
Expand Up @@ -6,11 +6,11 @@
// Copyright © 2020 Chris Li. All rights reserved.
//

#import "reader.h"
#import "searcher.h"
#import "SearchOperation.h"
#import "SearchResult.h"
#import "ZimMultiReader.h"
#import "reader.h"
#import "searcher.h"

struct SharedReaders {
NSArray *readerIDs;
Expand All @@ -19,7 +19,7 @@

@interface SearchOperation ()

@property (strong) NSSet *identifiers;
@property (nonatomic, strong) NSSet *identifiers;

@end

Expand Down
21 changes: 9 additions & 12 deletions Model/ZimMultiReader/ZimMultiReader.mm
Expand Up @@ -8,12 +8,12 @@

#include <set>
#include <unordered_map>
#include "book.h"
#include "entry.h"
#include "reader.h"
#include "searcher.h"
#import "ZimMultiReader.h"
#import "ZimFileMetaData.h"
#include "book.h"

struct SharedReaders {
NSArray *readerIDs;
Expand All @@ -23,15 +23,13 @@
@interface ZimMultiReader ()

@property (assign) std::unordered_map<std::string, std::shared_ptr<kiwix::Reader>> *readers;
@property (assign) std::unordered_map<std::string, kiwix::Reader> *readers2;
@property (strong) NSMutableDictionary *fileURLs; // [ID: FileURL]

@end

@implementation ZimMultiReader

kiwix::Searcher *searcher = nullptr;
NSMutableArray *searcherZimIDs = [[NSMutableArray alloc] init];

#pragma mark - init

- (instancetype)init {
Expand All @@ -46,7 +44,7 @@ - (instancetype)init {

+ (ZimMultiReader *)sharedInstance {
static ZimMultiReader *sharedInstance = nil;
static dispatch_once_t onceToken; // onceToken = 0
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[ZimMultiReader alloc] init];
});
Expand Down Expand Up @@ -96,13 +94,12 @@ - (struct SharedReaders)getSharedReaders:(nonnull NSSet *)identifiers {
NSMutableArray *readerIDs = [[NSMutableArray alloc] initWithCapacity:[identifiers count]];
auto readers = std::vector<std::shared_ptr<kiwix::Reader>>();

for(auto iter: *self.readers) {
NSString *identifier = [NSString stringWithCString:iter.first.c_str() encoding:NSUTF8StringEncoding];
if (![identifiers containsObject:identifier]) {
continue;
}
[readerIDs addObject:identifier];
readers.push_back(iter.second);
for (NSString *identifier in identifiers) {
try {
auto reader = self.readers->at([identifier cStringUsingEncoding:NSUTF8StringEncoding]);
[readerIDs addObject:identifier];
readers.push_back(reader);
} catch (std::out_of_range) { }
}

struct SharedReaders sharedReaders;
Expand Down

0 comments on commit 459cd86

Please sign in to comment.