Mercurial > hg > orthanc
changeset 1646:da799f767e5d
simplification in error casting with plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 24 Sep 2015 16:01:09 +0200 |
parents | 1558b3226b18 |
children | fe458dde986e 69f7822ee254 |
files | Plugins/Engine/OrthancPluginDatabase.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/PluginsEnumerations.cpp Plugins/Engine/PluginsEnumerations.h Resources/GenerateErrorCodes.py |
diffstat | 5 files changed, 52 insertions(+), 349 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPluginDatabase.cpp Thu Sep 24 15:55:17 2015 +0200 +++ b/Plugins/Engine/OrthancPluginDatabase.cpp Thu Sep 24 16:01:09 2015 +0200 @@ -236,7 +236,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -248,7 +248,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -259,7 +259,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -270,7 +270,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -284,7 +284,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return id; @@ -298,7 +298,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -310,7 +310,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -321,7 +321,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -357,7 +357,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -379,7 +379,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -432,7 +432,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -446,7 +446,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -462,7 +462,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -483,7 +483,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -500,7 +500,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -517,7 +517,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -532,7 +532,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -546,7 +546,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } if (!ForwardSingleAnswer(s)) @@ -566,7 +566,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return count; @@ -581,7 +581,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return Convert(type); @@ -596,7 +596,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return size; @@ -611,7 +611,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return size; @@ -626,7 +626,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return (existing != 0); @@ -641,7 +641,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return (isProtected != 0); @@ -657,7 +657,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } if (type_ != _OrthancPluginDatabaseAnswerType_None && @@ -688,7 +688,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } if (type_ != _OrthancPluginDatabaseAnswerType_None && @@ -724,7 +724,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -746,7 +746,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -762,7 +762,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } if (type_ == _OrthancPluginDatabaseAnswerType_None) @@ -792,7 +792,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return ForwardSingleAnswer(target); @@ -814,7 +814,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -830,7 +830,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } ForwardAnswers(target); @@ -847,7 +847,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return ForwardSingleAnswer(target); @@ -863,7 +863,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return ForwardSingleAnswer(parentId); @@ -880,7 +880,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } if (type_ == _OrthancPluginDatabaseAnswerType_None) @@ -909,7 +909,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return ForwardSingleAnswer(internalId); @@ -925,7 +925,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return ForwardSingleAnswer(internalId); @@ -940,7 +940,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -967,7 +967,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -981,7 +981,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -993,7 +993,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -1018,7 +1018,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -1028,7 +1028,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -1038,7 +1038,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } }; @@ -1093,7 +1093,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } return version; @@ -1119,7 +1119,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } }
--- a/Plugins/Engine/OrthancPlugins.cpp Thu Sep 24 15:55:17 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Sep 24 16:01:09 2015 +0200 @@ -91,7 +91,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -108,7 +108,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } try @@ -138,7 +138,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } }; @@ -464,7 +464,7 @@ } else { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } @@ -485,7 +485,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } } @@ -507,7 +507,7 @@ if (error != OrthancPluginErrorCode_Success) { - throw OrthancException(Plugins::Convert(error)); + throw OrthancException(static_cast<ErrorCode>(error)); } } }
--- a/Plugins/Engine/PluginsEnumerations.cpp Thu Sep 24 15:55:17 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.cpp Thu Sep 24 16:01:09 2015 +0200 @@ -44,283 +44,6 @@ { namespace Plugins { - ErrorCode Convert(OrthancPluginErrorCode error) - { - switch (error) - { - case OrthancPluginErrorCode_InternalError: - return ErrorCode_InternalError; - - case OrthancPluginErrorCode_Success: - return ErrorCode_Success; - - case OrthancPluginErrorCode_Plugin: - return ErrorCode_Plugin; - - case OrthancPluginErrorCode_NotImplemented: - return ErrorCode_NotImplemented; - - case OrthancPluginErrorCode_ParameterOutOfRange: - return ErrorCode_ParameterOutOfRange; - - case OrthancPluginErrorCode_NotEnoughMemory: - return ErrorCode_NotEnoughMemory; - - case OrthancPluginErrorCode_BadParameterType: - return ErrorCode_BadParameterType; - - case OrthancPluginErrorCode_BadSequenceOfCalls: - return ErrorCode_BadSequenceOfCalls; - - case OrthancPluginErrorCode_InexistentItem: - return ErrorCode_InexistentItem; - - case OrthancPluginErrorCode_BadRequest: - return ErrorCode_BadRequest; - - case OrthancPluginErrorCode_NetworkProtocol: - return ErrorCode_NetworkProtocol; - - case OrthancPluginErrorCode_SystemCommand: - return ErrorCode_SystemCommand; - - case OrthancPluginErrorCode_Database: - return ErrorCode_Database; - - case OrthancPluginErrorCode_UriSyntax: - return ErrorCode_UriSyntax; - - case OrthancPluginErrorCode_InexistentFile: - return ErrorCode_InexistentFile; - - case OrthancPluginErrorCode_CannotWriteFile: - return ErrorCode_CannotWriteFile; - - case OrthancPluginErrorCode_BadFileFormat: - return ErrorCode_BadFileFormat; - - case OrthancPluginErrorCode_Timeout: - return ErrorCode_Timeout; - - case OrthancPluginErrorCode_UnknownResource: - return ErrorCode_UnknownResource; - - case OrthancPluginErrorCode_IncompatibleDatabaseVersion: - return ErrorCode_IncompatibleDatabaseVersion; - - case OrthancPluginErrorCode_FullStorage: - return ErrorCode_FullStorage; - - case OrthancPluginErrorCode_CorruptedFile: - return ErrorCode_CorruptedFile; - - case OrthancPluginErrorCode_InexistentTag: - return ErrorCode_InexistentTag; - - case OrthancPluginErrorCode_ReadOnly: - return ErrorCode_ReadOnly; - - case OrthancPluginErrorCode_IncompatibleImageFormat: - return ErrorCode_IncompatibleImageFormat; - - case OrthancPluginErrorCode_IncompatibleImageSize: - return ErrorCode_IncompatibleImageSize; - - case OrthancPluginErrorCode_SharedLibrary: - return ErrorCode_SharedLibrary; - - case OrthancPluginErrorCode_UnknownPluginService: - return ErrorCode_UnknownPluginService; - - case OrthancPluginErrorCode_UnknownDicomTag: - return ErrorCode_UnknownDicomTag; - - case OrthancPluginErrorCode_BadJson: - return ErrorCode_BadJson; - - case OrthancPluginErrorCode_Unauthorized: - return ErrorCode_Unauthorized; - - case OrthancPluginErrorCode_BadFont: - return ErrorCode_BadFont; - - case OrthancPluginErrorCode_DatabasePlugin: - return ErrorCode_DatabasePlugin; - - case OrthancPluginErrorCode_StorageAreaPlugin: - return ErrorCode_StorageAreaPlugin; - - case OrthancPluginErrorCode_SQLiteNotOpened: - return ErrorCode_SQLiteNotOpened; - - case OrthancPluginErrorCode_SQLiteAlreadyOpened: - return ErrorCode_SQLiteAlreadyOpened; - - case OrthancPluginErrorCode_SQLiteCannotOpen: - return ErrorCode_SQLiteCannotOpen; - - case OrthancPluginErrorCode_SQLiteStatementAlreadyUsed: - return ErrorCode_SQLiteStatementAlreadyUsed; - - case OrthancPluginErrorCode_SQLiteExecute: - return ErrorCode_SQLiteExecute; - - case OrthancPluginErrorCode_SQLiteRollbackWithoutTransaction: - return ErrorCode_SQLiteRollbackWithoutTransaction; - - case OrthancPluginErrorCode_SQLiteCommitWithoutTransaction: - return ErrorCode_SQLiteCommitWithoutTransaction; - - case OrthancPluginErrorCode_SQLiteRegisterFunction: - return ErrorCode_SQLiteRegisterFunction; - - case OrthancPluginErrorCode_SQLiteFlush: - return ErrorCode_SQLiteFlush; - - case OrthancPluginErrorCode_SQLiteCannotRun: - return ErrorCode_SQLiteCannotRun; - - case OrthancPluginErrorCode_SQLiteCannotStep: - return ErrorCode_SQLiteCannotStep; - - case OrthancPluginErrorCode_SQLiteBindOutOfRange: - return ErrorCode_SQLiteBindOutOfRange; - - case OrthancPluginErrorCode_SQLitePrepareStatement: - return ErrorCode_SQLitePrepareStatement; - - case OrthancPluginErrorCode_SQLiteTransactionAlreadyStarted: - return ErrorCode_SQLiteTransactionAlreadyStarted; - - case OrthancPluginErrorCode_SQLiteTransactionCommit: - return ErrorCode_SQLiteTransactionCommit; - - case OrthancPluginErrorCode_SQLiteTransactionBegin: - return ErrorCode_SQLiteTransactionBegin; - - case OrthancPluginErrorCode_DirectoryOverFile: - return ErrorCode_DirectoryOverFile; - - case OrthancPluginErrorCode_FileStorageCannotWrite: - return ErrorCode_FileStorageCannotWrite; - - case OrthancPluginErrorCode_DirectoryExpected: - return ErrorCode_DirectoryExpected; - - case OrthancPluginErrorCode_HttpPortInUse: - return ErrorCode_HttpPortInUse; - - case OrthancPluginErrorCode_DicomPortInUse: - return ErrorCode_DicomPortInUse; - - case OrthancPluginErrorCode_BadHttpStatusInRest: - return ErrorCode_BadHttpStatusInRest; - - case OrthancPluginErrorCode_RegularFileExpected: - return ErrorCode_RegularFileExpected; - - case OrthancPluginErrorCode_PathToExecutable: - return ErrorCode_PathToExecutable; - - case OrthancPluginErrorCode_MakeDirectory: - return ErrorCode_MakeDirectory; - - case OrthancPluginErrorCode_BadApplicationEntityTitle: - return ErrorCode_BadApplicationEntityTitle; - - case OrthancPluginErrorCode_NoCFindHandler: - return ErrorCode_NoCFindHandler; - - case OrthancPluginErrorCode_NoCMoveHandler: - return ErrorCode_NoCMoveHandler; - - case OrthancPluginErrorCode_NoCStoreHandler: - return ErrorCode_NoCStoreHandler; - - case OrthancPluginErrorCode_NoApplicationEntityFilter: - return ErrorCode_NoApplicationEntityFilter; - - case OrthancPluginErrorCode_NoSopClassOrInstance: - return ErrorCode_NoSopClassOrInstance; - - case OrthancPluginErrorCode_NoPresentationContext: - return ErrorCode_NoPresentationContext; - - case OrthancPluginErrorCode_DicomFindUnavailable: - return ErrorCode_DicomFindUnavailable; - - case OrthancPluginErrorCode_DicomMoveUnavailable: - return ErrorCode_DicomMoveUnavailable; - - case OrthancPluginErrorCode_CannotStoreInstance: - return ErrorCode_CannotStoreInstance; - - case OrthancPluginErrorCode_CreateDicomNotString: - return ErrorCode_CreateDicomNotString; - - case OrthancPluginErrorCode_CreateDicomOverrideTag: - return ErrorCode_CreateDicomOverrideTag; - - case OrthancPluginErrorCode_CreateDicomUseContent: - return ErrorCode_CreateDicomUseContent; - - case OrthancPluginErrorCode_CreateDicomNoPayload: - return ErrorCode_CreateDicomNoPayload; - - case OrthancPluginErrorCode_CreateDicomUseDataUriScheme: - return ErrorCode_CreateDicomUseDataUriScheme; - - case OrthancPluginErrorCode_CreateDicomBadParent: - return ErrorCode_CreateDicomBadParent; - - case OrthancPluginErrorCode_CreateDicomParentIsInstance: - return ErrorCode_CreateDicomParentIsInstance; - - case OrthancPluginErrorCode_CreateDicomParentEncoding: - return ErrorCode_CreateDicomParentEncoding; - - case OrthancPluginErrorCode_UnknownModality: - return ErrorCode_UnknownModality; - - case OrthancPluginErrorCode_BadJobOrdering: - return ErrorCode_BadJobOrdering; - - case OrthancPluginErrorCode_JsonToLuaTable: - return ErrorCode_JsonToLuaTable; - - case OrthancPluginErrorCode_CannotCreateLua: - return ErrorCode_CannotCreateLua; - - case OrthancPluginErrorCode_CannotExecuteLua: - return ErrorCode_CannotExecuteLua; - - case OrthancPluginErrorCode_LuaAlreadyExecuted: - return ErrorCode_LuaAlreadyExecuted; - - case OrthancPluginErrorCode_LuaBadOutput: - return ErrorCode_LuaBadOutput; - - case OrthancPluginErrorCode_NotLuaPredicate: - return ErrorCode_NotLuaPredicate; - - case OrthancPluginErrorCode_LuaReturnsNoString: - return ErrorCode_LuaReturnsNoString; - - case OrthancPluginErrorCode_StorageAreaAlreadyRegistered: - return ErrorCode_StorageAreaAlreadyRegistered; - - case OrthancPluginErrorCode_DatabaseBackendAlreadyRegistered: - return ErrorCode_DatabaseBackendAlreadyRegistered; - - case OrthancPluginErrorCode_DatabaseNotInitialized: - return ErrorCode_DatabaseNotInitialized; - - default: - return ErrorCode_InternalError; - } - } - - OrthancPluginResourceType Convert(ResourceType type) { switch (type)
--- a/Plugins/Engine/PluginsEnumerations.h Thu Sep 24 15:55:17 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.h Thu Sep 24 16:01:09 2015 +0200 @@ -41,8 +41,6 @@ { namespace Plugins { - ErrorCode Convert(OrthancPluginErrorCode error); - OrthancPluginResourceType Convert(ResourceType type); OrthancPluginChangeType Convert(ChangeType type);
--- a/Resources/GenerateErrorCodes.py Thu Sep 24 15:55:17 2015 +0200 +++ b/Resources/GenerateErrorCodes.py Thu Sep 24 16:01:09 2015 +0200 @@ -141,21 +141,3 @@ with open(path, 'w') as f: f.write(a) - - - -## -## Generate the "Plugins::Convert(OrthancPluginErrorCode)" in -## "PluginsEnumerations.cpp" -## - -path = os.path.join(BASE, 'Plugins', 'Engine', 'PluginsEnumerations.cpp') -with open(path, 'r') as f: - a = f.read() - -s = '\n\n'.join(map(lambda x: ' case OrthancPluginErrorCode_%s:\n return ErrorCode_%s;' % (x['Name'], x['Name']), ERRORS)) -a = re.sub('(Convert\(OrthancPluginErrorCode.*?\)\s*{\s*switch \([^)]*?\)\s*{)[^}]*?(\s*default:)', - r'\1\n%s\2' % s, a, re.DOTALL) - -with open(path, 'w') as f: - f.write(a)