Mercurial > hg > orthanc
comparison Core/DicomFormat/DicomMap.cpp @ 2863:da12ba232119
serialization of DicomMap
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Oct 2018 17:49:05 +0200 |
parents | d88970f1ffbf |
children | 8265a6b56100 |
comparison
equal
deleted
inserted
replaced
2860:8b00e4cb4a6b | 2863:da12ba232119 |
---|---|
177 { | 177 { |
178 SetValue(tag.GetGroup(), tag.GetElement(), value); | 178 SetValue(tag.GetGroup(), tag.GetElement(), value); |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 | |
183 | |
184 void DicomMap::Clear() | 182 void DicomMap::Clear() |
185 { | 183 { |
186 for (Map::iterator it = map_.begin(); it != map_.end(); ++it) | 184 for (Map::iterator it = map_.begin(); it != map_.end(); ++it) |
187 { | 185 { |
186 assert(it->second != NULL); | |
188 delete it->second; | 187 delete it->second; |
189 } | 188 } |
190 | 189 |
191 map_.clear(); | 190 map_.clear(); |
192 } | 191 } |
979 else | 978 else |
980 { | 979 { |
981 return value->ParseDouble(result); | 980 return value->ParseDouble(result); |
982 } | 981 } |
983 } | 982 } |
983 | |
984 | |
985 void DicomMap::Serialize(Json::Value& target) const | |
986 { | |
987 target = Json::objectValue; | |
988 | |
989 for (Map::const_iterator it = map_.begin(); it != map_.end(); ++it) | |
990 { | |
991 assert(it->second != NULL); | |
992 | |
993 std::string tag = it->first.Format(); | |
994 | |
995 Json::Value value; | |
996 it->second->Serialize(value); | |
997 | |
998 target[tag] = value; | |
999 } | |
1000 } | |
1001 | |
1002 | |
1003 void DicomMap::Unserialize(const Json::Value& source) | |
1004 { | |
1005 Clear(); | |
1006 | |
1007 if (source.type() != Json::objectValue) | |
1008 { | |
1009 throw OrthancException(ErrorCode_BadFileFormat); | |
1010 } | |
1011 | |
1012 Json::Value::Members tags = source.getMemberNames(); | |
1013 | |
1014 for (size_t i = 0; i < tags.size(); i++) | |
1015 { | |
1016 DicomTag tag(0, 0); | |
1017 | |
1018 if (!DicomTag::ParseHexadecimal(tag, tags[i].c_str()) || | |
1019 map_.find(tag) != map_.end()) | |
1020 { | |
1021 throw OrthancException(ErrorCode_BadFileFormat); | |
1022 } | |
1023 | |
1024 std::auto_ptr<DicomValue> value(new DicomValue); | |
1025 value->Unserialize(source[tags[i]]); | |
1026 | |
1027 map_[tag] = value.release(); | |
1028 } | |
1029 } | |
984 } | 1030 } |