Upgrade to Pro — share decks privately, control downloads, hide ads and more …

iOSとAndroidで共通のc++のコードを使いたいけど厳しかった話

 iOSとAndroidで共通のc++のコードを使いたいけど厳しかった話

2015/08/29 社内勉強会(chocotips)用

chocomelonchan

August 21, 2015
Tweet

More Decks by chocomelonchan

Other Decks in Programming

Transcript

  1. 6TFT$ GPS$SPTT 1MBUGPSNJ04BOE "OESPJE%FWFMPQNFOU 2015/08/29 @__chocomelon

  2. Ϟνϕʔγϣϯ w J04΋"OESPJE࡞Γ͍ͨ w ಉ͡ϩδοΫॻ͘ͷ͕ΊΜͲ͍

  3. ஌Βͳ͍ਓͷͨΊʹ ͓͞Β͍

  4. D DBMMGSPN4XJGU w 4XJGU͔Β͸௚઀ݺ΂ͳ͍ w 4XJGU0CKFDUJWF$ NN D ͰݺͿ w

    ͪΐͬͱΊΜͲ͍͘͞
  5. )FMMP 8SBQQJOHTXJGU extension Hello { class func hello() { Hello.helloFromNative()

    } } )FMMPNN @implementation Hello + (void)helloFromNative { return Hello::hello(); } @end )FMMPDQQ void Hello::hello() { printf("Hello"); }
  6. D DBMMGSPN+BWB w "OESPJE4UVEJP (SBEMFͰ TVQQPSU   w /%,Λ࢖ͬͯD

    ΛݺͿ w +/*ͳͷͰD ͷίʔυΛ+/*Ͱѻ͑Δܗʹ͢Δ ඞཁ͕͋Δʢ'VDLʣ w ͍ͩͿΊΜͲ͍͘͞
  7. )FMMPKBWB public class Hello {
 
 public static String hello()

    {
 return helloFromJNI();
 }
 
 public static native String helloFromJNI();
 
 static {
 System.loadLibrary("Hello-JNI");
 }
 } )FMMP+/*DQQ #include <jni.h>
 
 extern "C" {
 JNIEXPORT jstring Java_com_example_hellojni_Utils_stringFromJNI(JNIEnv *env, jobject thiz) {
 return env->NewStringUTF("Hello from JNI!");
 }
 }
  8. ࠔͬͨ͜ͱ w D Ͱѻ͑ΔΑ͏ʹUZQFΛௐ੔ w ྫ͑͹4XJGUͷ*OU͸CJU؀ڥͰ͸*OUɺ CJUͰ͸*OUʹͳΔͷͰ*OUʹͯ͠౉͢ w ྫ͑͹D ͩͱଟ࣍ݩ഑ྻͷѻ͍͕೉͍͠ͷͰ

    ࣍ݩ഑ྻʹ௚ͨ͠Γ
  9. ࣮ࡍͷίʔυྫ J04ฤ

  10. -PHJD6UJMT 8SBQQJOHTXJGU extension LogicUtil { class func isStep(map: [[Int32]], characterPoint:

    Point, direction: Direction) -> Bool { let numberOfSquares: Int = map.count let charaIndex: Int = characterPoint.x + characterPoint.y * numberOfSquares var mapIntArray: [Int32] = [] for y in 0..<numberOfSquares { for x in 0..<numberOfSquares { mapIntArray.append(map[y][x]) } } return LogicUtil.isStep(UnsafeMutablePointer<Int32>(mapIntArray), numOfSquares: Int32(numberOfSquares), charaIndex: Int32(charaIndex), direction: Int32(direction.rawValue)) } }
  11. -PHJD6UJMT 8SBQQJOHTXJGU extension LogicUtil { class func isStep(map: [[Int32]], characterPoint:

    Point, direction: Direction) -> Bool { let numberOfSquares: Int = map.count let charaIndex: Int = characterPoint.x + characterPoint.y * numberOfSquares var mapIntArray: [Int32] = [] for y in 0..<numberOfSquares { for x in 0..<numberOfSquares { mapIntArray.append(map[y][x]) } } return LogicUtil.isStep(UnsafeMutablePointer<Int32>(mapIntArray), numOfSquares: Int32(numberOfSquares), charaIndex: Int32(charaIndex), direction: Int32(direction.rawValue)) } }
  12. -PHJD6UJMTNN + (bool)isStep:(int[])map numOfSquares:(int)numOfSquares charaIndex: (int)charaIndex direction:(int)direction { return Logic::isStepToDirection(map,

    numOfSquares, charaIndex, direction); }
  13. ΊΜͲ͍

  14. ͞Βʹࠔͬͨ͜ͱ w "OESPJEଆ͕+/*ͳͷͰD ͷίʔυΛ+/*Ͱѻ ͑Δܗʹ͢Δඞཁ͕͋ͬͯͦͷ··D ࢖͑ͳ͍ w ຐ๏εΫϦϓτΛॻ͍ͯࣗಈੜ੒ʁ w "OESPJE+/"4XJH+/*ʁ

  15. ݫ͍͠

  16. ·ͱΊ w ͪΐͼͬͱͷ-PHJDڞ௨ԽͷͨΊʹD ࢖͏ͷ͸ ϊʔνϟϯ w ͋͘·Ͱڞ௨Խ͢Δͷ͸ָ͢Δͷϝϯςφϯεੑ ޲্ͷͨΊɺࠓճͷέʔεͰ͸ഁ୼͍ͯ͠Δɻ w ΋ͬͱؾܰʹ΍Βͤͯཉ͍͠

  17. ࠓޙ w DPDPTEYͱ͔6OJUZࢼ͍ͨ͠ w ͱ΋͍͑ɺDPDPTEYͱ͔6OJUZ͸୯ಠͷ*%&։ ൃʹͳΔ͔ΒήʔϜدΓʹͳͬͯ͠·͏ʢϩδο Ϋ͚ͩD Ͱڞ௨Խͱ͍͏༻్ʹ͸࢖͑ͳ͍ʣ w ۀ຿తʹ΋஌ݟ͕ଟ͍͜ͱ͕͍ͨ͠

    w ͳͷͰࢼͯ͠͸Έ͍͕ͨϞνϕʔγϣϯ௿Ί