forked from DCMTK/dcmtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdsrctpl.cc
195 lines (164 loc) · 5.66 KB
/
dsrctpl.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
*
* Copyright (C) 2015-2017, J. Riesmeier, Oldenburg, Germany
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation are maintained by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmsr
*
* Author: Joerg Riesmeier
*
* Purpose:
* classes: DSRTemplateCommon
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmsr/dsrctpl.h"
#include "dcmtk/dcmsr/dsrdocst.h"
#include "dcmtk/dcmdata/dcvrcs.h"
#include "dcmtk/dcmdata/dcvrui.h"
DSRTemplateCommon::DSRTemplateCommon(const OFString &templateIdentifier,
const OFString &mappingResource,
const OFString &mappingResourceUID)
: TemplateIdentifier(templateIdentifier),
MappingResource(mappingResource),
MappingResourceUID(mappingResourceUID),
ExtensibleMode(OFFalse),
OrderSignificantMode(OFFalse),
NodeList()
{
/* by default, a template is non-extensible */
}
DSRTemplateCommon::~DSRTemplateCommon()
{
}
void DSRTemplateCommon::clear()
{
clearEntriesInNodeList();
}
OFBool DSRTemplateCommon::hasTemplateIdentification() const
{
/* mapping resource UID is optional, so do not check it */
return !TemplateIdentifier.empty() && !MappingResource.empty();
}
OFBool DSRTemplateCommon::isTemplateIdentificationValid(const OFBool check) const
{
OFBool result = OFFalse;
/* either all three values are empty ... */
if (TemplateIdentifier.empty() && MappingResource.empty() && MappingResourceUID.empty())
result = OFTrue;
/* ... or the first two are both non-empty */
else if (!TemplateIdentifier.empty() && !MappingResource.empty())
{
/* check more thoroughly whether the stored values are valid */
if (check)
{
if (DcmCodeString::checkStringValue(TemplateIdentifier, "1").good() &&
DcmCodeString::checkStringValue(MappingResource, "1").good() &&
DcmUniqueIdentifier::checkStringValue(MappingResourceUID, "1").good())
{
result = OFTrue;
}
} else
result = OFTrue;
}
return result;
}
OFBool DSRTemplateCommon::compareTemplateIdentication(const OFString &templateIdentifier,
const OFString &mappingResource,
const OFString &mappingResourceUID) const
{
OFBool result = (TemplateIdentifier == templateIdentifier) && (MappingResource == mappingResource);
/* mapping resource UID is optional, so only check it if present */
if (result && !MappingResourceUID.empty() && !mappingResourceUID.empty())
result = (MappingResourceUID == mappingResourceUID);
return result;
}
// protected methods
void DSRTemplateCommon::clearEntriesInNodeList()
{
/* set all entries to 0 */
for (size_t i = 0; i < NodeList.size(); ++i)
NodeList[i] = 0;
}
void DSRTemplateCommon::reserveEntriesInNodeList(const size_t count,
const OFBool initialize)
{
/* check whether the entries should be initialized... */
if (initialize)
{
NodeList.resize(count);
clearEntriesInNodeList();
} else {
/* ... or only reserved (not created and initialized) */
NodeList.reserve(count);
}
}
void DSRTemplateCommon::storeEntryInNodeList(const size_t pos,
const size_t nodeID)
{
/* make sure that entry can be stored */
if (pos >= NodeList.size())
NodeList.resize(pos + 1, 0);
NodeList[pos] = nodeID;
}
size_t DSRTemplateCommon::getEntryFromNodeList(const size_t pos) const
{
size_t nodeID = 0;
/* make sure that entry exists */
if (pos < NodeList.size())
nodeID = NodeList[pos];
return nodeID;
}
size_t DSRTemplateCommon::gotoEntryFromNodeList(DSRDocumentTreeNodeCursor &cursor,
const size_t pos) const
{
size_t nodeID = 0;
/* make sure that cursor is valid and list entry exists */
if ((cursor.isValid()) && (pos < NodeList.size()))
{
nodeID = NodeList[pos];
/* check whether current node is already the right one */
if (cursor.getNodeID() != nodeID)
nodeID = cursor.gotoNode(nodeID);
}
return nodeID;
}
size_t DSRTemplateCommon::gotoEntryFromNodeList(DSRDocumentSubTree *tree,
const size_t pos)
{
size_t nodeID = 0;
/* make sure that tree is valid and list entry exists */
if ((tree != NULL) && (pos < NodeList.size()))
{
nodeID = NodeList[pos];
/* check whether current node is already the right one */
if (tree->getNodeID() != nodeID)
nodeID = tree->gotoNode(nodeID, OFTrue /*startFromRoot*/);
}
return nodeID;
}
size_t DSRTemplateCommon::gotoLastEntryFromNodeList(DSRDocumentSubTree *tree,
const size_t lastPos,
const size_t firstPos)
{
size_t nodeID = 0;
/* make sure that tree is valid and list entry exists */
if ((tree != NULL) && (firstPos <= lastPos) && (lastPos < NodeList.size()))
{
size_t pos = lastPos + 1;
while ((pos > firstPos) && (nodeID == 0))
nodeID = NodeList[--pos];
/* check whether current node is already the right one */
if (tree->getNodeID() != nodeID)
nodeID = tree->gotoNode(nodeID, OFTrue /*startFromRoot*/);
}
return nodeID;
}