Mercurial > hg > orthanc
comparison Core/DicomFormat/DicomTag.cpp @ 2662:47d812308d63 jobs
serialization of DicomModification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 17:47:41 +0200 |
parents | 878b59270859 |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
2660:27b7884512be | 2662:47d812308d63 |
---|---|
37 #include "../OrthancException.h" | 37 #include "../OrthancException.h" |
38 | 38 |
39 #include <iostream> | 39 #include <iostream> |
40 #include <iomanip> | 40 #include <iomanip> |
41 #include <stdio.h> | 41 #include <stdio.h> |
42 #include <string.h> | |
42 | 43 |
43 namespace Orthanc | 44 namespace Orthanc |
44 { | 45 { |
46 static inline uint16_t GetCharValue(char c) | |
47 { | |
48 if (c >= '0' && c <= '9') | |
49 return c - '0'; | |
50 else if (c >= 'a' && c <= 'f') | |
51 return c - 'a' + 10; | |
52 else if (c >= 'A' && c <= 'F') | |
53 return c - 'A' + 10; | |
54 else | |
55 return 0; | |
56 } | |
57 | |
58 | |
59 static inline uint16_t GetTagValue(const char* c) | |
60 { | |
61 return ((GetCharValue(c[0]) << 12) + | |
62 (GetCharValue(c[1]) << 8) + | |
63 (GetCharValue(c[2]) << 4) + | |
64 GetCharValue(c[3])); | |
65 } | |
66 | |
67 | |
45 bool DicomTag::operator< (const DicomTag& other) const | 68 bool DicomTag::operator< (const DicomTag& other) const |
46 { | 69 { |
47 if (group_ < other.group_) | 70 if (group_ < other.group_) |
48 return true; | 71 return true; |
49 | 72 |
69 std::string DicomTag::Format() const | 92 std::string DicomTag::Format() const |
70 { | 93 { |
71 char b[16]; | 94 char b[16]; |
72 sprintf(b, "%04x,%04x", group_, element_); | 95 sprintf(b, "%04x,%04x", group_, element_); |
73 return std::string(b); | 96 return std::string(b); |
97 } | |
98 | |
99 | |
100 bool DicomTag::ParseHexadecimal(DicomTag& tag, | |
101 const char* value) | |
102 { | |
103 size_t length = strlen(value); | |
104 | |
105 if (length == 9 && | |
106 isxdigit(value[0]) && | |
107 isxdigit(value[1]) && | |
108 isxdigit(value[2]) && | |
109 isxdigit(value[3]) && | |
110 (value[4] == '-' || value[4] == ',') && | |
111 isxdigit(value[5]) && | |
112 isxdigit(value[6]) && | |
113 isxdigit(value[7]) && | |
114 isxdigit(value[8])) | |
115 { | |
116 uint16_t group = GetTagValue(value); | |
117 uint16_t element = GetTagValue(value + 5); | |
118 tag = DicomTag(group, element); | |
119 return true; | |
120 } | |
121 else if (length == 8 && | |
122 isxdigit(value[0]) && | |
123 isxdigit(value[1]) && | |
124 isxdigit(value[2]) && | |
125 isxdigit(value[3]) && | |
126 isxdigit(value[4]) && | |
127 isxdigit(value[5]) && | |
128 isxdigit(value[6]) && | |
129 isxdigit(value[7])) | |
130 { | |
131 uint16_t group = GetTagValue(value); | |
132 uint16_t element = GetTagValue(value + 4); | |
133 tag = DicomTag(group, element); | |
134 return true; | |
135 } | |
136 else | |
137 { | |
138 return false; | |
139 } | |
74 } | 140 } |
75 | 141 |
76 | 142 |
77 const char* DicomTag::GetMainTagsName() const | 143 const char* DicomTag::GetMainTagsName() const |
78 { | 144 { |