Skip to content

Commit

Permalink
Merge pull request #3 from Nelson-numerical-software/validators
Browse files Browse the repository at this point in the history
Validators
  • Loading branch information
Nelson-numerical-software authored May 20, 2021
2 parents f2ea648 + c14270b commit a52c99d
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ builtin/CMakeCache.txt
builtin/CMakeFiles/
builtin/CMakeLists.txt
builtin/Makefile
builtin/*.manifest
builtin/cleaner.nls
builtin/cmake_install.cmake
builtin/loader.nls
builtin/unloader.nls
builtin/cpp/Gateway.cpp
help/en_US/org.nelson.modules.*.help.qch
src/CMakeCache.txt
src/*.manifest
src/CMakeFiles/
src/CMakeLists.txt
src/Makefile
Expand Down
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Next
# 2.0.0 (05/20/2021)

- remove Evaluator reference (breaking change) available in Nelson 0.4.4
- appveyor CI
- CHANGELOG.md added
- uses validators functions,
- comments moved from '//' to '%',
- remove Evaluator reference (breaking change) available in Nelson 0.4.4,
- appveyor CI,
- CHANGELOG.md added,
- module-lock.json added to .gitignore

- requires nelson 0.5.5.

# 1.0.0

Expand Down
28 changes: 14 additions & 14 deletions builder.nls
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
MODULE_NAME = 'module_skeleton';
//=============================================================================
%=============================================================================
if ismodule(MODULE_NAME)
error(_('Module already loaded.'));
end
//=============================================================================
%=============================================================================
if ~havecompiler()
error(_('Please install and configure a C/C++ compiler'));
end
//=============================================================================
%=============================================================================
fprintf(_('Building ''%s'' dependencies.\n'), MODULE_NAME);
nmm_build_dependencies(fileparts(nfilename('fullpath')));
//=============================================================================
%=============================================================================
fprintf(_('Building ''%s'' sources.\n'), MODULE_NAME);
run([fileparts(nfilename('fullpath')), '/src/builder.nls']);
//=============================================================================
%=============================================================================
fprintf(_('Building ''%s'' builtin.\n'), MODULE_NAME);
run([fileparts(nfilename('fullpath')), '/builtin/builder.nls']);
//=============================================================================
%=============================================================================
fprintf(_('Building ''%s'' loader.\n'), MODULE_NAME);
nmm_build_loader(MODULE_NAME, fileparts(nfilename('fullpath')));
//=============================================================================
%=============================================================================
nmm_build_help(MODULE_NAME, fileparts(nfilename('fullpath')));
//=============================================================================
%=============================================================================
clear('MODULE_NAME');
//=============================================================================
%=============================================================================
14 changes: 7 additions & 7 deletions builtin/builder.nls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
currentpath = fileparts(nfilename('fullpathext'));
dlgeneratecleaner(currentpath);
dlgenerategateway([currentpath, '/cpp/'], 'module_skeleton', {{'cpp_sum', 1, 2}})
Expand All @@ -21,8 +21,8 @@ dlgenerateunloader(currentpath, 'module_skeleton');
if ~status
error(message);
end
//=============================================================================
%=============================================================================
clear('status');
clear('message');
clear('currentpath');
//=============================================================================
%=============================================================================
20 changes: 9 additions & 11 deletions builtin/cpp/cpp_sumBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
#include "cpp_sumBuiltin.hpp"
#include "cpp_sum.hpp"
#include "Error.hpp"
#include "Validators.hpp"
//=============================================================================
ArrayOfVector cpp_sumBuiltin(int nLhs, const ArrayOfVector& argIn)
{
ArrayOfVector retval;
if (argIn.size() != 2)
{
Error(ERROR_WRONG_NUMBERS_INPUT_ARGS);
}
if (nLhs > 1)
{
Error(ERROR_WRONG_NUMBERS_OUTPUT_ARGS);
}
nargincheck(argIn, 2, 2);
nargoutcheck(nLhs, 0, 1);
mustBeScalarOrEmpty(argIn, 0);
mustBeFloat(argIn, 0);
mustBeScalarOrEmpty(argIn, 1);
mustBeFloat(argIn, 1);
ArrayOf param1 = argIn[0];
ArrayOf param2 = argIn[1];
retval.push_back(
ArrayOf::doubleConstructor(
cpp_sum(param1.getContentAsDoubleScalar(), param2.getContentAsDoubleScalar())));
retval << ArrayOf::doubleConstructor(
cpp_sum(param1.getContentAsDoubleScalar(), param2.getContentAsDoubleScalar()));
return retval;
}
//=============================================================================
24 changes: 12 additions & 12 deletions etc/finish.nls
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
// remove C/C++ gateway
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
% remove C/C++ gateway
MODULE_NAME = 'module_skeleton';
removegateway([fileparts(nfilename('fullpath')), '/../builtin/', [MODULE_NAME, '_builtin'], getdynlibext()]);
//=============================================================================
// remove C/C++ code associated to the previous gateway
%=============================================================================
% remove C/C++ code associated to the previous gateway
run([fileparts(nfilename('fullpath')), '/../src/unloader.nls']);
//=============================================================================
// remove macros
%=============================================================================
% remove macros
rmpath([fileparts(nfilename('fullpath')), '/../functions']);
//=============================================================================
%=============================================================================
clear('MODULE_NAME');
//=============================================================================
%=============================================================================
24 changes: 12 additions & 12 deletions etc/startup.nls
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
// load C/C++ business code used by the gateway
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
% load C/C++ business code used by the gateway
run([fileparts(nfilename('fullpath')), '/../src/loader.nls']);
//=============================================================================
// load C/C++ gateway
%=============================================================================
% load C/C++ gateway
MODULE_NAME = 'module_skeleton';
addgateway([fileparts(nfilename('fullpath')), '/../builtin/', [MODULE_NAME, '_builtin'], getdynlibext()]);
//=============================================================================
// load macros
%=============================================================================
% load macros
addpath([fileparts(nfilename('fullpath')), '/../functions']);
//=============================================================================
%=============================================================================
clear('MODULE_NAME');
//=============================================================================
%=============================================================================
25 changes: 18 additions & 7 deletions functions/nelson_sum.nlf
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
function C = nelson_sum(A, B)
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
function varargout = macro_sum(varargin)
narginchk(1, 2)
if (nargout > 1)
error(_('Wrong number of output arguments.'));
end
A = varargin{1};
B = varargin{2};
mustBeScalarOrEmpty(A, 1);
mustBeReal(A, 1);
mustBeScalarOrEmpty(B, 2);
mustBeReal(B, 2);
C = A + B;
varargout{1} = C;
endfunction
//=============================================================================
%=============================================================================
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"module": "module_skeleton",
"title": "Module skeleton",
"summary": "Skeleton of a valid nelson package",
"version": "1.0.0",
"version": "2.0.0",
"platforms": "all",
"nelson": "<2.0.0",
"builtin": true,
Expand Down
16 changes: 8 additions & 8 deletions src/builder.nls
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
currentpath = fileparts(nfilename('fullpathext'));
[status, message] = dlgeneratemake(currentpath, ...
MODULE_NAME, ...
Expand All @@ -14,13 +14,13 @@ end
dlgeneratecleaner(currentpath);
dlgenerateloader(currentpath, MODULE_NAME);
dlgenerateunloader(currentpath, MODULE_NAME);
//=============================================================================
%=============================================================================
[status, message] = dlmake(currentpath);
if ~status
error(message);
end
//=============================================================================
%=============================================================================
clear('status');
clear('message');
clear('currentpath');
//=============================================================================
%=============================================================================
21 changes: 11 additions & 10 deletions tests/test_cpp_sum.nls
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//=============================================================================
// Copyright (c) 2018-present Allan CORNET (Nelson)
//
// This file is released under the 3-clause BSD license. See COPYING-BSD.
//=============================================================================
%=============================================================================
% Copyright (c) 2018-present Allan CORNET (Nelson)
%
% This file is released under the 3-clause BSD license. See COPYING-BSD.
%=============================================================================
if ~ismodule('module_skeleton')
run([fileparts(nfilename('fullpathext')), '/../loader.nls']);
end
//=============================================================================
%=============================================================================
assert_isequal(nargin('cpp_sum'), 2);
assert_isequal(nargout('cpp_sum'), 1);
//=============================================================================
%=============================================================================
assert_isequal(cpp_sum(3, 2), 5);
//=============================================================================
%=============================================================================
assert_checkerror('cpp_sum(3, 2, 4)', _('Wrong number of input arguments.'));
assert_checkerror('cpp_sum([3, 4], 2)', _('Expected a real value scalar.'));
//=============================================================================
msg = [sprintf(_('Invalid input argument at position %d.'), 1), char(10), _('Value must be scalar or empty.')];
assert_checkerror('cpp_sum([3, 4], 2)', msg);
%=============================================================================

0 comments on commit a52c99d

Please sign in to comment.