[iPhone] Factor out search processing from UI in SearchVC and create SloynikSearchVC for UI stuff. Remove trailing whitespaces.

This commit is contained in:
Yury Melnichek 2011-04-01 16:42:09 +02:00 committed by Alex Zolotarev
parent 0c4fe69d5a
commit f3c5565224
13 changed files with 164 additions and 87 deletions

View file

@ -169,7 +169,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState,
* and determine if it is assencing or descending.
* And then start checking how long respective patterns go.
*/
if ((*aCmpCb)(sArray + (aIndexLow * sWidth),
if ((*aCmpCb)(sArray + (aIndexLow * sWidth),
sArray + ((aIndexLow + 1) * sWidth)) == -1)
{
/*
@ -183,7 +183,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState,
while (sIndexCur < aIndexHigh)
{
if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth),
if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth),
sArray + (sIndexCur * sWidth)) != 1)
{
/* <= */
@ -211,7 +211,7 @@ static uint32_t timCountRunAndMakeAscending(timMergeState *aState,
while (sIndexCur < aIndexHigh)
{
if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth),
if ((*aCmpCb)(sArray + ((sIndexCur - 1) * sWidth),
sArray + (sIndexCur * sWidth)) == 1)
{
/* > */
@ -1062,9 +1062,9 @@ LABEL_COPY_A:
/*
* Merges the two runs at stack indices i and i + 1.
* Run i must be the penultimate or antepenultimate run on the stack.
* IOW, i must be equal to
* IOW, i must be equal to
*
* i == PendingRunCnt - 2 or
* i == PendingRunCnt - 2 or
* i == PendingRuncnt - 3.
*/
static void timMergeAt(timMergeState *aState, uint32_t aWhere, cmpFunc *aCmpCb)

View file

@ -1,14 +1,14 @@
#import <UIKit/UIKit.h>
@class SearchVC;
@class SloynikSearchVC;
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow * window;
SearchVC * searchVC;
SloynikSearchVC * searchVC;
}
@property (nonatomic, retain) UIWindow * window;
@property (nonatomic, retain) SearchVC * searchVC;
@property (nonatomic, retain) SloynikSearchVC * searchVC;
@end

View file

@ -1,5 +1,5 @@
#import "AppDelegate.h"
#import "SearchVC.h"
#import "SloynikSearchVC.h"
#import "PerfCount.h"
@implementation AppDelegate
@ -28,7 +28,7 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor whiteColor];
self.searchVC = [[[SearchVC alloc] init] autorelease];
self.searchVC = [[[SloynikSearchVC alloc] init] autorelease];
[self.window addSubview:searchVC.view];
[self.window makeKeyAndVisible];
LogTimeCounter("StartTime", "applicationDidFinishLaunching_end");

View file

@ -134,7 +134,7 @@
initWithCustomView:self.backForwardButtons];
self.navArticle.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
if ([NSClassFromString(@"UISwipeGestureRecognizer")
instancesRespondToSelector:@selector(setDirection:)])
{
@ -157,7 +157,7 @@
autorelease];
self.pinchGestureRecognizer.delegate = self;
}
[self loadWebView];
UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease];
@ -212,7 +212,7 @@
- (void)setArticleData:(NSString *)htmlString name:(NSString *)name
{
// Make sure, that WebView is created.
[self view];
[self view];
// Load data into WebView.
[self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://s/"]];

View file

@ -3,7 +3,7 @@
#if __cplusplus
extern "C" {
#endif
void LogTimeCounter(const char * counter, const char * message);
#if __cplusplus

View file

@ -18,6 +18,6 @@ void LogTimeCounter(const char * counter, const char * message)
else
{
NSLog(@"LogTimeCounter: %s %s %f", counter, message, t - it->second);
it->second = t;
it->second = t;
}
}

View file

@ -10,18 +10,13 @@ typedef struct SloynikData SloynikData;
SloynikData * m_pSloynikData;
UISearchBar * searchBar;
UITableView * resultsView;
UIBarButtonItem * menuButton;
ArticleVC * articleVC;
CGRect initFrame;
}
@property (nonatomic, retain) UISearchBar * searchBar;
@property (nonatomic, retain) UITableView * resultsView;
@property (nonatomic, retain) UIBarButtonItem * menuButton;
@property (nonatomic, retain) IBOutlet UISearchBar * searchBar;
@property (nonatomic, retain) IBOutlet UITableView * resultsView;
@property (nonatomic, retain) ArticleVC * articleVC;
@property (nonatomic) CGRect initFrame;
- (void)menuButtonPressed;
- (void)willShowArticle;
- (void)showArticle;

View file

@ -10,11 +10,11 @@
struct SloynikData
{
sl::SloynikEngine::SearchResult m_SearchResult;
SloynikData() : m_SearchResult()
{
}
~SloynikData()
{
}
@ -24,84 +24,34 @@ struct SloynikData
@synthesize searchBar;
@synthesize resultsView;
@synthesize menuButton;
@synthesize articleVC;
@synthesize initFrame;
- (void)dealloc
{
delete m_pSloynikData;
self.searchBar = nil;
self.resultsView = nil;
self.menuButton = nil;
self.articleVC = nil;
[super dealloc];
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
int const buttonW = 40;
int const toolbarH = 44;
int const marginW = 5;
CGRect frame = initFrame;
int const frameW = frame.size.width;
int const frameH = frame.size.height;
CGRect searchBarFrame = CGRectMake(0, 0, frameW - buttonW - 2 * marginW, toolbarH);
CGRect navBarFrame = CGRectMake(frameW - buttonW - 2 * marginW, 0,
buttonW + 2 * marginW, toolbarH);
CGRect resultsFrame = CGRectMake(0, toolbarH, frameW, frameH - toolbarH);
self.searchBar = [[[UISearchBar alloc] initWithFrame:searchBarFrame] autorelease];
self.searchBar.delegate = self;
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.searchBar becomeFirstResponder];
self.menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu-20.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(menuButtonPressed)];
UINavigationItem * navItem = [[[UINavigationItem alloc] initWithTitle:@""] autorelease];
navItem.rightBarButtonItem = self.menuButton;
UINavigationBar * navBar = [[[UINavigationBar alloc] initWithFrame:navBarFrame] autorelease];
navBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[navBar pushNavigationItem:navItem animated:NO];
self.resultsView = [[[UITableView alloc] initWithFrame:resultsFrame] autorelease];
self.resultsView.rowHeight = 40;
self.resultsView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
self.resultsView.dataSource = self;
self.resultsView.delegate = self;
self.resultsView.hidden = YES;
UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease];
[mainView addSubview:self.searchBar];
[mainView addSubview:navBar];
[mainView addSubview:self.resultsView];
self.view = mainView;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchBar.delegate = self;
self.resultsView.dataSource = self;
self.resultsView.delegate = self;
self.resultsView.hidden = YES;
LogTimeCounter("StartTime", "SearchVC initializing.");
m_pSloynikData = new SloynikData;
GetSloynikEngine()->Search("", m_pSloynikData->m_SearchResult);
LogTimeCounter("StartTime", "SearchVC initialized.");
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
@ -233,8 +183,4 @@ struct SloynikData
[[superView layer] addAnimation:animation forKey:@"SwitchToArticleView"];
}
- (void)menuButtonPressed
{
}
@end

