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

DO NOT REPEAT YOURSELF

DO NOT REPEAT YOURSELF

Leverage the power of C++ and Djinni to write native cross platform code on iOS and Android

Marco Sero

March 13, 2015
Tweet

More Decks by Marco Sero

Other Decks in Programming

Transcript

  1. C++

  2. DEFINE INTERFACE IN A .djinni FILE image_cache = interface +c

    { static create_with_path(path: string): image_cache; image_for_key(key: string): binary; save_image_for_key(key: string, image_data: binary); }
  3. IMPLEMENT IT IN C++ shared_ptr<ImageCache> ImageCache::create_with_path(const std::string &path) { ...

    } vector<uint8_t> ImageCache::image_for_key(const string &key) { ... } void ImageCache::save_image_for_key(const string &key, const vector<uint8_t> &image_data) { ... }
  4. USE IT FROM OBJECTIVE-C id<YCCPImageCache> imageCache = [YCPPImageCacheCppProxy createWithPath:cachePath]; NSData

    *imageData = [imageCache imageForKey:cacheKey]; [imageCache saveImageForKey:cacheKey imageData:imageData]; AND JAVA ImageCache imageCache = ImageCache.createWithPath(cachePath); byte[] imageBlob = this.imageCache.imageForKey(cacheKey); imageCache.saveImageForKey(cacheKey, imageBlob);