Mercurial > hg > orthanc-webviewer
changeset 47:616c5e13abc1
sync
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 30 Jul 2015 13:54:27 +0200 |
parents | bd68285248b7 |
children | 1c776248a8eb |
files | Orthanc/Resources/EmbedResources.py |
diffstat | 1 files changed, 35 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/Orthanc/Resources/EmbedResources.py Thu Jul 30 13:53:50 2015 +0200 +++ b/Orthanc/Resources/EmbedResources.py Thu Jul 30 13:54:27 2015 +0200 @@ -37,16 +37,27 @@ import re UPCASE_CHECK = True +USE_SYSTEM_EXCEPTION = False +EXCEPTION_CLASS = 'OrthancException' +OUT_OF_RANGE_EXCEPTION = 'OrthancException(ErrorCode_ParameterOutOfRange)' +NAMESPACE = 'Orthanc' + ARGS = [] for i in range(len(sys.argv)): if not sys.argv[i].startswith('--'): ARGS.append(sys.argv[i]) elif sys.argv[i].lower() == '--no-upcase-check': UPCASE_CHECK = False + elif sys.argv[i].lower() == '--system-exception': + USE_SYSTEM_EXCEPTION = True + EXCEPTION_CLASS = '::std::runtime_error' + OUT_OF_RANGE_EXCEPTION = '%s("Parameter out of range")' % EXCEPTION_CLASS + elif sys.argv[i].startswith('--namespace='): + NAMESPACE = sys.argv[i][sys.argv[i].find('=') + 1 : ] if len(ARGS) < 2 or len(ARGS) % 2 != 0: print ('Usage:') - print ('python %s [--no-upcase-check] <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0]) + print ('python %s [--no-upcase-check] [--system-exception] [--namespace=<Namespace>] <TargetBaseFilename> [ <Name> <Source> ]*' % sys.argv[0]) exit(-1) TARGET_BASE_FILENAME = ARGS[1] @@ -146,13 +157,13 @@ #include <string> #include <list> -namespace Orthanc +namespace %s { namespace EmbeddedResources { enum FileResourceId { -""") +""" % NAMESPACE) isFirst = True for name in resources: @@ -241,19 +252,22 @@ cpp = open(TARGET_BASE_FILENAME + '.cpp', 'w') +cpp.write('#include "%s.h"\n' % os.path.basename(TARGET_BASE_FILENAME)) + +if USE_SYSTEM_EXCEPTION: + cpp.write('#include <stdexcept>') +else: + cpp.write('#include "%s/Core/OrthancException.h"' % os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + cpp.write(""" -#include "%s.h" -#include "%s/Core/OrthancException.h" - #include <stdint.h> #include <string.h> -namespace Orthanc +namespace %s { namespace EmbeddedResources { -""" % (os.path.basename(TARGET_BASE_FILENAME), - os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))) +""" % NAMESPACE) for name in resources: @@ -282,7 +296,7 @@ cpp.write(""" default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw %s; } } @@ -290,7 +304,7 @@ { switch (id) { -""") +""" % OUT_OF_RANGE_EXCEPTION) for name in resources: if resources[name]['Type'] == 'File': @@ -299,10 +313,10 @@ cpp.write(""" default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw %s; } } -""") +""" % OUT_OF_RANGE_EXCEPTION) @@ -324,10 +338,10 @@ for path in resources[name]['Files']: cpp.write(' if (!strcmp(path, "%s"))\n' % path) cpp.write(' return resource%dBuffer;\n' % resources[name]['Files'][path]['Index']) - cpp.write(' throw OrthancException("Unknown path in a directory resource");\n\n') + cpp.write(' throw %s("Unknown path in a directory resource");\n\n' % EXCEPTION_CLASS) cpp.write(""" default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw %s; } } @@ -335,7 +349,7 @@ { switch (id) { -""") +""" % OUT_OF_RANGE_EXCEPTION) for name in resources: if resources[name]['Type'] == 'Directory': @@ -344,13 +358,13 @@ for path in resources[name]['Files']: cpp.write(' if (!strcmp(path, "%s"))\n' % path) cpp.write(' return resource%dSize;\n' % resources[name]['Files'][path]['Index']) - cpp.write(' throw OrthancException("Unknown path in a directory resource");\n\n') + cpp.write(' throw %s("Unknown path in a directory resource");\n\n' % EXCEPTION_CLASS) cpp.write(""" default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw %s; } } -""") +""" % OUT_OF_RANGE_EXCEPTION) @@ -376,10 +390,10 @@ cpp.write(' break;\n\n') cpp.write(""" default: - throw OrthancException(ErrorCode_ParameterOutOfRange); + throw %s; } } -""") +""" % OUT_OF_RANGE_EXCEPTION)