Skip to content

Commit

Permalink
fix(Args): better handle const& to STL types
Browse files Browse the repository at this point in the history
  • Loading branch information
BotellaA committed Feb 12, 2021
1 parent 387bf92 commit f685df0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
"string_view": "cpp",
"system_error": "cpp",
"typeinfo": "cpp",
"algorithm": "cpp"
"algorithm": "cpp",
"cstddef": "cpp",
"atomic": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string": "cpp",
"cinttypes": "cpp",
"bit": "cpp"
},
}
30 changes: 25 additions & 5 deletions include/genepi/binding_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,27 @@ namespace genepi
}
};

template < typename ArgType, size_t size >
struct BindingType< const std::array< ArgType, size > & >
{
using Type = std::array< ArgType, size >;

static bool checkType( Napi::Value arg )
{
return arg.IsArray();
}

static Type fromNapiValue( Napi::Value arg )
{
return BindingType< Type >::fromNapiValue( arg );
}

static Napi::Value toNapiValue( Napi::Env env, Type &&arg )
{
return BindingType< Type >::toNapiValue( env, arg );
}
};

// Vector.
template < typename ArgType >
struct BindingType< std::vector< ArgType > >
Expand Down Expand Up @@ -131,22 +152,21 @@ namespace genepi
template < typename ArgType >
struct BindingType< const std::vector< ArgType > & >
{
using Type = const std::vector< ArgType > &;
using BaseType = std::vector< ArgType >;
using Type = std::vector< ArgType >;

static bool checkType( Napi::Value arg )
{
return arg.IsArray();
}

static BaseType fromNapiValue( Napi::Value arg )
static Type fromNapiValue( Napi::Value arg )
{
return BindingType< BaseType >::fromNapiValue( arg );
return BindingType< Type >::fromNapiValue( arg );
}

static Napi::Value toNapiValue( Napi::Env env, Type &&arg )
{
return BindingType< BaseType >::toNapiValue( env, arg );
return BindingType< Type >::toNapiValue( env, arg );
}
};

Expand Down
2 changes: 2 additions & 0 deletions include/genepi/class_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#pragma once

#include <napi.h>

#include <genepi/method_definition.h>
#include <genepi/signature/signature_param.h>
#include <genepi/singleton.h>
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"cmake-js": "^6.1.0",
"node-addon-api": "^3.1.0"
"node-addon-api": "^1.7.2"
},
"devDependencies": {
"bindings": "^1.5.0"
Expand Down

0 comments on commit f685df0

Please sign in to comment.