Skip to content

Commit

Permalink
Add template array and some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Aug 11, 2024
1 parent fe1d438 commit 0105946
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 149 deletions.
24 changes: 24 additions & 0 deletions .run/jParser_example_app-test_desktop [run-app-desktop].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="jParser:example:app-test:desktop [run-app-desktop]" type="GradleRunConfiguration" factoryName="Gradle" folderName="lib-test">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/example/app-test/desktop" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run-app-desktop" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 24 additions & 0 deletions .run/jParser_example_app_desktop [run-app-desktop].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="jParser:example:app:desktop [run-app-desktop]" type="GradleRunConfiguration" factoryName="Gradle" folderName="lib">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/example/app/desktop" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run-app-desktop" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 24 additions & 0 deletions .run/jParser_example_app_teavm [run-app-teavm].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="jParser:example:app:teavm [run-app-teavm]" type="GradleRunConfiguration" factoryName="Gradle" folderName="lib">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/example/app/teavm" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="run-app-teavm" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="jParser:example:lib-test:lib-build [build_project_all]" type="GradleRunConfiguration" factoryName="Gradle" folderName="lib-test">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/example/lib-test/lib-build" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build_project_all" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
24 changes: 24 additions & 0 deletions .run/jParser_example_lib_lib-build [build_project_all].run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="jParser:example:lib:lib-build [build_project_all]" type="GradleRunConfiguration" factoryName="Gradle" folderName="lib">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/example/lib/lib-build" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build_project_all" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.utils.ScreenUtils;
import lib.emscripten.TestLibLoader;
import lib.test.ArrayArgumentTest;
import lib.test.ArrayClass;
import lib.test.Child1;
Expand All @@ -17,6 +16,7 @@
import lib.test.StoreArray;
import lib.test.StringUser;
import lib.test.StructInArray;
import lib.test.TestLibLoader;
import lib.test.TypeTestClass;
import lib.test.VoidPointerUser;
import lib.test.idl.helper.IDLByteArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib.emscripten;
package lib.test;

import com.github.xpenatan.jparser.loader.JParserLibraryLoader;

Expand Down
3 changes: 1 addition & 2 deletions example/lib/lib-build/src/main/cpp/exampleLib.idl
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,5 @@ enum EnumClassWithinClass {
};

enum EnumInNamespace {
// [-NAMESPACE]
"EnumNamespace::e_namespace_val"
"EnumInNamespace::e_namespace_val"
};
147 changes: 28 additions & 119 deletions jParser/base/src/main/resources/IDLHelper.h
Original file line number Diff line number Diff line change
@@ -1,52 +1,25 @@
#pragma once

#include <string>
#include <vector>
#include <stddef.h> // NULL
#include <stdint.h> // intptr_t

typedef std::string IDLString;
typedef std::string_view IDLStringView;

