diff 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
line wrap: on
line diff
--- a/OrthancServer/ServerEnumerations.cpp	Wed Feb 05 13:58:00 2014 +0100
+++ b/OrthancServer/ServerEnumerations.cpp	Wed Feb 05 15:00:29 2014 +0100
@@ -41,6 +41,7 @@
 {
   static boost::mutex enumerationsMutex_;
   static Toolbox::EnumerationDictionary<MetadataType> dictMetadataType_;
+  static Toolbox::EnumerationDictionary<FileContentType> dictContentType_;
 
   void InitializeServerEnumerations()
   {
@@ -53,6 +54,9 @@
     dictMetadataType_.Add(MetadataType_ModifiedFrom, "ModifiedFrom");
     dictMetadataType_.Add(MetadataType_AnonymizedFrom, "AnonymizedFrom");
     dictMetadataType_.Add(MetadataType_LastUpdate, "LastUpdate");
+
+    dictContentType_.Add(FileContentType_Dicom, "dicom");
+    dictContentType_.Add(FileContentType_JsonSummary, "json-summary");
   }
 
   void RegisterUserMetadata(int metadata,
@@ -83,6 +87,34 @@
     return dictMetadataType_.Translate(str);
   }
 
+  void RegisterUserContentType(int contentType,
+                               const std::string& name)
+  {
+    boost::mutex::scoped_lock lock(enumerationsMutex_);
+
+    if (contentType < static_cast<int>(FileContentType_StartUser) ||
+        contentType > static_cast<int>(FileContentType_EndUser))
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+
+    dictContentType_.Add(static_cast<FileContentType>(contentType), name);
+  }
+
+  std::string EnumerationToString(FileContentType type)
+  {
+    // This function MUST return a "std::string" and not "const
+    // char*", as the result is not a static string
+    boost::mutex::scoped_lock lock(enumerationsMutex_);
+    return dictContentType_.Translate(type);
+  }
+
+  FileContentType StringToContentType(const std::string& str)
+  {
+    boost::mutex::scoped_lock lock(enumerationsMutex_);
+    return dictContentType_.Translate(str);
+  }
+
   std::string GetBasePath(ResourceType type,
                           const std::string& publicId)
   {