From: <c99...@us...> - 2006-12-03 18:23:41
|
Revision: 388 http://svn.sourceforge.net/cadcdev/?rev=388&view=rev Author: c99koder Date: 2006-12-03 10:23:38 -0800 (Sun, 03 Dec 2006) Log Message: ----------- Tiki: add File::writele16() and File::writele32() Modified Paths: -------------- tiki/include/Tiki/file.h tiki/src/base/file.cpp Modified: tiki/include/Tiki/file.h =================================================================== --- tiki/include/Tiki/file.h 2006-12-03 03:47:53 UTC (rev 387) +++ tiki/include/Tiki/file.h 2006-12-03 18:23:38 UTC (rev 388) @@ -42,6 +42,13 @@ // Read cnt 32-bit little-endian words from the file. bool readle32(void * out, int cnt); + // Write cnt 16-bit little-endian words to the file. + bool writele16(uint16 * in, int cnt); + + // Write cnt 32-bit little-endian words to the file. + bool writele32(uint32 * in, int cnt); + + // Seek in the file. int seek(int where, int whence); Modified: tiki/src/base/file.cpp =================================================================== --- tiki/src/base/file.cpp 2006-12-03 03:47:53 UTC (rev 387) +++ tiki/src/base/file.cpp 2006-12-03 18:23:38 UTC (rev 388) @@ -90,6 +90,42 @@ #endif } +bool File::writele16(uint16 * in, int cnt) { +#if BYTE_ORDER == BIG_ENDIAN + for (int i=0; i<cnt; i++) { + uint16 v = *in; + v = ((v & 0xff00) >> 8) + | ((v & 0x00ff) << 8); + + if (write(&v, 2) < 2) + return false; + in = ((uint16 *)in) + 1; + } + return true; +#else + return write(in, 2 * cnt) == 2 * cnt; +#endif +} + +bool File::writele32(uint32 * in, int cnt) { +#if BYTE_ORDER == BIG_ENDIAN + for (int i=0; i<cnt; i++) { + uint16 v = *in; + v = ((v & 0x000000ff) << 24) | + ((v & 0x0000ff00) << 8) | + ((v & 0x00ff0000) >> 8) | + ((v & 0xff000000) >> 24); + + if (write(&v, 4) < 4) + return false; + in = ((uint32 *)in) + 1; + } + return true; +#else + return write(in, 4 * cnt) == 4 * cnt; +#endif +} + int File::seek(int where, int whence) { if (!isValid()) return -1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |