]> Zhao Yanbai Git Server - acecode.git/commitdiff
...
authoracevest <zhaoyanbai@126.com>
Tue, 23 Jun 2015 09:39:17 +0000 (17:39 +0800)
committeracevest <zhaoyanbai@126.com>
Tue, 23 Jun 2015 09:39:17 +0000 (17:39 +0800)
16 files changed:
.DS_Store [moved from learn/swift/.DS_Store with 82% similarity]
learn/.DS_Store [new file with mode: 0644]
learn/AppleSwift/.DS_Store [new file with mode: 0644]
learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj [new file with mode: 0644]
learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata [moved from learn/swift/MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata with 70% similarity]
learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcshareddata/AppleSwift.xccheckout [moved from learn/swift/MyPlayground.playground/playground.xcworkspace/xcshareddata/MyPlayground.xccheckout with 87% similarity]
learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate [new file with mode: 0644]
learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/AppleSwift.xcscheme [new file with mode: 0644]
learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/xcschememanagement.plist [new file with mode: 0644]
learn/AppleSwift/AppleSwift/main.swift [new file with mode: 0644]
learn/swift/MyPlayground.playground/contents.xcplayground [deleted file]
learn/swift/MyPlayground.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate [deleted file]
learn/swift/MyPlayground.playground/section-1.swift [deleted file]
learn/swift/MyPlayground.playground/timeline.xctimeline [deleted file]
lib/RingBuffer.cpp [new file with mode: 0644]
tools/comm/countc.c

