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