Bullet Collision Detection & Physics Library: bFile.h Source File

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 // ----------------------------------------------------- //
26 enum bFileFlags
27 {
28 FD_INVALID =0,
29 FD_OK =1,
30 FD_VOID_IS_8 =2,
31 FD_ENDIAN_SWAP =4,
32 FD_FILE_64 =8,
33 FD_BITS_VARIES =16,
34 FD_VERSION_VARIES = 32,
35 FD_DOUBLE_PRECISION =64,
36 FD_BROKEN_DNA = 128
37 };
38
39 enum bFileVerboseMode
40 {
41 FD_VERBOSE_EXPORT_XML = 1,
42 FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS = 2,
43 FD_VERBOSE_DUMP_CHUNKS = 4,
44 FD_VERBOSE_DUMP_FILE_INFO=8,
45 };
46 // ----------------------------------------------------- //
47 class bFile
48 {
49 protected:
50
51 char m_headerString[7];
52
53 bool mOwnsBuffer;
54 char* mFileBuffer;
55 int mFileLen;
56 int mVersion;
57
58
59 bPtrMap mLibPointers;
60
61 int mDataStart;
62 bDNA* mFileDNA;
63 bDNA* mMemoryDNA;
64
65 btAlignedObjectArray<char*> m_pointerFixupArray;
66 btAlignedObjectArray<char*> m_pointerPtrFixupArray;
67
68 btAlignedObjectArray<bChunkInd> m_chunks;
69 btHashMap<btHashPtr, bChunkInd> m_chunkPtrPtrMap;
70
71 //
72
73 bPtrMap mDataPointers;
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
88 void resolvePointersMismatch();
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
119 bDNA* getFileDNA()
120 {
121 return mFileDNA;
122 }
123
124 virtual void addDataBlock(char* dataBlock) = 0;
125
126 int getFlags() const
127 {
128 return mFlags;
129 }
130
131 bPtrMap& getLibPointers()
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__
bParse::bFile::getVersion
int getVersion() const
Definition: bFile.h:153
bParse::bFile::writeDNA
virtual void writeDNA(FILE *fp)=0
bParse::bFile::resolvePointersChunk
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
bParse::FD_VERBOSE_DUMP_FILE_INFO
Definition: bFile.h:44
bParse::bFile::m_pointerPtrFixupArray
btAlignedObjectArray< char * > m_pointerPtrFixupArray
Definition: bFile.h:66
bParse::bFile::getNextBlock
int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags)
Definition: bFile.cpp:1639
btAlignedObjectArray< char * >
bParse::bFile
Definition: bFile.h:47
bParse::bFile::mMemoryDNA
bDNA * mMemoryDNA
Definition: bFile.h:63
bParse::bFile::readStruct
char * readStruct(char *head, class bChunkInd &chunk)
Definition: bFile.cpp:655
bParse::bFile::parseData
virtual void parseData()=0
bParse::bFile::parseInternal
void parseInternal(int verboseMode, char *memDna, int memDnaLength)
Definition: bFile.cpp:191
bParse::bChunkInd
Definition: bChunk.h:62
bParse::bFile::write
virtual int write(const char *fileName, bool fixupPointers=false)=0
bParse::FD_VOID_IS_8
Definition: bFile.h:30
bParse::bFile::addDataBlock
virtual void addDataBlock(char *dataBlock)=0
bParse::bFile::mFileBuffer
char * mFileBuffer
Definition: bFile.h:54
bParse::bFile::swapDNA
void swapDNA(char *ptr)
Definition: bFile.cpp:387
bParse::FD_VERSION_VARIES
Definition: bFile.h:34
bParse::bFile::dumpChunks
void dumpChunks(bDNA *dna)
Definition: bFile.cpp:1528
bParse::bFileFlags
bFileFlags
Definition: bFile.h:26
bParse::FD_FILE_64
Definition: bFile.h:32
bParse::bFile::resolvePointersStructRecursive
int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion)
Definition: bFile.cpp:1244
bParse::bFile::bFile
bFile(const char *filename, const char headerString[7])
Definition: bFile.cpp:55
bParse::FD_BROKEN_DNA
Definition: bFile.h:36
bParse::bFile::getFileDNA
bDNA * getFileDNA()
Definition: bFile.h:119
btHashMap< btHashPtr, bStructHandle * >
bParse::bFile::swapLen
void swapLen(char *dataPtr)
Definition: bFile.cpp:337
bParse::bFile::preSwap
void preSwap()
Definition: bFile.cpp:572
bParse::FD_ENDIAN_SWAP
Definition: bFile.h:31
bParse::FD_OK
Definition: bFile.h:29
bParse::bFile::m_pointerFixupArray
btAlignedObjectArray< char * > m_pointerFixupArray
Definition: bFile.h:65
bParse::FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS
Definition: bFile.h:42
bParse::bFile::resolvePointers
void resolvePointers(int verboseMode)
Resolve pointers replaces the original pointers in structures, and linked lists by the new in-memory ...
Definition: bFile.cpp:1456
bParse::bFile::swapStruct
void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag)
Definition: bFile.cpp:1112
bParse::bFile::parseStruct
void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers)
Definition: bFile.cpp:780
bParse::bFileVerboseMode
bFileVerboseMode
Definition: bFile.h:39
bParse::bFile::mFlags
int mFlags
Definition: bFile.h:76
bParse::bFile::safeSwapPtr
void safeSwapPtr(char *dst, const char *src)
Definition: bFile.cpp:937
bParse::bFile::parseHeader
virtual void parseHeader()
Definition: bFile.cpp:130
bParse::FD_DOUBLE_PRECISION
Definition: bFile.h:35
bChunk.h
bParse::bFile::writeFile
void writeFile(const char *fileName)
Definition: bFile.cpp:565
bParse::bFile::mFileLen
int mFileLen
Definition: bFile.h:55
bCommon.h
bParse::bFile::parse
virtual void parse(int verboseMode)=0
bParse::bFile::~bFile
virtual ~bFile()
Definition: bFile.cpp:112
bParse::bFile::getAsString
char * getAsString(int code)
bParse::bFile::mDataStart
int mDataStart
Definition: bFile.h:61
bParse::bFile::mDataPointers
bPtrMap mDataPointers
Definition: bFile.h:73
bParse::bFile::getLibPointers
bPtrMap & getLibPointers()
Definition: bFile.h:131
bParse::bFile::mVersion
int mVersion
Definition: bFile.h:56
bParse::FD_INVALID
Definition: bFile.h:28
bParse::bFile::m_chunks
btAlignedObjectArray< bChunkInd > m_chunks
Definition: bFile.h:68
bParse::FD_VERBOSE_EXPORT_XML
Definition: bFile.h:41
bParse
Definition: btBulletWorldImporter.h:29
bParse::FD_VERBOSE_DUMP_CHUNKS
Definition: bFile.h:43
bParse::bDNA
Definition: bDNA.h:32
bParse::bFile::getMatchingFileDNA
void getMatchingFileDNA(short *old, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers)
Definition: bFile.cpp:996
bParse::bFile::writeChunks
virtual void writeChunks(FILE *fp, bool fixupPointers)
Definition: bFile.cpp:1575
bParse::FD_BITS_VARIES
Definition: bFile.h:33
bParse::bFile::findLibPointer
void * findLibPointer(void *ptr)
Definition: bFile.cpp:1508
bParse::bFile::swapData
void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag)
Definition: bFile.cpp:904
bParse::bFile::m_headerString
char m_headerString[7]
Definition: bFile.h:51
bParse::bFile::getFileElement
char * getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos)
Definition: bFile.cpp:1083
bParse::bFile::mFileDNA
bDNA * mFileDNA
Definition: bFile.h:62
bParse::bFile::swap
void swap(char *head, class bChunkInd &ch, bool ignoreEndianFlag)
Definition: bFile.cpp:308
bParse::bFile::getFlags
int getFlags() const
Definition: bFile.h:126
bParse::bFile::mLibPointers
bPtrMap mLibPointers
Definition: bFile.h:59
bParse::bFile::ok
bool ok()
Definition: bFile.cpp:185
bParse::bFile::updateOldPointers
void updateOldPointers()
Definition: bFile.cpp:1518
bParse::bFile::m_chunkPtrPtrMap
btHashMap< btHashPtr, bChunkInd > m_chunkPtrPtrMap
Definition: bFile.h:69
bParse::bFile::mOwnsBuffer
bool mOwnsBuffer
Definition: bFile.h:53
bParse::bFile::resolvePointersMismatch
void resolvePointersMismatch()
Definition: bFile.cpp:1159