-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUID.cpp
86 lines (75 loc) · 2.05 KB
/
UID.cpp
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
/************************************************************************
* DICOMLIB
* Copyright 2003 Sunnybrook and Women's College Health Science Center
* Implemented by Trevor Morgan ([email protected])
*
* See LICENSE.txt for copyright and licensing info.
*************************************************************************/
#include "UID.hpp"
#include <cctype>
#include <sstream>
#include <time.h>
#include <algorithm>
//#include "iso646.h"
#include "Utility.hpp"
namespace dicom
{
namespace
{
//!UIDs can only contain [0-9],'.' and '*' (when wildcards are being used in a C-FIND query)
void ThrowIfInvalid(const char c)
{
// !since Mayo Clinic DICOM images contain '-'in UID,
// !it's violation of the standard, however,
// !Gord asked me to break the law, Apr 24, 2006
//if(c!='.' && !std::isdigit(c) && c!='*' )
if(c!='.' && !std::isdigit(c) && c!='*' && c!='-' )
{
std::ostringstream s;
s << c << " is an invalid UID character";
throw InvalidUID(s.str());
}
}
}
/*!
a UID can only be created from a std::string object.
The construct verifies that the string conforms to
the standard description of unique identifiers.
*/
UID::UID(const std::string& s) : data_(s)
{
if(data_.size()>64)
{
std::ostringstream error;
error << "UID : " << s << " is too long";
throw InvalidUID(error.str());
}
// Following line was previously commented out.
StripTrailingWhitespace(data_);
StripTrailingNull(data_);
std::for_each(data_.begin(),data_.end(),ThrowIfInvalid);
}
std::string UID::str()const
{
return data_;
}
InvalidUID::InvalidUID(std::string what):dicom::exception(what)
{
}
/*!
Generates a (hopefully!) unique UID.
This may not be thread safe.
*/
UID makeUID(const std::string &Prefix)
{
std::ostringstream stream;
stream << Prefix
<< "." << time(0)
<< "." << clock()
<< "." << rand();
std::string s=stream.str();
if(s.size()>64)
throw dicom::exception("Generated UID is larger than 64 characters.");
return UID(s);
}
}//namespace dicom