Skip to content

Commit

Permalink
Merge pull request #42 from alexlee002/master
Browse files Browse the repository at this point in the history
Made some refactor, fix some bugs
  • Loading branch information
yuhua-chen committed Jan 26, 2016
2 parents 86b043b + ec566a6 commit ffe03f6
Show file tree
Hide file tree
Showing 44 changed files with 2,834 additions and 886 deletions.
66 changes: 66 additions & 0 deletions .clang-format
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ xcuserdata
*.moved-aside
DerivedData
*.xcuserstate

bak/
395 changes: 389 additions & 6 deletions MCLog.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions MCLog/ALAssociatedWeakObject.h
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
57 changes: 57 additions & 0 deletions MCLog/ALAssociatedWeakObject.m
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
24 changes: 24 additions & 0 deletions MCLog/HHTimer.h
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
75 changes: 75 additions & 0 deletions MCLog/HHTimer.m
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
11 changes: 4 additions & 7 deletions MCLog/MCDVTTextStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@

#import "MCXcodeHeaders.h"

@interface NSTextStorage (MCDVTTextStorage)
@interface NSTextStorage(MCDVTTextStorage)

- (void)mc_fixAttributesInRange:(NSRange)range;
- (void)updateAttributes:(NSMutableDictionary *)attrs withANSIESCString:(NSString *)ansiEscString;
@property(nonatomic, strong) NSDictionary *currentAttributes;
@property(nonatomic, getter=isConsoleStorage) BOOL consoleStorage;

- (void)setLastAttribute:(NSDictionary *)attribute;
- (NSDictionary *)lastAttribute;
- (void)setConsoleStorage:(BOOL)consoleStorage;
- (BOOL)consoleStorage;
- (void)mc_fixAttributesInRange:(NSRange)range;

@end
Loading

0 comments on commit ffe03f6

Please sign in to comment.