Browse Source

add uint32uint8array

David Rose 24 years ago
parent
commit
6ef2d00675

+ 22 - 0
direct/src/dcparser/dcAtomicField.cxx

@@ -204,6 +204,26 @@ end_array() {
     // These types accept arrays.
     return true;
 
+  case ST_uint32uint8array:
+    {
+      // In this special case type, we collapse every other 32-bit
+      // value down to an 8-bit value after formatting.
+      string new_value;
+      size_t p = 0;
+      while (p < _default_value.size()) {
+        // We should have at least 8 bytes for each two elements.  If
+        // we don't, maybe the user gave us an odd number of elements.
+        if (p + 8 > _default_value.size()) {
+          return false;
+        }
+        new_value += _default_value.substr(p, 5);
+        p += 8;
+      }
+
+      _default_value = new_value;
+      return true;
+    }
+
   default:
     return false;
   }
@@ -244,6 +264,7 @@ format_default_value(double num, string &formatted) const {
   case ST_uint32:
   case ST_int32array:
   case ST_uint32array:
+  case ST_uint32uint8array:
     formatted =
       string(1, (char)(int_value & 0xff)) +
       string(1, (char)((int_value >> 8) & 0xff)) +
@@ -423,6 +444,7 @@ get_element_default(int n) const {
   case ST_uint8array:
   case ST_uint16array:
   case ST_uint32array:
+  case ST_uint32uint8array:
   case ST_blob:
   case ST_string:
     // These array types also want an implicit length.

+ 5 - 0
direct/src/dcparser/dcLexer.lxx

@@ -418,6 +418,11 @@ REALNUM          ([+-]?(([0-9]+[.])|([0-9]*[.][0-9]+))([eE][+-]?[0-9]+)?)
   return KW_UINT32ARRAY;
 }
 
+"uint32uint8array" {
+  accept();
+  return KW_UINT32UINT8ARRAY;
+}
+
 mol[0-9]+ {
   // A molecular keyword.
   accept();

+ 5 - 0
direct/src/dcparser/dcParser.yxx

@@ -65,6 +65,7 @@ dc_cleanup_parser() {
 %token KW_UINT8ARRAY
 %token KW_UINT16ARRAY
 %token KW_UINT32ARRAY
+%token KW_UINT32UINT8ARRAY
 
 %token KW_MOL
 
@@ -371,6 +372,10 @@ type_token:
         | KW_UINT32ARRAY
 {
   $$ = ST_uint32array;
+}
+        | KW_UINT32UINT8ARRAY
+{
+  $$ = ST_uint32uint8array;
 }
         ;
 

+ 3 - 0
direct/src/dcparser/dcSubatomicType.cxx

@@ -72,6 +72,9 @@ operator << (ostream &out, DCSubatomicType type) {
   case ST_uint32array:
     return out << "uint32array";
 
+  case ST_uint32uint8array:
+    return out << "uint32uint8array";
+
   case ST_invalid:
     return out << "invalid";
   }

+ 4 - 0
direct/src/dcparser/dcSubatomicType.h

@@ -52,6 +52,10 @@ enum DCSubatomicType {
   ST_int8array,
   ST_uint8array,
 
+  // A special-purpose array: a list of alternating uint32 and uint8
+  // values.  In Python, this becomes a list of 2-tuples.
+  ST_uint32uint8array,
+
   // New additions should be added at the end to prevent the file hash
   // code from changing.