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

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 // ----------------------------------------------------- //
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 FD_FILEDNA_IS_MEMDNA = 256
38 };
39
40 enum bFileVerboseMode
41 {
42 FD_VERBOSE_EXPORT_XML = 1,
43 FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS = 2,
44 FD_VERBOSE_DUMP_CHUNKS = 4,
45 FD_VERBOSE_DUMP_FILE_INFO=8,
46 };
47 // ----------------------------------------------------- //
48 class bFile
49 {
50 protected:
51
52 char m_headerString[7];
53
54 bool mOwnsBuffer;
55 char* mFileBuffer;
56 int mFileLen;
57 int mVersion;
58
59
60 bPtrMap mLibPointers;
61
62 int mDataStart;
63 bDNA* mFileDNA;
64 bDNA* mMemoryDNA;
65
66 btAlignedObjectArray<char*> m_pointerFixupArray;
67 btAlignedObjectArray<char*> m_pointerPtrFixupArray;
68
69 btAlignedObjectArray<bChunkInd> m_chunks;
70 btHashMap<btHashPtr, bChunkInd> m_chunkPtrPtrMap;
71
72 //
73
74 bPtrMap mDataPointers;
75
76
77 int mFlags;
78
79 // ////////////////////////////////////////////////////////////////////////////
80
81 // buffer offset util
82 int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags);
83 void safeSwapPtr(char *dst, const char *src);
84
85 virtual void parseHeader();
86
87 virtual void parseData() = 0;
88
89 void resolvePointersMismatch();
90 void resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode);
91
92 int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion);
93 //void swapPtr(char *dst, char *src);
94
95 void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers);
96 void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers);
97 char* getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos);
98
99
100 void swap(char *head, class bChunkInd& ch, bool ignoreEndianFlag);
101 void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag);
102 void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag);
103 void swapLen(char *dataPtr);
104 void swapDNA(char* ptr);
105
106
107 char* readStruct(char *head, class bChunkInd& chunk);
108 char *getAsString(int code);
109
110 virtual void parseInternal(int verboseMode, char* memDna,int memDnaLength);
111
112 public:
113 bFile(const char *filename, const char headerString[7]);
114
115 //todo: make memoryBuffer const char
116 //bFile( const char *memoryBuffer, int len);
117 bFile( char *memoryBuffer, int len, const char headerString[7]);
118 virtual ~bFile();
119
120 bDNA* getFileDNA()
121 {
122 return mFileDNA;
123 }
124
125 virtual void addDataBlock(char* dataBlock) = 0;
126
127 int getFlags() const
128 {
129 return mFlags;
130 }
131
132 void setFileDNAisMemoryDNA()
133 {
134 mFlags |= FD_FILEDNA_IS_MEMDNA;
135 }
136
137 bPtrMap& getLibPointers()
138 {
139 return mLibPointers;
140 }
141
142 void* findLibPointer(void *ptr);
143
144 bool ok();
145
146 virtual void parse(int verboseMode) = 0;
147
148 virtual int write(const char* fileName, bool fixupPointers=false) = 0;
149
150 virtual void writeChunks(FILE* fp, bool fixupPointers );
151
152 virtual void writeDNA(FILE* fp) = 0;
153
154 void updateOldPointers();
155 void resolvePointers(int verboseMode);
156
157 void dumpChunks(bDNA* dna);
158
159 virtual void setFileDNA(int verboseMode, char* buffer, int len);
160
161 int getVersion() const
162 {
163 return mVersion;
164 }
165 //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped
166 void preSwap();
167 void writeFile(const char* fileName);
168
169
170
171 };
172 }
173
174
175 #endif//__BFILE_H__
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:1228
bParse::FD_VERBOSE_DUMP_FILE_INFO
Definition: bFile.h:45
bParse::bFile::m_pointerPtrFixupArray
btAlignedObjectArray< char * > m_pointerPtrFixupArray
Definition: bFile.h:67
bParse::bFile::getNextBlock
int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags)
Definition: bFile.cpp:1640
bParse::FD_FILEDNA_IS_MEMDNA
Definition: bFile.h:37
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
bParse::bFile
Definition: bFile.h:48
bParse::bFile::mMemoryDNA
bDNA * mMemoryDNA
Definition: bFile.h:64
bParse::bFile::readStruct
char * readStruct(char *head, class bChunkInd &chunk)
Definition: bFile.cpp:656
bParse::bFile::parseData
virtual void parseData()=0
bParse::bFile::parseInternal
virtual void parseInternal(int verboseMode, char *memDna, int memDnaLength)
Definition: bFile.cpp:202
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:55
bParse::bFile::swapDNA
void swapDNA(char *ptr)
Definition: bFile.cpp:405
bParse::FD_VERSION_VARIES
Definition: bFile.h:34
bParse::bFile::dumpChunks
void dumpChunks(bDNA *dna)
Definition: bFile.cpp:1529
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:1245
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:120
btHashMap
The btHashMap template class implements a generic and lightweight hashmap.
Definition: btHashMap.h:220
bParse::bFile::swapLen
void swapLen(char *dataPtr)
Definition: bFile.cpp:355
bParse::bFile::setFileDNAisMemoryDNA
void setFileDNAisMemoryDNA()
Definition: bFile.h:132
bParse::bFile::preSwap
void preSwap()
Definition: bFile.cpp:573
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:66
bParse::FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS
Definition: bFile.h:43
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:1457
bParse::bFile::swapStruct
void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag)
Definition: bFile.cpp:1113
bParse::bFile::parseStruct
void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers)
Definition: bFile.cpp:781
bParse::bFileVerboseMode
bFileVerboseMode
Definition: bFile.h:40
bParse::bFile::mFlags
int mFlags
Definition: bFile.h:77
bParse::bFile::safeSwapPtr
void safeSwapPtr(char *dst, const char *src)
Definition: bFile.cpp:938
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:566
bParse::bFile::mFileLen
int mFileLen
Definition: bFile.h:56
bParse::bFile::getVersion
int getVersion() const
Definition: bFile.h:161
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:62
bParse::bFile::mDataPointers
bPtrMap mDataPointers
Definition: bFile.h:74
bParse::bFile::getLibPointers
bPtrMap & getLibPointers()
Definition: bFile.h:137
bParse::bFile::mVersion
int mVersion
Definition: bFile.h:57
bParse::FD_INVALID
Definition: bFile.h:28
bParse::bFile::m_chunks
btAlignedObjectArray< bChunkInd > m_chunks
Definition: bFile.h:69
bParse::bFile::setFileDNA
virtual void setFileDNA(int verboseMode, char *buffer, int len)
Definition: bFile.cpp:190
bParse::FD_VERBOSE_EXPORT_XML
Definition: bFile.h:42
bParse
Definition: btBulletWorldImporter.h:29
bParse::FD_VERBOSE_DUMP_CHUNKS
Definition: bFile.h:44
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:997
bParse::bFile::writeChunks
virtual void writeChunks(FILE *fp, bool fixupPointers)
Definition: bFile.cpp:1576
bParse::FD_BITS_VARIES
Definition: bFile.h:33
bParse::bFile::findLibPointer
void * findLibPointer(void *ptr)
Definition: bFile.cpp:1509
bParse::bFile::swapData
void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag)
Definition: bFile.cpp:905
bParse::bFile::m_headerString
char m_headerString[7]
Definition: bFile.h:52
bParse::bFile::getFileElement
char * getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos)
Definition: bFile.cpp:1084
bParse::bFile::mFileDNA
bDNA * mFileDNA
Definition: bFile.h:63
bParse::bFile::swap
void swap(char *head, class bChunkInd &ch, bool ignoreEndianFlag)
Definition: bFile.cpp:326
bParse::bFile::mLibPointers
bPtrMap mLibPointers
Definition: bFile.h:60
bParse::bFile::ok
bool ok()
Definition: bFile.cpp:185
bParse::bFile::updateOldPointers
void updateOldPointers()
Definition: bFile.cpp:1519
bParse::bFile::m_chunkPtrPtrMap
btHashMap< btHashPtr, bChunkInd > m_chunkPtrPtrMap
Definition: bFile.h:70
bParse::bFile::mOwnsBuffer
bool mOwnsBuffer
Definition: bFile.h:54
bParse::bFile::getFlags
int getFlags() const
Definition: bFile.h:127
bParse::bFile::resolvePointersMismatch
void resolvePointersMismatch()
Definition: bFile.cpp:1160