# HG changeset patch # User Sebastien Jodogne # Date 1438257267 -7200 # Node ID 616c5e13abc1d52b4e7a12371bcccb7556620c7c # Parent bd68285248b77d929568da396475c745bbbb2ae2 sync diff -r bd68285248b7 -r 616c5e13abc1 Orthanc/Resources/EmbedResources.py --- 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] [ ]*' % sys.argv[0]) + print ('python %s [--no-upcase-check] [--system-exception] [--namespace=] [ ]*' % sys.argv[0]) exit(-1) TARGET_BASE_FILENAME = ARGS[1] @@ -146,13 +157,13 @@ #include #include -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 ') +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 #include -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)