Ver Fonte

Added helper getters for casting metadata payloads

Doug Stephen há 8 anos atrás
pai
commit
42e2c30b4b
1 ficheiros alterados com 57 adições e 0 exclusões
  1. 57 0
      port/jassimp/jassimp/src/jassimp/AiMetadataEntry.java

+ 57 - 0
port/jassimp/jassimp/src/jassimp/AiMetadataEntry.java

@@ -58,4 +58,61 @@ public class AiMetadataEntry
    {
       return mData;
    }
+
+   public static boolean getAiBoolAsBoolean(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_BOOL);
+
+      return (boolean) metadataEntry.mData;
+   }
+
+   public static int getAiInt32AsInteger(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_INT32);
+
+      return (int) metadataEntry.mData;
+   }
+
+   public static long getAiUint64AsLong(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_UINT64);
+
+      return (long) metadataEntry.mData;
+   }
+
+   public static float getAiFloatAsFloat(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_FLOAT);
+
+      return (float) metadataEntry.mData;
+   }
+
+   public static double getAiDoubleAsDouble(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_DOUBLE);
+
+      return (double) metadataEntry.mData;
+   }
+
+   public static String getAiStringAsString(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_AISTRING);
+
+      return (String) metadataEntry.mData;
+   }
+
+   public static AiVector getAiAiVector3DAsAiVector(AiMetadataEntry metadataEntry)
+   {
+      checkTypeBeforeCasting(metadataEntry, AiMetadataType.AI_AIVECTOR3D);
+
+      return (AiVector) metadataEntry.mData;
+   }
+
+   private static void checkTypeBeforeCasting(AiMetadataEntry entry, AiMetadataType expectedType)
+   {
+      if(entry.mType != expectedType)
+      {
+         throw new RuntimeException("Cannot cast entry of type " + entry.mType.name() + " to " + expectedType.name());
+      }
+   }
 }