/src/dcmtk/dcmdata/libsrc/dcvrlt.cc
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (C) 1994-2024, OFFIS e.V. |
4 | | * All rights reserved. See COPYRIGHT file for details. |
5 | | * |
6 | | * This software and supporting documentation were developed by |
7 | | * |
8 | | * OFFIS e.V. |
9 | | * R&D Division Health |
10 | | * Escherweg 2 |
11 | | * D-26121 Oldenburg, Germany |
12 | | * |
13 | | * |
14 | | * Module: dcmdata |
15 | | * |
16 | | * Author: Gerd Ehlers, Andreas Barth |
17 | | * |
18 | | * Purpose: Implementation of class DcmLongText |
19 | | * |
20 | | */ |
21 | | |
22 | | |
23 | | #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ |
24 | | |
25 | | #include "dcmtk/dcmdata/dcvrlt.h" |
26 | | |
27 | | |
28 | | // ******************************** |
29 | | |
30 | | |
31 | | DcmLongText::DcmLongText(const DcmTag &tag, |
32 | | const Uint32 len) |
33 | 0 | : DcmCharString(tag, len) |
34 | 0 | { |
35 | 0 | setMaxLength(10240); |
36 | 0 | } |
37 | | |
38 | | |
39 | | DcmLongText::DcmLongText(const DcmLongText& old) |
40 | 0 | : DcmCharString(old) |
41 | 0 | { |
42 | 0 | } |
43 | | |
44 | | |
45 | | DcmLongText::~DcmLongText() |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | |
50 | | DcmLongText &DcmLongText::operator=(const DcmLongText &obj) |
51 | 0 | { |
52 | 0 | DcmCharString::operator=(obj); |
53 | 0 | return *this; |
54 | 0 | } |
55 | | |
56 | | |
57 | | OFCondition DcmLongText::copyFrom(const DcmObject& rhs) |
58 | 0 | { |
59 | 0 | if (this != &rhs) |
60 | 0 | { |
61 | 0 | if (rhs.ident() != ident()) return EC_IllegalCall; |
62 | 0 | *this = OFstatic_cast(const DcmLongText &, rhs); |
63 | 0 | } |
64 | 0 | return EC_Normal; |
65 | 0 | } |
66 | | |
67 | | |
68 | | int DcmLongText::compare(const DcmElement& rhs) const |
69 | 0 | { |
70 | 0 | int result = DcmElement::compare(rhs); |
71 | 0 | if (result != 0) |
72 | 0 | { |
73 | 0 | return result; |
74 | 0 | } |
75 | | |
76 | | /* cast away constness (dcmdata is not const correct...) */ |
77 | 0 | DcmLongText* myThis = NULL; |
78 | 0 | DcmLongText* myRhs = NULL; |
79 | 0 | myThis = OFconst_cast(DcmLongText*, this); |
80 | 0 | myRhs = OFstatic_cast(DcmLongText*, OFconst_cast(DcmElement*, &rhs)); |
81 | | |
82 | | /* compare length */ |
83 | 0 | unsigned long thisLength = myThis->getLength(); |
84 | 0 | unsigned long rhsLength = myRhs->getLength(); |
85 | 0 | if (thisLength < rhsLength) |
86 | 0 | { |
87 | 0 | return -1; |
88 | 0 | } |
89 | 0 | else if (thisLength > rhsLength) |
90 | 0 | { |
91 | 0 | return 1; |
92 | 0 | } |
93 | | |
94 | | /* check whether values are equal */ |
95 | 0 | OFString thisValue, rhsValue; |
96 | 0 | myThis->getOFStringArray(thisValue); |
97 | 0 | myRhs->getOFStringArray(rhsValue); |
98 | 0 | return thisValue.compare(rhsValue); |
99 | 0 | } |
100 | | |
101 | | |
102 | | // ******************************** |
103 | | |
104 | | |
105 | | DcmEVR DcmLongText::ident() const |
106 | 0 | { |
107 | 0 | return EVR_LT; |
108 | 0 | } |
109 | | |
110 | | |
111 | | OFCondition DcmLongText::checkValue(const OFString & /*vm*/, |
112 | | const OFBool /*oldFormat*/) |
113 | 0 | { |
114 | 0 | OFString strVal; |
115 | | /* get "raw value" without any modifications (if possible) */ |
116 | 0 | OFCondition l_error = getStringValue(strVal); |
117 | 0 | if (l_error.good()) |
118 | 0 | { |
119 | 0 | OFString charset; |
120 | | /* try to determine the value of the SpecificCharacterSet element */ |
121 | 0 | if (getSpecificCharacterSet(charset) == EC_CorruptedData) |
122 | 0 | charset = "UNKNOWN"; |
123 | 0 | l_error = DcmLongText::checkStringValue(strVal, charset); |
124 | 0 | } |
125 | 0 | return l_error; |
126 | 0 | } |
127 | | |
128 | | |
129 | | unsigned long DcmLongText::getVM() |
130 | 0 | { |
131 | | /* value multiplicity is 1 for non-empty string, 0 otherwise */ |
132 | 0 | return (getRealLength() > 0) ? 1 : 0; |
133 | 0 | } |
134 | | |
135 | | |
136 | | // ******************************** |
137 | | |
138 | | |
139 | | OFCondition DcmLongText::getOFString(OFString &stringVal, |
140 | | const unsigned long /*pos*/, |
141 | | OFBool normalize) |
142 | 0 | { |
143 | | /* treat backslash as a normal character */ |
144 | 0 | return getOFStringArray(stringVal, normalize); |
145 | 0 | } |
146 | | |
147 | | |
148 | | OFCondition DcmLongText::getOFStringArray(OFString &stringVal, |
149 | | OFBool normalize) |
150 | 0 | { |
151 | | /* get string value without handling the "\" as a delimiter */ |
152 | 0 | OFCondition l_error = getStringValue(stringVal); |
153 | 0 | if (l_error.good() && normalize) |
154 | 0 | normalizeString(stringVal, !MULTIPART, !DELETE_LEADING, DELETE_TRAILING); |
155 | 0 | return l_error; |
156 | 0 | } |
157 | | |
158 | | |
159 | | // ******************************** |
160 | | |
161 | | |
162 | | OFCondition DcmLongText::checkStringValue(const OFString &value, |
163 | | const OFString &charset) |
164 | 0 | { |
165 | 0 | return DcmByteString::checkStringValue(value, "" /* vm */, "lt", 14, 0 /* maxLen: no check */, charset); |
166 | 0 | } |