Joe Abbate jma@freedomcircle.com [eiffel_software]
2015-07-31 02:21:48 UTC
Hello,
Is it possible to declare a binary structure in Eiffel, i.e., one that
corresponds to a fixed length record in a RAW_FILE, and in particular
one that may contain fixed length, possibly zero-terminated strings?
From what I've read, one can declare a "raw" structure that contains
single characters, integers and reals, e.g.,
struct: TUPLE [CHARACTER_8, INTEGER_32, REAL]
Then, presumably if one were to use RAW_FILE read_stream (9) one could
read a fixed length record into RAW_FILE's last_string. However, it
would still be necessary to split apart last_string and assign it to the
TUPLE components, or perhaps directly to a regular Eiffel class.
FIRST QUESTION: Can one read from a RAW_FILE directly into such a TUPLE?
Also, can a TUPLE be expanded, and can the expanded size (i.e., the 9
above) be obtained somewhere?
However, how can one declare a C-style string, e.g., something like a
char text[16];
I know that ARRAY maintains its data in a SPECIAL [G] attribute, but
declaring a SPECIAL [CHARACTER_8] element in the tuple above would not
allocate 16 bytes. One could create a TEXT_16 class whose creation
routine would allocate the 16 bytes, but I think that still wouldn't
help because what's really needed is an expanded class.
SECOND QUESTION: Is there a way to declare something equivalent to a
char [n] where n is a fixed value?
FINAL or COROLLARY QUESTION: Is there a way to do what I describe above
purely in Eiffel, or is it necessary to descend to a C interface?
Thanks for your feedback,
Joe
Is it possible to declare a binary structure in Eiffel, i.e., one that
corresponds to a fixed length record in a RAW_FILE, and in particular
one that may contain fixed length, possibly zero-terminated strings?
From what I've read, one can declare a "raw" structure that contains
single characters, integers and reals, e.g.,
struct: TUPLE [CHARACTER_8, INTEGER_32, REAL]
Then, presumably if one were to use RAW_FILE read_stream (9) one could
read a fixed length record into RAW_FILE's last_string. However, it
would still be necessary to split apart last_string and assign it to the
TUPLE components, or perhaps directly to a regular Eiffel class.
FIRST QUESTION: Can one read from a RAW_FILE directly into such a TUPLE?
Also, can a TUPLE be expanded, and can the expanded size (i.e., the 9
above) be obtained somewhere?
However, how can one declare a C-style string, e.g., something like a
char text[16];
I know that ARRAY maintains its data in a SPECIAL [G] attribute, but
declaring a SPECIAL [CHARACTER_8] element in the tuple above would not
allocate 16 bytes. One could create a TEXT_16 class whose creation
routine would allocate the 16 bytes, but I think that still wouldn't
help because what's really needed is an expanded class.
SECOND QUESTION: Is there a way to declare something equivalent to a
char [n] where n is a fixed value?
FINAL or COROLLARY QUESTION: Is there a way to do what I describe above
purely in Eiffel, or is it necessary to descend to a C interface?
Thanks for your feedback,
Joe