View file

@ -71,5 +71,5 @@ sl::SloynikEngine * GetSloynikEngine()
s_pEngine = new sl::SloynikEngine(dictionaryPath, indexPath, strFn);
LogTimeCounter("EngineStartUp", "Engine started.");
}
return s_pEngine;
return s_pEngine;
}

View file

@ -11,7 +11,7 @@
int main(int argc, char *argv[])
{
LogTimeCounter("StartTime", "main");
LogTimeCounter("StartTime", "main");
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");

View file

@ -35,6 +35,7 @@
49698404121E877E00048CF1 /* huffman.c in Sources */ = {isa = PBXBuildFile; fileRef = 496983FF121E877E00048CF1 /* huffman.c */; };
49698405121E877E00048CF1 /* randtable.c in Sources */ = {isa = PBXBuildFile; fileRef = 49698400121E877E00048CF1 /* randtable.c */; };
4972C89B120CB8D5001F025D /* menu-20.png in Resources */ = {isa = PBXBuildFile; fileRef = 4972C89A120CB8D5001F025D /* menu-20.png */; };
4983ADC8134618AE00C82DB7 /* SloynikSearchVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */; };
499A290F120CDF4000E14B47 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499A290E120CDF4000E14B47 /* AppDelegate.mm */; };
499F013212344F3C00EB6964 /* ArticleVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 499F013112344F3C00EB6964 /* ArticleVC.mm */; };
49A67547132EE7C2005189E6 /* timsort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49A67546132EE7C2005189E6 /* timsort.cpp */; };
@ -79,6 +80,8 @@
496983FF121E877E00048CF1 /* huffman.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = huffman.c; path = ../../3party/bzip2/huffman.c; sourceTree = SOURCE_ROOT; };
49698400121E877E00048CF1 /* randtable.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = randtable.c; path = ../../3party/bzip2/randtable.c; sourceTree = SOURCE_ROOT; };
4972C89A120CB8D5001F025D /* menu-20.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "menu-20.png"; path = "Images/menu-20.png"; sourceTree = "<group>"; };
4983ADC6134618AE00C82DB7 /* SloynikSearchVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SloynikSearchVC.h; sourceTree = "<group>"; };
4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SloynikSearchVC.m; sourceTree = "<group>"; };
499A290D120CDF4000E14B47 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Shared/AppDelegate.h; sourceTree = "<group>"; };
499A290E120CDF4000E14B47 /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = Shared/AppDelegate.mm; sourceTree = "<group>"; };
499F013012344F3C00EB6964 /* ArticleVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ArticleVC.h; path = Shared/ArticleVC.h; sourceTree = "<group>"; };
@ -122,6 +125,8 @@
499A290E120CDF4000E14B47 /* AppDelegate.mm */,
496982CF121DE3F700048CF1 /* SearchVC.h */,
496982D0121DE3F700048CF1 /* SearchVC.mm */,
4983ADC6134618AE00C82DB7 /* SloynikSearchVC.h */,
4983ADC7134618AE00C82DB7 /* SloynikSearchVC.m */,
499F013012344F3C00EB6964 /* ArticleVC.h */,
499F013112344F3C00EB6964 /* ArticleVC.mm */,
491F5E5512E8F4650072775A /* global.hpp */,
@ -339,6 +344,7 @@
499F013212344F3C00EB6964 /* ArticleVC.mm in Sources */,
491F5E5712E8F4AB0072775A /* global.mm in Sources */,
49A67547132EE7C2005189E6 /* timsort.cpp in Sources */,
4983ADC8134618AE00C82DB7 /* SloynikSearchVC.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -0,0 +1,21 @@
//
// SloynikSearchVC.h
// Sloynik
//
// Created by Yury Melnichek on 01.04.11.
// Copyright 2011 -. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "SearchVC.h"
@interface SloynikSearchVC : SearchVC
{
UIBarButtonItem * menuButton;
}
@property (nonatomic, retain) UIBarButtonItem * menuButton;
- (void)menuButtonPressed;
@end

View file

@ -0,0 +1,109 @@
//
// SloynikSearchVC.m
// Sloynik
//
// Created by Yury Melnichek on 01.04.11.
// Copyright 2011 -. All rights reserved.
//
#import "SloynikSearchVC.h"
@implementation SloynikSearchVC
@synthesize menuButton;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
self.menuButton = nil;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
int const buttonW = 40;
int const toolbarH = 44;
int const marginW = 5;
CGRect frame = [[UIScreen mainScreen] applicationFrame];
int const frameW = frame.size.width;
int const frameH = frame.size.height;
CGRect searchBarFrame = CGRectMake(0, 0, frameW - buttonW - 2 * marginW, toolbarH);
CGRect navBarFrame = CGRectMake(frameW - buttonW - 2 * marginW, 0,
buttonW + 2 * marginW, toolbarH);
CGRect resultsFrame = CGRectMake(0, toolbarH, frameW, frameH - toolbarH);
self.searchBar = [[[UISearchBar alloc] initWithFrame:searchBarFrame] autorelease];
self.searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.searchBar becomeFirstResponder];
self.menuButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"menu-20.png"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(menuButtonPressed)];
UINavigationItem * navItem = [[[UINavigationItem alloc] initWithTitle:@""] autorelease];
navItem.rightBarButtonItem = self.menuButton;
UINavigationBar * navBar = [[[UINavigationBar alloc] initWithFrame:navBarFrame] autorelease];
navBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[navBar pushNavigationItem:navItem animated:NO];
self.resultsView = [[[UITableView alloc] initWithFrame:resultsFrame] autorelease];
self.resultsView.rowHeight = 40;
self.resultsView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
UIView * mainView = [[[UIView alloc] initWithFrame:frame] autorelease];
[mainView addSubview:self.searchBar];
[mainView addSubview:navBar];
[mainView addSubview:self.resultsView];
self.view = mainView;
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)menuButtonPressed
{
}
@end