[endian] views and conversions

Hi, I have pushed the endian typed approach a little more. Given an C/C++ builtin integer, we can see it as an endian with a given endianness using a cast or view operation. This operation doesn't do any conversion when its parameter is a fundamental (integer) type, but just let the user states that the integer stored in the variable has been stored with the given endianness. int b; Let me say that b contains an integer with big endian format (this has been done by reading from an external device, e.g.) The following expression as<big>(i) or endian_cast<big>(i) will see the i storage as a big endian integer holder. Now we can convert from big to native as follows int n; as<native>(n) = as<big>(b); as<endianness>(x) can be implemented as a function that return a endian reference to an integer with a specific endianness. Let me call this class endian_view. endian_view will define the assignment operator so the there is a conversion when both sides have the same endianness. In place conversion can be done as follows: as<native>(b) = as<big>(b); In order to support the in place version the assignement operator on endian_views, needs to check in addition if the reference integer is the same. But this check could be inefficient when we are converting a whole structure. The same operation can be overloaded for endian_views and do a in_place conversion in this case as<native>(as<big>(b)); can be read as: make the integer b (which is formatted with big endian format) have a native endian format. Just some more thougths that can grow on the endian forest. Best, _____________________ Vicente Juan Botet Escribá http://viboes.blogspot.com/
participants (1)
-
vicente.botet