Mercurial > forge
changeset 10244:cd808d3516dd octave-forge
inputParser: proper and pretty display method for class
author | carandraug |
---|---|
date | Mon, 14 May 2012 07:10:59 +0000 |
parents | 249938380b7a |
children | 65496daaf367 |
files | main/general/inst/@inputParser/display.m |
diffstat | 1 files changed, 40 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/main/general/inst/@inputParser/display.m Sat May 12 19:04:36 2012 +0000 +++ b/main/general/inst/@inputParser/display.m Mon May 14 07:10:59 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2011 Carnë Draug <carandraug+dev@gmail.com> +## Copyright (C) 2011-2012 Carnë Draug <carandraug+dev@gmail.com> ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software @@ -15,10 +15,44 @@ function display (inPar) - fields = fieldnames (inPar); - for i = 1 : numel(fields) - printf ("%s\n", fields{i}); - inPar.(fields{i}) - end + if (inPar.FunctionName) + name = inPar.FunctionName(1:end-3); + else + name = ""; + endif + + required = arg_list (inPar.Required); + optional = arg_list (inPar.Optional); + paramvalue = arg_list (inPar.ParamValue); + switches = arg_list (inPar.Switch); + + printf ("Input Parser object with:\n"); + printf ("CaseSensitive: %s\n", binstr (inPar.CaseSensitive)); + printf ("StructExpand : %s\n", binstr (inPar.StructExpand)); + printf ("KeepUnmatched: %s\n", binstr (inPar.KeepUnmatched)); + printf ("FunctionName : '%s'\n", name); + printf ("\n"); + printf ("Required arguments : %s\n", required); + printf ("Optional arguments : %s\n", optional); + printf ("ParamValue arguments: %s\n", paramvalue); + printf ("Switch arguments : %s\n", switches); endfunction + +function [str] = binstr (bin) + if (bin) + str = "true"; + else + str = "false"; + endif +endfunction + +function [str] = arg_list (args) + str = strcat ("'", fieldnames (args), {"', "}); + if (!isempty (str)) + str = cstrcat (str{:}); + str = str(1:end-2); # remove the last comma and space + else + str = ""; + endif +endfunction