add uint32uint8array

This commit is contained in:
David Rose 2001-09-24 21:25:11 +00:00
parent f3a4143ba7
commit 6ef2d00675
5 changed files with 39 additions and 0 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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;
}
;

View File

@ -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";
}

View File

@ -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.