00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "eptacode.h"
00027
00028
00029 #include <assert.h>
00030
00031 namespace IXE {
00032
00033 using namespace std;
00034
00035 #ifdef _MSC_VER
00036 #define OUTPUT_DIGIT(o, n) reinterpret_cast<ostream&>(o) << static_cast<unsigned char>(n)
00037 #else
00038 #define OUTPUT_DIGIT(o, n) o << static_cast<unsigned char>(n)
00039 #endif
00040
00041
00073
00074
00075 ostream& outEptacode(ostream& o, register unsigned n)
00076 {
00077 while (n >= 128) {
00078 OUTPUT_DIGIT(o, (n & 0x7F));
00079 n >>= 7;
00080 }
00081 OUTPUT_DIGIT(o, (n | 0x80));
00082
00083 return o;
00084 }
00085
00091 ostream& padEptacode(ostream& o, register unsigned no, unsigned old)
00092 {
00093 assert(no <= old);
00094 if (no == old)
00095 return outEptacode(o, no);
00096 unsigned n = no;
00097 while (n >= 128) {
00098 n >>= 7;
00099 old >>= 7;
00100 }
00101
00102 while (old >= 128) {
00103 OUTPUT_DIGIT(o, 0);
00104 old >>= 7;
00105 }
00106 return outEptacode(o, no);
00107 }
00108
00109 unsigned int toEptacode(unsigned char* dst, register unsigned n)
00110 {
00111 register unsigned char *p = dst;
00112 while (n >= 128) {
00113 *p++ = n & 0x7F;
00114 n >>= 7;
00115 }
00116 *p = n | 0x80;
00117
00118 return p - dst + 1;
00119 }
00120
00121 }