class IDLBoolArray {
template<typename T>
class IDLArray {
private:
int size;
public:
bool * data;
IDLBoolArray(int size) { data = NULL; resize(size); }
~IDLBoolArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
bool * newData = new bool[newSize];
this->data = newData;
size = newSize;
clear();
}
void clear() {
for(int i = 0; i < size; i++) {
data[i] = 0;
}
}
void deleteData() { delete data; }
bool getValue(int index) { return data[index]; }
void setValue(int index, bool value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
int getSize() { return size; }
};
T* data;

class IDLIntArray {
private:
int size;
void deleteData() { delete[] data; data = NULL; }
public:
int * data;
IDLIntArray(int size) { data = NULL; resize(size); }
~IDLIntArray() { if(data != NULL) { deleteData(); } }
IDLArray(int size) { data = NULL; resize(size); }
~IDLArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
int * newData = new int[newSize];
T * newData = new T[newSize];
this->data = newData;
size = newSize;
clear();
Expand All @@ -56,93 +29,29 @@ class IDLIntArray {
data[i] = 0;
}
}
void deleteData() { delete data; }
int getValue(int index) { return data[index]; }
void setValue(int index, int value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
int getSize() { return size; }
};

class IDLFloatArray {
private:
int size;
public:
float * data;
IDLFloatArray(int size) { data = NULL; resize(size); }
~IDLFloatArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
float * newData = new float[newSize];
this->data = newData;
size = newSize;
clear();
}
void clear() {
for(int i = 0; i < size; i++) {
data[i] = 0;
void copy(IDLArray<T>& src, int srcPos, int destPos, int length) {
T* dest = data;
int srcP = srcPos;
int destP = destPos;
int count = 0;
while(count < length) {
T srcByte = src.getValue(srcP);
srcP++;
dest[destP] = srcByte;
destP++;
count++;
}
}
void deleteData() { delete data; }
float getValue(int index) { return data[index]; }
void setValue(int index, float value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
T getValue(int index) { return data[index]; }
void setValue(int index, T value) { data[index] = value; }
int getSize() { return size; }
};

class IDLDoubleArray {
private:
int size;
public:
double * data;
IDLDoubleArray(int size) { data = NULL; resize(size); }
~IDLDoubleArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
double * newData = new double[newSize];
this->data = newData;
size = newSize;
clear();
}
void clear() {
for(int i = 0; i < size; i++) {
data[i] = 0;
}
}
void deleteData() { delete data; }
double getValue(int index) { return data[index]; }
void setValue(int index, double value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
int getSize() { return size; }
};

class IDLByteArray {
private:
int size;
public:
char * data;
IDLByteArray(int size) { data = NULL; resize(size); }
~IDLByteArray() { if(data != NULL) { deleteData(); } }
void resize(int newSize) {
if(this->data != NULL) {
deleteData();
}
char * newData = new char[newSize];
this->data = newData;
size = newSize;
clear();
}
void clear() {
for(int i = 0; i < size; i++) {
data[i] = 0;
}
}
void deleteData() { delete data; }
char getValue(int index) { return data[index]; }
void setValue(int index, char value) { data[index] = value; }
intptr_t getPointer() { return (intptr_t)data; }
int getSize() { return size; }
};
typedef std::string IDLString;
typedef std::string_view IDLStringView;
typedef IDLArray<bool> IDLBoolArray;
typedef IDLArray<int> IDLIntArray;
typedef IDLArray<float> IDLFloatArray;
typedef IDLArray<double> IDLDoubleArray;
typedef IDLArray<char> IDLByteArray;
20 changes: 15 additions & 5 deletions jParser/base/src/main/resources/IDLHelper.idl
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,54 @@ interface IDLStringView {
interface IDLBoolArray {
void IDLBoolArray(long size);
void resize(long size);
void clear();
boolean getValue(long index);
void setValue(long index, boolean value);
long getPointer();
long getSize();
long getPointer();
void copy([Ref] IDLBoolArray src, long srcOffset, long destOffset, long length);
};

interface IDLIntArray {
void IDLIntArray(long size);
void resize(long size);
void clear();
long getValue(long index);
void setValue(long index, long value);
long getPointer();
long getSize();
long getPointer();
void copy([Ref] IDLIntArray src, long srcOffset, long destOffset, long length);
};

interface IDLFloatArray {
void IDLFloatArray(long size);
void resize(long size);
void clear();
float getValue(long index);
void setValue(long index, float value);
long getPointer();
long getSize();
long getPointer();
void copy([Ref] IDLFloatArray src, long srcOffset, long destOffset, long length);
};

interface IDLDoubleArray {
void IDLDoubleArray(long size);
void resize(long size);
void clear();
double getValue(long index);
void setValue(long index, double value);
long getPointer();
long getSize();
long getPointer();
void copy([Ref] IDLDoubleArray src, long srcOffset, long destOffset, long length);
};

interface IDLByteArray {
void IDLByteArray(long size);
void resize(long size);
void clear();
byte getValue(long index);
void setValue(long index, byte value);
long getPointer();
long getSize();
long getPointer();
void copy([Ref] IDLByteArray src, long srcOffset, long destOffset, long length);
};
Loading

0 comments on commit 0105946

Please sign in to comment.