Skip to content

Commit

Permalink
Use pointers (#1)
Browse files Browse the repository at this point in the history
* Use pointers whenever possible

* [skip ci] bump version
  • Loading branch information
skiptirengu authored Jun 21, 2018
1 parent 73c86cc commit ba9876b
Show file tree
Hide file tree
Showing 8 changed files with 1,266 additions and 1,262 deletions.
Empty file removed build/.gitkeep
Empty file.
152 changes: 76 additions & 76 deletions build/anitomy-build.js

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/bundle.min.js

Large diffs are not rendered by default.

2,152 changes: 1,076 additions & 1,076 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "anitomyscript",
"version": "1.0.0",
"version": "1.0.1",
"description": "Pure JavaScript bindings for Anitomy, ported with emscripten",
"main": "index.js",
"scripts": {
"test": "mocha test/*.spec.js",
"build": "gulp",
"build": "gulp build",
"rebuild": "gulp rebuild"
},
"repository": {
Expand Down
65 changes: 35 additions & 30 deletions src/anitomy_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ using namespace std;
class AnitomyCompat : public Anitomy
{
public:
void setOptions(Options newOptions)
void setOptions(Options *newOptions)
{
Options &opts = options();
opts.allowed_delimiters = newOptions.allowed_delimiters;
opts.ignored_strings = newOptions.ignored_strings;
opts.parse_episode_number = newOptions.parse_episode_number;
opts.parse_episode_title = newOptions.parse_episode_title;
opts.parse_file_extension = newOptions.parse_file_extension;
opts.parse_release_group = newOptions.parse_release_group;
opts.allowed_delimiters = newOptions->allowed_delimiters;
opts.ignored_strings = newOptions->ignored_strings;
opts.parse_episode_number = newOptions->parse_episode_number;
opts.parse_episode_title = newOptions->parse_episode_title;
opts.parse_file_extension = newOptions->parse_file_extension;
opts.parse_release_group = newOptions->parse_release_group;
}
};

Expand All @@ -31,37 +31,42 @@ vector<Elements> *elementVectorFromIntPointer(uintptr_t vec)
return reinterpret_cast<vector<Elements> *>(vec);
}

Options createOptions()
Options *createOptions()
{
return Options();
return new Options();
}

vector<Elements> parseArray(vector<string_t> vec, Options options)
vector<Elements> parseArray(vector<string_t> vec, Options *options)
{
vector<Elements> ret;
AnitomyCompat an;
an.setOptions(options);
AnitomyCompat *an = new AnitomyCompat();
an->setOptions(options);
for (string_t filename : vec)
{
an.Parse(filename);
ret.emplace_back(an.elements());
an->Parse(filename);
ret.push_back(an->elements());
}
free(options);
delete an;
return ret;
}

Elements parseFile(string_t filename, Options options)
Elements parseFile(string_t filename, Options *options)
{
AnitomyCompat an;
an.setOptions(options);
an.Parse(filename);
return an.elements();
AnitomyCompat *an = new AnitomyCompat();
an->setOptions(options);
an->Parse(filename);
free(options);
Elements el = an->elements();
delete an;
return el;
}

EMSCRIPTEN_BINDINGS(Anitomy)
{
emscripten::function("_parseArray", &parseArray);
emscripten::function("_parseFile", &parseFile);
emscripten::function("_createOptions", &createOptions);
emscripten::function("_parseArray", &parseArray, allow_raw_pointers());
emscripten::function("_parseFile", &parseFile, allow_raw_pointers());
emscripten::function("_createOptions", &createOptions, allow_raw_pointers());

register_vector<string_t>("VectorString_t")
.constructor(&string_tVectorFromIntPointer, allow_raw_pointers());
Expand All @@ -78,7 +83,7 @@ EMSCRIPTEN_BINDINGS(Anitomy)

class_<AnitomyCompat, base<Anitomy>>("Anitomy")
.constructor<>()
.function("setOptions", &AnitomyCompat::setOptions);
.function("setOptions", &AnitomyCompat::setOptions, allow_raw_pointers());

class_<Elements>("Elements")
.constructor<>()
Expand All @@ -89,13 +94,13 @@ EMSCRIPTEN_BINDINGS(Anitomy)
.function("count", &Elements::count)
.function("get_all", &Elements::get_all);

value_object<Options>("Options")
.field("allowed_delimiters", &Options::allowed_delimiters)
.field("ignored_strings", &Options::ignored_strings)
.field("parse_episode_number", &Options::parse_episode_number)
.field("parse_episode_title", &Options::parse_episode_title)
.field("parse_file_extension", &Options::parse_file_extension)
.field("parse_release_group", &Options::parse_release_group);
class_<Options>("Options")
.property("allowed_delimiters", &Options::allowed_delimiters)
.property("ignored_strings", &Options::ignored_strings)
.property("parse_episode_number", &Options::parse_episode_number)
.property("parse_episode_title", &Options::parse_episode_title)
.property("parse_file_extension", &Options::parse_file_extension)
.property("parse_release_group", &Options::parse_release_group);

enum_<ElementCategory>("ElementCategory")
.value("kElementIterateFirst", ElementCategory::kElementIterateFirst)
Expand Down
1 change: 0 additions & 1 deletion test/anitomyscript.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ describe('anitomyscript', function () {
describe('AnitomyNative', function () {
it('Anitomy.setOptions', function () {
const anitomy_native = new anitomyscript.AnitomyNative();
const defaultOptions = anitomy_native._createOptions();
const anitomy = new anitomy_native.Anitomy();
const newOpts = anitomy_native._createOptions();
const ignored = new anitomy_native.VectorString_t();
Expand Down

0 comments on commit ba9876b

Please sign in to comment.