Last active
August 28, 2020 05:13
-
-
Save saudet/9ec4697364403118ffaf400df69f6ddb to your computer and use it in GitHub Desktop.
A minimal example of a way to map std::chrono::system_clock::time_point with JavaCPP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bytedeco.javacpp.*; | |
import org.bytedeco.javacpp.annotation.*; | |
/** | |
* java -jar /path/to/javacpp.jar NanoChrono.java | |
* java -cp /path/to/javacpp.jar:. NanoChrono | |
*/ | |
@Platform(include = "chrono") | |
public class NanoChrono { | |
static { Loader.load(); } | |
@Name("std::chrono::system_clock::time_point") | |
public static class TimePoint extends Pointer { | |
static { Loader.load(); } | |
public TimePoint() { allocate(); } | |
public TimePoint(Pointer p) { super(p); } | |
private native void allocate(); | |
@ByVal @Namespace @Name("std::chrono::system_clock::now") | |
public static native TimePoint now(); | |
@Name("time_since_epoch().count") | |
public native long nano(); | |
} | |
public static void main(String[] args) { | |
long time1 = TimePoint.now().nano() / 1000000; | |
long time2 = System.currentTimeMillis(); | |
System.out.println(time1); | |
System.out.println(time2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment