Skip to content

Instantly share code, notes, and snippets.

@Jotschi
Created August 26, 2011 10:54
Show Gist options
  • Save Jotschi/1173186 to your computer and use it in GitHub Desktop.
Save Jotschi/1173186 to your computer and use it in GitHub Desktop.
Cube CCP File
#include "Cube.h"
Cube::Cube() {}
Cube::~Cube() {}
void Cube::setSide(double s) {
side = s <= 0 ? 1 : s;
}
double Cube::getSide() {
return side;
}
double Cube::Area() {
return 6 * side * side;
}
double Cube::Volume() {
return side * side * side;
}
#ifndef CUBE_H
#define CUBE_H
class Cube {
public:
Cube();
~Cube();
void setSide(double s);
double getSide();
double Area();
double Volume();
private:
double side;
};
#endif
import static com.googlecode.javacpp.Loader.load;
import com.googlecode.javacpp.Pointer;
import com.googlecode.javacpp.annotation.Name;
import com.googlecode.javacpp.annotation.Platform;
@Platform(include = "Cube.h")
public class JavaCube {
static {
load();
}
public JavaCube() {
NativeCube cube = new NativeCube();
cube.setSide(9);
}
@Name("Cube")
public static class NativeCube extends Pointer {
static {
load();
}
public NativeCube() {
Cube();
}
public native void setSide(double s);
// this = new std::Cube()
private native void Cube();
private native double Area();
private native double getSide();
private native double Volume();
public double getArea() {
return this.Area();
}
public double getVolume() {
return this.Volume();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment