-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from alexlee002/master
Made some refactor, fix some bugs
- Loading branch information
Showing
44 changed files
with
2,834 additions
and
886 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# | ||
# clang-format的最基本code style是LLVM, | ||
# 其他的所有内置code style都是继承于 LLVM, | ||
# 下边是 clang-format 的全部59个配置项 | ||
# | ||
BasedOnStyle: Google | ||
Language: Cpp | ||
### | ||
AccessModifierOffset: -2 | ||
AlignAfterOpenBracket: true | ||
AlignOperands: true | ||
AlignTrailingComments: true | ||
AlignConsecutiveAssignments: true | ||
AllowAllParametersOfDeclarationOnNextLine: true | ||
AllowShortFunctionsOnASingleLine: All | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortCaseLabelsOnASingleLine: false | ||
#AlwaysBreakAfterDefinitionReturnType: None | ||
BinPackParameters: true | ||
BinPackArguments: true | ||
BreakBeforeBinaryOperators: None | ||
BreakBeforeTernaryOperators: true | ||
BreakBeforeBraces: Attach | ||
BreakConstructorInitializersBeforeComma: false | ||
ColumnLimit: 120 | ||
CommentPragmas: "^ IWYU pragma:" | ||
ConstructorInitializerIndentWidth: 4 | ||
ContinuationIndentWidth: 4 | ||
Cpp11BracedListStyle: true | ||
ExperimentalAutoDetectBinPacking: false | ||
IndentWrappedFunctionNames: false | ||
IndentWidth: 4 | ||
TabWidth: 8 | ||
MaxEmptyLinesToKeep: 1 | ||
NamespaceIndentation: None | ||
ObjCBlockIndentWidth: 4 | ||
PointerAlignment: Right | ||
UseTab: Never | ||
SpacesInParentheses: false | ||
SpacesInSquareBrackets: false | ||
SpaceInEmptyParentheses: false | ||
SpacesInContainerLiterals: true | ||
SpacesInCStyleCastParentheses: false | ||
SpaceAfterCStyleCast: true | ||
SpaceBeforeParens: ControlStatements | ||
SpaceBeforeAssignmentOperators: true | ||
SpacesInAngles: false | ||
PenaltyBreakComment: 300 | ||
PenaltyBreakFirstLessLess: 120 | ||
PenaltyBreakString: 1000 | ||
PenaltyExcessCharacter: 1000000 | ||
AlignEscapedNewlinesLeft: true | ||
AllowShortIfStatementsOnASingleLine: true | ||
AllowShortLoopsOnASingleLine: true | ||
AlwaysBreakBeforeMultilineStrings: true | ||
AlwaysBreakTemplateDeclarations: true | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: true | ||
DerivePointerAlignment: true | ||
IndentCaseLabels: true | ||
KeepEmptyLinesAtTheStartOfBlocks: false | ||
ObjCSpaceAfterProperty: false | ||
ObjCSpaceBeforeProtocolList: true | ||
SpacesBeforeTrailingComments: 2 | ||
Standard: Auto | ||
PenaltyReturnTypeOnItsOwnLine: 200 | ||
PenaltyBreakBeforeFirstCallParameter: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ xcuserdata | |
*.moved-aside | ||
DerivedData | ||
*.xcuserstate | ||
|
||
bak/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// ALAssociatedWeakObject.h | ||
// MCLog | ||
// | ||
// Created by Alex Lee on 1/9/16. | ||
// Copyright © 2016 Yuhua Chen. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
//@see: http://stackoverflow.com/questions/22809848/objective-c-runtime-run-code-at-deallocation-of-any-object/31560217#31560217 | ||
|
||
|
||
@interface NSObject (AssociatedWeakObject) | ||
|
||
- (void)mc_runAtDealloc:(void(^)(void))block; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// ALAssociatedWeakObject.m | ||
// MCLog | ||
// | ||
// Created by Alex Lee on 1/9/16. | ||
// Copyright © 2016 Yuhua Chen. All rights reserved. | ||
// | ||
|
||
#import "ALAssociatedWeakObject.h" | ||
#import <objc/runtime.h> | ||
|
||
typedef void (^deallocBlock)(void); | ||
|
||
@interface ALAssociatedWeakObject : NSObject | ||
|
||
+ (instancetype)weakAssociatedObjectWithDeallocCallback:(deallocBlock)block; | ||
|
||
@end | ||
|
||
@implementation ALAssociatedWeakObject { | ||
deallocBlock _block; | ||
} | ||
|
||
+ (instancetype)weakAssociatedObjectWithDeallocCallback:(deallocBlock)block { | ||
return [[self alloc] initWithDeallocCallback:block]; | ||
} | ||
|
||
- (instancetype)initWithDeallocCallback:(deallocBlock)block { | ||
self = [super init]; | ||
if (self) { | ||
_block = [block copy]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc { | ||
if (_block) { | ||
_block(); | ||
} | ||
} | ||
|
||
@end | ||
|
||
|
||
@implementation NSObject (AssociatedWeakObject) | ||
static const char kRunAtDeallocBlockKey; | ||
- (void)mc_runAtDealloc:(void(^)(void))block { | ||
if (block) { | ||
ALAssociatedWeakObject *proxy = [ALAssociatedWeakObject weakAssociatedObjectWithDeallocCallback:block]; | ||
objc_setAssociatedObject(self, | ||
&kRunAtDeallocBlockKey, | ||
proxy, | ||
OBJC_ASSOCIATION_RETAIN); | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// HHTimer.h | ||
// BusinessLayer | ||
// | ||
// Created by lingaohe on 3/5/14. | ||
// Copyright (c) 2014 Baidu. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface HHTimer : NSObject | ||
|
||
+ (HHTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds | ||
dispatchQueue:(dispatch_queue_t)queue | ||
block:(dispatch_block_t)block | ||
userInfo:(id)userInfo | ||
repeats:(BOOL)yesOrNo; | ||
|
||
- (void)fire; | ||
- (void)invalidate; | ||
|
||
- (BOOL)isValid; | ||
- (id)userInfo; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// HHTimer.m | ||
// BusinessLayer | ||
// | ||
// Created by lingaohe on 3/5/14. | ||
// Copyright (c) 2014 Baidu. All rights reserved. | ||
// | ||
|
||
#import "HHTimer.h" | ||
|
||
@interface HHTimer () | ||
@property(nonatomic, readwrite, copy) dispatch_block_t block; | ||
@property(nonatomic, readwrite, strong) dispatch_source_t source; | ||
@property(nonatomic, strong) id internalUserInfo; | ||
@end | ||
|
||
@implementation HHTimer | ||
|
||
#pragma mark-- Init | ||
+ (HHTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds | ||
dispatchQueue:(dispatch_queue_t)queue | ||
block:(dispatch_block_t)block | ||
userInfo:(id)userInfo | ||
repeats:(BOOL)yesOrNo { | ||
NSParameterAssert(seconds); | ||
NSParameterAssert(block); | ||
|
||
HHTimer *timer = [[self alloc] init]; | ||
timer.internalUserInfo = userInfo; | ||
timer.block = block; | ||
timer.source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); | ||
uint64_t nsec = (uint64_t)(seconds * NSEC_PER_SEC); | ||
dispatch_source_set_timer(timer.source, dispatch_time(DISPATCH_TIME_NOW, nsec), nsec, 0); | ||
void (^internalBlock)(void) = ^{ | ||
if (!yesOrNo) { | ||
block(); | ||
[timer invalidate]; | ||
} else { | ||
block(); | ||
} | ||
}; | ||
dispatch_source_set_event_handler(timer.source, internalBlock); | ||
dispatch_resume(timer.source); | ||
return timer; | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[self invalidate]; | ||
} | ||
#pragma mark--Action | ||
- (void)fire { | ||
self.block(); | ||
} | ||
|
||
- (void)invalidate { | ||
if (self.source) { | ||
dispatch_source_cancel(self.source); | ||
#if !__has_feature(objc_arc) | ||
dispatch_release(self.source); | ||
#endif | ||
self.source = nil; | ||
} | ||
self.block = nil; | ||
} | ||
|
||
#pragma mark-- State | ||
- (BOOL)isValid { | ||
return (self.source != nil); | ||
} | ||
|
||
- (id)userInfo { | ||
return self.internalUserInfo; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.