comparison OrthancServer/ServerEnumerations.cpp @ 696:4c1860179cc5

dictionary of user-defined content types
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Feb 2014 15:00:29 +0100
parents 2d0a347e8cfc
children dd1ce9a2844c
comparison
equal deleted inserted replaced
695:c59bc408fb10 696:4c1860179cc5
39 39
40 namespace Orthanc 40 namespace Orthanc
41 { 41 {
42 static boost::mutex enumerationsMutex_; 42 static boost::mutex enumerationsMutex_;
43 static Toolbox::EnumerationDictionary<MetadataType> dictMetadataType_; 43 static Toolbox::EnumerationDictionary<MetadataType> dictMetadataType_;
44 static Toolbox::EnumerationDictionary<FileContentType> dictContentType_;
44 45
45 void InitializeServerEnumerations() 46 void InitializeServerEnumerations()
46 { 47 {
47 boost::mutex::scoped_lock lock(enumerationsMutex_); 48 boost::mutex::scoped_lock lock(enumerationsMutex_);
48 49
51 dictMetadataType_.Add(MetadataType_Instance_RemoteAet, "RemoteAET"); 52 dictMetadataType_.Add(MetadataType_Instance_RemoteAet, "RemoteAET");
52 dictMetadataType_.Add(MetadataType_Series_ExpectedNumberOfInstances, "ExpectedNumberOfInstances"); 53 dictMetadataType_.Add(MetadataType_Series_ExpectedNumberOfInstances, "ExpectedNumberOfInstances");
53 dictMetadataType_.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); 54 dictMetadataType_.Add(MetadataType_ModifiedFrom, "ModifiedFrom");
54 dictMetadataType_.Add(MetadataType_AnonymizedFrom, "AnonymizedFrom"); 55 dictMetadataType_.Add(MetadataType_AnonymizedFrom, "AnonymizedFrom");
55 dictMetadataType_.Add(MetadataType_LastUpdate, "LastUpdate"); 56 dictMetadataType_.Add(MetadataType_LastUpdate, "LastUpdate");
57
58 dictContentType_.Add(FileContentType_Dicom, "dicom");
59 dictContentType_.Add(FileContentType_JsonSummary, "json-summary");
56 } 60 }
57 61
58 void RegisterUserMetadata(int metadata, 62 void RegisterUserMetadata(int metadata,
59 const std::string& name) 63 const std::string& name)
60 { 64 {
81 { 85 {
82 boost::mutex::scoped_lock lock(enumerationsMutex_); 86 boost::mutex::scoped_lock lock(enumerationsMutex_);
83 return dictMetadataType_.Translate(str); 87 return dictMetadataType_.Translate(str);
84 } 88 }
85 89
90 void RegisterUserContentType(int contentType,
91 const std::string& name)
92 {
93 boost::mutex::scoped_lock lock(enumerationsMutex_);
94
95 if (contentType < static_cast<int>(FileContentType_StartUser) ||
96 contentType > static_cast<int>(FileContentType_EndUser))
97 {
98 throw OrthancException(ErrorCode_ParameterOutOfRange);
99 }
100
101 dictContentType_.Add(static_cast<FileContentType>(contentType), name);
102 }
103
104 std::string EnumerationToString(FileContentType type)
105 {
106 // This function MUST return a "std::string" and not "const
107 // char*", as the result is not a static string
108 boost::mutex::scoped_lock lock(enumerationsMutex_);
109 return dictContentType_.Translate(type);
110 }
111
112 FileContentType StringToContentType(const std::string& str)
113 {
114 boost::mutex::scoped_lock lock(enumerationsMutex_);
115 return dictContentType_.Translate(str);
116 }
117
86 std::string GetBasePath(ResourceType type, 118 std::string GetBasePath(ResourceType type,
87 const std::string& publicId) 119 const std::string& publicId)
88 { 120 {
89 switch (type) 121 switch (type)
90 { 122 {