-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
274 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "NormalClassTest.h" | ||
|
||
int NormalClassTest::getIntValue() | ||
{ | ||
return 0; | ||
} | ||
|
||
bool NormalClassTest::getBoolValue(float floatValue) | ||
{ | ||
return true; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef NORMALCLASSTEST_H | ||
#define NORMALCLASSTEST_H | ||
|
||
class NormalClassTest | ||
{ | ||
public: | ||
int getIntValue(); | ||
bool getBoolValue(float floatValue); | ||
} | ||
|
||
#endif //NORMALCLASSTEST_H |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,9 @@ | ||
[NoDelete] | ||
interface NoDeleteClassTest { | ||
[Value] static NormalClassTest GetNormalValueClass(); | ||
[Ref] ExtendClassTest getExtendClass(float floatParam, long intParam, [Const, Ref]NormalClassTest normalClass, float[] vertices); | ||
|
||
static readonly attribute unsigned long ReadOnlyInt; | ||
[Const]attribute NormalClassTest constNormalClass; | ||
[Value]attribute NormalClassTest valueNormalClass; | ||
attribute float floatAttribute; | ||
attribute boolean boolAttribute; | ||
attribute unsigned long flags; | ||
attribute boolean [] arrayBoolean | ||
attribute unsigned long[] arrayInt | ||
attribute any anyObject; | ||
}; | ||
|
||
[Prefix="MyPrefix::"] | ||
interface PrefixClassTest { | ||
|
||
}; | ||
|
||
[Prefix = "MyPrefix::", NoDelete] | ||
interface PrefixNoDeleteClassTest { | ||
|
||
}; | ||
|
||
[NoDelete, Prefix = "MyPrefix::"] | ||
interface NoDeletePrefixClassTest { | ||
|
||
}; | ||
|
||
[JSImplementation="NoDeletePrefixClassTest"] | ||
interface ConcreteJSImplementationClassTest { | ||
void ConcreteJSImplementationClassTest(); | ||
interface ParentClassTest { | ||
float getFloatValue(); | ||
}; | ||
|
||
interface NormalClassTest { | ||
long getIntValue(); | ||
boolean getBoolValue(float floatValue); | ||
}; | ||
|
||
interface ExtendClassTest { | ||
float getFloatValue(); | ||
} | ||
ExtendClassTest implements NormalClassTest; | ||
|
||
enum EnumTest { | ||
"Test_Enum" | ||
}; | ||
NormalClassTest implements ParentClassTest; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/** | ||
* @author xpenatan | ||
*/ | ||
public abstract class IDLBase { | ||
|
||
public static boolean USE_REF_COUNTING = false; | ||
public static boolean ENABLE_LOGGING = true; | ||
|
||
protected long cPointer; | ||
protected boolean cMemOwn; | ||
private boolean disposed; | ||
protected boolean destroyed; | ||
private int refCount; | ||
|
||
public IDLBase() { | ||
} | ||
|
||
protected void initObject(long cPtr, boolean cMemoryOwn) { | ||
cMemOwn = cMemoryOwn; | ||
cPointer = cPtr; | ||
} | ||
|
||
/** | ||
* Set pointer if it's not owned by this object. Useful for setting temp objets | ||
*/ | ||
public void setPointer(long cPtr) { | ||
if(!cMemOwn) { | ||
cPointer = cPtr; | ||
} | ||
} | ||
|
||
/** | ||
* Obtains a reference to this object, call release to free the reference. | ||
*/ | ||
public void obtain() { | ||
refCount++; | ||
} | ||
|
||
/** | ||
* Release a previously obtained reference, causing the object to be disposed when this was the last reference. | ||
*/ | ||
public void release() { | ||
if(--refCount <= 0 && USE_REF_COUNTING) dispose(); | ||
} | ||
|
||
/** | ||
* @return Whether this instance is obtained using the {@link #obtain()} method. | ||
*/ | ||
public boolean isObtained() { | ||
return refCount > 0; | ||
} | ||
|
||
protected void construct() { | ||
destroyed = false; | ||
} | ||
|
||
protected void reset(long cPtr, boolean cMemoryOwn) { | ||
if(!destroyed) destroy(); | ||
cMemOwn = cMemoryOwn; | ||
cPointer = cPtr; | ||
construct(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
return (obj instanceof IDLBase) && (((IDLBase)obj).cPointer == this.cPointer); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return (int)cPointer; | ||
} | ||
|
||
/** | ||
* @return The memory location (pointer) of this instance. | ||
*/ | ||
public long getCPointer() { | ||
return cPointer; | ||
} | ||
|
||
/** | ||
* Take ownership of the native instance, causing the native object to be deleted when this object gets out of scope. | ||
*/ | ||
public void takeOwnership() { | ||
cMemOwn = true; | ||
} | ||
|
||
/** | ||
* Release ownership of the native instance, causing the native object NOT to be deleted when this object gets out of | ||
* scope. | ||
*/ | ||
public void releaseOwnership() { | ||
cMemOwn = false; | ||
} | ||
|
||
/** | ||
* @return True if the native is destroyed when this object gets out of scope, false otherwise. | ||
*/ | ||
public boolean hasOwnership() { | ||
return cMemOwn; | ||
} | ||
|
||
/** | ||
* Deletes the bullet object this class encapsulates. Do not call directly, instead use the {@link #dispose()} method. | ||
*/ | ||
protected void deleteNative() { | ||
|
||
} | ||
|
||
public void dispose() { | ||
if(refCount > 0 && USE_REF_COUNTING && ENABLE_LOGGING) { | ||
error("Bullet", "Disposing " + toString() + " while it still has " + refCount + " references."); | ||
} | ||
if(cMemOwn) { | ||
// Don't try to delete if this object did not create the pointer | ||
disposed = true; | ||
deleteNative(); | ||
cPointer = 0; | ||
} | ||
} | ||
|
||
/** | ||
* @return Whether the {@link #dispose()} method of this instance is called. | ||
*/ | ||
public boolean isDisposed() { | ||
return disposed; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "(" + cPointer + "," + cMemOwn + ")"; | ||
} | ||
|
||
protected void destroy() { | ||
try { | ||
if(destroyed && ENABLE_LOGGING) { | ||
error("Bullet", "Already destroyed " + toString()); | ||
} | ||
destroyed = true; | ||
|
||
if(cMemOwn && !disposed) { | ||
if(ENABLE_LOGGING) { | ||
error("Bullet", "Disposing " + toString() + " due to garbage collection."); | ||
} | ||
dispose(); | ||
} | ||
} catch(Throwable e) { | ||
error("Bullet", "Exception while destroying " + toString(), e); | ||
} | ||
} | ||
|
||
@Override | ||
protected void finalize() throws Throwable { | ||
if(!destroyed && ENABLE_LOGGING) { | ||
error("Bullet", "The " + getClass().getSimpleName() + " class does not override the finalize method."); | ||
} | ||
super.finalize(); | ||
} | ||
|
||
/** | ||
* Logs an error message to the console or logcat | ||
*/ | ||
public static void error(String tag, String message) { | ||
//TODO impl | ||
} | ||
|
||
/** | ||
* Logs an error message to the console or logcat | ||
*/ | ||
public static void error(String tag, String message, Throwable exception) { | ||
//TODO impl | ||
} | ||
} |
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