similarity index 82%
rename from learn/swift/.DS_Store
rename to .DS_Store
index 0af6509e8bbda9106a7fcb0fe74feb24d9cbab14..2c3105d4c15de905e8e096c03661b1f8bccfafbc 100644 (file)
Binary files a/learn/swift/.DS_Store and b/.DS_Store differ
diff --git a/learn/.DS_Store b/learn/.DS_Store
new file mode 100644 (file)
index 0000000..8cc4f85
Binary files /dev/null and b/learn/.DS_Store differ
diff --git a/learn/AppleSwift/.DS_Store b/learn/AppleSwift/.DS_Store
new file mode 100644 (file)
index 0000000..4bc2632
Binary files /dev/null and b/learn/AppleSwift/.DS_Store differ
diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj b/learn/AppleSwift/AppleSwift.xcodeproj/project.pbxproj
new file mode 100644 (file)
index 0000000..79dc39c
--- /dev/null
@@ -0,0 +1,243 @@
+// !$*UTF8*$!
+{
+       archiveVersion = 1;
+       classes = {
+       };
+       objectVersion = 46;
+       objects = {
+
+/* Begin PBXBuildFile section */
+               5063B2A61B390AAF009C5821 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5063B2A51B390AAF009C5821 /* main.swift */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+               5063B2A01B390AAF009C5821 /* CopyFiles */ = {
+                       isa = PBXCopyFilesBuildPhase;
+                       buildActionMask = 2147483647;
+                       dstPath = /usr/share/man/man1/;
+                       dstSubfolderSpec = 0;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 1;
+               };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+               5063B2A21B390AAF009C5821 /* AppleSwift */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = AppleSwift; sourceTree = BUILT_PRODUCTS_DIR; };
+               5063B2A51B390AAF009C5821 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+               5063B29F1B390AAF009C5821 /* Frameworks */ = {
+                       isa = PBXFrameworksBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+               5063B2991B390AAF009C5821 = {
+                       isa = PBXGroup;
+                       children = (
+                               5063B2A41B390AAF009C5821 /* AppleSwift */,
+                               5063B2A31B390AAF009C5821 /* Products */,
+                       );
+                       sourceTree = "<group>";
+               };
+               5063B2A31B390AAF009C5821 /* Products */ = {
+                       isa = PBXGroup;
+                       children = (
+                               5063B2A21B390AAF009C5821 /* AppleSwift */,
+                       );
+                       name = Products;
+                       sourceTree = "<group>";
+               };
+               5063B2A41B390AAF009C5821 /* AppleSwift */ = {
+                       isa = PBXGroup;
+                       children = (
+                               5063B2A51B390AAF009C5821 /* main.swift */,
+                       );
+                       path = AppleSwift;
+                       sourceTree = "<group>";
+               };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+               5063B2A11B390AAF009C5821 /* AppleSwift */ = {
+                       isa = PBXNativeTarget;
+                       buildConfigurationList = 5063B2A91B390AAF009C5821 /* Build configuration list for PBXNativeTarget "AppleSwift" */;
+                       buildPhases = (
+                               5063B29E1B390AAF009C5821 /* Sources */,
+                               5063B29F1B390AAF009C5821 /* Frameworks */,
+                               5063B2A01B390AAF009C5821 /* CopyFiles */,
+                       );
+                       buildRules = (
+                       );
+                       dependencies = (
+                       );
+                       name = AppleSwift;
+                       productName = AppleSwift;
+                       productReference = 5063B2A21B390AAF009C5821 /* AppleSwift */;
+                       productType = "com.apple.product-type.tool";
+               };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+               5063B29A1B390AAF009C5821 /* Project object */ = {
+                       isa = PBXProject;
+                       attributes = {
+                               LastUpgradeCheck = 0630;
+                               ORGANIZATIONNAME = Ace;
+                               TargetAttributes = {
+                                       5063B2A11B390AAF009C5821 = {
+                                               CreatedOnToolsVersion = 6.3.2;
+                                       };
+                               };
+                       };
+                       buildConfigurationList = 5063B29D1B390AAF009C5821 /* Build configuration list for PBXProject "AppleSwift" */;
+                       compatibilityVersion = "Xcode 3.2";
+                       developmentRegion = English;
+                       hasScannedForEncodings = 0;
+                       knownRegions = (
+                               en,
+                       );
+                       mainGroup = 5063B2991B390AAF009C5821;
+                       productRefGroup = 5063B2A31B390AAF009C5821 /* Products */;
+                       projectDirPath = "";
+                       projectRoot = "";
+                       targets = (
+                               5063B2A11B390AAF009C5821 /* AppleSwift */,
+                       );
+               };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+               5063B29E1B390AAF009C5821 /* Sources */ = {
+                       isa = PBXSourcesBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                               5063B2A61B390AAF009C5821 /* main.swift in Sources */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+               5063B2A71B390AAF009C5821 /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+                               CLANG_CXX_LIBRARY = "libc++";
+                               CLANG_ENABLE_MODULES = YES;
+                               CLANG_ENABLE_OBJC_ARC = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               COPY_PHASE_STRIP = NO;
+                               DEBUG_INFORMATION_FORMAT = dwarf;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               GCC_C_LANGUAGE_STANDARD = gnu99;
+                               GCC_DYNAMIC_NO_PIC = NO;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_OPTIMIZATION_LEVEL = 0;
+                               GCC_PREPROCESSOR_DEFINITIONS = (
+                                       "DEBUG=1",
+                                       "$(inherited)",
+                               );
+                               GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.10;
+                               MTL_ENABLE_DEBUG_INFO = YES;
+                               ONLY_ACTIVE_ARCH = YES;
+                               SDKROOT = macosx;
+                               SWIFT_OPTIMIZATION_LEVEL = "-Onone";
+                       };
+                       name = Debug;
+               };
+               5063B2A81B390AAF009C5821 /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+                               CLANG_CXX_LIBRARY = "libc++";
+                               CLANG_ENABLE_MODULES = YES;
+                               CLANG_ENABLE_OBJC_ARC = YES;
+                               CLANG_WARN_BOOL_CONVERSION = YES;
+                               CLANG_WARN_CONSTANT_CONVERSION = YES;
+                               CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
+                               CLANG_WARN_EMPTY_BODY = YES;
+                               CLANG_WARN_ENUM_CONVERSION = YES;
+                               CLANG_WARN_INT_CONVERSION = YES;
+                               CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+                               CLANG_WARN_UNREACHABLE_CODE = YES;
+                               CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+                               COPY_PHASE_STRIP = NO;
+                               DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                               ENABLE_NS_ASSERTIONS = NO;
+                               ENABLE_STRICT_OBJC_MSGSEND = YES;
+                               GCC_C_LANGUAGE_STANDARD = gnu99;
+                               GCC_NO_COMMON_BLOCKS = YES;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
+                               GCC_WARN_UNDECLARED_SELECTOR = YES;
+                               GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
+                               GCC_WARN_UNUSED_FUNCTION = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.10;
+                               MTL_ENABLE_DEBUG_INFO = NO;
+                               SDKROOT = macosx;
+                       };
+                       name = Release;
+               };
+               5063B2AA1B390AAF009C5821 /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Debug;
+               };
+               5063B2AB1B390AAF009C5821 /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Release;
+               };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+               5063B29D1B390AAF009C5821 /* Build configuration list for PBXProject "AppleSwift" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               5063B2A71B390AAF009C5821 /* Debug */,
+                               5063B2A81B390AAF009C5821 /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+                       defaultConfigurationName = Release;
+               };
+               5063B2A91B390AAF009C5821 /* Build configuration list for PBXNativeTarget "AppleSwift" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               5063B2AA1B390AAF009C5821 /* Debug */,
+                               5063B2AB1B390AAF009C5821 /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+               };
+/* End XCConfigurationList section */
+       };
+       rootObject = 5063B29A1B390AAF009C5821 /* Project object */;
+}
similarity index 70%
rename from learn/swift/MyPlayground.playground/playground.xcworkspace/contents.xcworkspacedata
rename to learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/contents.xcworkspacedata
index 919434a6254f0e9651f402737811be6634a03e9c..5e84e35fa3d140f8a098b8d910e3a38a75d0320e 100644 (file)
@@ -2,6 +2,6 @@
 <Workspace
    version = "1.0">
    <FileRef
-      location = "self:">
+      location = "self:AppleSwift.xcodeproj">
    </FileRef>
 </Workspace>
similarity index 87%
rename from learn/swift/MyPlayground.playground/playground.xcworkspace/xcshareddata/MyPlayground.xccheckout
rename to learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcshareddata/AppleSwift.xccheckout
index 51108a5b4d3d267a85b930c6b7b093370d2664e0..e196f852830293144717c4717a1912f83a13840b 100644 (file)
@@ -5,20 +5,20 @@
        <key>IDESourceControlProjectFavoriteDictionaryKey</key>
        <false/>
        <key>IDESourceControlProjectIdentifier</key>
-       <string>1330DDA2-1B99-4E60-9F3A-B7DE1D7ECB22</string>
+       <string>C6698B6B-E176-4266-9A99-7EA7B71954A4</string>
        <key>IDESourceControlProjectName</key>
-       <string>MyPlayground</string>
+       <string>project</string>
        <key>IDESourceControlProjectOriginsDictionary</key>
        <dict>
                <key>BA634633803B1A00DDD2BCDEF5C645E5844F56E6</key>
                <string>https://github.com/acevest/acecode.git</string>
        </dict>
        <key>IDESourceControlProjectPath</key>
-       <string>learn/swift/MyPlayground.playground</string>
+       <string>learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace</string>
        <key>IDESourceControlProjectRelativeInstallPathDictionary</key>
        <dict>
                <key>BA634633803B1A00DDD2BCDEF5C645E5844F56E6</key>
-               <string>../../..</string>
+               <string>../../../..</string>
        </dict>
        <key>IDESourceControlProjectURL</key>
        <string>https://github.com/acevest/acecode.git</string>
diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644 (file)
index 0000000..596ab3f
Binary files /dev/null and b/learn/AppleSwift/AppleSwift.xcodeproj/project.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/AppleSwift.xcscheme b/learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/AppleSwift.xcscheme
new file mode 100644 (file)
index 0000000..8bc289c
--- /dev/null
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+   LastUpgradeVersion = "0630"
+   version = "1.3">
+   <BuildAction
+      parallelizeBuildables = "YES"
+      buildImplicitDependencies = "YES">
+      <BuildActionEntries>
+         <BuildActionEntry
+            buildForTesting = "YES"
+            buildForRunning = "YES"
+            buildForProfiling = "YES"
+            buildForArchiving = "YES"
+            buildForAnalyzing = "YES">
+            <BuildableReference
+               BuildableIdentifier = "primary"
+               BlueprintIdentifier = "5063B2A11B390AAF009C5821"
+               BuildableName = "AppleSwift"
+               BlueprintName = "AppleSwift"
+               ReferencedContainer = "container:AppleSwift.xcodeproj">
+            </BuildableReference>
+         </BuildActionEntry>
+      </BuildActionEntries>
+   </BuildAction>
+   <TestAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      buildConfiguration = "Debug">
+      <Testables>
+      </Testables>
+      <MacroExpansion>
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "5063B2A11B390AAF009C5821"
+            BuildableName = "AppleSwift"
+            BlueprintName = "AppleSwift"
+            ReferencedContainer = "container:AppleSwift.xcodeproj">
+         </BuildableReference>
+      </MacroExpansion>
+   </TestAction>
+   <LaunchAction
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
+      launchStyle = "0"
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Debug"
+      ignoresPersistentStateOnLaunch = "NO"
+      debugDocumentVersioning = "YES"
+      allowLocationSimulation = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "5063B2A11B390AAF009C5821"
+            BuildableName = "AppleSwift"
+            BlueprintName = "AppleSwift"
+            ReferencedContainer = "container:AppleSwift.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+      <AdditionalOptions>
+      </AdditionalOptions>
+   </LaunchAction>
+   <ProfileAction
+      shouldUseLaunchSchemeArgsEnv = "YES"
+      savedToolIdentifier = ""
+      useCustomWorkingDirectory = "NO"
+      buildConfiguration = "Release"
+      debugDocumentVersioning = "YES">
+      <BuildableProductRunnable
+         runnableDebuggingMode = "0">
+         <BuildableReference
+            BuildableIdentifier = "primary"
+            BlueprintIdentifier = "5063B2A11B390AAF009C5821"
+            BuildableName = "AppleSwift"
+            BlueprintName = "AppleSwift"
+            ReferencedContainer = "container:AppleSwift.xcodeproj">
+         </BuildableReference>
+      </BuildableProductRunnable>
+   </ProfileAction>
+   <AnalyzeAction
+      buildConfiguration = "Debug">
+   </AnalyzeAction>
+   <ArchiveAction
+      buildConfiguration = "Release"
+      revealArchiveInOrganizer = "YES">
+   </ArchiveAction>
+</Scheme>
diff --git a/learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/xcschememanagement.plist b/learn/AppleSwift/AppleSwift.xcodeproj/xcuserdata/Ace.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644 (file)
index 0000000..15e61c0
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>SchemeUserState</key>
+       <dict>
+               <key>AppleSwift.xcscheme</key>
+               <dict>
+                       <key>orderHint</key>
+                       <integer>0</integer>
+               </dict>
+       </dict>
+       <key>SuppressBuildableAutocreation</key>
+       <dict>
+               <key>5063B2A11B390AAF009C5821</key>
+               <dict>
+                       <key>primary</key>
+                       <true/>
+               </dict>
+       </dict>
+</dict>
+</plist>
diff --git a/learn/AppleSwift/AppleSwift/main.swift b/learn/AppleSwift/AppleSwift/main.swift
new file mode 100644 (file)
index 0000000..da38bb1
--- /dev/null
@@ -0,0 +1,240 @@
+//
+//  main.swift
+//  AppleSwift
+//
+//  Created by Ace on 15/6/23.
+//  Copyright (c) 2015年 Ace. All rights reserved.
+//
+
+import Foundation
+
+
+let Constant = 0x1234   // let 声明常量
+var Variable = 0xAFEC   // var 声明变量
+var VarInt   = 8421
+var VarFloat = 3.1415926
+var VarDouble:Double = 2.71828182846    //如果初始类型信息不足,可以在变量后加":类型"
+var VarF:Float = 0.1314
+var str:String = "Hello, World!"
+
+
+let ss = str + " " + String(Variable)  // 类型必需显示转换
+
+
+// 可以通过在客串中加\()的方式把值转换成字符串
+let Int2Str = "translate int in string with \(VarInt) \(ss)"
+println(Int2Str)
+
+
+// 数组
+var arrayList = ["apple", "microsoft", "xx", "google", "tencent", "twitter"]
+arrayList[2] = "amazon"
+println(arrayList)
+
+// 字典
+var dict = [
+    "apple" : "USA",
+    "tencnet" : "CN"
+]
+println(dict)
+println(dict["apple"])
+println(dict["apple"]!)
+
+// 创建空数组和空字典
+var EmptyArray = [String]()
+var EmptyDict  = [String:String]()
+// or
+var EmptArrayWithNoType = []
+var EmptDictWithNoType = [:]
+
+for cp in arrayList {
+    println(cp)
+}
+
+
+
+var OptionalVar:String? = "hehe"
+//OptionalVar = nil
+if let name = OptionalVar {
+    println("Hello \(OptionalVar)")
+}
+else
+{
+    println("sssssss")
+}
+
+
+let word = "ff"
+
+switch word {
+case "dd" :
+    println("unknown")
+case "ff" :
+    println("fallthrough")
+    fallthrough // 会走到下一个case
+case "red apple", "blue apple" :
+    println("red")
+default:            // 必须在最后。。。
+    println("default");
+}
+
+
+// 闭区间
+for i in 0...3 {
+    print(i)
+}
+println("")
+// 开区间
+for i in 0..<3 {
+    print(i)
+}
+
+
+for i in 0..<arrayList.count {
+    println("arrayList的第\(i+1)个元素为 \(arrayList[i])")
+}
+
+//let optIntStr = "ffffffff"
+let optIntStr = "123"
+let optInt = optIntStr.toInt()
+if optInt != nil {
+    println("\(optIntStr) has integer value of \(optInt!)")
+    println("\(optIntStr) has integer value of \(optInt)")
+} else {
+    println("\(optIntStr) could not be converted to an integer")
+}
+
+
+let possableString:String?="An optional string"
+println(possableString!)
+let assumedString:String!="An implicitly unwrapped optional string"
+println(assumedString)
+
+
+var opt:String="aaa"
+// opt=nil // 如果声明没有? 或 ! 来表明这是一个可选类型,那么 nil的赋值不合法
+print(opt)
+//assert(opt != "aaa", "assert failed")
+
+
+// String
+var s = "aaaaaa\0bbbbb\tccccc\\\n\"\'"
+println(s)
+
+var emptySa = ""
+var emptySb = String()
+
+if emptySa.isEmpty && emptySb.isEmpty {
+    println("emptySa and emptySb is empty")
+}
+
+var emojiStr = "😘😡👿😜"
+for c in  emojiStr {
+    print(c)
+}
+
+
+var smileChar:Character = "😀"
+emojiStr.append(smileChar)
+println("  emojistr \(emojiStr) charactor count is \(count(emojiStr))")
+
+
+s = "Prefix----Suffix"
+if s.hasPrefix("Prefix") && s.hasSuffix("Suffix") {
+    println(s.lowercaseString)
+    println(s.uppercaseString)
+}
+
+
+// Array
+var IntArray:Array<Int>=[]
+for i in 1...5 {
+    IntArray.append(i)
+}
+IntArray += [0, -1, -2, -3, -4]
+IntArray[0] = 1024
+IntArray[1..<4]=[999, 888, 777]
+IntArray.insert(1, atIndex: 0)
+IntArray.removeAtIndex(5)
+IntArray.removeLast()
+println(IntArray)
+for (index, value) in enumerate(IntArray) {
+    println("Item \(index+1): \(value)")
+}
+
+
+var StringArray = [String]()
+StringArray.append("dd")
+StringArray = []
+
+var DoubleArray = [Double](count:3, repeatedValue:9.9)
+for i in 1...5 {
+    DoubleArray.append(Double(i)*1.1)
+}
+println(DoubleArray)
+
+
+// Set
+var SetA=Set<Int>()
+var SetB:Set<Character>=[]
+var SetC: Set<Character> = ["a", "b", "b"]
+
+SetA.insert(1)
+SetA.insert(2)
+SetA.insert(1)
+if SetA.contains(1) {
+    println(SetA)
+}
+
+for genre in sorted(SetA) {
+    println("\(genre)")
+}
+
+let oddSet:Set = [1, 3, 5, 7, 9]
+let evenSet:Set = [0, 2, 4, 6, 8]
+println(sorted(oddSet.intersect(evenSet)))  // 交
+println(sorted(oddSet.union(evenSet)))      // 并
+println(oddSet.hashValue)
+
+
+// Dict
+var airports: [String:String] = ["TYO" : "Tokyo", "DUB":"Dublin"]
+airports["LHR"] = "London"
+airports["APL"] = "Apple Internation"
+if let oldValue = airports.updateValue("Dublin Internation", forKey: "DUB") {
+    println("The old value for DIB was \(oldValue)")
+}
+
+for (k, v) in airports {
+    println("\(k): \(v)")
+}
+
+for k in airports.keys {
+    println("Airport Code: \(k)")
+}
+
+for v in airports.values {
+    println("Airport Name: \(v)")
+}
+
+println(airports)
+airports["APL"] = nil   // Delete
+println(airports)
+
+if let removedValue = airports.removeValueForKey("DUB") {
+    println("The removed airport's name is \(removedValue)")
+} else {
+    println("The airports dictionary does not contain a value for DUB")
+}
+
+// create an empty dict
+var emptyDict = Dictionary<Int, String>()
+emptyDict[16] = "sixteen"
+emptyDict = [:]
+
+
+
+
+
+
+
diff --git a/learn/swift/MyPlayground.playground/contents.xcplayground b/learn/swift/MyPlayground.playground/contents.xcplayground
deleted file mode 100644 (file)
index 8e39341..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<playground version='3.0' sdk='iphonesimulator'>
-    <sections>
-        <code source-file-name='section-1.swift'/>
-    </sections>
-    <timeline fileName='timeline.xctimeline'/>
-</playground>
\ No newline at end of file
diff --git a/learn/swift/MyPlayground.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate b/learn/swift/MyPlayground.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644 (file)
index 0624362..0000000
Binary files a/learn/swift/MyPlayground.playground/playground.xcworkspace/xcuserdata/Ace.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/learn/swift/MyPlayground.playground/section-1.swift b/learn/swift/MyPlayground.playground/section-1.swift
deleted file mode 100644 (file)
index bb6b9ec..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-// Playground - noun: a place where people can play
-
-import UIKit
-
-var str = "Hello, playground"
-println(str)
-
-let Constant = 0x1234   // let 声明常量
-var Variable = 0xAFEC   // var 声明变量
-var VarInt   = 8421
-var VarFloat = 3.1415926
-var VarDouble:Double = 2.71828182846    //如果初始类型信息不足,可以在变量后加":类型"
-var VarF:Float = 0.1314
-
-
-let s = str + String(Variable)  // 类型必需显示转换
-
-
-// 可以通过在客串中加\()的方式把值转换成字符串
-let Int2Str = "translate int in string with \(VarInt) \(str)"
-println(Int2Str)
-
-
-// 数组
-var arrayList = ["apple", "microsoft", "xx", "google", "tencent", "twitter"]
-arrayList[2] = "amazon"
-println(arrayList)
-
-// 字典
-var dict = [
-    "apple" : "USA",
-    "tencnet" : "CN"
-]
-println(dict)
-
-// 创建空数组和空字典
-var EmptyArray = [String]()
-var EmptyDict  = [String:String]()
-// or
-var EmptArrayWithNoType = []
-var EmptDictWithNoType = [:]
-
-for cp in arrayList {
-    println(cp)
-}
-
-
-
-var OptionalVar: String? = "hehe"
-OptionalVar == nil
-if let name = OptionalVar {
-    println("Hello \(OptionalVar)")
-}
-else
-{
-    println("sssssss")
-}
-
-
-let word = "red apple"
-
-//switch word {
-//case "dd" :
-//}
-
-
-
-
diff --git a/learn/swift/MyPlayground.playground/timeline.xctimeline b/learn/swift/MyPlayground.playground/timeline.xctimeline
deleted file mode 100644 (file)
index bf468af..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Timeline
-   version = "3.0">
-   <TimelineItems>
-   </TimelineItems>
-</Timeline>
diff --git a/lib/RingBuffer.cpp b/lib/RingBuffer.cpp
new file mode 100644 (file)
index 0000000..ac000d0
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: RingBuffer.cpp
+ *              Thu Jun 18 16:13:49 2015
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#include <cstdlib>
+#include <string.h>
+
+class RingBuffer
+{
+public:
+    RingBuffer(): buffer_(NULL), in_(0), out_(0), size_(0) {}
+    ~RingBuffer() {}
+
+public:
+    // Init - 初始化缓冲区
+    // @buffer: 已经申请的用作缓冲区的内存指针
+    // @size: 缓冲区的大小, 必须是2的整数次幂
+    //
+    // 通过@buffer传入的内存, 可以是通过Alloc申请的, 也可以是外部自行分配的
+    // 后者需要自行释放内存, 不适合通过Free释放
+    int Init(unsigned char *buffer, unsigned int size)
+    {
+        if (!is_power_of_two(size))
+            return -1;
+
+        buffer_ = buffer;
+        size_ = size;
+        in_ = out_ = 0;
+
+        return 0;
+    }
+    
+    // Alloc - 在堆上申请指定大小的缓冲区内存并初始化
+    // @size: 缓冲区大小, 会向上调整到2的整数次幂
+    //
+    // 通过Alloc申请的内存需要通过Free进行释放, 即Alloc和Free要配对使用
+    int Alloc(unsigned int size)
+    {
+        unsigned char *buffer;
+        int ret;
+
+        if (!is_power_of_two(size))
+            size = roundup_power_of_two(size);
+
+        buffer = new unsigned char[size];
+        if (!buffer)
+            return -1;
+
+        ret = Init(buffer, size);
+        if (ret != 0)
+            delete[] buffer;
+
+        return 0;
+    }
+
+    // Put - 向缓冲区拷贝指定长度的数据
+    // @buffer: 拷贝到缓冲区的数据
+    // @len: 数据长度
+    //
+    // 从@buffer向缓冲区拷贝至多@len字节的数据, 具体拷贝长度依赖缓冲区的
+    // 剩余空间大小, 实际拷贝长度通过返回值返回
+    unsigned int Put(const unsigned char *buffer, unsigned int len)
+    {
+        unsigned int l;
+
+        len = min(len, size_ - Len());
+
+        // 从buffer_的in_位置开始写入数据, 直到buffer_的结尾位置
+        l = min(len, size_ - (in_ & (size_ - 1)));
+        memcpy(buffer_ + (in_ & (size_ - 1)), buffer, l);
+
+        // 把剩余数据从buffer_的起始位置开始写入, 直到完成len字节写入
+        memcpy(buffer_, buffer + l, len - l);
+
+        in_ += len;
+
+        return len;
+    }
+
+    // Get - 从缓冲区中取出指定长度的数据
+    // @buffer: 取出数据的拷贝内存
+    // @len: 拷贝内存的长度
+    //
+    // 向@buffer拷贝至多@len字节的数据, 实际拷贝长度通过返回值返回
+    unsigned int Get(unsigned char *buffer, unsigned int len)
+    {
+        unsigned int l;
+
+        len = min(len, Len());
+
+        // 从buffer_的out_位置开始读出数据, 直到buffer_的结束位置
+        l = min(len, size_ - (out_ & (size_ - 1)));
+        memcpy(buffer, buffer_ + (out_ & (size_ - 1)), l);
+
+        // 然后从buffer_的起始位置开始读出, 直到完成len字节读出
+        memcpy(buffer + l, buffer_, len - l);
+
+        out_ += len;
+
+        return len;
+    }
+    
+    // Len - 返回缓冲区的数据长度
+    unsigned int Len()
+    {
+        return in_ - out_;
+    }
+
+    // Reset - 重置缓冲区, 即清空缓冲区数据
+    void Reset()
+    {
+        in_ = out_ = 0;
+    }
+
+    // Free - 释放缓冲区内存
+    // 释放通过Alloc申请的缓冲区内存, 和Alloc配对使用
+    void Free()
+    {
+        if (buffer_)
+        {
+            delete[] buffer_;
+            buffer_ = NULL;
+        }
+    }
+
+private:
+    template <typename T>
+    T min(T a, T b)
+    {
+        return a > b ? b : a;
+    }
+
+    bool is_power_of_two(unsigned int n)
+    {
+        return (n != 0 && ((n & (n - 1)) == 0));
+    }
+
+    unsigned int roundup_power_of_two(unsigned int n)
+    {
+        unsigned int fls = __builtin_clz(n);
+        return 1 << (sizeof(n) * 8 - fls);
+    }
+
+private:
+    unsigned char   *buffer_;    // 缓冲区指针
+    unsigned int    in_;         // 写指针
+    unsigned int    out_;        // 读指针
+    unsigned int    size_;       // 缓冲区大小
+};
+
+int main()
+{
+    RingBuffer rb;
+    rb.Alloc(7);
+
+    unsigned char str[128] = {0};
+    int n;
+
+    str[0] = 'a';
+    n = rb.Put(str, 1);
+
+    str[1] = 'b';
+    n = rb.Put(str, 2);
+
+    str[2] = 'c';
+    n = rb.Put(str, 3);
+
+    str[3] = 'd';
+    n = rb.Put(str, 4);
+
+    str[4] = 'e';
+    n = rb.Put(str, 5);
+
+    n = rb.Get(str, 2);
+    n = rb.Get(str, 1);
+
+    rb.Free();
+
+    return 0;
+}
index e71f771ec242d6960f7b998d9f2c1c0ed11bfc40..1b978fc0060fa83e8787a858fba30f3be95bbb1d 100644 (file)
@@ -91,6 +91,7 @@ void  count_file(char *path)
        && !valid_type(path,"py")
        && !valid_type(path,"go")
        && !valid_type(path,"php")
+       && !valid_type(path,"swift")
        )
        {
 #if 0