Skip to content

Commit

Permalink
Import initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
itsravenous committed Jun 4, 2017
0 parents commit 36928cb
Show file tree
Hide file tree
Showing 9 changed files with 837 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import PackageDescription

let package = Package(
name: "i3s",
targets: [
Target(name: "sharkcwrapper", dependencies:["sharkcpp"]),
Target(name: "swift-exec", dependencies:["sharkcwrapper"]),
]
)
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# swift-cpp-package
Playground project for writing Swift packages which use C++ code

# Prerequesites
- [Swift 3](https://swift.org/download/)

# Build
`swift build`

# Run
`.build/debug/swift-exec`
12 changes: 12 additions & 0 deletions Sources/sharkcpp/include/shark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __SHARK_H
#define __SHARK_H

class Shark {
private:
int id;
public:
void set_id(int i);
int get_id();
};

#endif
9 changes: 9 additions & 0 deletions Sources/sharkcpp/shark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "shark.h"

void Shark::set_id(int i) {
id = i;
}

int Shark::get_id() {
return id;
}
21 changes: 21 additions & 0 deletions Sources/sharkcwrapper/cwrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "shark.h"
#include "cwrapper.h"

extern "C" {
Shark* Shark_new() {
return new Shark();
}

void Shark_set_id(Shark* shark, int i) {
shark->set_id(i);
}

int Shark_get_id(Shark* shark) {
return shark->get_id();
}

void Shark_delete(Shark* shark) {
delete shark;
}
}

20 changes: 20 additions & 0 deletions Sources/sharkcwrapper/include/cwrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef SHARKWRAPPER_H
#define SHARKWRAPPER_H

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Shark Shark;

Shark* Shark_new();
void Shark_set_id(Shark* shark, int i);
int Shark_get_id(Shark* shark);
void Shark_delete(Shark* shark);

#ifdef __cplusplus
}
#endif
#endif


14 changes: 14 additions & 0 deletions Sources/swift-exec/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sharkcwrapper

// Create shark; get pointer
var shark = Shark_new()

// Set shark ID number
Shark_set_id(shark, 71)

// Retreive and print shark ID number
var id = Shark_get_id(shark)
print("Shark id is \(id)")

// Destroy shark object
Shark_delete(shark)

0 comments on commit 36928cb

Please sign in to comment.