Rodhos Soft

備忘録を兼ねた技術的なメモです。Rofhos SoftではiOSアプリ開発を中心としてAndroid, Webサービス等の開発を承っております。まずはご相談下さい。

cpp

分割コンパイル

cpp

hojo.hpp int hello(); hojo.cpp #include "hojo.hpp" int hello() { return 1000; } hello.cpp #include <iostream> #include "hojo.hpp" using namespace std; int main(){ cout << "Hello world." << endl; int x = hello(); cout << x << endl; return 0; } という</iostream>…

文字列受け渡し

class Hello { companion object { init { System.loadLibrary("Hello") } } external fun printHello() external fun printNative(str:String, len:Int); } fun main(args: Array<String>) { Hello().printHello() val str = "hello form kotoln" Hello().printNati</string>…

kotlinでhelloworld

class Hello { companion object { init { System.loadLibrary("Hello") } } external fun printHello() } fun main(args: Array<String>) { Hello().printHello() } でコンパイル kotlinc hello.kt前回同様ライブラリを用意して実行 kotlin HelloKt</string>

cppでhelloworld

cのときと同様でhello.cppを作る。 #include "Hello.h" #include <iostream> extern "C" { JNIEXPORT void JNICALL Java_Hello_printHello (JNIEnv *env, jclass obj) { std::cout << "hello cpp" << std::endl; } } あとはコンパイル時に-libc++をつける。 gcc -share</iostream>…

cでhelloworld

java側を用意 public class Hello { static{ System.out.println(java.library.path); System.loadLibrary("Hello"); } static native void printHello(); public static void main(String args[]){ printHello(); } } コンパイル javac Hello.java C側を作…

チュートリアル2

さらに簡単な例 #include <rxcpp/rx.hpp> rxcpp::observable<std::string> twice(std::string word) { return rxcpp::observable<>::just(word + word); } rxcpp::observable<int> length(std::string word) { int l = (int)word.length(); return rxcpp::observable<>::just(l); } rxcpp::ob</int></std::string></rxcpp/rx.hpp>…

チュートリアル

一番簡単な使い方 rxcpp::observable<int> obs = rxcpp::observable<>::create<int> ( [=](rxcpp::subscriber<int> s) { s.on_next(100); s.on_next(200); s.on_next(300); s.on_completed(); } ); auto x = obs.flat_map([=](int x) { return rxcpp::observable<>::just(x </int></int></int>…

ライブラリ

Boost Libraries

variant 共用体

かなり便利なことがわかった。 #include <boost/variant.hpp> #include <iostream> int main(int argc, const char * argv[]) { // insert code here... std::cout << "Hello, World!\n"; boost::variant<int, std::string> v; v = 100; boost::variant<int, std::string> s; s = "200"; if (v.type() == typeid(int)) { int l =</int,></int,></iostream></boost/variant.hpp>…

boost設定

Macの場合。brewでinstall /usr/local/Cellar/boost/1.67.0_1 ここにincludeヘッダーとlibがあるのでXCodeのパスを通す。 Header Search Pathsにinclude Library Search Pathsにlib non-recursiveOther linker flagに -lboost_system設定

チュートリアル的な記述7

cpp

typeerase的なものを作ってみたがポインタ周りが怪しいので修正中 #include "TypeErase.hpp" #include <iostream> #include <map> class AnyBase; using AnyBase_sp = std::shared_ptr<AnyBase>; class AnyBase { public: AnyBase() = default; virtual ~AnyBase() = default; templa</anybase></map></iostream>…

チュートリアル的な記述6

cpp

継承やテンプレートなどを色々使ってみた。 #include <iostream> void hello() { std::cout << "hello/bye" << std::endl; std::string s; while (true) { std::cin >> s; if (s == "hello") { std::cout << "hello!" << std::endl; } else if (s == "bye") { std::cou</iostream>…

チュートリアル的な記述5

cpp

クラス、構造体 // class デフォルトのアクセス指定子がprivate // struct デフォルトのアクセウ指定子がpublic struct Animal; struct Man2; struct Animal { int age = 10; virtual void attack(); }; struct Man2 : Animal { typedef std:: shared_ptr<std::string> st</std::string>…

チュートリアル的な記述4

cpp

ファイル操作 #include <iostream> #include <fstream> void fileSample() { // file std::ofstream ofs("test.txt"); if (!ofs) { std::cerr << "[error]open file" << std::endl; std::exit(1); } ofs << "Hello, World\n123" << std::endl; // auto close std::ifstream ifs(</fstream></iostream>…

チュートリアル的な記述3

cpp

変数 #include <sstream> #include <iomanip> #include <fstream> void basicVariable() { const int c = 10; // ref int r = 0; int& r2 = r; r2 = 100; std::cout << r << std::endl; // 100 // 構造体 Point p; p.x = 10; p.y = 10; std::cout << p.d2() <</fstream></iomanip></sstream>

チュートリアル的な記述2

cpp

参照 // class class CPYCost { public: CPYCost(); ~CPYCost(); /// オブジェクトのコピー用の代入演算子 CPYCost& operator=(const CPYCost& rhs); int x; private: }; void refAdd(int &x); void pAdd(int *x); void refUse() { // 参照 int x = 1; int& …

チュートリアル的な記述

cpp

関数 int twice(int x); int twice(int x) { return x * 2; } auto nfunc2(int x) -> decltype(x) { return x * 100; } namespace FunctionauUse { int add(int x); void echo(int x); } /// 関数を変数に格納する。 void functionalUse() { std::function<void(int)> f</void(int)>…

木構造的なもの

cpp

LISPのようなものを作ろうとしたら単に文字列の結合を木構造でやるということになっていた。でもクラスについてだいぶ勉強になった。 // // RDLisp.hpp // RDLisp // // Created by KatagiriSo on 2017/09/26. // Copyright © 2017年 RodhosSoft. All rights…

練習 文字列等

cpp

文字列等の練習にコマンドと引数の対をとるコードを書いてみた。引数には対自体を入れることができるとする。結果はこんな感じになる。 >+ * 100 (+ (* ( 100))) #ifndef RDCalc_hpp #define RDCalc_hpp #include <stdio.h> #include "RDConfig.hpp" class Command { </stdio.h>…

右辺値参照

cpp

参照とは 宣言と同時に値を入れる必要がある。 右辺値参照 値型をコピーせずに持っておくことができる。 ユニバーサル参照 テンプレートを使う際にそれが右辺値参照なのか参照なのかが展開されるかわからない。 そこで展開に応じてよしなに右辺値参照、参照…