Navit SVN

/work/compile/navit/src/navit/data.h

00001 
00020 #ifndef NAVIT_DATA_H
00021 #define NAVIT_DATA_H
00022 
00023 #include "config.h"
00024 
00025 #ifdef WORDS_BIGENDIAN
00026 #include <byteswap.h>
00027 #endif
00028 
00029 static inline unsigned char
00030 get_u8(unsigned char **p)
00031 {
00032         return *((*p)++);
00033 }
00034 
00035 static inline unsigned short
00036 get_u16(unsigned char **p) {
00037         unsigned short ret;
00038         ret=*((unsigned short *)*p);
00039         *p+=sizeof(unsigned short);
00040 #ifdef WORDS_BIGENDIAN
00041         return __bswap_16(ret);
00042 #else
00043         return ret;
00044 #endif
00045 }
00046 
00047 static inline unsigned short
00048 get_u16_unal(unsigned char **p) {
00049         unsigned short ret;
00050         ret=*(*p)++;
00051         ret|=(*(*p)++) << 8;
00052         return ret;
00053 }
00054 
00055 
00056 static inline unsigned int
00057 get_u24(unsigned char **p) {
00058         unsigned long ret;
00059         ret=get_u16(p);
00060         ret|=*((*p)++) << 16;
00061         return ret;
00062 }
00063 
00064 
00065 static inline unsigned int
00066 get_u24_unal(unsigned char **p) {
00067         unsigned long ret;
00068         ret=get_u16_unal(p);
00069         ret|=*((*p)++) << 16;
00070         return ret;
00071 }
00072 
00073 
00074 static inline unsigned int
00075 get_u32(unsigned char **p) {
00076         unsigned long ret;
00077         ret=*((unsigned int *)*p);
00078         *p+=sizeof(unsigned int);
00079 #ifdef WORDS_BIGENDIAN
00080         return __bswap_32(ret);
00081 #else
00082         return ret;
00083 #endif
00084 }
00085 
00086 static inline unsigned int
00087 get_u32_unal(unsigned char **p) {
00088         unsigned long ret;
00089         ret=*(*p)++;
00090         ret|=(*(*p)++) << 8;
00091         ret|=(*(*p)++) << 16;
00092         ret|=(*(*p)++) << 24;
00093         return ret;
00094 }
00095 
00096 static inline char *
00097 get_string(unsigned char **p)
00098 {
00099         char *ret=(char *)(*p);
00100         while (**p) (*p)++;
00101         (*p)++;
00102         return ret;
00103 }      
00104 
00105 #define L(x) ({ unsigned char *t=(unsigned char *)&(x); t[0] | (t[1] << 8) | (t[2] << 16) | (t[3] << 24); })
00106 
00107 #endif
00108