comparison Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2176:fead5549aaa7

introduction of HAS_ORTHANC_EXCEPTION to avoid PluginException if not necessary
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 25 Nov 2016 12:07:36 +0100
parents aa2915963531
children 11420238f337
comparison
equal deleted inserted replaced
2175:bed8e7ad8bab 2176:fead5549aaa7
35 #include <orthanc/OrthancCPlugin.h> 35 #include <orthanc/OrthancCPlugin.h>
36 #include <boost/noncopyable.hpp> 36 #include <boost/noncopyable.hpp>
37 #include <boost/lexical_cast.hpp> 37 #include <boost/lexical_cast.hpp>
38 #include <json/value.h> 38 #include <json/value.h>
39 39
40 #if !defined(HAS_ORTHANC_EXCEPTION)
41 # error The macro HAS_ORTHANC_EXCEPTION must be defined
42 #endif
43
44
40 #if HAS_ORTHANC_EXCEPTION == 1 45 #if HAS_ORTHANC_EXCEPTION == 1
41 # include "../../../Core/OrthancException.h" 46 # include "../../../Core/OrthancException.h"
42 #endif 47 #endif
43 48
44 49
46 { 51 {
47 typedef void (*RestCallback) (OrthancPluginRestOutput* output, 52 typedef void (*RestCallback) (OrthancPluginRestOutput* output,
48 const char* url, 53 const char* url,
49 const OrthancPluginHttpRequest* request); 54 const OrthancPluginHttpRequest* request);
50 55
51 56 const char* GetErrorDescription(OrthancPluginContext* context,
57 OrthancPluginErrorCode code);
58
59 void ThrowException(OrthancPluginErrorCode code);
60
61 #if HAS_ORTHANC_EXCEPTION == 0
52 class PluginException 62 class PluginException
53 { 63 {
54 private: 64 private:
55 OrthancPluginErrorCode code_; 65 OrthancPluginErrorCode code_;
56 66
62 OrthancPluginErrorCode GetErrorCode() const 72 OrthancPluginErrorCode GetErrorCode() const
63 { 73 {
64 return code_; 74 return code_;
65 } 75 }
66 76
67 const char* GetErrorDescription(OrthancPluginContext* context) const; 77 const char* What(OrthancPluginContext* context) const
78 {
79 return ::OrthancPlugins::GetErrorDescription(context, code_);
80 }
68 81
69 static void Check(OrthancPluginErrorCode code); 82 static void Check(OrthancPluginErrorCode code);
70 }; 83 };
84 #endif
71 85
72 86
73 class MemoryBuffer : public boost::noncopyable 87 class MemoryBuffer : public boost::noncopyable
74 { 88 {
75 private: 89 private:
406 try 420 try
407 { 421 {
408 Callback(output, url, request); 422 Callback(output, url, request);
409 return OrthancPluginErrorCode_Success; 423 return OrthancPluginErrorCode_Success;
410 } 424 }
411 catch (OrthancPlugins::PluginException& e)
412 {
413 return e.GetErrorCode();
414 }
415 #if HAS_ORTHANC_EXCEPTION == 1 425 #if HAS_ORTHANC_EXCEPTION == 1
416 catch (Orthanc::OrthancException& e) 426 catch (Orthanc::OrthancException& e)
417 { 427 {
418 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); 428 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
429 }
430 #else
431 catch (OrthancPlugins::PluginException& e)
432 {
433 return e.GetErrorCode();
419 } 434 }
420 #endif 435 #endif
421 catch (boost::bad_lexical_cast&) 436 catch (boost::bad_lexical_cast&)
422 { 437 {
423 return OrthancPluginErrorCode_BadFileFormat; 438 return OrthancPluginErrorCode_BadFileFormat;