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
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __BIG_ENDIAN__
00035 #define LITTLE_MACHINE
00036 #endif
00037
00038 #ifdef WIN32
00039 #define assert ASSERT
00040 #else
00041 #include <assert.h>
00042 #endif
00043 #ifdef _MSC_VER
00044 #pragma warning( disable : 4267 )
00045 #define strtok_r strtok_s
00046 #endif
00047
00048 #ifdef WIN32
00049 #include <direct.h>
00050 #endif
00051
00052 #include <fcntl.h>
00053 #include <sys/types.h>
00054 #include <sys/stat.h>
00055 #include <time.h>
00056 #include <stdio.h>
00057 #include <stdlib.h>
00058 #include <math.h>
00059 #include <string.h>
00060 #include <assert.h>
00061
00062 #include <vector>
00063 #include <algorithm>
00064
00065 #include "plylib.h"
00066 using namespace std;
00067 namespace vcg{
00068 namespace ply{
00069 typedef unsigned short ushort;
00070 typedef unsigned long ulong;
00071 typedef unsigned char uchar;
00072 typedef unsigned int uint;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #define XFILE FILE
00083 #define pb_fclose fclose
00084 #define pb_fopen fopen
00085 #define pb_fgets(s,n,f) fgets(s,n,f)
00086 #define pb_fread(b,s,n,f) fread(b,s,n,f)
00087
00088
00089
00090
00091 #define pb_mkdir(n) _mkdir(n)
00092 #define pb_access _access
00093 #define pb_stat _stat
00094 #define pb_open _open
00095 #define pb_close _close
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 int ReadBin ( XFILE * fp, const PlyProperty * pr, void * mem, int fmt );
00112 int ReadAscii( XFILE * fp, const PlyProperty * pr, void * mem, int fmt );
00113
00114
00115 const char * ::vcg::ply::PlyFile::typenames[9]=
00116 {
00117 "none",
00118 "char",
00119 "short",
00120 "int",
00121 "uchar",
00122 "ushort",
00123 "uint",
00124 "float",
00125 "double"
00126 };
00127 const char * PlyFile::newtypenames[9]=
00128 {
00129 "none",
00130 "int8",
00131 "int16",
00132 "int32",
00133 "uint8",
00134 "uint16",
00135 "uint32",
00136 "float32",
00137 "float64"
00138 };
00139
00140 static int TypeSize[] = {
00141 0, 1, 2, 4, 1, 2, 4, 4, 8
00142 };
00143
00144 size_t PropDescriptor::memtypesize() const {return TypeSize[memtype1];}
00145 size_t PropDescriptor::stotypesize() const {return TypeSize[stotype1];}
00146 const char *PropDescriptor::memtypename() const {return PlyFile::typenames[memtype1];}
00147 const char *PropDescriptor::stotypename() const {return PlyFile::typenames[stotype1];}
00148
00149 static char CrossType[9][9]=
00150 {
00151 {0,0,0,0,0,0,0,0,0},
00152 {0,1,1,1,1,1,1,0,0},
00153 {0,0,1,1,0,1,1,0,0},
00154 {0,0,0,1,0,0,1,0,0},
00155 {0,1,1,1,1,1,1,0,0},
00156 {0,0,1,1,0,1,1,0,0},
00157 {0,0,0,1,0,0,1,0,0},
00158 {0,0,0,0,0,0,0,1,1},
00159 {0,0,0,0,0,0,0,1,1}
00160 };
00161
00162
00163
00164
00165
00166
00167
00168 static inline void SwapShort( ushort * s )
00169 {
00170 assert(s);
00171 *s = ushort( (int(*s)>>8) | (int(*s)<<8) );
00172 }
00173
00174
00175 static inline void SwapInt( uint * x )
00176 {
00177 assert(x);
00178 *x =
00179 ( ((*x)>>24) & 0x000000FF ) |
00180 ( ((*x)>> 8) & 0x0000FF00 ) |
00181 ( ((*x)<< 8) & 0x00FF0000 ) |
00182 ( ((*x)<<24) & 0xFF000000 ) ;
00183 }
00184
00185
00186 static inline void SwapDouble( double * )
00187 {
00188
00189 assert(0);
00190 }
00191
00192
00193
00194
00195 static inline int ReadCharB( XFILE * fp, char * c, int )
00196 {
00197 assert(fp);
00198 assert(c);
00199
00200 return pb_fread(c,1,1,fp);
00201 }
00202
00203
00204 static inline int ReadShortB( XFILE * fp, short * s, int format )
00205 {
00206 assert(fp);
00207 assert(s);
00208
00209 int r;
00210 r = pb_fread(s,sizeof(short),1,fp);
00211
00212 #ifdef LITTLE_MACHINE
00213 if(format==F_BINBIG)
00214 #else
00215 if(format==F_BINLITTLE)
00216 #endif
00217 SwapShort((ushort *)s);
00218
00219 return r;
00220 }
00221
00222
00223 static inline int ReadIntB( XFILE * fp, int * i, int format )
00224 {
00225 assert(fp);
00226 assert(i);
00227
00228 int r;
00229 r = pb_fread(i,sizeof(int),1,fp);
00230
00231 #ifdef LITTLE_MACHINE
00232 if(format==F_BINBIG)
00233 #else
00234 if(format==F_BINLITTLE)
00235 #endif
00236 SwapInt((uint *)i);
00237
00238 return r;
00239 }
00240
00241
00242 static inline int ReadUCharB( XFILE * fp, uchar * uc, int )
00243 {
00244 assert(fp);
00245 assert(uc);
00246
00247 return pb_fread(uc,1,1,fp);
00248 }
00249
00250
00251 static inline int ReadUShortB( XFILE * fp, ushort * us, int format )
00252 {
00253 assert(fp);
00254 assert(us);
00255
00256 int r;
00257 r = pb_fread(us,sizeof(ushort),1,fp);
00258
00259 #ifdef LITTLE_MACHINE
00260 if(format==F_BINBIG)
00261 #else
00262 if(format==F_BINLITTLE)
00263 #endif
00264 SwapShort(us);
00265
00266 return r;
00267 }
00268
00269
00270 static inline int ReadUIntB( XFILE * fp, uint * ui, int format )
00271 {
00272 assert(fp);
00273 assert(ui);
00274
00275 int r;
00276 r = pb_fread(ui,sizeof(uint),1,fp);
00277
00278 #ifdef LITTLE_MACHINE
00279 if(format==F_BINBIG)
00280 #else
00281 if(format==F_BINLITTLE)
00282 #endif
00283 SwapInt(ui);
00284
00285 return r;
00286 }
00287
00288
00289 static inline int ReadFloatB( XFILE * fp, float * f, int format )
00290 {
00291 assert(fp);
00292 assert(f);
00293
00294 int r;
00295 r = pb_fread(f,sizeof(float),1,fp);
00296
00297 #ifdef LITTLE_MACHINE
00298 if(format==F_BINBIG)
00299 #else
00300 if(format==F_BINLITTLE)
00301 #endif
00302 SwapInt((uint *)f);
00303
00304 return r;
00305 }
00306
00307
00308 static inline int ReadDoubleB( XFILE * fp, double * d, int format )
00309 {
00310 assert(fp);
00311 assert(d);
00312
00313 int r;
00314 r = pb_fread(d,sizeof(double),1,fp);
00315
00316 #ifdef LITTLE_MACHINE
00317 if(format==F_BINBIG)
00318 #else
00319 if(format==F_BINLITTLE)
00320 #endif
00321 SwapDouble(d);
00322
00323 return r;
00324 }
00325
00326
00327
00328
00329
00330
00331
00332
00333 static void InitSBuffer()
00334 {
00335
00336 }
00337
00338 static inline int ReadInt( XFILE * fp, int & t )
00339 {
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360 int r = fscanf(fp,"%d",&t);
00361 if(r==EOF) r = 0;
00362 return r;
00363 }
00364
00365
00366 static inline int ReadUInt( XFILE * fp, unsigned int & t )
00367 {
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 int r = fscanf(fp,"%u",&t);
00389 if(r==EOF) r = 0;
00390 return r;
00391 }
00392
00393
00394 static inline int ReadFloat( XFILE * fp, float & f )
00395 {
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416 int r = fscanf(fp,"%f",&f);
00417 if(r==EOF) r = 0;
00418 return r;
00419 }
00420
00421 static inline int ReadDouble( XFILE * fp, double & d )
00422 {
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443 int r = fscanf(fp,"%lf",&d);
00444 if(r==EOF) r = 0;
00445 return r;
00446 }
00447
00448
00449
00450
00451 static inline int ReadCharA( XFILE * fp, char * c )
00452 {
00453 assert(fp);
00454 assert(c);
00455
00456 int r,t;
00457 r = ReadInt(fp,t);
00458 *c = (char)t;
00459 return r;
00460 }
00461
00462
00463 static inline int ReadShortA( XFILE * fp, short * s )
00464 {
00465 assert(fp);
00466 assert(s);
00467
00468 int r,t;
00469 r = ReadInt(fp,t);
00470 *s = (short)t;
00471 return r;
00472 }
00473
00474
00475 static inline int ReadIntA( XFILE * fp, int * i )
00476 {
00477 assert(fp);
00478 assert(i);
00479
00480 return ReadInt(fp,*i);
00481 }
00482
00483 static inline int ReadUCharA( XFILE * fp, uchar * uc )
00484 {
00485 assert(fp);
00486 assert(uc);
00487
00488 int r;
00489 uint t;
00490 r = ReadUInt(fp,t);
00491 *uc = (uchar)t;
00492 return r;
00493 }
00494
00495
00496 static inline int ReadUShortA( XFILE * fp, ushort * us )
00497 {
00498 assert(fp);
00499 assert(us);
00500
00501 int r;
00502 uint t;
00503 r = ReadUInt(fp,t);
00504 *us = (ushort)t;
00505 return r;
00506 }
00507
00508
00509 static inline int ReadUIntA( XFILE * fp, uint * ui )
00510 {
00511 assert(fp);
00512 assert(ui);
00513
00514 return ReadUInt(fp,*ui);
00515 }
00516
00517 static inline int ReadFloatA( XFILE * fp, float * f )
00518 {
00519 assert(fp);
00520 assert(f);
00521
00522 return ReadFloat(fp,*f);
00523 }
00524
00525
00526 static inline int ReadDoubleA( XFILE * fp, double * d )
00527 {
00528 assert(fp);
00529 assert(d);
00530
00531 return ReadDouble(fp,*d);
00532 }
00533
00534
00535
00536
00537
00538 static inline void StoreInt( void * mem, const int tm, const int val )
00539 {
00540 assert(mem);
00541
00542 switch(tm)
00543 {
00544 case T_CHAR: *(char *)mem = (char )val; break;
00545 case T_SHORT: *(short *)mem = (short )val; break;
00546 case T_INT: *(int *)mem = (int )val; break;
00547 case T_UCHAR: *(uchar *)mem = (uchar )val; break;
00548 case T_USHORT: *(ushort *)mem = (ushort)val; break;
00549 case T_UINT: *(uint *)mem = (uint )val; break;
00550 case T_FLOAT: *(float *)mem = (float )val; break;
00551 case T_DOUBLE: *(double *)mem = (double)val; break;
00552 default: assert(0);
00553 }
00554 }
00555
00556
00557
00558 static inline int SkipScalarA( XFILE * fp, const int tf )
00559 {
00560 int t;
00561 float f;
00562
00563 assert(fp);
00564
00565 switch(tf)
00566 {
00567 case T_CHAR:
00568 case T_SHORT:
00569 case T_INT:
00570 case T_UCHAR:
00571 case T_USHORT:
00572 case T_UINT:
00573 return ReadInt(fp,t);
00574 case T_FLOAT:
00575 case T_DOUBLE:
00576 return ReadFloat(fp,f);
00577 default:
00578 assert(0);
00579 return 0;
00580 }
00581 }
00582
00583
00584
00585 static inline int SkipScalarB( XFILE * fp, const int tf)
00586 {
00587 char dummy[8];
00588
00589 assert(fp);
00590 return pb_fread(dummy,1,TypeSize[tf],fp);
00591 }
00592
00593 static int ReadScalarB( XFILE * fp, void * mem, const int tf, const int tm, int fmt )
00594 {
00595 char ch;
00596 short sh;
00597 int in;
00598 uchar uc;
00599 ushort us;
00600 uint ui;
00601 float fl;
00602 double dd;
00603
00604 int r = 0;
00605
00606 switch(tf)
00607 {
00608 case T_CHAR:
00609 r = ReadCharB(fp,&ch,fmt);
00610 switch(tm)
00611 {
00612 case T_CHAR: *(char *)mem = (char )ch; break;
00613 case T_SHORT: *(short *)mem = (short )ch; break;
00614 case T_INT: *(int *)mem = (int )ch; break;
00615 case T_UCHAR: *(uchar *)mem = (uchar )ch; break;
00616 case T_USHORT: *(ushort *)mem = (ushort)ch; break;
00617 case T_UINT: *(uint *)mem = (uint )ch; break;
00618 case T_FLOAT: *(float *)mem = (float )ch; break;
00619 case T_DOUBLE: *(double *)mem = (double)ch; break;
00620 default: assert(0);
00621 }
00622 break;
00623 case T_SHORT:
00624 r = ReadShortB(fp,&sh,fmt);
00625 switch(tm)
00626 {
00627 case T_CHAR: *(char *)mem = (char )sh; break;
00628 case T_SHORT: *(short *)mem = (short )sh; break;
00629 case T_INT: *(int *)mem = (int )sh; break;
00630 case T_UCHAR: *(uchar *)mem = (uchar )sh; break;
00631 case T_USHORT: *(ushort *)mem = (ushort)sh; break;
00632 case T_UINT: *(uint *)mem = (uint )sh; break;
00633 case T_FLOAT: *(float *)mem = (float )sh; break;
00634 case T_DOUBLE: *(double *)mem = (double)sh; break;
00635 default: assert(0);
00636 }
00637 break;
00638 case T_INT:
00639 r = ReadIntB(fp,&in,fmt);
00640 switch(tm)
00641 {
00642 case T_CHAR: *(char *)mem = (char )in; break;
00643 case T_SHORT: *(short *)mem = (short )in; break;
00644 case T_INT: *(int *)mem = (int )in; break;
00645 case T_UCHAR: *(uchar *)mem = (uchar )in; break;
00646 case T_USHORT: *(ushort *)mem = (ushort)in; break;
00647 case T_UINT: *(uint *)mem = (uint )in; break;
00648 case T_FLOAT: *(float *)mem = (float )in; break;
00649 case T_DOUBLE: *(double *)mem = (double)in; break;
00650 default: assert(0);
00651 }
00652 break;
00653 case T_UCHAR:
00654 r = ReadUCharB(fp,&uc,fmt);
00655 switch(tm)
00656 {
00657 case T_CHAR: *(char *)mem = (char )uc; break;
00658 case T_SHORT: *(short *)mem = (short )uc; break;
00659 case T_INT: *(int *)mem = (int )uc; break;
00660 case T_UCHAR: *(uchar *)mem = (uchar )uc; break;
00661 case T_USHORT: *(ushort *)mem = (ushort)uc; break;
00662 case T_UINT: *(uint *)mem = (uint )uc; break;
00663 case T_FLOAT: *(float *)mem = (float )uc; break;
00664 case T_DOUBLE: *(double *)mem = (double)uc; break;
00665 default: assert(0);
00666 }
00667 break;
00668 case T_USHORT:
00669 r = ReadUShortB(fp,&us,fmt);
00670 switch(tm)
00671 {
00672 case T_CHAR: *(char *)mem = (char )us; break;
00673 case T_SHORT: *(short *)mem = (short )us; break;
00674 case T_INT: *(int *)mem = (int )us; break;
00675 case T_UCHAR: *(uchar *)mem = (uchar )us; break;
00676 case T_USHORT: *(ushort *)mem = (ushort)us; break;
00677 case T_UINT: *(uint *)mem = (uint )us; break;
00678 case T_FLOAT: *(float *)mem = (float )us; break;
00679 case T_DOUBLE: *(double *)mem = (double)us; break;
00680 default: assert(0);
00681 }
00682 break;
00683 case T_UINT:
00684 r = ReadUIntB(fp,&ui,fmt);
00685 switch(tm)
00686 {
00687 case T_CHAR: *(char *)mem = (char )ui; break;
00688 case T_SHORT: *(short *)mem = (short )ui; break;
00689 case T_INT: *(int *)mem = (int )ui; break;
00690 case T_UCHAR: *(uchar *)mem = (uchar )ui; break;
00691 case T_USHORT: *(ushort *)mem = (ushort)ui; break;
00692 case T_UINT: *(uint *)mem = (uint )ui; break;
00693 case T_FLOAT: *(float *)mem = (float )ui; break;
00694 case T_DOUBLE: *(double *)mem = (double)ui; break;
00695 default: assert(0);
00696 }
00697 break;
00698 case T_FLOAT:
00699 r = ReadFloatB(fp,&fl,fmt);
00700 switch(tm)
00701 {
00702 case T_FLOAT: *(float *)mem = fl; break;
00703 case T_DOUBLE: *(double *)mem = fl; break;
00704 default: assert(0);
00705 }
00706 break;
00707 case T_DOUBLE:
00708 r = ReadDoubleB(fp,&dd,fmt);
00709 switch(tm)
00710 {
00711 case T_FLOAT: *(float *)mem = (float)dd; break;
00712 case T_DOUBLE: *(double *)mem = dd; break;
00713 default: assert(0);
00714 }
00715 break;
00716 default:
00717 assert(0);
00718 }
00719
00720 return r;
00721 }
00722
00723
00724
00725 static int ReadScalarA( XFILE * fp, void * mem, const int tf, const int tm )
00726 {
00727 char ch;
00728 short sh;
00729 int in;
00730 uchar uc;
00731 ushort us;
00732 uint ui;
00733 float fl;
00734 double dd;
00735
00736 int r = 0;
00737
00738 switch(tf)
00739 {
00740 case T_CHAR:
00741 r = ReadCharA(fp,&ch);
00742 switch(tm)
00743 {
00744 case T_CHAR: *(char *)mem = (char )ch; break;
00745 case T_SHORT: *(short *)mem = (short )ch; break;
00746 case T_INT: *(int *)mem = (int )ch; break;
00747 case T_UCHAR: *(uchar *)mem = (uchar )ch; break;
00748 case T_USHORT: *(ushort *)mem = (ushort)ch; break;
00749 case T_UINT: *(uint *)mem = (uint )ch; break;
00750 case T_FLOAT: *(float *)mem = (float )ch; break;
00751 case T_DOUBLE: *(double *)mem = (double)ch; break;
00752 default: assert(0);
00753 }
00754 break;
00755 case T_SHORT:
00756 r = ReadShortA(fp,&sh);
00757 switch(tm)
00758 {
00759 case T_CHAR: *(char *)mem = (char )sh; break;
00760 case T_SHORT: *(short *)mem = (short )sh; break;
00761 case T_INT: *(int *)mem = (int )sh; break;
00762 case T_UCHAR: *(uchar *)mem = (uchar )sh; break;
00763 case T_USHORT: *(ushort *)mem = (ushort)sh; break;
00764 case T_UINT: *(uint *)mem = (uint )sh; break;
00765 case T_FLOAT: *(float *)mem = (float )sh; break;
00766 case T_DOUBLE: *(double *)mem = (double)sh; break;
00767 default: assert(0);
00768 }
00769 break;
00770 case T_INT:
00771 r = ReadIntA(fp,&in);
00772 switch(tm)
00773 {
00774 case T_CHAR: *(char *)mem = (char )in; break;
00775 case T_SHORT: *(short *)mem = (short )in; break;
00776 case T_INT: *(int *)mem = (int )in; break;
00777 case T_UCHAR: *(uchar *)mem = (uchar )in; break;
00778 case T_USHORT: *(ushort *)mem = (ushort)in; break;
00779 case T_UINT: *(uint *)mem = (uint )in; break;
00780 case T_FLOAT: *(float *)mem = (float )in; break;
00781 case T_DOUBLE: *(double *)mem = (double)in; break;
00782 default: assert(0);
00783 }
00784 break;
00785 case T_UCHAR:
00786 r = ReadUCharA(fp,&uc);
00787 switch(tm)
00788 {
00789 case T_CHAR: *(char *)mem = (char )uc; break;
00790 case T_SHORT: *(short *)mem = (short )uc; break;
00791 case T_INT: *(int *)mem = (int )uc; break;
00792 case T_UCHAR: *(uchar *)mem = (uchar )uc; break;
00793 case T_USHORT: *(ushort *)mem = (ushort)uc; break;
00794 case T_UINT: *(uint *)mem = (uint )uc; break;
00795 case T_FLOAT: *(float *)mem = (float )uc; break;
00796 case T_DOUBLE: *(double *)mem = (double)uc; break;
00797 default: assert(0);
00798 }
00799 break;
00800 case T_USHORT:
00801 r = ReadUShortA(fp,&us);
00802 switch(tm)
00803 {
00804 case T_CHAR: *(char *)mem = (char )us; break;
00805 case T_SHORT: *(short *)mem = (short )us; break;
00806 case T_INT: *(int *)mem = (int )us; break;
00807 case T_UCHAR: *(uchar *)mem = (uchar )us; break;
00808 case T_USHORT: *(ushort *)mem = (ushort)us; break;
00809 case T_UINT: *(uint *)mem = (uint )us; break;
00810 case T_FLOAT: *(float *)mem = (float )us; break;
00811 case T_DOUBLE: *(double *)mem = (double)us; break;
00812 default: assert(0);
00813 }
00814 break;
00815 case T_UINT:
00816 r = ReadUIntA(fp,&ui);
00817 switch(tm)
00818 {
00819 case T_CHAR: *(char *)mem = (char )ui; break;
00820 case T_SHORT: *(short *)mem = (short )ui; break;
00821 case T_INT: *(int *)mem = (int )ui; break;
00822 case T_UCHAR: *(uchar *)mem = (uchar )ui; break;
00823 case T_USHORT: *(ushort *)mem = (ushort)ui; break;
00824 case T_UINT: *(uint *)mem = (uint )ui; break;
00825 case T_FLOAT: *(float *)mem = (float )ui; break;
00826 case T_DOUBLE: *(double *)mem = (double)ui; break;
00827 default: assert(0);
00828 }
00829 break;
00830 case T_FLOAT:
00831 r = ReadFloatA(fp,&fl);
00832 switch(tm)
00833 {
00834 case T_FLOAT: *(float *)mem = fl; break;
00835 case T_DOUBLE: *(double *)mem = fl; break;
00836 default: assert(0);
00837 }
00838 break;
00839 case T_DOUBLE:
00840 r = ReadDoubleA(fp,&dd);
00841 switch(tm)
00842 {
00843 case T_FLOAT: *(float *)mem = (float)dd; break;
00844 case T_DOUBLE: *(double *)mem = dd; break;
00845 default: assert(0);
00846 }
00847 break;
00848 default:
00849 assert(0);
00850 }
00851
00852 return r;
00853 }
00854
00855
00856
00857
00858 void PlyElement::AddProp( const char * na, int ti, int isl, int t2 )
00859 {
00860 assert(na);
00861 assert(ti>0);
00862 assert(ti<T_MAXTYPE);
00863 assert( t2>0 || (t2==0 && isl==0));
00864 assert(t2<T_MAXTYPE);
00865
00866 props.push_back( PlyProperty (na,ti,isl,t2) );
00867 }
00868
00869 PlyProperty * PlyElement::FindProp( const char * na )
00870 {
00871 assert(na);
00872 vector<PlyProperty>::iterator i;
00873
00874 for(i=props.begin();i!=props.end();++i)
00875 if( i->name == na )
00876 return &*i;
00877 return 0;
00878 }
00879
00880 int PlyElement::AddToRead(
00881 const char * propname,
00882 int stotype1,
00883 int memtype1,
00884 size_t offset1,
00885 int islist,
00886 int alloclist,
00887 int stotype2,
00888 int memtype2,
00889 size_t offset2
00890 )
00891 {
00892 assert(propname);
00893
00894 PlyProperty * p = FindProp(propname);
00895 if(p==0)
00896 {
00897 return E_PROPNOTFOUND;
00898 }
00899
00900 if( stotype1<1 || stotype1>=T_MAXTYPE ||
00901 memtype1<1 || memtype1>=T_MAXTYPE )
00902 {
00903 return E_BADTYPE;
00904 }
00905
00906 if( islist && (stotype2<1 || stotype2>=T_MAXTYPE ||
00907 memtype2<1 || memtype2>=T_MAXTYPE ) )
00908 {
00909 return E_BADTYPE;
00910 }
00911
00912 if( islist!= p->islist || stotype1 != p->tipo ||
00913 ( islist && stotype2!=p->tipoindex) )
00914 {
00915 return E_INCOMPATIBLETYPE;
00916 }
00917
00918 if( !CrossType[p->tipo][stotype1] ||
00919 (islist && !CrossType[p->tipoindex][stotype2] ) )
00920 {
00921 return E_BADCAST;
00922 }
00923
00924 p->bestored = 1;
00925
00926 p->desc.stotype1 = stotype1;
00927 p->desc.memtype1 = memtype1;
00928 p->desc.offset1 = offset1;
00929 p->desc.islist = islist;
00930 p->desc.alloclist = alloclist;
00931 p->desc.stotype2 = stotype2;
00932 p->desc.memtype2 = memtype2;
00933 p->desc.offset2 = offset2;
00934
00935
00936 return E_NOERROR;
00937 }
00938
00939
00940
00941
00942
00943 PlyFile::PlyFile( void )
00944 {
00945 gzfp = 0;
00946 version = 0.0f;
00947 error = E_NOERROR;
00948 format = F_UNSPECIFIED;
00949 cure = 0;
00950 ReadCB = 0;
00951 InitSBuffer();
00952 }
00953
00954 PlyFile::~PlyFile( void )
00955 {
00956 Destroy();
00957 }
00958
00959 int PlyFile::Open( const char * filename, int mode )
00960 {
00961 if(filename==0 || (mode!=MODE_READ && mode!=MODE_WRITE) )
00962 {
00963 error = E_CANTOPEN;
00964 return -1;
00965 }
00966 if(mode==MODE_READ)
00967 return OpenRead(filename);
00968 else
00969 return OpenWrite(filename);
00970 }
00971
00972 void PlyFile::Destroy( void )
00973 {
00974 if(gzfp!=0)
00975 {
00976 pb_fclose(gzfp);
00977 gzfp = 0;
00978 }
00979
00980 ReadCB = 0;
00981 }
00982
00983 int PlyFile::OpenRead( const char * filename )
00984 {
00985
00986
00987 const char * SEP = " \t\n\r";
00988 const char * HEADER = "ply";
00989 const char * FORMAT = "format";
00990 const char * TASCII = "ascii";
00991 const char * TBINBIG = "binary_big_endian";
00992 const char * TBINLITTLE = "binary_little_endian";
00993 const char * COMMENT = "comment";
00994 const char * OBJ_INFO = "obj_info";
00995 const char * ELEMENT = "element";
00996 const char * PROPERTY = "property";
00997 const char * ENDHEADER = "end_header";
00998 const char * LIST = "list";
00999
01000 const int MAXB = 512;
01001 char buf[MAXB];
01002 char * token;
01003 PlyElement * curelement;
01004
01005
01006
01007 Destroy();
01008
01009
01010 gzfp = pb_fopen(filename,"rb");
01011 if(gzfp==0)
01012 {
01013 error = E_CANTOPEN;
01014 goto error;
01015 }
01016
01017 header.clear();
01018 header.reserve(1536);
01019
01020
01021
01022 if( pb_fgets(buf,MAXB-1,gzfp)==0 )
01023 {
01024 error = E_UNESPECTEDEOF;
01025 goto error;
01026 }
01027 header.append(buf);
01028
01029 if( strncmp(buf,HEADER,strlen(HEADER)) )
01030 {
01031 error = E_NOTHEADER;
01032 goto error;
01033 }
01034
01035
01036
01037
01038 if( pb_fgets(buf,MAXB-1,gzfp)==0 )
01039 {
01040 error = E_UNESPECTEDEOF;
01041 goto error;
01042 }
01043 header.append(buf);
01044 #ifdef __MINGW32__
01045 token = strtok(buf,SEP);
01046 #else
01047 char *tokenPtr;
01048 token = strtok_r(buf,SEP,&tokenPtr);
01049 #endif
01050 if(token==0)
01051 {
01052 error = E_UNESPECTEDEOF;
01053 goto error;
01054 }
01055 if( strcmp(token,FORMAT) )
01056 {
01057 error = E_NOFORMAT;
01058 goto error;
01059 }
01060 #ifdef __MINGW32__
01061 token = strtok(0,SEP);
01062 #else
01063 token = strtok_r(0,SEP,&tokenPtr);
01064 #endif
01065 if(token==0)
01066 {
01067 error = E_UNESPECTEDEOF;
01068 goto error;
01069 }
01070 if( !strcmp(token,TASCII) )
01071 format = F_ASCII;
01072 else if( !strcmp(token,TBINBIG) )
01073 format = F_BINBIG;
01074 else if( !strcmp(token,TBINLITTLE) )
01075 format = F_BINLITTLE;
01076 else
01077 {
01078 error = E_NOFORMAT;
01079 goto error;
01080 }
01081 #ifdef __MINGW32__
01082 token = strtok(0,SEP);
01083 #else
01084 token = strtok_r(0,SEP,&tokenPtr);
01085 #endif
01086 if(token==0)
01087 {
01088 error = E_UNESPECTEDEOF;
01089 goto error;
01090 }
01091 version = float(atof(token));
01092
01093
01094 curelement = 0;
01095 for(;;)
01096 {
01097 if( pb_fgets(buf,MAXB-1,gzfp)==0 )
01098 {
01099 error = E_UNESPECTEDEOF;
01100 goto error;
01101 }
01102 header.append(buf);
01103
01104 #ifdef __MINGW32__
01105 token = strtok(buf,SEP);
01106 #else
01107 token = strtok_r(buf,SEP,&tokenPtr);
01108 #endif
01109 if(token==0)
01110 {
01111 error = E_UNESPECTEDEOF;
01112 goto error;
01113 }
01114
01115 if( !strcmp(token,COMMENT) )
01116 {
01117 comments.push_back( string(token+strlen(token)+1) );
01118
01119 }
01120 else if( !strcmp(token,OBJ_INFO) )
01121 {
01122 comments.push_back( string(token+strlen(token)+1) );
01123
01124 }
01125 else if( !strcmp(token,ENDHEADER) )
01126 {
01127 break;
01128 }
01129 else if( !strcmp(token,ELEMENT) )
01130 {
01131
01132 #ifdef __MINGW32__
01133 char * name = strtok(0,SEP);
01134 #else
01135 char * name = strtok_r(0,SEP,&tokenPtr);
01136 #endif
01137 if(name==0)
01138 {
01139 error = E_SYNTAX;
01140 goto error;
01141 }
01142
01143 #ifdef __MINGW32__
01144 token = strtok(0,SEP);
01145 #else
01146 token = strtok_r(0,SEP,&tokenPtr);
01147 #endif
01148 if(name==0)
01149 {
01150 error = E_SYNTAX;
01151 goto error;
01152 }
01153 int number = atoi(token);
01154
01155 PlyElement t(name,number);
01156 elements.push_back(t);
01157 curelement = &(elements.back());
01158 }
01159 else if( !strcmp(token,PROPERTY) )
01160 {
01161 if(curelement==0)
01162 {
01163 error = E_PROPOUTOFELEMENT;
01164 goto error;
01165 }
01166 #ifdef __MINGW32__
01167 token = strtok(0,SEP);
01168 #else
01169 token = strtok_r(0,SEP,&tokenPtr);
01170 #endif
01171 if(token==0)
01172 {
01173 error = E_SYNTAX;
01174 goto error;
01175 }
01176 if( !strcmp(token,LIST) )
01177 {
01178 #ifdef __MINGW32__
01179 token = strtok(0,SEP);
01180 #else
01181 token = strtok_r(0,SEP,&tokenPtr);
01182 #endif
01183 if(token==0)
01184 {
01185 error = E_SYNTAX;
01186 goto error;
01187 }
01188 int t2 = FindType(token);
01189 if(t2==-1)
01190 {
01191 error = E_BADTYPENAME;
01192 goto error;
01193 }
01194 #ifdef __MINGW32__
01195 token = strtok(0,SEP);
01196 #else
01197 token = strtok_r(0,SEP,&tokenPtr);
01198 #endif
01199 if(token==0)
01200 {
01201 error = E_SYNTAX;
01202 goto error;
01203 }
01204 int t1 = FindType(token);
01205 if(t1==-1)
01206 {
01207 error = E_BADTYPENAME;
01208 goto error;
01209 }
01210 #ifdef __MINGW32__
01211 token = strtok(0,SEP);
01212 #else
01213 token = strtok_r(0,SEP,&tokenPtr);
01214 #endif
01215 if(token==0)
01216 {
01217 error = E_SYNTAX;
01218 goto error;
01219 }
01220
01221 curelement->AddProp(token,t1,1,t2);
01222 }
01223 else
01224 {
01225 int t1 = FindType(token);
01226 if(t1==-1)
01227 {
01228 error = E_BADTYPENAME;
01229 goto error;
01230 }
01231 #ifdef __MINGW32__
01232 token = strtok(0,SEP);
01233 #else
01234 token = strtok_r(0,SEP,&tokenPtr);
01235 #endif
01236 if(token==0)
01237 {
01238 error = E_SYNTAX;
01239 goto error;
01240 }
01241 curelement->AddProp(token,t1,0,T_NOTYPE);
01242 }
01243 }
01244 else
01245 {
01246 error = E_SYNTAX;
01247 goto error;
01248 }
01249
01250 }
01251
01252 if(format==F_ASCII)
01253 ReadCB = ReadAscii;
01254 else
01255 ReadCB = ReadBin;
01256
01257 return 0;
01258
01259 error:
01260 Destroy();
01261 return -1;
01262 }
01263
01264
01265 int PlyFile::OpenWrite( const char * )
01266 {
01267
01268 assert(0);
01269 return -1;
01270 }
01271
01272
01273
01274
01275 int PlyFile::FindType( const char * name ) const
01276 {
01277 int i;
01278 assert(name);
01279
01280 for(i=1;i<9;++i)
01281 if( !strcmp(name,typenames[i]) || !strcmp(name,newtypenames[i]))
01282 return i;
01283 return -1;
01284 }
01285
01286 PlyElement * PlyFile::FindElement( const char * na )
01287 {
01288 assert(na);
01289 vector<PlyElement>::iterator i;
01290
01291 for(i=elements.begin();i!=elements.end();++i)
01292 if( i->name == na )
01293 return &*i;
01294 return 0;
01295 }
01296
01297 int PlyFile::AddToRead(
01298 const char * elemname,
01299 const char * propname,
01300 int stotype1,
01301 int memtype1,
01302 size_t offset1,
01303 int islist,
01304 int alloclist,
01305 int stotype2,
01306 int memtype2,
01307 size_t offset2
01308 )
01309 {
01310 assert(elemname);
01311 PlyElement * e = FindElement(elemname);
01312 if(e==0)
01313 {
01314 error = E_ELEMNOTFOUND;
01315 return -1;
01316 }
01317
01318 int r = e->AddToRead(propname,stotype1,memtype1,offset1,islist,
01319 alloclist,stotype2,memtype2,offset2 );
01320
01321 if(r==E_NOERROR)
01322 return 0;
01323 else
01324 {
01325 error = r;
01326 return -1;
01327 }
01328 }
01329
01330 const char * PlyFile::ElemName( int i )
01331 {
01332 if(i<0 || i>=int(elements.size()))
01333 return 0;
01334 else
01335 return elements[i].name.c_str();
01336 }
01337
01338 int PlyFile::ElemNumber( int i ) const
01339 {
01340 if(i<0 || i>=int(elements.size()))
01341 return 0;
01342 else
01343 return elements[i].number;
01344 }
01345
01346
01347
01348 static bool cb_skip_bin1( GZFILE fp, void * , PropDescriptor * )
01349 {
01350 char dummy[1];
01351
01352 assert(fp);
01353 return pb_fread(dummy,1,1,fp)!=0;
01354 }
01355
01356 static bool cb_skip_bin2( GZFILE fp, void * , PropDescriptor * )
01357 {
01358 char dummy[2];
01359
01360 assert(fp);
01361 return pb_fread(dummy,1,2,fp)!=0;
01362 }
01363
01364 static bool cb_skip_bin4( GZFILE fp, void * , PropDescriptor * )
01365 {
01366 char dummy[4];
01367
01368 assert(fp);
01369 return pb_fread(dummy,1,4,fp)!=0;
01370 }
01371
01372 static bool cb_skip_bin8( GZFILE fp, void * , PropDescriptor * )
01373 {
01374 char dummy[8];
01375
01376 assert(fp);
01377 return pb_fread(dummy,1,8,fp)!=0;
01378 }
01379
01380 static bool cb_skip_float_ascii( GZFILE fp, void * , PropDescriptor * )
01381 {
01382 float dummy;
01383
01384 assert(fp);
01385 return fscanf(fp,"%f",&dummy)!=EOF;
01386 }
01387
01388 static bool cb_skip_int_ascii( GZFILE fp, void * , PropDescriptor * )
01389 {
01390 int dummy;
01391
01392 assert(fp);
01393 return fscanf(fp,"%d",&dummy)!=EOF;
01394 }
01395
01396
01397 static bool cb_read_chch( GZFILE fp, void * mem, PropDescriptor * d )
01398 {
01399 return pb_fread( ((char *)mem)+d->offset1,1,1,fp)!=0;
01400 }
01401
01402 static bool cb_read_chsh( GZFILE fp, void * mem, PropDescriptor * d )
01403 {
01404 char c;
01405 if( pb_fread(&c,1,1,fp)==0) return false;
01406 return true;
01407
01408 *(short *)(((char *)mem)+d->offset1) = short(c);
01409 return true;
01410 }
01411
01412 static bool cb_read_chin( GZFILE fp, void * mem, PropDescriptor * d )
01413 {
01414 char c;
01415 if( pb_fread(&c,1,1,fp)==0) return false;
01416 return true;
01417
01418 *(int *)(((char *)mem)+d->offset1) = int(c);
01419 return true;
01420 }
01421
01422 static bool cb_read_chuc( GZFILE fp, void * mem, PropDescriptor * d )
01423 {
01424 char c;
01425 if( pb_fread(&c,1,1,fp)==0) return false;
01426 return true;
01427
01428 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01429 return true;
01430 }
01431
01432 static bool cb_read_chus( GZFILE fp, void * mem, PropDescriptor * d )
01433 {
01434 char c;
01435 if( pb_fread(&c,1,1,fp)==0) return false;
01436 return true;
01437
01438 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01439 return true;
01440 }
01441
01442 static bool cb_read_chui( GZFILE fp, void * mem, PropDescriptor * d )
01443 {
01444 char c;
01445 if( pb_fread(&c,1,1,fp)==0) return false;
01446 return true;
01447
01448 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01449 return true;
01450 }
01451
01452 static bool cb_read_chfl( GZFILE fp, void * mem, PropDescriptor * d )
01453 {
01454 char c;
01455 if( pb_fread(&c,1,1,fp)==0) return false;
01456 return true;
01457
01458 *(float *)(((char *)mem)+d->offset1) = float(c);
01459 return true;
01460 }
01461
01462 static bool cb_read_chdo( GZFILE fp, void * mem, PropDescriptor * d )
01463 {
01464 char c;
01465 if( pb_fread(&c,1,1,fp)==0) return false;
01466 return true;
01467
01468 *(double *)(((char *)mem)+d->offset1) = double(c);
01469 return true;
01470 }
01471
01472
01473
01474 static bool cb_read_shch( GZFILE fp, void * mem, PropDescriptor * d )
01475 {
01476 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01477
01478 *(char *)(((char *)mem)+d->offset1) = char(c);
01479 return true;
01480 }
01481
01482 static bool cb_read_shsh( GZFILE fp, void * mem, PropDescriptor * d )
01483 {
01484 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01485
01486 *(short *)(((char *)mem)+d->offset1) = short(c);
01487 return true;
01488 }
01489
01490 static bool cb_read_shin( GZFILE fp, void * mem, PropDescriptor * d )
01491 {
01492 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01493
01494 *(int *)(((char *)mem)+d->offset1) = int(c);
01495 return true;
01496 }
01497
01498 static bool cb_read_shuc( GZFILE fp, void * mem, PropDescriptor * d )
01499 {
01500 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01501
01502 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01503 return true;
01504 }
01505
01506 static bool cb_read_shus( GZFILE fp, void * mem, PropDescriptor * d )
01507 {
01508 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01509
01510 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01511 return true;
01512 }
01513
01514 static bool cb_read_shui( GZFILE fp, void * mem, PropDescriptor * d )
01515 {
01516 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01517
01518 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01519 return true;
01520 }
01521
01522 static bool cb_read_shfl( GZFILE fp, void * mem, PropDescriptor * d )
01523 {
01524 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01525
01526 *(float *)(((char *)mem)+d->offset1) = float(c);
01527 return true;
01528 }
01529
01530 static bool cb_read_shdo( GZFILE fp, void * mem, PropDescriptor * d )
01531 {
01532 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
01533
01534 *(double *)(((char *)mem)+d->offset1) = double(c);
01535 return true;
01536 }
01537
01538
01539
01540
01541 static bool cb_read_inch( GZFILE fp, void * mem, PropDescriptor * d )
01542 {
01543 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01544
01545 *(char *)(((char *)mem)+d->offset1) = char(c);
01546 return true;
01547 }
01548
01549 static bool cb_read_insh( GZFILE fp, void * mem, PropDescriptor * d )
01550 {
01551 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01552
01553 *(short *)(((char *)mem)+d->offset1) = short(c);
01554 return true;
01555 }
01556
01557 static bool cb_read_inin( GZFILE fp, void * mem, PropDescriptor * d )
01558 {
01559 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01560
01561 *(int *)(((char *)mem)+d->offset1) = int(c);
01562 return true;
01563 }
01564
01565 static bool cb_read_inuc( GZFILE fp, void * mem, PropDescriptor * d )
01566 {
01567 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01568
01569 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01570 return true;
01571 }
01572
01573 static bool cb_read_inus( GZFILE fp, void * mem, PropDescriptor * d )
01574 {
01575 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01576
01577 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01578 return true;
01579 }
01580
01581 static bool cb_read_inui( GZFILE fp, void * mem, PropDescriptor * d )
01582 {
01583 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01584
01585 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01586 return true;
01587 }
01588
01589 static bool cb_read_infl( GZFILE fp, void * mem, PropDescriptor * d )
01590 {
01591 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01592
01593 *(float *)(((char *)mem)+d->offset1) = float(c);
01594 return true;
01595 }
01596
01597 static bool cb_read_indo( GZFILE fp, void * mem, PropDescriptor * d )
01598 {
01599 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
01600
01601 *(double *)(((char *)mem)+d->offset1) = double(c);
01602 return true;
01603 }
01604
01605
01606
01607 static bool cb_read_ucch( GZFILE fp, void * mem, PropDescriptor * d )
01608 {
01609 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01610
01611 *(char *)(((char *)mem)+d->offset1) = char(c);
01612 return true;
01613 }
01614
01615 static bool cb_read_ucsh( GZFILE fp, void * mem, PropDescriptor * d )
01616 {
01617 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01618
01619 *(short *)(((char *)mem)+d->offset1) = short(c);
01620 return true;
01621 }
01622
01623 static bool cb_read_ucin( GZFILE fp, void * mem, PropDescriptor * d )
01624 {
01625 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01626
01627 *(int *)(((char *)mem)+d->offset1) = int(c);
01628 return true;
01629 }
01630
01631 static bool cb_read_ucuc( GZFILE fp, void * mem, PropDescriptor * d )
01632 {
01633 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01634
01635 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01636 return true;
01637 }
01638
01639 static bool cb_read_ucus( GZFILE fp, void * mem, PropDescriptor * d )
01640 {
01641 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01642
01643 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01644 return true;
01645 }
01646
01647 static bool cb_read_ucui( GZFILE fp, void * mem, PropDescriptor * d )
01648 {
01649 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01650
01651 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01652 return true;
01653 }
01654
01655 static bool cb_read_ucfl( GZFILE fp, void * mem, PropDescriptor * d )
01656 {
01657 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01658
01659 *(float *)(((char *)mem)+d->offset1) = float(c);
01660 return true;
01661 }
01662
01663 static bool cb_read_ucdo( GZFILE fp, void * mem, PropDescriptor * d )
01664 {
01665 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
01666
01667 *(double *)(((char *)mem)+d->offset1) = double(c);
01668 return true;
01669 }
01670
01671
01672
01673
01674 static bool cb_read_usch( GZFILE fp, void * mem, PropDescriptor * d )
01675 {
01676 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01677
01678 *(char *)(((char *)mem)+d->offset1) = char(c);
01679 return true;
01680 }
01681
01682 static bool cb_read_ussh( GZFILE fp, void * mem, PropDescriptor * d )
01683 {
01684 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01685
01686 *(short *)(((char *)mem)+d->offset1) = short(c);
01687 return true;
01688 }
01689
01690 static bool cb_read_usin( GZFILE fp, void * mem, PropDescriptor * d )
01691 {
01692 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01693
01694 *(int *)(((char *)mem)+d->offset1) = int(c);
01695 return true;
01696 }
01697
01698 static bool cb_read_usuc( GZFILE fp, void * mem, PropDescriptor * d )
01699 {
01700 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01701
01702 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01703 return true;
01704 }
01705
01706 static bool cb_read_usus( GZFILE fp, void * mem, PropDescriptor * d )
01707 {
01708 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01709
01710 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01711 return true;
01712 }
01713
01714 static bool cb_read_usui( GZFILE fp, void * mem, PropDescriptor * d )
01715 {
01716 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01717
01718 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01719 return true;
01720 }
01721
01722 static bool cb_read_usfl( GZFILE fp, void * mem, PropDescriptor * d )
01723 {
01724 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01725
01726 *(float *)(((char *)mem)+d->offset1) = float(c);
01727 return true;
01728 }
01729
01730 static bool cb_read_usdo( GZFILE fp, void * mem, PropDescriptor * d )
01731 {
01732 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
01733
01734 *(double *)(((char *)mem)+d->offset1) = double(c);
01735 return true;
01736 }
01737
01738
01739
01740
01741 static bool cb_read_uich( GZFILE fp, void * mem, PropDescriptor * d )
01742 {
01743 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01744
01745 *(char *)(((char *)mem)+d->offset1) = char(c);
01746 return true;
01747 }
01748
01749 static bool cb_read_uish( GZFILE fp, void * mem, PropDescriptor * d )
01750 {
01751 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01752
01753 *(short *)(((char *)mem)+d->offset1) = short(c);
01754 return true;
01755 }
01756
01757 static bool cb_read_uiin( GZFILE fp, void * mem, PropDescriptor * d )
01758 {
01759 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01760
01761 *(int *)(((char *)mem)+d->offset1) = int(c);
01762 return true;
01763 }
01764
01765 static bool cb_read_uiuc( GZFILE fp, void * mem, PropDescriptor * d )
01766 {
01767 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01768
01769 *(uchar *)(((char *)mem)+d->offset1) = uchar(c);
01770 return true;
01771 }
01772
01773 static bool cb_read_uius( GZFILE fp, void * mem, PropDescriptor * d )
01774 {
01775 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01776
01777 *(ushort *)(((char *)mem)+d->offset1) = ushort(c);
01778 return true;
01779 }
01780
01781 static bool cb_read_uiui( GZFILE fp, void * mem, PropDescriptor * d )
01782 {
01783 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01784
01785 *(uint *)(((char *)mem)+d->offset1) = uint(c);
01786 return true;
01787 }
01788
01789 static bool cb_read_uifl( GZFILE fp, void * mem, PropDescriptor * d )
01790 {
01791 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01792
01793 *(float *)(((char *)mem)+d->offset1) = float(c);
01794 return true;
01795 }
01796
01797 static bool cb_read_uido( GZFILE fp, void * mem, PropDescriptor * d )
01798 {
01799 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
01800
01801 *(double *)(((char *)mem)+d->offset1) = double(c);
01802 return true;
01803 }
01804
01805
01806
01807 static bool cb_read_flfl( GZFILE fp, void * mem, PropDescriptor * d )
01808 {
01809 float c; if( ReadFloatB(fp,&c,d->format)==0 ) return false;
01810
01811 *(float *)(((char *)mem)+d->offset1) = float(c);
01812 return true;
01813 }
01814
01815 static bool cb_read_fldo( GZFILE fp, void * mem, PropDescriptor * d )
01816 {
01817 float c; if( ReadFloatB(fp,&c,d->format)==0 ) return false;
01818
01819 *(double *)(((char *)mem)+d->offset1) = double(c);
01820 return true;
01821 }
01822
01823 static bool cb_read_dofl( GZFILE fp, void * mem, PropDescriptor * d )
01824 {
01825 double c; if( ReadDoubleB(fp,&c,d->format)==0 ) return false;
01826
01827 *(float *)(((char *)mem)+d->offset1) = float(c);
01828 return true;
01829 }
01830
01831 static bool cb_read_dodo( GZFILE fp, void * mem, PropDescriptor * d )
01832 {
01833 double c; if( ReadDoubleB(fp,&c,d->format)==0 ) return false;
01834
01835 *(double *)(((char *)mem)+d->offset1) = double(c);
01836 return true;
01837 }
01838
01839
01840
01841 static bool cb_read_ascii( GZFILE fp, void * mem, PropDescriptor * d )
01842 {
01843 return ReadScalarA(fp, ((char *)mem)+d->offset1, d->stotype1, d->memtype1)!=0;
01844 }
01845
01846
01847 const int SKIP_MAX_BUF = 512;
01848
01849 static bool cb_skip_list_bin1( GZFILE fp, void * , PropDescriptor * )
01850 {
01851 char skip_buf[SKIP_MAX_BUF];
01852 uchar n;
01853
01854 if( pb_fread(&n,1,1,fp)==0 ) return false;
01855
01856 if( pb_fread(skip_buf,1,n,fp)==0) return false;
01857 return true;
01858 }
01859
01860 static bool cb_skip_list_bin2( GZFILE fp, void * , PropDescriptor * )
01861 {
01862 char skip_buf[SKIP_MAX_BUF];
01863 uchar n;
01864
01865 if( pb_fread(&n,1,1,fp)==0 ) return false;
01866
01867 if( pb_fread(skip_buf,2,n,fp)==0) return false;
01868 return true;
01869 }
01870
01871 static bool cb_skip_list_bin4( GZFILE fp, void * , PropDescriptor * )
01872 {
01873 char skip_buf[SKIP_MAX_BUF];
01874 uchar n;
01875
01876 if( pb_fread(&n,1,1,fp)==0 ) return false;
01877
01878 if( pb_fread(skip_buf,4,n,fp)==0) return false;
01879 return true;
01880 }
01881
01882 static bool cb_skip_list_bin8( GZFILE fp, void * , PropDescriptor * )
01883 {
01884 char skip_buf[SKIP_MAX_BUF];
01885 uchar n;
01886
01887 if( pb_fread(&n,1,1,fp)==0 ) return false;
01888
01889 if( pb_fread(skip_buf,8,n,fp)==0) return false;
01890 return true;
01891 }
01892
01893 static bool cb_skip_list_ascii ( GZFILE fp, void * , PropDescriptor * )
01894 {
01895 int i,n;
01896
01897 if( !ReadScalarA(fp,&n,T_INT, T_INT) )return false;
01898 for(i=0;i<n;++i)
01899
01900 if( !SkipScalarA(fp,T_FLOAT) )
01901 return false;
01902 return true;
01903 }
01904
01905
01906 static bool cb_read_list_ascii( GZFILE fp, void * mem, PropDescriptor * d )
01907 {
01908 int i,n;
01909
01910 if( ReadIntA(fp,&n)==0) return false;
01911
01912
01913 char * store;
01914
01915 StoreInt( ((char *)mem)+d->offset2, d->memtype2, n);
01916
01917 if(d->alloclist)
01918 {
01919 store = (char *)calloc(n,TypeSize[d->memtype1]);
01920 assert(store);
01921 *(char **)(((char *)mem)+d->offset1) = store;
01922 }
01923 else
01924 {
01925 store = ((char *)mem)+d->offset1;
01926 }
01927
01928 for(i=0;i<n;++i)
01929 {
01930 if( !ReadScalarA(
01931 fp,
01932 store+i*TypeSize[d->memtype1],
01933 d->stotype1,
01934 d->memtype1
01935 ) )
01936 return 0;
01937 }
01938 return true;
01939 }
01940
01941
01942
01943 static bool cb_read_list_chch( GZFILE fp, void * mem, PropDescriptor * d )
01944 {
01945 uchar n,i;
01946 if( pb_fread(&n,1,1,fp)==0 ) return false;
01947 char * store;
01948 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
01949 if(d->alloclist)
01950 {
01951 store = (char *)calloc(n,sizeof(char));
01952 assert(store);
01953 *(char **)(((char *)mem)+d->offset1) = store;
01954 }
01955 else
01956 store = ((char *)mem)+d->offset1;
01957
01958 for(i=0;i<n;++i)
01959 if( pb_fread( store+i*sizeof(char),1,1,fp)==0 ) return false;
01960 return true;
01961 }
01962
01963 static bool cb_read_list_chsh( GZFILE fp, void * mem, PropDescriptor * d )
01964 {
01965 uchar n,i;
01966 if( pb_fread(&n,1,1,fp)==0 ) return false;
01967 char * store;
01968 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
01969 if(d->alloclist)
01970 {
01971 store = (char *)calloc(n,sizeof(short));
01972 assert(store);
01973 *(char **)(((char *)mem)+d->offset1) = store;
01974 }
01975 else
01976 store = ((char *)mem)+d->offset1;
01977
01978 for(i=0;i<n;++i)
01979 {
01980 char c;
01981 if( pb_fread(&c,1,1,fp)==0) return false;
01982 *(short *)(store+i*sizeof(short)) = short(c);
01983 }
01984 return true;
01985 }
01986
01987 static bool cb_read_list_chin( GZFILE fp, void * mem, PropDescriptor * d )
01988 {
01989 uchar n,i;
01990 if( pb_fread(&n,1,1,fp)==0 ) return false;
01991 char * store;
01992 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
01993 if(d->alloclist)
01994 {
01995 store = (char *)calloc(n,sizeof(int));
01996 assert(store);
01997 *(char **)(((char *)mem)+d->offset1) = store;
01998 }
01999 else
02000 store = ((char *)mem)+d->offset1;
02001
02002 for(i=0;i<n;++i)
02003 {
02004 char c;
02005 if( pb_fread(&c,1,1,fp)==0) return false;
02006 *(int *)(store+i*sizeof(int)) = int(c);
02007 }
02008 return true;
02009 }
02010
02011 static bool cb_read_list_chuc( GZFILE fp, void * mem, PropDescriptor * d )
02012 {
02013 uchar n,i;
02014 if( pb_fread(&n,1,1,fp)==0 ) return false;
02015 char * store;
02016 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02017 if(d->alloclist)
02018 {
02019 store = (char *)calloc(n,sizeof(uchar));
02020 assert(store);
02021 *(char **)(((char *)mem)+d->offset1) = store;
02022 }
02023 else
02024 store = ((char *)mem)+d->offset1;
02025
02026 for(i=0;i<n;++i)
02027 {
02028 char c;
02029 if( pb_fread(&c,1,1,fp)==0) return false;
02030 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02031 }
02032 return true;
02033 }
02034
02035 static bool cb_read_list_chus( GZFILE fp, void * mem, PropDescriptor * d )
02036 {
02037 uchar n,i;
02038 if( pb_fread(&n,1,1,fp)==0 ) return false;
02039 char * store;
02040 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02041 if(d->alloclist)
02042 {
02043 store = (char *)calloc(n,sizeof(ushort));
02044 assert(store);
02045 *(char **)(((char *)mem)+d->offset1) = store;
02046 }
02047 else
02048 store = ((char *)mem)+d->offset1;
02049
02050 for(i=0;i<n;++i)
02051 {
02052 char c;
02053 if( pb_fread(&c,1,1,fp)==0) return false;
02054 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
02055 }
02056 return true;
02057 }
02058
02059 static bool cb_read_list_chui( GZFILE fp, void * mem, PropDescriptor * d )
02060 {
02061 uchar n,i;
02062 if( pb_fread(&n,1,1,fp)==0 ) return false;
02063 char * store;
02064 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02065 if(d->alloclist)
02066 {
02067 store = (char *)calloc(n,sizeof(uint));
02068 assert(store);
02069 *(char **)(((char *)mem)+d->offset1) = store;
02070 }
02071 else
02072 store = ((char *)mem)+d->offset1;
02073
02074 for(i=0;i<n;++i)
02075 {
02076 char c;
02077 if( pb_fread(&c,1,1,fp)==0) return false;
02078 *(uint *)(store+i*sizeof(uint)) = uint(c);
02079 }
02080 return true;
02081 }
02082
02083 static bool cb_read_list_chfl( GZFILE fp, void * mem, PropDescriptor * d )
02084 {
02085 uchar n,i;
02086 if( pb_fread(&n,1,1,fp)==0 ) return false;
02087 char * store;
02088 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02089 if(d->alloclist)
02090 {
02091 store = (char *)calloc(n,sizeof(float));
02092 assert(store);
02093 *(char **)(((char *)mem)+d->offset1) = store;
02094 }
02095 else
02096 store = ((char *)mem)+d->offset1;
02097
02098 for(i=0;i<n;++i)
02099 {
02100 char c;
02101 if( pb_fread(&c,1,1,fp)==0) return false;
02102 *(float *)(store+i*sizeof(float)) = float(c);
02103 }
02104 return true;
02105 }
02106
02107 static bool cb_read_list_chdo( GZFILE fp, void * mem, PropDescriptor * d )
02108 {
02109 uchar n,i;
02110 if( pb_fread(&n,1,1,fp)==0 ) return false;
02111 char * store;
02112 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02113 if(d->alloclist)
02114 {
02115 store = (char *)calloc(n,sizeof(double));
02116 assert(store);
02117 *(char **)(((char *)mem)+d->offset1) = store;
02118 }
02119 else
02120 store = ((char *)mem)+d->offset1;
02121
02122 for(i=0;i<n;++i)
02123 {
02124 char c;
02125 if( pb_fread(&c,1,1,fp)==0) return false;
02126 *(double *)(store+i*sizeof(float)) = double(c);
02127 }
02128 return true;
02129 }
02130
02131
02132
02133 static bool cb_read_list_shch( GZFILE fp, void * mem, PropDescriptor * d )
02134 {
02135 uchar n,i;
02136 if( pb_fread(&n,1,1,fp)==0 ) return false;
02137 char * store;
02138 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02139 if(d->alloclist)
02140 {
02141 store = (char *)calloc(n,sizeof(char));
02142 assert(store);
02143 *(char **)(((char *)mem)+d->offset1) = store;
02144 }
02145 else
02146 store = ((char *)mem)+d->offset1;
02147
02148 for(i=0;i<n;++i)
02149 {
02150 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02151 *(char *)(store+i*sizeof(char)) = char(c);
02152 }
02153 return true;
02154 }
02155
02156 static bool cb_read_list_shsh( GZFILE fp, void * mem, PropDescriptor * d )
02157 {
02158 uchar n,i;
02159 if( pb_fread(&n,1,1,fp)==0 ) return false;
02160 char * store;
02161 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02162 if(d->alloclist)
02163 {
02164 store = (char *)calloc(n,sizeof(short));
02165 assert(store);
02166 *(char **)(((char *)mem)+d->offset1) = store;
02167 }
02168 else
02169 store = ((char *)mem)+d->offset1;
02170
02171 for(i=0;i<n;++i)
02172 {
02173 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02174 *(short *)(store+i*sizeof(short)) = short(c);
02175 }
02176 return true;
02177 }
02178
02179 static bool cb_read_list_shin( GZFILE fp, void * mem, PropDescriptor * d )
02180 {
02181 uchar n,i;
02182 if( pb_fread(&n,1,1,fp)==0 ) return false;
02183 char * store;
02184 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02185 if(d->alloclist)
02186 {
02187 store = (char *)calloc(n,sizeof(int));
02188 assert(store);
02189 *(char **)(((char *)mem)+d->offset1) = store;
02190 }
02191 else
02192 store = ((char *)mem)+d->offset1;
02193
02194 for(i=0;i<n;++i)
02195 {
02196 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02197 *(int *)(store+i*sizeof(int)) = int(c);
02198 }
02199 return true;
02200 }
02201
02202 static bool cb_read_list_shuc( GZFILE fp, void * mem, PropDescriptor * d )
02203 {
02204 uchar n,i;
02205 if( pb_fread(&n,1,1,fp)==0 ) return false;
02206 char * store;
02207 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02208 if(d->alloclist)
02209 {
02210 store = (char *)calloc(n,sizeof(uchar));
02211 assert(store);
02212 *(char **)(((char *)mem)+d->offset1) = store;
02213 }
02214 else
02215 store = ((char *)mem)+d->offset1;
02216
02217 for(i=0;i<n;++i)
02218 {
02219 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02220 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02221 }
02222 return true;
02223 }
02224
02225 static bool cb_read_list_shus( GZFILE fp, void * mem, PropDescriptor * d )
02226 {
02227 uchar n,i;
02228 if( pb_fread(&n,1,1,fp)==0 ) return false;
02229 char * store;
02230 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02231 if(d->alloclist)
02232 {
02233 store = (char *)calloc(n,sizeof(ushort));
02234 assert(store);
02235 *(char **)(((char *)mem)+d->offset1) = store;
02236 }
02237 else
02238 store = ((char *)mem)+d->offset1;
02239
02240 for(i=0;i<n;++i)
02241 {
02242 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02243 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
02244 }
02245 return true;
02246 }
02247
02248 static bool cb_read_list_shui( GZFILE fp, void * mem, PropDescriptor * d )
02249 {
02250 uchar n,i;
02251 if( pb_fread(&n,1,1,fp)==0 ) return false;
02252 char * store;
02253 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02254 if(d->alloclist)
02255 {
02256 store = (char *)calloc(n,sizeof(uint));
02257 assert(store);
02258 *(char **)(((char *)mem)+d->offset1) = store;
02259 }
02260 else
02261 store = ((char *)mem)+d->offset1;
02262
02263 for(i=0;i<n;++i)
02264 {
02265 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02266 *(uint *)(store+i*sizeof(uint)) = uint(c);
02267 }
02268 return true;
02269 }
02270
02271 static bool cb_read_list_shfl( GZFILE fp, void * mem, PropDescriptor * d )
02272 {
02273 uchar n,i;
02274 if( pb_fread(&n,1,1,fp)==0 ) return false;
02275 char * store;
02276 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02277 if(d->alloclist)
02278 {
02279 store = (char *)calloc(n,sizeof(float));
02280 assert(store);
02281 *(char **)(((char *)mem)+d->offset1) = store;
02282 }
02283 else
02284 store = ((char *)mem)+d->offset1;
02285
02286 for(i=0;i<n;++i)
02287 {
02288 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02289 *(float *)(store+i*sizeof(float)) = float(c);
02290 }
02291 return true;
02292 }
02293
02294 static bool cb_read_list_shdo( GZFILE fp, void * mem, PropDescriptor * d )
02295 {
02296 uchar n,i;
02297 if( pb_fread(&n,1,1,fp)==0 ) return false;
02298 char * store;
02299 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02300 if(d->alloclist)
02301 {
02302 store = (char *)calloc(n,sizeof(double));
02303 assert(store);
02304 *(char **)(((char *)mem)+d->offset1) = store;
02305 }
02306 else
02307 store = ((char *)mem)+d->offset1;
02308
02309 for(i=0;i<n;++i)
02310 {
02311 short c; if( ReadShortB(fp,&c,d->format)==0) return false;
02312 *(double *)(store+i*sizeof(double)) = double(c);
02313 }
02314 return true;
02315 }
02316
02317
02318
02319
02320 static bool cb_read_list_inch( GZFILE fp, void * mem, PropDescriptor * d )
02321 {
02322 uchar n,i;
02323 if( pb_fread(&n,1,1,fp)==0 ) return false;
02324 char * store;
02325 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02326 if(d->alloclist)
02327 {
02328 store = (char *)calloc(n,sizeof(char));
02329 assert(store);
02330 *(char **)(((char *)mem)+d->offset1) = store;
02331 }
02332 else
02333 store = ((char *)mem)+d->offset1;
02334
02335 for(i=0;i<n;++i)
02336 {
02337 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02338 *(char *)(store+i*sizeof(char)) = char(c);
02339 }
02340 return true;
02341 }
02342
02343 static bool cb_read_list_insh( GZFILE fp, void * mem, PropDescriptor * d )
02344 {
02345 uchar n,i;
02346 if( pb_fread(&n,1,1,fp)==0 ) return false;
02347 char * store;
02348 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02349 if(d->alloclist)
02350 {
02351 store = (char *)calloc(n,sizeof(short));
02352 assert(store);
02353 *(char **)(((char *)mem)+d->offset1) = store;
02354 }
02355 else
02356 store = ((char *)mem)+d->offset1;
02357
02358 for(i=0;i<n;++i)
02359 {
02360 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02361 *(short *)(store+i*sizeof(short)) = short(c);
02362 }
02363 return true;
02364 }
02365
02366 static bool cb_read_list_inin( GZFILE fp, void * mem, PropDescriptor * d )
02367 {
02368
02369
02370 int n=0,i;
02371 switch(d->stotype2)
02372 {
02373 case T_CHAR : { char val; if( ReadCharB(fp,&val,d->format)==0 ) return false; n=val; } break;
02374 case T_UCHAR : { uchar val; if( ReadUCharB(fp,&val,d->format)==0 ) return false; n=val; } break;
02375 case T_SHORT : { short val; if( ReadShortB(fp,&val,d->format)==0 ) return false; n=val; } break;
02376 case T_UINT : { uint val; if( ReadUIntB(fp,&val,d->format)==0 ) return false; n=val; } break;
02377 case T_INT : { int val; if( ReadIntB(fp,&val,d->format)==0 ) return false; n=val; } break;
02378 default: assert(0); break;
02379 }
02380 char * store;
02381 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02382 if(d->alloclist)
02383 {
02384 store = (char *)calloc(n,sizeof(int));
02385 assert(store);
02386 *(char **)(((char *)mem)+d->offset1) = store;
02387 }
02388 else
02389 store = ((char *)mem)+d->offset1;
02390
02391 for(i=0;i<n;++i)
02392 {
02393 if( ReadIntB(fp,(int *)(store+i*sizeof(int)),d->format)==0 ) return false;
02394 }
02395 return true;
02396 }
02397
02398 static bool cb_read_list_inuc( GZFILE fp, void * mem, PropDescriptor * d )
02399 {
02400 uchar n,i;
02401 if( pb_fread(&n,1,1,fp)==0 ) return false;
02402 char * store;
02403 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02404 if(d->alloclist)
02405 {
02406 store = (char *)calloc(n,sizeof(uchar));
02407 assert(store);
02408 *(char **)(((char *)mem)+d->offset1) = store;
02409 }
02410 else
02411 store = ((char *)mem)+d->offset1;
02412
02413 for(i=0;i<n;++i)
02414 {
02415 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02416 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02417 }
02418 return true;
02419 }
02420
02421 static bool cb_read_list_inus( GZFILE fp, void * mem, PropDescriptor * d )
02422 {
02423 uchar n,i;
02424 if( pb_fread(&n,1,1,fp)==0 ) return false;
02425 char * store;
02426 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02427 if(d->alloclist)
02428 {
02429 store = (char *)calloc(n,sizeof(ushort));
02430 assert(store);
02431 *(char **)(((char *)mem)+d->offset1) = store;
02432 }
02433 else
02434 store = ((char *)mem)+d->offset1;
02435
02436 for(i=0;i<n;++i)
02437 {
02438 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02439 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
02440 }
02441 return true;
02442 }
02443
02444 static bool cb_read_list_inui( GZFILE fp, void * mem, PropDescriptor * d )
02445 {
02446 uchar n,i;
02447 if( pb_fread(&n,1,1,fp)==0 ) return false;
02448 char * store;
02449 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02450 if(d->alloclist)
02451 {
02452 store = (char *)calloc(n,sizeof(uint));
02453 assert(store);
02454 *(char **)(((char *)mem)+d->offset1) = store;
02455 }
02456 else
02457 store = ((char *)mem)+d->offset1;
02458
02459 for(i=0;i<n;++i)
02460 {
02461 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02462 *(uint *)(store+i*sizeof(uint)) = uint(c);
02463 }
02464 return true;
02465 }
02466
02467 static bool cb_read_list_infl( GZFILE fp, void * mem, PropDescriptor * d )
02468 {
02469 uchar n,i;
02470 if( pb_fread(&n,1,1,fp)==0 ) return false;
02471 char * store;
02472 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02473 if(d->alloclist)
02474 {
02475 store = (char *)calloc(n,sizeof(float));
02476 assert(store);
02477 *(char **)(((char *)mem)+d->offset1) = store;
02478 }
02479 else
02480 store = ((char *)mem)+d->offset1;
02481
02482 for(i=0;i<n;++i)
02483 {
02484 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02485 *(float *)(store+i*sizeof(float)) = float(c);
02486 }
02487 return true;
02488 }
02489
02490 static bool cb_read_list_indo( GZFILE fp, void * mem, PropDescriptor * d )
02491 {
02492 uchar n,i;
02493 if( pb_fread(&n,1,1,fp)==0 ) return false;
02494 char * store;
02495 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02496 if(d->alloclist)
02497 {
02498 store = (char *)calloc(n,sizeof(double));
02499 assert(store);
02500 *(char **)(((char *)mem)+d->offset1) = store;
02501 }
02502 else
02503 store = ((char *)mem)+d->offset1;
02504
02505 for(i=0;i<n;++i)
02506 {
02507 int c; if( ReadIntB(fp,&c,d->format)==0 ) return false;
02508 *(double *)(store+i*sizeof(double)) = double(c);
02509 }
02510 return true;
02511 }
02512
02513
02514
02515 static bool cb_read_list_ucch( GZFILE fp, void * mem, PropDescriptor * d )
02516 {
02517 uchar n,i;
02518 if( pb_fread(&n,1,1,fp)==0 ) return false;
02519 char * store;
02520 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02521 if(d->alloclist)
02522 {
02523 store = (char *)calloc(n,sizeof(char));
02524 assert(store);
02525 *(char **)(((char *)mem)+d->offset1) = store;
02526 }
02527 else
02528 store = ((char *)mem)+d->offset1;
02529
02530 for(i=0;i<n;++i)
02531 {
02532 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02533 *(char *)(store+i*sizeof(char)) = char(c);
02534 }
02535 return true;
02536 }
02537
02538 static bool cb_read_list_ucsh( GZFILE fp, void * mem, PropDescriptor * d )
02539 {
02540 uchar n,i;
02541 if( pb_fread(&n,1,1,fp)==0 ) return false;
02542 char * store;
02543 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02544 if(d->alloclist)
02545 {
02546 store = (char *)calloc(n,sizeof(short));
02547 assert(store);
02548 *(char **)(((char *)mem)+d->offset1) = store;
02549 }
02550 else
02551 store = ((char *)mem)+d->offset1;
02552
02553 for(i=0;i<n;++i)
02554 {
02555 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02556 *(short *)(store+i*sizeof(short)) = short(c);
02557 }
02558 return true;
02559 }
02560
02561 static bool cb_read_list_ucin( GZFILE fp, void * mem, PropDescriptor * d )
02562 {
02563 uchar n,i;
02564 if( pb_fread(&n,1,1,fp)==0 ) return false;
02565 char * store;
02566 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02567 if(d->alloclist)
02568 {
02569 store = (char *)calloc(n,sizeof(int));
02570 assert(store);
02571 *(char **)(((char *)mem)+d->offset1) = store;
02572 }
02573 else
02574 store = ((char *)mem)+d->offset1;
02575
02576 for(i=0;i<n;++i)
02577 {
02578 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02579 *(int *)(store+i*sizeof(int)) = int(c);
02580 }
02581 return true;
02582 }
02583
02584 static bool cb_read_list_ucuc( GZFILE fp, void * mem, PropDescriptor * d )
02585 {
02586 uchar n,i;
02587 if( pb_fread(&n,1,1,fp)==0 ) return false;
02588 char * store;
02589 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02590 if(d->alloclist)
02591 {
02592 store = (char *)calloc(n,sizeof(uchar));
02593 assert(store);
02594 *(char **)(((char *)mem)+d->offset1) = store;
02595 }
02596 else
02597 store = ((char *)mem)+d->offset1;
02598
02599 for(i=0;i<n;++i)
02600 {
02601 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02602 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02603 }
02604 return true;
02605 }
02606
02607 static bool cb_read_list_ucus( GZFILE fp, void * mem, PropDescriptor * d )
02608 {
02609 uchar n,i;
02610 if( pb_fread(&n,1,1,fp)==0 ) return false;
02611 char * store;
02612 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02613 if(d->alloclist)
02614 {
02615 store = (char *)calloc(n,sizeof(ushort));
02616 assert(store);
02617 *(char **)(((char *)mem)+d->offset1) = store;
02618 }
02619 else
02620 store = ((char *)mem)+d->offset1;
02621
02622 for(i=0;i<n;++i)
02623 {
02624 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02625 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
02626 }
02627 return true;
02628 }
02629
02630 static bool cb_read_list_ucui( GZFILE fp, void * mem, PropDescriptor * d )
02631 {
02632 uchar n,i;
02633 if( pb_fread(&n,1,1,fp)==0 ) return false;
02634 char * store;
02635 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02636 if(d->alloclist)
02637 {
02638 store = (char *)calloc(n,sizeof(uint));
02639 assert(store);
02640 *(char **)(((char *)mem)+d->offset1) = store;
02641 }
02642 else
02643 store = ((char *)mem)+d->offset1;
02644
02645 for(i=0;i<n;++i)
02646 {
02647 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02648 *(uint *)(store+i*sizeof(uint)) = uint(c);
02649 }
02650 return true;
02651 }
02652
02653 static bool cb_read_list_ucfl( GZFILE fp, void * mem, PropDescriptor * d )
02654 {
02655 uchar n,i;
02656 if( pb_fread(&n,1,1,fp)==0 ) return false;
02657 char * store;
02658 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02659 if(d->alloclist)
02660 {
02661 store = (char *)calloc(n,sizeof(float));
02662 assert(store);
02663 *(char **)(((char *)mem)+d->offset1) = store;
02664 }
02665 else
02666 store = ((char *)mem)+d->offset1;
02667
02668 for(i=0;i<n;++i)
02669 {
02670 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02671 *(float *)(store+i*sizeof(float)) = float(c);
02672 }
02673 return true;
02674 }
02675
02676 static bool cb_read_list_ucdo( GZFILE fp, void * mem, PropDescriptor * d )
02677 {
02678 uchar n,i;
02679 if( pb_fread(&n,1,1,fp)==0 ) return false;
02680 char * store;
02681 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02682 if(d->alloclist)
02683 {
02684 store = (char *)calloc(n,sizeof(double));
02685 assert(store);
02686 *(char **)(((char *)mem)+d->offset1) = store;
02687 }
02688 else
02689 store = ((char *)mem)+d->offset1;
02690
02691 for(i=0;i<n;++i)
02692 {
02693 uchar c; if( pb_fread(&c,1,1,fp)==0 ) return false;
02694 *(double *)(store+i*sizeof(double)) = double(c);
02695 }
02696 return true;
02697 }
02698
02699
02700
02701
02702 static bool cb_read_list_usch( GZFILE fp, void * mem, PropDescriptor * d )
02703 {
02704 uchar n,i;
02705 if( pb_fread(&n,1,1,fp)==0 ) return false;
02706 char * store;
02707 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02708 if(d->alloclist)
02709 {
02710 store = (char *)calloc(n,sizeof(char));
02711 assert(store);
02712 *(char **)(((char *)mem)+d->offset1) = store;
02713 }
02714 else
02715 store = ((char *)mem)+d->offset1;
02716
02717 for(i=0;i<n;++i)
02718 {
02719 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02720 *(char *)(store+i*sizeof(char)) = char(c);
02721 }
02722 return true;
02723 }
02724
02725 static bool cb_read_list_ussh( GZFILE fp, void * mem, PropDescriptor * d )
02726 {
02727 uchar n,i;
02728 if( pb_fread(&n,1,1,fp)==0 ) return false;
02729 char * store;
02730 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02731 if(d->alloclist)
02732 {
02733 store = (char *)calloc(n,sizeof(short));
02734 assert(store);
02735 *(char **)(((char *)mem)+d->offset1) = store;
02736 }
02737 else
02738 store = ((char *)mem)+d->offset1;
02739
02740 for(i=0;i<n;++i)
02741 {
02742 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02743 *(short *)(store+i*sizeof(short)) = short(c);
02744 }
02745 return true;
02746 }
02747
02748 static bool cb_read_list_usin( GZFILE fp, void * mem, PropDescriptor * d )
02749 {
02750 uchar n,i;
02751 if( pb_fread(&n,1,1,fp)==0 ) return false;
02752 char * store;
02753 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02754 if(d->alloclist)
02755 {
02756 store = (char *)calloc(n,sizeof(int));
02757 assert(store);
02758 *(char **)(((char *)mem)+d->offset1) = store;
02759 }
02760 else
02761 store = ((char *)mem)+d->offset1;
02762
02763 for(i=0;i<n;++i)
02764 {
02765 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02766 *(int *)(store+i*sizeof(int)) = int(c);
02767 }
02768 return true;
02769 }
02770
02771 static bool cb_read_list_usuc( GZFILE fp, void * mem, PropDescriptor * d )
02772 {
02773 uchar n,i;
02774 if( pb_fread(&n,1,1,fp)==0 ) return false;
02775 char * store;
02776 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02777 if(d->alloclist)
02778 {
02779 store = (char *)calloc(n,sizeof(uchar));
02780 assert(store);
02781 *(char **)(((char *)mem)+d->offset1) = store;
02782 }
02783 else
02784 store = ((char *)mem)+d->offset1;
02785
02786 for(i=0;i<n;++i)
02787 {
02788 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02789 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02790 }
02791 return true;
02792 }
02793
02794 static bool cb_read_list_usus( GZFILE fp, void * mem, PropDescriptor * d )
02795 {
02796 uchar n,i;
02797 if( pb_fread(&n,1,1,fp)==0 ) return false;
02798 char * store;
02799 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02800 if(d->alloclist)
02801 {
02802 store = (char *)calloc(n,sizeof(ushort));
02803 assert(store);
02804 *(char **)(((char *)mem)+d->offset1) = store;
02805 }
02806 else
02807 store = ((char *)mem)+d->offset1;
02808
02809 for(i=0;i<n;++i)
02810 {
02811 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02812 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
02813 }
02814 return true;
02815 }
02816
02817 static bool cb_read_list_usui( GZFILE fp, void * mem, PropDescriptor * d )
02818 {
02819 uchar n,i;
02820 if( pb_fread(&n,1,1,fp)==0 ) return false;
02821 char * store;
02822 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02823 if(d->alloclist)
02824 {
02825 store = (char *)calloc(n,sizeof(uint));
02826 assert(store);
02827 *(char **)(((char *)mem)+d->offset1) = store;
02828 }
02829 else
02830 store = ((char *)mem)+d->offset1;
02831
02832 for(i=0;i<n;++i)
02833 {
02834 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02835 *(uint *)(store+i*sizeof(uint)) = uint(c);
02836 }
02837 return true;
02838 }
02839
02840 static bool cb_read_list_usfl( GZFILE fp, void * mem, PropDescriptor * d )
02841 {
02842 uchar n,i;
02843 if( pb_fread(&n,1,1,fp)==0 ) return false;
02844 char * store;
02845 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02846 if(d->alloclist)
02847 {
02848 store = (char *)calloc(n,sizeof(float));
02849 assert(store);
02850 *(char **)(((char *)mem)+d->offset1) = store;
02851 }
02852 else
02853 store = ((char *)mem)+d->offset1;
02854
02855 for(i=0;i<n;++i)
02856 {
02857 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02858 *(float *)(store+i*sizeof(float)) = float(c);
02859 }
02860 return true;
02861 }
02862
02863 static bool cb_read_list_usdo( GZFILE fp, void * mem, PropDescriptor * d )
02864 {
02865 uchar n,i;
02866 if( pb_fread(&n,1,1,fp)==0 ) return false;
02867 char * store;
02868 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02869 if(d->alloclist)
02870 {
02871 store = (char *)calloc(n,sizeof(double));
02872 assert(store);
02873 *(char **)(((char *)mem)+d->offset1) = store;
02874 }
02875 else
02876 store = ((char *)mem)+d->offset1;
02877
02878 for(i=0;i<n;++i)
02879 {
02880 ushort c; if( ReadUShortB(fp,&c,d->format)==0) return false;
02881 *(double *)(store+i*sizeof(double)) = double(c);
02882 }
02883 return true;
02884 }
02885
02886
02887
02888
02889 static bool cb_read_list_uich( GZFILE fp, void * mem, PropDescriptor * d )
02890 {
02891 uchar n,i;
02892 if( pb_fread(&n,1,1,fp)==0 ) return false;
02893 char * store;
02894 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02895 if(d->alloclist)
02896 {
02897 store = (char *)calloc(n,sizeof(char));
02898 assert(store);
02899 *(char **)(((char *)mem)+d->offset1) = store;
02900 }
02901 else
02902 store = ((char *)mem)+d->offset1;
02903
02904 for(i=0;i<n;++i)
02905 {
02906 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
02907 *(char *)(store+i*sizeof(char)) = char(c);
02908 }
02909 return true;
02910 }
02911
02912 static bool cb_read_list_uish( GZFILE fp, void * mem, PropDescriptor * d )
02913 {
02914 uchar n,i;
02915 if( pb_fread(&n,1,1,fp)==0 ) return false;
02916 char * store;
02917 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02918 if(d->alloclist)
02919 {
02920 store = (char *)calloc(n,sizeof(short));
02921 assert(store);
02922 *(char **)(((char *)mem)+d->offset1) = store;
02923 }
02924 else
02925 store = ((char *)mem)+d->offset1;
02926
02927 for(i=0;i<n;++i)
02928 {
02929 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
02930 *(short *)(store+i*sizeof(short)) = short(c);
02931 }
02932 return true;
02933 }
02934
02935 static bool cb_read_list_uiin( GZFILE fp, void * mem, PropDescriptor * d )
02936 {
02937 uchar n,i;
02938 if( pb_fread(&n,1,1,fp)==0 ) return false;
02939 char * store;
02940 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02941 if(d->alloclist)
02942 {
02943 store = (char *)calloc(n,sizeof(int));
02944 assert(store);
02945 *(char **)(((char *)mem)+d->offset1) = store;
02946 }
02947 else
02948 store = ((char *)mem)+d->offset1;
02949
02950 for(i=0;i<n;++i)
02951 {
02952 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
02953 *(int *)(store+i*sizeof(int)) = int(c);
02954 }
02955 return true;
02956 }
02957
02958 static bool cb_read_list_uiuc( GZFILE fp, void * mem, PropDescriptor * d )
02959 {
02960 uchar n,i;
02961 if( pb_fread(&n,1,1,fp)==0 ) return false;
02962 char * store;
02963 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02964 if(d->alloclist)
02965 {
02966 store = (char *)calloc(n,sizeof(uchar));
02967 assert(store);
02968 *(char **)(((char *)mem)+d->offset1) = store;
02969 }
02970 else
02971 store = ((char *)mem)+d->offset1;
02972
02973 for(i=0;i<n;++i)
02974 {
02975 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
02976 *(uchar *)(store+i*sizeof(uchar)) = uchar(c);
02977 }
02978 return true;
02979 }
02980
02981 static bool cb_read_list_uius( GZFILE fp, void * mem, PropDescriptor * d )
02982 {
02983 uchar n,i;
02984 if( pb_fread(&n,1,1,fp)==0 ) return false;
02985 char * store;
02986 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
02987 if(d->alloclist)
02988 {
02989 store = (char *)calloc(n,sizeof(ushort));
02990 assert(store);
02991 *(char **)(((char *)mem)+d->offset1) = store;
02992 }
02993 else
02994 store = ((char *)mem)+d->offset1;
02995
02996 for(i=0;i<n;++i)
02997 {
02998 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
02999 *(ushort *)(store+i*sizeof(ushort)) = ushort(c);
03000 }
03001 return true;
03002 }
03003
03004 static bool cb_read_list_uiui( GZFILE fp, void * mem, PropDescriptor * d )
03005 {
03006 uchar n,i;
03007 if( pb_fread(&n,1,1,fp)==0 ) return false;
03008 char * store;
03009 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03010 if(d->alloclist)
03011 {
03012 store = (char *)calloc(n,sizeof(uint));
03013 assert(store);
03014 *(char **)(((char *)mem)+d->offset1) = store;
03015 }
03016 else
03017 store = ((char *)mem)+d->offset1;
03018
03019 for(i=0;i<n;++i)
03020 {
03021 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
03022 *(uint *)(store+i*sizeof(uint)) = uint(c);
03023 }
03024 return true;
03025 }
03026
03027 static bool cb_read_list_uifl( GZFILE fp, void * mem, PropDescriptor * d )
03028 {
03029 uchar n,i;
03030 if( pb_fread(&n,1,1,fp)==0 ) return false;
03031 char * store;
03032 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03033 if(d->alloclist)
03034 {
03035 store = (char *)calloc(n,sizeof(float));
03036 assert(store);
03037 *(char **)(((char *)mem)+d->offset1) = store;
03038 }
03039 else
03040 store = ((char *)mem)+d->offset1;
03041
03042 for(i=0;i<n;++i)
03043 {
03044 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
03045 *(float *)(store+i*sizeof(float)) = float(c);
03046 }
03047 return true;
03048 }
03049
03050 static bool cb_read_list_uido( GZFILE fp, void * mem, PropDescriptor * d )
03051 {
03052 uchar n,i;
03053 if( pb_fread(&n,1,1,fp)==0 ) return false;
03054 char * store;
03055 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03056 if(d->alloclist)
03057 {
03058 store = (char *)calloc(n,sizeof(double));
03059 assert(store);
03060 *(char **)(((char *)mem)+d->offset1) = store;
03061 }
03062 else
03063 store = ((char *)mem)+d->offset1;
03064
03065 for(i=0;i<n;++i)
03066 {
03067 uint c; if( ReadUIntB(fp,&c,d->format)==0 ) return false;
03068 *(double *)(store+i*sizeof(double)) = double(c);
03069 }
03070 return true;
03071 }
03072
03073
03074
03075 static bool cb_read_list_flfl( GZFILE fp, void * mem, PropDescriptor * d )
03076 {
03077 uchar n,i;
03078 if( pb_fread(&n,1,1,fp)==0 ) return false;
03079 char * store;
03080 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03081 if(d->alloclist)
03082 {
03083 store = (char *)calloc(n,sizeof(float));
03084 assert(store);
03085 *(char **)(((char *)mem)+d->offset1) = store;
03086 }
03087 else
03088 store = ((char *)mem)+d->offset1;
03089
03090 for(i=0;i<n;++i)
03091 {
03092 float c; if( ReadFloatB(fp,&c,d->format)==0 ) return false;
03093 *(float *)(store+i*sizeof(float)) = float(c);
03094 }
03095 return true;
03096 }
03097
03098 static bool cb_read_list_fldo( GZFILE fp, void * mem, PropDescriptor * d )
03099 {
03100 uchar n,i;
03101 if( pb_fread(&n,1,1,fp)==0 ) return false;
03102 char * store;
03103 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03104 if(d->alloclist)
03105 {
03106 store = (char *)calloc(n,sizeof(double));
03107 assert(store);
03108 *(char **)(((char *)mem)+d->offset1) = store;
03109 }
03110 else
03111 store = ((char *)mem)+d->offset1;
03112
03113 for(i=0;i<n;++i)
03114 {
03115 float c; if( ReadFloatB(fp,&c,d->format)==0 ) return false;
03116 *(double *)(store+i*sizeof(double)) = double(c);
03117 }
03118 return true;
03119 }
03120
03121 static bool cb_read_list_dofl( GZFILE fp, void * mem, PropDescriptor * d )
03122 {
03123 uchar n,i;
03124 if( pb_fread(&n,1,1,fp)==0 ) return false;
03125 char * store;
03126 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03127 if(d->alloclist)
03128 {
03129 store = (char *)calloc(n,sizeof(float));
03130 assert(store);
03131 *(char **)(((char *)mem)+d->offset1) = store;
03132 }
03133 else
03134 store = ((char *)mem)+d->offset1;
03135
03136 for(i=0;i<n;++i)
03137 {
03138 double c; if( ReadDoubleB(fp,&c,d->format)==0 ) return false;
03139 *(float *)(store+i*sizeof(float)) = float(c);
03140 }
03141 return true;
03142 }
03143
03144 static bool cb_read_list_dodo( GZFILE fp, void * mem, PropDescriptor * d )
03145 {
03146 uchar n,i;
03147 if( pb_fread(&n,1,1,fp)==0 ) return false;
03148 char * store;
03149 StoreInt( ((char *)mem)+d->offset2, d->memtype2, int(n));
03150 if(d->alloclist)
03151 {
03152 store = (char *)calloc(n,sizeof(double));
03153 assert(store);
03154 *(char **)(((char *)mem)+d->offset1) = store;
03155 }
03156 else
03157 store = ((char *)mem)+d->offset1;
03158
03159 for(i=0;i<n;++i)
03160 {
03161 double c; if( ReadDoubleB(fp,&c,d->format)==0 ) return false;
03162 *(double *)(store+i*sizeof(double)) = double(c);
03163 }
03164 return true;
03165 }
03166
03167
03168
03169 void PlyFile::compile( PlyProperty * p )
03170 {
03171 p->desc.format = format;
03172
03173 if(format==F_ASCII)
03174 {
03175 if(p->islist)
03176 {
03177 if(p->bestored)
03178 p->cb = cb_read_list_ascii;
03179 else
03180 p->cb = cb_skip_list_ascii;
03181 }
03182 else
03183 {
03184 if(p->bestored)
03185 {
03186 p->cb = cb_read_ascii;
03187 }
03188 else
03189 {
03190 switch(p->tipo)
03191 {
03192 case T_CHAR:
03193 case T_SHORT:
03194 case T_INT:
03195 case T_UCHAR:
03196 case T_USHORT:
03197 case T_UINT:
03198 p->cb = cb_skip_int_ascii;
03199 break;
03200 case T_FLOAT:
03201 case T_DOUBLE:
03202 p->cb = cb_skip_float_ascii;
03203 break;
03204 default: p->cb = 0; assert(0); break;
03205 }
03206 }
03207 }
03208 }
03209 else
03210 {
03211 if(p->islist)
03212 {
03213 if(p->bestored)
03214 {
03215 switch(p->desc.stotype1)
03216 {
03217 case T_CHAR:
03218 switch(p->desc.memtype1)
03219 {
03220 case T_CHAR: p->cb = cb_read_list_chch; break;
03221 case T_SHORT: p->cb = cb_read_list_chsh; break;
03222 case T_INT: p->cb = cb_read_list_chin; break;
03223 case T_UCHAR: p->cb = cb_read_list_chuc; break;
03224 case T_USHORT: p->cb = cb_read_list_chus; break;
03225 case T_UINT: p->cb = cb_read_list_chui; break;
03226 case T_FLOAT: p->cb = cb_read_list_chfl; break;
03227 case T_DOUBLE: p->cb = cb_read_list_chdo; break;
03228 default: assert(0);
03229 }
03230 break;
03231 case T_SHORT:
03232 switch(p->desc.memtype1)
03233 {
03234 case T_CHAR: p->cb = cb_read_list_shch; break;
03235 case T_SHORT: p->cb = cb_read_list_shsh; break;
03236 case T_INT: p->cb = cb_read_list_shin; break;
03237 case T_UCHAR: p->cb = cb_read_list_shuc; break;
03238 case T_USHORT: p->cb = cb_read_list_shus; break;
03239 case T_UINT: p->cb = cb_read_list_shui; break;
03240 case T_FLOAT: p->cb = cb_read_list_shfl; break;
03241 case T_DOUBLE: p->cb = cb_read_list_shdo; break;
03242 default: assert(0);
03243 }
03244 break;
03245 case T_INT:
03246 switch(p->desc.memtype1)
03247 {
03248 case T_CHAR: p->cb = cb_read_list_inch; break;
03249 case T_SHORT: p->cb = cb_read_list_insh; break;
03250 case T_INT: p->cb = cb_read_list_inin; break;
03251 case T_UCHAR: p->cb = cb_read_list_inuc; break;
03252 case T_USHORT: p->cb = cb_read_list_inus; break;
03253 case T_UINT: p->cb = cb_read_list_inui; break;
03254 case T_FLOAT: p->cb = cb_read_list_infl; break;
03255 case T_DOUBLE: p->cb = cb_read_list_indo; break;
03256 default: assert(0);
03257 }
03258 break;
03259 case T_UCHAR:
03260 switch(p->desc.memtype1)
03261 {
03262 case T_CHAR: p->cb = cb_read_list_ucch; break;
03263 case T_SHORT: p->cb = cb_read_list_ucsh; break;
03264 case T_INT: p->cb = cb_read_list_ucin; break;
03265 case T_UCHAR: p->cb = cb_read_list_ucuc; break;
03266 case T_USHORT: p->cb = cb_read_list_ucus; break;
03267 case T_UINT: p->cb = cb_read_list_ucui; break;
03268 case T_FLOAT: p->cb = cb_read_list_ucfl; break;
03269 case T_DOUBLE: p->cb = cb_read_list_ucdo; break;
03270 default: assert(0);
03271 }
03272 break;
03273 case T_USHORT:
03274 switch(p->desc.memtype1)
03275 {
03276 case T_CHAR: p->cb = cb_read_list_usch; break;
03277 case T_SHORT: p->cb = cb_read_list_ussh; break;
03278 case T_INT: p->cb = cb_read_list_usin; break;
03279 case T_UCHAR: p->cb = cb_read_list_usuc; break;
03280 case T_USHORT: p->cb = cb_read_list_usus; break;
03281 case T_UINT: p->cb = cb_read_list_usui; break;
03282 case T_FLOAT: p->cb = cb_read_list_usfl; break;
03283 case T_DOUBLE: p->cb = cb_read_list_usdo; break;
03284 default: assert(0);
03285 }
03286 break;
03287 case T_UINT:
03288 switch(p->desc.memtype1)
03289 {
03290 case T_CHAR: p->cb = cb_read_list_uich; break;
03291 case T_SHORT: p->cb = cb_read_list_uish; break;
03292 case T_INT: p->cb = cb_read_list_uiin; break;
03293 case T_UCHAR: p->cb = cb_read_list_uiuc; break;
03294 case T_USHORT: p->cb = cb_read_list_uius; break;
03295 case T_UINT: p->cb = cb_read_list_uiui; break;
03296 case T_FLOAT: p->cb = cb_read_list_uifl; break;
03297 case T_DOUBLE: p->cb = cb_read_list_uido; break;
03298 default: assert(0);
03299 }
03300 break;
03301 case T_FLOAT:
03302 switch(p->desc.memtype1)
03303 {
03304 case T_FLOAT: p->cb = cb_read_list_flfl; break;
03305 case T_DOUBLE: p->cb = cb_read_list_fldo; break;
03306 default: assert(0);
03307 }
03308 break;
03309 case T_DOUBLE:
03310 switch(p->desc.memtype1)
03311 {
03312 case T_FLOAT: p->cb = cb_read_list_dofl; break;
03313 case T_DOUBLE: p->cb = cb_read_list_dodo; break;
03314 default: assert(0);
03315 }
03316 break;
03317 default:
03318 assert(0);
03319 }
03320 }
03321 else
03322 {
03323 switch(TypeSize[p->tipo])
03324 {
03325 case 1: p->cb = cb_skip_list_bin1; break;
03326 case 2: p->cb = cb_skip_list_bin2; break;
03327 case 4: p->cb = cb_skip_list_bin4; break;
03328 case 8: p->cb = cb_skip_list_bin8; break;
03329 default:p->cb = 0; assert(0); break;
03330 }
03331 }
03332 }
03333 else
03334 {
03335 if(p->bestored)
03336 {
03337 switch(p->desc.stotype1)
03338 {
03339 case T_CHAR:
03340 switch(p->desc.memtype1)
03341 {
03342 case T_CHAR: p->cb = cb_read_chch; break;
03343 case T_SHORT: p->cb = cb_read_chsh; break;
03344 case T_INT: p->cb = cb_read_chin; break;
03345 case T_UCHAR: p->cb = cb_read_chuc; break;
03346 case T_USHORT: p->cb = cb_read_chus; break;
03347 case T_UINT: p->cb = cb_read_chui; break;
03348 case T_FLOAT: p->cb = cb_read_chfl; break;
03349 case T_DOUBLE: p->cb = cb_read_chdo; break;
03350 default: assert(0);
03351 }
03352 break;
03353 case T_SHORT:
03354 switch(p->desc.memtype1)
03355 {
03356 case T_CHAR: p->cb = cb_read_shch; break;
03357 case T_SHORT: p->cb = cb_read_shsh; break;
03358 case T_INT: p->cb = cb_read_shin; break;
03359 case T_UCHAR: p->cb = cb_read_shuc; break;
03360 case T_USHORT: p->cb = cb_read_shus; break;
03361 case T_UINT: p->cb = cb_read_shui; break;
03362 case T_FLOAT: p->cb = cb_read_shfl; break;
03363 case T_DOUBLE: p->cb = cb_read_shdo; break;
03364 default: assert(0);
03365 }
03366 break;
03367 case T_INT:
03368 switch(p->desc.memtype1)
03369 {
03370 case T_CHAR: p->cb = cb_read_inch; break;
03371 case T_SHORT: p->cb = cb_read_insh; break;
03372 case T_INT: p->cb = cb_read_inin; break;
03373 case T_UCHAR: p->cb = cb_read_inuc; break;
03374 case T_USHORT: p->cb = cb_read_inus; break;
03375 case T_UINT: p->cb = cb_read_inui; break;
03376 case T_FLOAT: p->cb = cb_read_infl; break;
03377 case T_DOUBLE: p->cb = cb_read_indo; break;
03378 default: assert(0);
03379 }
03380 break;
03381 case T_UCHAR:
03382 switch(p->desc.memtype1)
03383 {
03384 case T_CHAR: p->cb = cb_read_ucch; break;
03385 case T_SHORT: p->cb = cb_read_ucsh; break;
03386 case T_INT: p->cb = cb_read_ucin; break;
03387 case T_UCHAR: p->cb = cb_read_ucuc; break;
03388 case T_USHORT: p->cb = cb_read_ucus; break;
03389 case T_UINT: p->cb = cb_read_ucui; break;
03390 case T_FLOAT: p->cb = cb_read_ucfl; break;
03391 case T_DOUBLE: p->cb = cb_read_ucdo; break;
03392 default: assert(0);
03393 }
03394 break;
03395 case T_USHORT:
03396 switch(p->desc.memtype1)
03397 {
03398 case T_CHAR: p->cb = cb_read_usch; break;
03399 case T_SHORT: p->cb = cb_read_ussh; break;
03400 case T_INT: p->cb = cb_read_usin; break;
03401 case T_UCHAR: p->cb = cb_read_usuc; break;
03402 case T_USHORT: p->cb = cb_read_usus; break;
03403 case T_UINT: p->cb = cb_read_usui; break;
03404 case T_FLOAT: p->cb = cb_read_usfl; break;
03405 case T_DOUBLE: p->cb = cb_read_usdo; break;
03406 default: assert(0);
03407 }
03408 break;
03409 case T_UINT:
03410 switch(p->desc.memtype1)
03411 {
03412 case T_CHAR: p->cb = cb_read_uich; break;
03413 case T_SHORT: p->cb = cb_read_uish; break;
03414 case T_INT: p->cb = cb_read_uiin; break;
03415 case T_UCHAR: p->cb = cb_read_uiuc; break;
03416 case T_USHORT: p->cb = cb_read_uius; break;
03417 case T_UINT: p->cb = cb_read_uiui; break;
03418 case T_FLOAT: p->cb = cb_read_uifl; break;
03419 case T_DOUBLE: p->cb = cb_read_uido; break;
03420 default: assert(0);
03421 }
03422 break;
03423 case T_FLOAT:
03424 switch(p->desc.memtype1)
03425 {
03426 case T_FLOAT: p->cb = cb_read_flfl; break;
03427 case T_DOUBLE: p->cb = cb_read_fldo; break;
03428 default: assert(0);
03429 }
03430 break;
03431 case T_DOUBLE:
03432 switch(p->desc.memtype1)
03433 {
03434 case T_FLOAT: p->cb = cb_read_dofl; break;
03435 case T_DOUBLE: p->cb = cb_read_dodo; break;
03436 default: assert(0);
03437 }
03438 break;
03439 default:
03440 assert(0);
03441 }
03442 }
03443 else
03444 {
03445 switch(TypeSize[p->tipo])
03446 {
03447 case 1: p->cb = cb_skip_bin1; break;
03448 case 2: p->cb = cb_skip_bin2; break;
03449 case 4: p->cb = cb_skip_bin4; break;
03450 case 8: p->cb = cb_skip_bin8; break;
03451 default:p->cb = 0; assert(0); break;
03452 }
03453 }
03454 }
03455 }
03456 }
03457
03458 void PlyFile::compile( PlyElement * e )
03459 {
03460 vector<PlyProperty>::iterator i;
03461 for(i=e->props.begin();i!=e->props.end();++i)
03462 compile(&*i);
03463 }
03464
03465
03466
03467
03468
03469 int ReadBin ( XFILE * fp, const PlyProperty * pr, void * mem, int fmt )
03470 {
03471 assert(pr);
03472
03473
03474 if(pr->islist)
03475 {
03476 int i,n;
03477
03478 if( !ReadScalarB(fp,&n,pr->tipoindex, T_INT, fmt) )
03479 return 0;
03480
03481 assert(n<12);
03482
03483
03484 if(pr->bestored)
03485 {
03486 char * store;
03487
03488 StoreInt( ((char *)mem)+pr->desc.offset2, pr->desc.memtype2, n);
03489
03490 if(pr->desc.alloclist)
03491 {
03492 store = (char *)calloc(n,TypeSize[pr->desc.memtype1]);
03493 assert(store);
03494 *(char **)(((char *)mem)+pr->desc.offset1) = store;
03495 }
03496 else
03497 {
03498 store = ((char *)mem)+pr->desc.offset1;
03499 }
03500
03501 for(i=0;i<n;++i)
03502 {
03503 if( !ReadScalarB(
03504 fp,
03505 store+i*TypeSize[pr->desc.memtype1],
03506 pr->desc.stotype1,
03507 pr->desc.memtype1,
03508 fmt
03509 ) )
03510 return 0;
03511 }
03512 }
03513
03514 else
03515 {
03516 for(i=0;i<n;i++)
03517 if( !SkipScalarB(fp,pr->tipo) )
03518 return 0;
03519 }
03520 }
03521
03522 else
03523 {
03524
03525 if(pr->bestored)
03526 return ReadScalarB(
03527 fp,
03528 ((char *)mem)+pr->desc.offset1,
03529 pr->desc.stotype1, pr->desc.memtype1,
03530 fmt
03531 );
03532
03533 else
03534 return SkipScalarB(fp,pr->tipo);
03535 }
03536
03537 return 1;
03538 }
03539
03540
03541 int ReadAscii( XFILE * fp, const PlyProperty * pr, void * mem, int )
03542 {
03543 assert(pr);
03544 assert(mem);
03545
03546
03547
03548 if(pr->islist)
03549 {
03550 int i,n;
03551
03552 if( !ReadScalarA(fp,&n,pr->tipoindex, T_INT) )
03553 return 0;
03554
03555 assert(n<12);
03556
03557
03558 if(pr->bestored)
03559 {
03560 char * store;
03561
03562 StoreInt( ((char *)mem)+pr->desc.offset2, pr->desc.memtype2, n);
03563
03564 if(pr->desc.alloclist)
03565 {
03566 store = (char *)calloc(n,TypeSize[pr->desc.memtype1]);
03567 assert(store);
03568 *(char **)(((char *)mem)+pr->desc.offset1) = store;
03569 }
03570 else
03571 {
03572 store = ((char *)mem)+pr->desc.offset1;
03573 }
03574
03575 for(i=0;i<n;++i)
03576 {
03577 if( !ReadScalarA(
03578 fp,
03579 store+i*TypeSize[pr->desc.memtype1],
03580 pr->desc.stotype1,
03581 pr->desc.memtype1
03582 ) )
03583 return 0;
03584 }
03585 }
03586
03587 else
03588 {
03589 for(i=0;i<n;++i)
03590 if( !SkipScalarA(fp,pr->tipo) )
03591 return 0;
03592 }
03593 }
03594
03595 else
03596 {
03597
03598 if(pr->bestored)
03599 return ReadScalarA(
03600 fp,
03601 ((char *)mem)+pr->desc.offset1,
03602 pr->desc.stotype1, pr->desc.memtype1
03603 );
03604
03605 else
03606 return SkipScalarA(fp,pr->tipo);
03607 }
03608 return 1;
03609 }
03610
03611
03612
03613
03614 int PlyFile::Read( void * mem )
03615 {
03616 assert(cure);
03617 assert(ReadCB);
03618
03619 vector<PlyProperty>::iterator i;
03620
03621 for(i=cure->props.begin();i!=cure->props.end();++i)
03622 {
03623 if( ! i->cb(gzfp,mem,&(i->desc)) ) return -1;
03624
03625
03626
03627
03628
03629 }
03630
03631 return 0;
03632 }
03633
03634 void interpret_texture_name(const char*a, const char*fn, char*output){
03635 int ia=0,io=0;
03636 output[0]=0;
03637 while (a[ia]!=0){
03638 if (a[ia]=='<') {
03639 if (static_cast<int>(strlen(a)) > ia+5) {
03640 if ( ( (a[ia+1]=='t') || (a[ia+1]=='T') ) &&
03641 ( (a[ia+2]=='h') || (a[ia+2]=='H') ) &&
03642 ( (a[ia+3]=='i') || (a[ia+3]=='I') ) &&
03643 ( (a[ia+4]=='s') || (a[ia+4]=='S') ) &&
03644 ( a[ia+5]=='>' ) )
03645 {
03646
03647
03648 int lastbar=0;
03649 int ifn=0;
03650 while (fn[ifn]!=0) { if ((fn[ifn]=='/') || (fn[ifn]=='\\')) lastbar=ifn+1; ifn++;}
03651 ifn=lastbar;
03652 char fn2[255];
03653 while (fn[ifn]!=0) { fn2[ifn-lastbar]=fn[ifn]; ifn++;}
03654 fn2[ifn-lastbar]=0;
03655
03656
03657 int l=ifn-lastbar;
03658 if ((fn2[l-4]=='.')
03659 && ((fn2[l-3]=='P') || (fn2[l-3]=='p'))
03660 && ((fn2[l-2]=='L') || (fn2[l-2]=='l'))
03661 && ((fn2[l-1]=='Y') || (fn2[l-1]=='y')) )
03662 fn2[l-4]=0;
03663
03664
03665 output[io]=0;
03666 sprintf(output,"%s%s",output,fn2);
03667 io=strlen(output);
03668 ia+=6;
03669 continue;
03670 };
03671 }
03672 }
03673 output[io++]=a[ia++];
03674 };
03675 output[io]=0;
03676 };
03677 }
03678 }