diff Core/Enumerations.cpp @ 562:f64e3838d6e1 find-move-scp

refactoring enumerations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Sep 2013 16:49:48 +0200
parents 6f8ae46ed90e
children 2d0a347e8cfc
line wrap: on
line diff
--- a/Core/Enumerations.cpp	Wed Sep 18 16:22:21 2013 +0200
+++ b/Core/Enumerations.cpp	Wed Sep 18 16:49:48 2013 +0200
@@ -33,6 +33,7 @@
 #include "Enumerations.h"
 
 #include "OrthancException.h"
+#include "Toolbox.h"
 
 namespace Orthanc
 {
@@ -222,4 +223,54 @@
       throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
   }
+
+
+  const char* EnumerationToString(ResourceType type)
+  {
+    switch (type)
+    {
+      case ResourceType_Patient:
+        return "Patient";
+
+      case ResourceType_Study:
+        return "Study";
+
+      case ResourceType_Series:
+        return "Series";
+
+      case ResourceType_Instance:
+        return "Instance";
+      
+      default:
+        throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+
+  ResourceType StringToResourceType(const char* type)
+  {
+    std::string s(type);
+    Toolbox::ToUpperCase(s);
+
+    if (s == "PATIENT")
+    {
+      return ResourceType_Patient;
+    }
+    else if (s == "STUDY")
+    {
+      return ResourceType_Study;
+    }
+    else if (s == "SERIES")
+    {
+      return ResourceType_Series;
+    }
+    else if (s == "INSTANCE" || s == "IMAGE")
+    {
+      return ResourceType_Instance;
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_ParameterOutOfRange);
+    }
+  }
 }