1 /* ************************ 2 Copyright Terrain Experts Inc. 3 Terrain Experts Inc (TERREX) reserves all rights to this source code 4 unless otherwise specified in writing by the President of TERREX. 5 This copyright may be updated in the future, in which case that version 6 supercedes this one. 7 ------------------- 8 Terrex Experts Inc. 9 4400 East Broadway #314 10 Tucson, AZ 85711 11 info@terrex.com 12 Tel: (520) 323-7990 13 ************************ 14 */ 15 16 #ifndef _trpage_io_h_ 17 #define _trpage_io_h_ 18 19 /* trpage_io.h 20 Token definitions and basic classes. 21 */ 22 23 #include <trpage_sys.h> 24 25 #ifndef TeAttrH 26 /* was unsigned long, but it is used as if it was signed in the constructor 27 * and code that set the handle are using a signed value. 28 * 01-10-2006 David Fries 29 */ 30 typedef long TeAttrHdl; 31 #endif 32 33 // Macros we may need 34 #ifndef MIN 35 // {secret} 36 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 37 #endif 38 #ifndef MAX 39 // {secret} 40 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) 41 #endif 42 43 // File header Magic Number 44 #define TRPG_MAGIC 9480372 45 46 // Current TerraPage major version 47 #define TRPG_VERSION_MAJOR 2 48 // Current TerraPage minor version 49 #define TRPG_VERSION_MINOR 2 50 51 // defined values for the version that doesn't need 52 // a merge 53 #define TRPG_NOMERGE_VERSION_MAJOR 2 54 #define TRPG_NOMERGE_VERSION_MINOR 2 55 56 // Non-existent token 57 // {secret} 58 #define TRPG_NOTOKEN 0 59 60 // 16 bit token definition value. These are values such as TRPGTEXTABLE or TRPG_ATTACH, etc... 61 typedef short trpgToken; 62 63 // Tokens for paging data structures 64 // Update the MINTOKEN and MAXTOKEN when you add tokens 65 // {secret} 66 #define TRPG_MINTOKEN 100 67 // {secret} 68 #define TRPG_PUSH 100 69 // {secret} 70 #define TRPG_POP 101 71 72 // {secret} 73 #define TRPGHEADER 200 74 // {secret} 75 #define TRPGHEAD_LODINFO 201 76 77 // {secret} 78 #define TRPGMATTABLE 300 79 // Added 11/14/98 - New material table 80 // {secret} 81 #define TRPGMATTABLE2 301 82 // Added 11/14/98 83 // {secret} 84 #define TRPGSHORTMATTABLE 302 85 86 // {secret} 87 #define TRPGMATERIAL 400 88 // {secret} 89 #define TRPGMAT_BASIC 401 90 // {secret} 91 #define TRPGMAT_SHADE 402 92 // {secret} 93 // {secret} 94 #define TRPGMAT_SIZES 403 95 // {secret} 96 #define TRPGMAT_CULL 404 97 // {secret} 98 #define TRPGMAT_ALPHA 405 99 // {secret} 100 #define TRPGMAT_NORMAL 406 101 // {secret} 102 #define TRPGMAT_TEXTURE 407 103 // {secret} 104 #define TRPGMAT_BUMP 408 105 // {secret} 106 #define TRPGMAT_ATTR 409 107 // {secret} 108 #define TRPGMAT_HANDLE 410 109 110 // {secret} 111 #define TRPGMAT_TEXENV 500 112 // {secret} 113 #define TRPGMAT_TXENV_MODE 501 114 // {secret} 115 #define TRPGMAT_TXENV_FILTER 502 116 // {secret} 117 #define TRPGMAT_TXENV_WRAP 503 118 // {secret} 119 #define TRPGMAT_TXENV_BORDER 504 120 121 // {secret} 122 #define TRPGTEXTABLE 600 123 // {secret} 124 #define TRPGTEXTABLE2 601 125 // {secret} 126 #define TRPGTEXTURE 650 127 128 // {secret} 129 #define TRPGMODELREF 700 130 // {secret} 131 #define TRPGMODELREF2 701 132 // {secret} 133 #define TRPGMODELTABLE 800 134 135 // {secret} 136 #define TRPGTILETABLE 900 137 // {secret} 138 #define TRPG_TILE_ENTRY 901 139 // {secret} 140 #define TRPGTILETABLE2 902 141 142 // {secret} 143 #define TRPGTILEHEADER 1000 144 // {secret} 145 #define TRPG_TILE_MATLIST 1001 146 // {secret} 147 #define TRPG_TILE_MODELLIST 1002 148 // {secret} 149 #define TRPG_TILE_DATE 1003 150 // {secret} 151 #define TRPGLOCALMATERIAL 1004 152 // {secret} 153 #define TRPG_TILE_LOCMATLIST 1005 154 155 156 // Lights support added by Nick 157 // {secret} 158 #define TRPGLIGHTTABLE 1100 159 // {secret} 160 #define TRPGLIGHTATTR 1150 161 // {secret} 162 #define TRPGLIGHTATTR_BASIC 1151 163 // {secret} 164 #define TRPGLIGHTATTR_RASCAL 1152 165 // {secret} 166 #define TRPGLIGHTATTR_CALLIGRAPHIC 1153 167 // {secret} 168 #define TRPGLIGHTATTR_PERFORMER 1154 169 // {secret} 170 #define TRPGLIGHTATTR_ANIMATION 1155 171 // {secret} 172 #define TRPGLIGHTATTR_COMMENT 1156 173 // {secret} 174 #define TRPGLIGHTATTR_HANDLE 1157 175 // {secret} 176 #define TRPGLIGHT 1160 177 // {secret} 178 #define TRPG_LIGHT 1160 179 180 // {secret} 181 #define TRPGRANGETABLE 1200 182 // {secret} 183 #define TRPG_RANGE 1201 184 185 // Label and style support added 12-02 186 // {secret} 187 #define TRPG_TEXT_STYLE_TABLE 1300 188 // {secret} 189 #define TRPG_TEXT_STYLE 1301 190 // {secret} 191 #define TRPG_TEXT_STYLE_BASIC 1302 192 193 // {secret} 194 #define TRPG_SUPPORT_STYLE_TABLE 1310 195 // {secret} 196 #define TRPG_SUPPORT_STYLE 1311 197 // {secret} 198 #define TRPG_SUPPORT_STYLE_BASIC 1312 199 200 // {secret} 201 #define TRPG_LABEL_PROPERTY_TABLE 1320 202 // {secret} 203 #define TRPG_LABEL_PROPERTY 1321 204 // {secret} 205 #define TRPG_LABEL_PROPERTY_BASIC 1322 206 207 208 // {secret} 209 #define TRPG_LABEL 1330 210 211 212 // {secret} 213 #define TRPG_GROUP 2001 214 // {secret} 215 #define TRPG_BILLBOARD 2002 216 // {secret} 217 #define TRPG_LOD 2003 218 // {secret} 219 #define TRPG_TRANSFORM 2004 220 // {secret} 221 #define TRPG_MODELREF 2005 222 // {secret} 223 #define TRPG_LAYER 2006 224 225 // {secret} 226 #define TRPG_GEOMETRY 3000 227 // {secret} 228 #define TRPG_GEOM_PRIM 3001 229 // {secret} 230 #define TRPG_GEOM_MATERIAL 3002 231 // {secret} 232 #define TRPG_GEOM_VERT32 3003 233 // {secret} 234 #define TRPG_GEOM_VERT64 3004 235 // {secret} 236 #define TRPG_GEOM_NORM32 3005 237 // {secret} 238 #define TRPG_GEOM_NORM64 3006 239 // {secret} 240 #define TRPG_GEOM_COLOR 3007 241 // {secret} 242 #define TRPG_GEOM_TEX32 3008 243 // {secret} 244 #define TRPG_GEOM_TEX64 3009 245 // {secret} 246 #define TRPG_GEOM_EFLAG 3010 247 248 // {secret} 249 #define TRPG_ATTACH 4000 250 251 // {secret} 252 #define TRPG_CHILDREF 5000 253 254 // {secret} 255 #define TRPG_MAXTOKEN 5000 256 257 // Basic data types 258 259 /* 64 bit disk reference value. */ 260 typedef trpgllong trpgDiskRef; 261 // {secret} 262 typedef int trpgMatRef; 263 264 /* Double precision 2 dimensional point. */ 265 TX_EXDECL class TX_CLDECL trpg2dPoint { 266 public: 267 double x, y; trpg2dPoint(void)268 trpg2dPoint (void) : x(0.0),y(0.0) { }; trpg2dPoint(double in_x,double in_y)269 trpg2dPoint (double in_x,double in_y) { x = in_x; y = in_y; }; 270 bool operator==(const trpg2dPoint& pt ) const { 271 if ( x != pt.x ) return false; 272 if ( y != pt.y ) return false; 273 return true; 274 }; 275 bool operator!=(const trpg2dPoint& pt ) const { return !operator==(pt); }; 276 }; 277 /* Integer 2 dimensional point. This is used primarily as a 2D index value. */ 278 TX_EXDECL class TX_CLDECL trpg2iPoint { 279 public: 280 int x,y; trpg2iPoint(void)281 trpg2iPoint (void) : x(0),y(0) { }; trpg2iPoint(int in_x,int in_y)282 trpg2iPoint (int in_x,int in_y) {x = in_x; y = in_y;}; 283 }; 284 /* Double precision 3 dimensional point. */ 285 TX_EXDECL class TX_CLDECL trpg3dPoint { 286 public: 287 double x,y,z; trpg3dPoint(void)288 trpg3dPoint(void) : x(0.0),y(0.0),z(0.0) { }; trpg3dPoint(double in_x,double in_y,double in_z)289 trpg3dPoint(double in_x,double in_y,double in_z) {x = in_x; y = in_y; z = in_z;} 290 bool operator==(const trpg3dPoint& pt ) const { 291 if ( x != pt.x ) return false; 292 if ( y != pt.y ) return false; 293 if ( z != pt.z ) return false; 294 return true; 295 }; 296 bool operator!=(const trpg3dPoint& pt ) const { return !operator==(pt); }; 297 }; 298 /* Simple red, green, blue color definition */ 299 TX_EXDECL class TX_CLDECL trpgColor { 300 public: trpgColor(float64 r,float64 g,float64 b)301 trpgColor(float64 r,float64 g,float64 b) {red = r; green = g; blue = b;} trpgColor(void)302 trpgColor(void) : red(1.0), green(1.0), blue(1.0) { }; 303 bool operator==(const trpgColor& color) { 304 if ( color.red != red ) return false; 305 if ( color.green != green ) return false; 306 if ( color.blue != blue ) return false; 307 return true; 308 }; 309 bool operator!=(const trpgColor& color) { return !operator==(color); }; 310 float64 red,green,blue; 311 }; 312 313 // Used to specify machine endianness 314 typedef enum {LittleEndian,BigEndian} trpgEndian; 315 316 /* This is a base class for an abstract buffer type. 317 It contains the virtual methods for writing 318 data to an abstract device. The device implementation is up 319 to the subclass. trpgReadBuffer performs the similar function 320 for reading. 321 {group:Low Level I/O} 322 */ 323 TX_EXDECL class TX_CLDECL trpgWriteBuffer { 324 public: ~trpgWriteBuffer(void)325 virtual ~trpgWriteBuffer(void) { }; 326 /* The add functions must be filled in by the child class 327 They add data of the appropriate type to the current buffer. */ 328 virtual void Add(int32) = 0; 329 virtual void Add(int64) = 0; 330 virtual void Add(const char *) = 0; 331 virtual void Add(float32) = 0; 332 virtual void Add(float64) = 0; 333 //#if (bool != int32) 334 virtual void Add(bool) = 0; 335 //#endif 336 virtual void Add(uint8) = 0; 337 #if (trpgDiskRef != int64) 338 virtual void Add(trpgDiskRef) = 0; 339 #endif 340 virtual void Add(trpgToken) = 0; 341 /* Child class method. Returns the buffer to an original state. */ 342 virtual void Reset(void) = 0; 343 // See trpgMemWriteBuffer for details 344 virtual void Begin(trpgToken) = 0; 345 // See trpgMemWriteBuffer for details 346 virtual void End(void) = 0; 347 // See trpgMemWriteBuffer for details 348 virtual void Push(void) = 0; 349 // See trpgMemWriteBuffer for details 350 virtual void Pop(void) = 0; 351 352 // Some add functions are helpers for composite values that call the basic add functions 353 virtual void Add(const trpg2iPoint &); 354 virtual void Add(const trpg2dPoint &); 355 virtual void Add(const trpg3dPoint &); 356 virtual void Add(const trpgColor &); 357 virtual void Add(const std::string &); 358 359 /* Endianness is something the child class buffer type must set and use. 360 This function returns the endianness of the current buffer. */ GetEndian(void)361 virtual trpgEndian GetEndian(void) { return ness; } 362 363 protected: 364 // Target endianness of the buffer. This should be set by the subclass on creation. 365 trpgEndian ness; 366 // Endianness of the machine we're running on. 367 trpgEndian cpuNess; 368 }; 369 370 /* The Memory Write Buffer is an implementation of the Write Buffer that 371 uses chunks of memory. It contains implementations of the all the virtual 372 methods straight to memory. This is used primarily in writing archives and 373 tiles. 374 {group:Low Level I/O} 375 */ 376 TX_EXDECL class TX_CLDECL trpgMemWriteBuffer : public trpgWriteBuffer { 377 public: 378 /* The constructor takes an endianness for this buffer. 379 Data will automatically be converted to that as it goes in. */ 380 trpgMemWriteBuffer(trpgEndian); 381 virtual ~trpgMemWriteBuffer(void); 382 // Return the current length of buffer 383 virtual int length(void) const; 384 // Return the raw data (if you want to write to disk, for example) 385 virtual const char *getData(void) const; 386 // Allocate the given amount of space for the buffer 387 virtual void setLength(unsigned int); 388 389 // Add a 32 bit integer to the buffer 390 virtual void Add(int32); 391 // Add a 64 bit integer to the buffer 392 virtual void Add(int64); 393 /* Add an arbitrary length string to the buffer. 394 This writes both the length and the string itself. 395 */ 396 virtual void Add(const char *); 397 // Same as const char * version 398 virtual void Add(const std::string &); 399 // Add a 32 bit float to the buffer 400 virtual void Add(float32); 401 // Add a 64 bit float to the buffer 402 virtual void Add(float64); 403 //#if (bool != int32) 404 // Add a boolean value to the buffer. It will become at least one byte. 405 virtual void Add(bool); 406 //#endif 407 // Add an unsigned character to the buffer 408 virtual void Add(uint8); 409 #if (trpgDiskRef != int64) 410 // Add a 64 bit disk reference to the buffer 411 virtual void Add(trpgDiskRef); 412 #endif 413 // Add a token (16 bit) to the buffer 414 virtual void Add(trpgToken); 415 // Reset this buffer. This will set the current length to zero, but will not deallocate memory 416 virtual void Reset(void); 417 /* Start defining an tokenized object. The token is put into the buffer stream 418 and the position of a size value following it is kept. When End() is called 419 the buffer will rewind to that value and save the size. This method ensures 420 that token data can be skipped if necessary. */ 421 virtual void Begin(trpgToken); 422 /* This method is called at the end of a tokenized object. See Begin for details. */ 423 virtual void End(void); 424 /* Adds the TRPG_PUSH token to the current buffer. This is done by objects 425 that have children as they're being written. See Pop as well. */ 426 virtual void Push(void); 427 /* Adds the TRPG_POP token to the current buffer. This is done by objects 428 that have defined children. See Push. */ 429 virtual void Pop(void); 430 /* Take out the pop from the end of the buffer, if there is one */ 431 /* Will return true if a pop was actually taken out */ 432 virtual bool UnPop(); 433 /* Take out the push from the end of the buffer, if there is one */ 434 /* Will return true if a push was actually taken out */ 435 virtual bool UnPush(); 436 437 protected: 438 virtual void append(unsigned int,const char *); 439 virtual void set(unsigned int pos,unsigned int len,const char *); 440 int curLen; 441 int totLen; 442 char *data; 443 std::vector<int> lengths; 444 }; 445 446 /* This is a virtual base class for reading data from a device. 447 The device implementation is left as an exercise to the sub class. 448 This class contains methods for getting data that must be filled in 449 as well as helper methods that call those. 450 {group:Low Level I/O} 451 */ 452 TX_EXDECL class TX_CLDECL trpgReadBuffer { 453 public: ~trpgReadBuffer(void)454 virtual ~trpgReadBuffer(void) { }; 455 /* The Get methods are utility routines that all call the GetData method. 456 Only that method need be filled in by a subclass. */ 457 virtual bool Get(int32 &); 458 virtual bool Get(int64 &); 459 virtual bool Get(char *,int); 460 virtual bool Get(std::string &); 461 virtual bool Get(float32 &); 462 virtual bool Get(float64 &); 463 //#if (bool != int32) 464 virtual bool Get(bool &); 465 //#endif 466 virtual bool Get(uint8 &); 467 #if (trpgDiskRef != int64) 468 virtual bool Get(trpgDiskRef &); 469 #endif 470 virtual bool Get(trpgToken &); 471 472 /* These methods return references to arrays of data of the given types. 473 These are all utility routines and depend upon GetDataRef. */ 474 virtual bool GetArray(int,float32 **); 475 virtual bool GetArray(int,float64 **); 476 virtual bool GetArray(int,int32 **); 477 virtual bool GetArray(int,trpgColor **); 478 virtual bool GetArray(int,char **); 479 480 virtual bool Get(trpg2iPoint &); 481 virtual bool Get(trpg2dPoint &); 482 virtual bool Get(trpg3dPoint &); 483 virtual bool Get(trpgColor &); 484 virtual bool GetToken(trpgToken &,int32 &); 485 486 /* Force the buffer to only allow the next N bytes to be read. 487 The limits are stack based. That is, this limit is the current one 488 until it's popped off the stack. Then it reverts to the previous one. 489 Any bytes read in the mean time count against all limits. */ 490 virtual void PushLimit(int); 491 /* Revert to the limit before this one. Typically this would happen when 492 a tokenized object has been read. */ 493 virtual void PopLimit(void); 494 /* Skip to the end of the current limit. This is done by a parser when 495 reading a tokenized object from the buffer to make sure that the next 496 object can be safely read even if the current one wasn't. */ 497 virtual bool SkipToLimit(void); 498 499 // Buffer is empty 500 virtual bool isEmpty(void) = 0; 501 502 // MD: making this public to unravel trpgModel read problem. 503 /* A utility function for subclasses to use to see if they would exceed an 504 outside imposed limit by reading the given number of bytes. */ 505 virtual bool TestLimit(int); 506 507 protected: 508 trpgEndian ness; // Endianness of the source we're reading 509 trpgEndian cpuNess; // Endiannees of the CPU 510 /* Virtual raw data retrieval function that must be implemented by a subclass. 511 It must return a given number of bytes in the array passed in. */ 512 virtual bool GetData(char *,int)=0; 513 /* Virtual raw data reference retrieval function. The difference between 514 this method and GetData is that this is supposed to return a pointer 515 to a given amount of bytes. This assumes some sort of memory caching 516 mechanism in the subclass. */ 517 virtual bool GetDataRef(char **,int)=0; 518 /* This virtual method must be filled in by the subclass so that SkipToLimit 519 will work correctly. */ 520 virtual bool Skip(int) = 0; 521 /* Utility function that must be called after a successful read to update 522 the outside imposed read limits. */ 523 virtual void UpdateLimits(int); 524 std::vector<int> limits; 525 }; 526 527 /* This class implements a read buffer that uses a chunk of memory. 528 Typically, raw data will be dumped into this class, then it will be 529 passed to a parser for object based reading. 530 {group:Low Level I/O} 531 */ 532 TX_EXDECL class TX_CLDECL trpgMemReadBuffer : public trpgReadBuffer { 533 public: 534 // Memory read buffers must be initialized with an endianness 535 trpgMemReadBuffer(trpgEndian); 536 ~trpgMemReadBuffer(void); 537 // Return true if we're out of data 538 bool isEmpty(void); 539 // Sets the size of this read buffer. 540 void SetLength(int); 541 // Gets the size of the buffer. GetLength(void)542 int GetLength(void) { return len; } 543 /* Return a pointer to the raw data cache for this object. Data will 544 be dumped straight into here (from disk, for example) and then parsed 545 by something that takes a trpgReadBuffer as input. */ 546 char *GetDataPtr(void); 547 protected: 548 bool GetData(char *,int); // Retrieve the given amount of data 549 bool GetDataRef(char **,int); // Retrieve a pointer to the given array 550 bool Skip(int); // Skip over the given amount 551 int len; // Data Length 552 int totLen; // Total allocated length 553 int pos; // Current position 554 char *data; 555 }; 556 557 /* A Checkable is purely a base class used by other classes that 558 need validity checks associated with them. By default, the 559 checkable will return false for isValid unless the valid flag is set. 560 */ 561 TX_EXDECL class TX_CLDECL trpgCheckable { 562 public: 563 trpgCheckable(void); 564 virtual ~trpgCheckable(void); 565 // Returns the state of the valid flag, or can be overridden by a subclass to do a more complex check. 566 bool isValid(void) const; 567 GetHandle()568 virtual TeAttrHdl GetHandle() const { 569 return handle; 570 } SetHandle(TeAttrHdl hdl)571 virtual void SetHandle(TeAttrHdl hdl) { 572 writeHandle = true; 573 handle = hdl; 574 } 575 576 protected: 577 /* Set this flag to true if your checkable structure doesn't have a complex 578 check it needs to do. */ 579 bool valid; 580 TeAttrHdl handle; 581 bool writeHandle; 582 }; 583 584 class trpgPrintBuffer; 585 /* The Read/Writeable is a class that knows how to read itself from a trpgReadBuffer 586 and write itself to a trpgWriteBuffer. This includes all the node and header 587 data in TerraPage. These classes are intended as marshalling points for reading 588 and writing data, not as data containers in and of themselves. If you find 589 yourself keeping a lot of classes derived from trpgReadWriteable around, you're 590 probably misusing them. 591 592 The classes derived from this one will have a lot of methods that begin with 593 "Set", "Get", and "Add". These will almost always return a bool value. This 594 is used to indicate whether the given call succeeded. In the case of "Set" and "Add" calls 595 this should always work if it possibly can. An out of range index might make it 596 fail, for example. "Get" calls will always fail if the object you're getting from 597 is not valid. Be sure to do an isValid check as soon as you've read or filled out 598 one of these objects. 599 {group:Read/Write Classes} 600 */ 601 TX_EXDECL class TX_CLDECL trpgReadWriteable : public trpgCheckable { 602 public: 603 trpgReadWriteable()604 trpgReadWriteable() { errMess[0] = '\0';} 605 606 /* The Write method is a virtual that must be filled in by the subclass. 607 It takes a trpgWriteBuffer and should return true on success. */ 608 virtual bool Write(trpgWriteBuffer &) = 0; 609 /* The Read method should be overridden by a subclass. It should read 610 the contents of the given trpgReadBuffer up to the current limit 611 into itself. It must return true on success. */ Read(trpgReadBuffer &)612 virtual bool Read(trpgReadBuffer &) { return false;}; 613 /* Every read/writeable must be able to reset itself to a pristine state 614 so that, for example, multiple objects of the same type can be read into 615 it, one after the other. */ 616 virtual void Reset(void) = 0; 617 /* The print method is optional. If it's not there, it won't do anything. 618 */ Print(trpgPrintBuffer &)619 virtual bool Print(trpgPrintBuffer &) const { return true; } 620 getErrMess()621 const char *getErrMess() const { return errMess.empty() ? 0 : errMess.c_str();} 622 623 protected: 624 625 mutable std::string errMess; 626 }; 627 628 /* Pointer into a trpgwAppFile. The full name of the file 629 is based on the context (e.g. texture vs. tile) 630 {group:Archive Writing} 631 */ 632 TX_EXDECL class TX_CLDECL trpgwAppAddress { 633 public: trpgwAppAddress()634 trpgwAppAddress() {file = -1; offset = -1; row = -1; col = -1;}; 635 // Which file 636 int32 file; 637 // Offset within the file 638 // Note: This is not a 64 bit value 639 int32 offset; 640 // Row and col are used for TerraPage 2.3 archives, so we 641 // can know which block to get the appropriate file from 642 int32 row; 643 int32 col; 644 645 }; 646 647 /* Archive File. 648 This class represents an appendable file archive used for 649 consolidating tiles and textures. 650 {group:Archive Writing} 651 */ 652 TX_EXDECL class TX_CLDECL trpgwAppFile { 653 public: trpgwAppFile()654 trpgwAppFile() {valid=false;}; 655 trpgwAppFile(trpgEndian,const char *,bool reuse=false); 656 virtual ~trpgwAppFile(void); 657 virtual bool Append(const trpgMemWriteBuffer *,const trpgMemWriteBuffer *); 658 virtual bool Append(const char *,int size); 659 virtual int64 Pos(void) const; 660 virtual int GetLengthWritten(); 661 virtual bool Flush(void); 662 virtual void Init(trpgEndian,const char *,bool reuse=false); 663 664 bool isValid(void) const; 665 protected: 666 bool valid; 667 trpgEndian ness,cpuNess; 668 FILE *fp; 669 int lengthSoFar; 670 }; 671 672 /* Archive File - Read version. 673 This class represents an appendable file archive from the 674 read perspective. This is the same type of file written by 675 trpgwAppFile. 676 */ 677 TX_EXDECL class TX_CLDECL trpgrAppFile { 678 public: trpgrAppFile()679 trpgrAppFile() {valid=false;}; 680 trpgrAppFile(trpgEndian,const char *); 681 // real construction is here 682 virtual void Init(trpgEndian,const char *); 683 virtual ~trpgrAppFile(void); 684 virtual bool Read(trpgMemReadBuffer *,int32 offset); 685 virtual bool Read(char *data,int32 baseOffset,int32 objOffset,int32 dataSize); 686 687 bool isValid(void) const; 688 protected: 689 bool valid; 690 trpgEndian ness,cpuNess; 691 FILE *fp; 692 }; 693 694 /* Archive File Cache. 695 This class keeps 696 */ 697 TX_EXDECL class TX_CLDECL trpgrAppFileCache { 698 public: trpgrAppFileCache()699 trpgrAppFileCache(){;}; 700 trpgrAppFileCache(const char *prefix,const char *ext,int noFiles=32); 701 // real construction is here 702 virtual void Init(const char *prefix,const char *ext,int noFiles); 703 virtual ~trpgrAppFileCache(void); 704 virtual trpgrAppFile *GetFile(trpgEndian ness,int id,int col,int row); 705 virtual trpgrAppFile *GetFile(trpgEndian ness,int id); 706 virtual trpgrAppFile *GetNewRAppFile(trpgEndian ness, const char *fileName); 707 protected: 708 // Prefix name and extension 709 char baseName[1024],ext[20]; 710 711 class OpenFile { 712 public: 713 OpenFile(void); 714 int id; // ID of open file 715 int row; 716 int col; 717 trpgrAppFile *afile; 718 int lastUsed; // When the file was last accessed 719 }; 720 721 std::vector<OpenFile> files; 722 int timeCount; // Incremented for every access 723 }; 724 725 #endif 726