comparison OrthancCppClient/Instance.cpp @ 504:50d9660f960c laaw

laaw exception
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 18 Jul 2013 10:12:20 +0200
parents ec19da4a1fe7
children eaca3d38b2aa
comparison
equal deleted inserted replaced
502:ee33c7d0cda0 504:50d9660f960c
31 31
32 32
33 #include "Instance.h" 33 #include "Instance.h"
34 34
35 #include "OrthancConnection.h" 35 #include "OrthancConnection.h"
36 #include "../Core/OrthancException.h"
37 36
38 #include <boost/lexical_cast.hpp> 37 #include <boost/lexical_cast.hpp>
39 38
40 namespace OrthancClient 39 namespace OrthancClient
41 { 40 {
61 case Orthanc::ImageExtractionMode_Int16: 60 case Orthanc::ImageExtractionMode_Int16:
62 suffix = "image-int16"; 61 suffix = "image-int16";
63 break; 62 break;
64 63
65 default: 64 default:
66 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 65 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
67 } 66 }
68 67
69 Orthanc::HttpClient client(connection_.GetHttpClient()); 68 Orthanc::HttpClient client(connection_.GetHttpClient());
70 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/" + suffix); 69 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/" + suffix);
71 std::string png; 70 std::string png;
72 71
73 if (!client.Apply(png)) 72 if (!client.Apply(png))
74 { 73 {
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); 74 throw OrthancClientException(Orthanc::ErrorCode_NotImplemented);
76 } 75 }
77 76
78 reader_.reset(new Orthanc::PngReader); 77 reader_.reset(new Orthanc::PngReader);
79 reader_->ReadFromMemory(png); 78 reader_->ReadFromMemory(png);
80 } 79 }
90 89
91 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/simplified-tags"); 90 client.SetUrl(std::string(connection_.GetOrthancUrl()) + "/instances/" + id_ + "/simplified-tags");
92 Json::Value v; 91 Json::Value v;
93 if (!client.Apply(tags_)) 92 if (!client.Apply(tags_))
94 { 93 {
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); 94 throw OrthancClientException(Orthanc::ErrorCode_NetworkProtocol);
96 } 95 }
97 } 96 }
98 97
99 const char* Instance::GetTagAsString(const char* tag) const 98 const char* Instance::GetTagAsString(const char* tag) const
100 { 99 {
102 { 101 {
103 return tags_[tag].asCString(); 102 return tags_[tag].asCString();
104 } 103 }
105 else 104 else
106 { 105 {
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); 106 throw OrthancClientException(Orthanc::ErrorCode_InexistentItem);
108 } 107 }
109 } 108 }
110 109
111 float Instance::GetTagAsFloat(const char* tag) const 110 float Instance::GetTagAsFloat(const char* tag) const
112 { 111 {
116 { 115 {
117 return boost::lexical_cast<float>(value); 116 return boost::lexical_cast<float>(value);
118 } 117 }
119 catch (boost::bad_lexical_cast) 118 catch (boost::bad_lexical_cast)
120 { 119 {
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 120 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
122 } 121 }
123 } 122 }
124 123
125 int Instance::GetTagAsInt(const char* tag) const 124 int Instance::GetTagAsInt(const char* tag) const
126 { 125 {
130 { 129 {
131 return boost::lexical_cast<int>(value); 130 return boost::lexical_cast<int>(value);
132 } 131 }
133 catch (boost::bad_lexical_cast) 132 catch (boost::bad_lexical_cast)
134 { 133 {
135 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 134 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
136 } 135 }
137 } 136 }
138 137
139 unsigned int Instance::GetWidth() 138 unsigned int Instance::GetWidth()
140 { 139 {
216 target.push_back(boost::lexical_cast<float>(tmp)); 215 target.push_back(boost::lexical_cast<float>(tmp));
217 } 216 }
218 catch (boost::bad_lexical_cast) 217 catch (boost::bad_lexical_cast)
219 { 218 {
220 // Unable to parse the Image Orientation Patient. 219 // Unable to parse the Image Orientation Patient.
221 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); 220 throw OrthancClientException(Orthanc::ErrorCode_BadFileFormat);
222 } 221 }
223 } 222 }
224 } 223 }