Bullet Collision Detection & Physics Library
bFile.h
Go to the documentation of this file.
1 /*
2 bParse
3 Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
4 
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10 
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15 
16 #ifndef __BFILE_H__
17 #define __BFILE_H__
18 
19 #include "bCommon.h"
20 #include "bChunk.h"
21 #include <stdio.h>
22 
23 namespace bParse {
24 
25  // ----------------------------------------------------- //
27  {
29  FD_OK =1,
37  };
38 
40  {
45  };
46  // ----------------------------------------------------- //
47  class bFile
48  {
49  protected:
50 
51  char m_headerString[7];
52 
54  char* mFileBuffer;
55  int mFileLen;
56  int mVersion;
57 
58 
60 
64 
67 
70 
71  //
72 
74 
75 
76  int mFlags;
77 
78  // ////////////////////////////////////////////////////////////////////////////
79 
80  // buffer offset util
81  int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags);
82  void safeSwapPtr(char *dst, const char *src);
83 
84  virtual void parseHeader();
85 
86  virtual void parseData() = 0;
87 
89  void resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode);
90 
91  int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion);
92  //void swapPtr(char *dst, char *src);
93 
94  void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers);
95  void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers);
96  char* getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos);
97 
98 
99  void swap(char *head, class bChunkInd& ch, bool ignoreEndianFlag);
100  void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag);
101  void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag);
102  void swapLen(char *dataPtr);
103  void swapDNA(char* ptr);
104 
105 
106  char* readStruct(char *head, class bChunkInd& chunk);
107  char *getAsString(int code);
108 
109  void parseInternal(int verboseMode, char* memDna,int memDnaLength);
110 
111  public:
112  bFile(const char *filename, const char headerString[7]);
113 
114  //todo: make memoryBuffer const char
115  //bFile( const char *memoryBuffer, int len);
116  bFile( char *memoryBuffer, int len, const char headerString[7]);
117  virtual ~bFile();
118 
120  {
121  return mFileDNA;
122  }
123 
124  virtual void addDataBlock(char* dataBlock) = 0;
125 
126  int getFlags() const
127  {
128  return mFlags;
129  }
130 
132  {
133  return mLibPointers;
134  }
135 
136  void* findLibPointer(void *ptr);
137 
138  bool ok();
139 
140  virtual void parse(int verboseMode) = 0;
141 
142  virtual int write(const char* fileName, bool fixupPointers=false) = 0;
143 
144  virtual void writeChunks(FILE* fp, bool fixupPointers );
145 
146  virtual void writeDNA(FILE* fp) = 0;
147 
148  void updateOldPointers();
149  void resolvePointers(int verboseMode);
150 
151  void dumpChunks(bDNA* dna);
152 
153  int getVersion() const
154  {
155  return mVersion;
156  }
157  //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped
158  void preSwap();
159  void writeFile(const char* fileName);
160 
161  };
162 }
163 
164 
165 #endif//__BFILE_H__
int getVersion() const
Definition: bFile.h:153
virtual void writeDNA(FILE *fp)=0
void resolvePointersChunk(const bChunkInd &dataChunk, int verboseMode)
this loop only works fine if the Blender DNA structure of the file matches the headerfiles ...
Definition: bFile.cpp:1227
btAlignedObjectArray< char * > m_pointerPtrFixupArray
Definition: bFile.h:66
int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags)
Definition: bFile.cpp:1639
bDNA * mMemoryDNA
Definition: bFile.h:63
char * readStruct(char *head, class bChunkInd &chunk)
Definition: bFile.cpp:655
virtual void parseData()=0
void parseInternal(int verboseMode, char *memDna, int memDnaLength)
Definition: bFile.cpp:191
virtual int write(const char *fileName, bool fixupPointers=false)=0
virtual void addDataBlock(char *dataBlock)=0
char * mFileBuffer
Definition: bFile.h:54
void swapDNA(char *ptr)
Definition: bFile.cpp:387
void dumpChunks(bDNA *dna)
Definition: bFile.cpp:1528
bFileFlags
Definition: bFile.h:26
int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion)
Definition: bFile.cpp:1244
bFile(const char *filename, const char headerString[7])
Definition: bFile.cpp:55
bDNA * getFileDNA()
Definition: bFile.h:119
void swapLen(char *dataPtr)
Definition: bFile.cpp:337
void preSwap()
Definition: bFile.cpp:572
btAlignedObjectArray< char * > m_pointerFixupArray
Definition: bFile.h:65
void resolvePointers(int verboseMode)
Resolve pointers replaces the original pointers in structures, and linked lists by the new in-memory ...
Definition: bFile.cpp:1456
void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag)
Definition: bFile.cpp:1112
void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers)
Definition: bFile.cpp:780
bFileVerboseMode
Definition: bFile.h:39
int mFlags
Definition: bFile.h:76
void safeSwapPtr(char *dst, const char *src)
Definition: bFile.cpp:937
virtual void parseHeader()
Definition: bFile.cpp:130
void writeFile(const char *fileName)
Definition: bFile.cpp:565
int mFileLen
Definition: bFile.h:55
virtual void parse(int verboseMode)=0
virtual ~bFile()
Definition: bFile.cpp:112
char * getAsString(int code)
int mDataStart
Definition: bFile.h:61
bPtrMap mDataPointers
Definition: bFile.h:73
bPtrMap & getLibPointers()
Definition: bFile.h:131
int mVersion
Definition: bFile.h:56
btAlignedObjectArray< bChunkInd > m_chunks
Definition: bFile.h:68
void getMatchingFileDNA(short *old, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers)
Definition: bFile.cpp:996
virtual void writeChunks(FILE *fp, bool fixupPointers)
Definition: bFile.cpp:1575
void * findLibPointer(void *ptr)
Definition: bFile.cpp:1508
void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag)
Definition: bFile.cpp:904
char m_headerString[7]
Definition: bFile.h:51
char * getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos)
Definition: bFile.cpp:1083
bDNA * mFileDNA
Definition: bFile.h:62
void swap(char *head, class bChunkInd &ch, bool ignoreEndianFlag)
Definition: bFile.cpp:308
int getFlags() const
Definition: bFile.h:126
bPtrMap mLibPointers
Definition: bFile.h:59
bool ok()
Definition: bFile.cpp:185
void updateOldPointers()
Definition: bFile.cpp:1518
btHashMap< btHashPtr, bChunkInd > m_chunkPtrPtrMap
Definition: bFile.h:69
bool mOwnsBuffer
Definition: bFile.h:53
void resolvePointersMismatch()
Definition: bFile.cpp:1159