File: dccfprmp.cc

package info (click to toggle)
dcmtk 3.6.9-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 95,648 kB
  • sloc: ansic: 426,874; cpp: 318,177; makefile: 6,401; sh: 4,341; yacc: 1,026; xml: 482; lex: 321; perl: 277
file content (229 lines) | stat: -rw-r--r-- 5,707 bytes parent folder | download | duplicates (6)
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
 *
 *  Copyright (C) 2003-2015, OFFIS e.V.
 *  All rights reserved.  See COPYRIGHT file for details.
 *
 *  This software and supporting documentation were developed by
 *
 *    OFFIS e.V.
 *    R&D Division Health
 *    Escherweg 2
 *    D-26121 Oldenburg, Germany
 *
 *
 *  Module:  dcmnet
 *
 *  Author:  Marco Eichelberg
 *
 *  Purpose:
 *    class DcmProfileEntry
 *    class DcmProfileMap
 *
 */

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmnet/dccfprmp.h" /* for class DcmProfileMap */
#include "dcmtk/dcmdata/dcerror.h"  /* for EC_IllegalCall */


DcmProfileEntry::DcmProfileEntry(
    const OFString& presentationContextGroup,
    const OFString& roleSelectionGroup,
    const OFString& extendedNegotiationGroup)
: presentationContextGroup_(presentationContextGroup)
, roleSelectionGroup_(roleSelectionGroup)
, extendedNegotiationGroup_(extendedNegotiationGroup)
{
}

DcmProfileEntry::DcmProfileEntry(const DcmProfileEntry& arg)
: presentationContextGroup_(arg.presentationContextGroup_)
, roleSelectionGroup_(arg.roleSelectionGroup_)
, extendedNegotiationGroup_(arg.extendedNegotiationGroup_)
{
}

DcmProfileEntry& DcmProfileEntry::operator=(const DcmProfileEntry& arg)
{
  if (this != &arg)
  {
    presentationContextGroup_ = arg.presentationContextGroup_;
    roleSelectionGroup_ = arg.roleSelectionGroup_;
    extendedNegotiationGroup_ = arg.extendedNegotiationGroup_;
  }
  return *this;
}

DcmProfileEntry::~DcmProfileEntry()
{
}

const char *DcmProfileEntry::getPresentationContextKey() const
{
  return presentationContextGroup_.c_str();
}

const char *DcmProfileEntry::getRoleSelectionKey() const
{
  if (roleSelectionGroup_.size() == 0) return NULL; else return roleSelectionGroup_.c_str();
}

const char *DcmProfileEntry::getExtendedNegotiationKey() const
{
  if (extendedNegotiationGroup_.size() == 0) return NULL; else return extendedNegotiationGroup_.c_str();
}

/* ========================================================= */

DcmProfileMap::DcmProfileMap()
: map_()
{
}

DcmProfileMap::~DcmProfileMap()
{
  clear();
}

DcmProfileMap::DcmProfileMap(const DcmProfileMap& arg)
{
  /* Copy all map entries */
  OFMap<OFString, DcmProfileEntry *>::const_iterator first = arg.map_.begin();
  OFMap<OFString, DcmProfileEntry *>::const_iterator last = arg.map_.end();
  while (first != last)
  {
    DcmProfileEntry* copy = new DcmProfileEntry( *(*first).second );
    map_.insert( OFPair<const OFString, DcmProfileEntry*>( (*first).first, copy ) );
    ++first;
  }
}

DcmProfileMap& DcmProfileMap::operator=(const DcmProfileMap& arg)
{
  if (this != &arg)
  {
     /* Clear old and copy all map entries */
    this->clear();
    OFMap<OFString, DcmProfileEntry *>::const_iterator first = arg.map_.begin();
    OFMap<OFString, DcmProfileEntry *>::const_iterator last = arg.map_.end();
    while (first != last)
    {
      DcmProfileEntry* copy = new DcmProfileEntry( *(*first).second );
      map_.insert( OFPair<const OFString, DcmProfileEntry*>( (*first).first, copy ) ); // TODO: Does that work?
      ++first;
    }
  }
  return *this;
}

OFMap<OFString, DcmProfileEntry*>::const_iterator DcmProfileMap::begin()
{
  return map_.begin();
}

OFMap<OFString, DcmProfileEntry*>::const_iterator DcmProfileMap::end()
{
  return map_.end();
}

const DcmProfileEntry* DcmProfileMap::getProfile(const OFString& name)
{
  OFMap<OFString,DcmProfileEntry*>::const_iterator it = map_.find(name);
  if ( it != map_.end() )
  {
    return (*it).second;
  }
  return NULL;
}

void DcmProfileMap::clear()
{
  while (map_.size () != 0)
  {
    OFMap<OFString, DcmProfileEntry *>::iterator first = map_.begin();
    delete (*first).second;
    map_.erase(first);
  }
}

OFCondition DcmProfileMap::add(
    const char *key,
    const char *presentationContextKey,
    const char *roleSelectionKey,
    const char *extendedNegotiationKey)
{
  if ((!key)||(!presentationContextKey)) return EC_IllegalCall;

  OFString presKey(presentationContextKey);
  OFString roleKey;
  if (roleSelectionKey) roleKey = roleSelectionKey;
  OFString extnegKey;
  if (extendedNegotiationKey) extnegKey = extendedNegotiationKey;

  OFString skey(key);
  OFMap<OFString, DcmProfileEntry*>::iterator it = map_.find(skey);

  if (it == map_.end())
  {
    DcmProfileEntry *newentry = new DcmProfileEntry(presKey, roleKey, extnegKey);
    map_.insert(OFPair<OFString, DcmProfileEntry*>(skey, newentry));
  }
  else
  {
    // error: key already present
    OFString s("two profiles defined for key: ");
    s += presKey;
    return makeOFCondition(OFM_dcmnet, 1030, OF_error, s.c_str());
  }

  return EC_Normal;
}

OFBool DcmProfileMap::isKnownKey(const char *key) const
{
  if (!key) return OFFalse;
  if (map_.find(OFString(key)) != map_.end()) return OFTrue;
  return OFFalse;
}


const char *DcmProfileMap::getPresentationContextKey(const char *key) const
{
  if (key)
  {
    OFMap<OFString, DcmProfileEntry*>::const_iterator it = map_.find(OFString(key));
    if (it != map_.end())
      return (*it).second->getPresentationContextKey();
  }
  return NULL;
}


const char *DcmProfileMap::getRoleSelectionKey(const char *key) const
{
  if (key)
  {
    OFMap<OFString, DcmProfileEntry*>::const_iterator it = map_.find(OFString(key));
    if (it != map_.end())
    {
      if ( (*it).second != NULL)
        return (*it).second->getRoleSelectionKey();
    }
  }
  return NULL;
}


const char *DcmProfileMap::getExtendedNegotiationKey(const char *key) const
{
  if (key)
  {
    OFMap<OFString, DcmProfileEntry*>::const_iterator it = map_.find(OFString(key));
    if (it != map_.end())
    {
      if ( (*it).second != NULL)
        return (*it).second->getExtendedNegotiationKey();
    }
  }
  return NULL;
}