comparison Core/DicomFormat/DicomValue.h @ 1737:ec66a16aa398

removal of DicomStringValue and DicomNullValue
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 22 Oct 2015 07:52:24 +0200
parents 6e7e5ed91c2d
children 15a788a63846
comparison
equal deleted inserted replaced
1736:b953c6eef28d 1737:ec66a16aa398
30 **/ 30 **/
31 31
32 32
33 #pragma once 33 #pragma once
34 34
35 #include "../IDynamicObject.h" 35 #include "../OrthancException.h"
36 36
37 #include <string> 37 #include <string>
38 #include <boost/noncopyable.hpp>
38 39
39 namespace Orthanc 40 namespace Orthanc
40 { 41 {
41 class DicomValue : public IDynamicObject 42 class DicomValue : public boost::noncopyable
42 { 43 {
44 private:
45 enum Type
46 {
47 Type_Null,
48 Type_String,
49 Type_Binary
50 };
51
52 Type type_;
53 std::string content_;
54
55 DicomValue(const DicomValue& other) :
56 type_(other.type_),
57 content_(other.content_)
58 {
59 }
60
43 public: 61 public:
44 virtual DicomValue* Clone() const = 0; 62 DicomValue() : type_(Type_Null)
63 {
64 }
65
66 DicomValue(const std::string& content,
67 bool isBinary) :
68 type_(isBinary ? Type_Binary : Type_String),
69 content_(content)
70 {
71 }
72
73 DicomValue(const char* data,
74 size_t size,
75 bool isBinary) :
76 type_(isBinary ? Type_Binary : Type_String)
77 {
78 content_.assign(data, size);
79 }
80
81 const std::string& GetContent() const
82 {
83 if (type_ == Type_Null)
84 {
85 throw OrthancException(ErrorCode_BadParameterType);
86 }
87 else
88 {
89 return content_;
90 }
91 }
45 92
46 virtual std::string AsString() const = 0; 93 bool IsNull() const
94 {
95 return type_ == Type_Null;
96 }
47 97
48 virtual bool IsNull() const 98 bool IsBinary() const
49 { 99 {
50 return false; 100 return type_ == Type_Binary;
101 }
102
103 DicomValue* Clone() const
104 {
105 return new DicomValue(*this);
51 } 106 }
52 }; 107 };
53 } 108 }