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

Bullet Collision Detection & Physics Library

bFile.h
Go to the documentation of this file.
1/*
2bParse
3Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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
23namespace 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{
50protected:
51 char m_headerString[7];
52
53 bool mOwnsBuffer;
54 char* mFileBuffer;
55 int mFileLen;
56 int mVersion;
57
58 bPtrMap mLibPointers;
59
60 int mDataStart;
61 bDNA* mFileDNA;
62 bDNA* mMemoryDNA;
63
64 btAlignedObjectArray<char*> m_pointerFixupArray;
65 btAlignedObjectArray<char*> m_pointerPtrFixupArray;
66
67 btAlignedObjectArray<bChunkInd> m_chunks;
68 btHashMap<btHashPtr, bChunkInd> m_chunkPtrPtrMap;
69
70 //
71
72 bPtrMap mDataPointers;
73
74 int mFlags;
75
76 // ////////////////////////////////////////////////////////////////////////////
77
78 // buffer offset util
79 int getNextBlock(bChunkInd* dataChunk, const char* dataPtr, const int flags);
80 void safeSwapPtr(char* dst, const char* src);
81
82 virtual void parseHeader();
83
84 virtual void parseData() = 0;
85
86 void resolvePointersMismatch();
87 void resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode);
88
89 int resolvePointersStructRecursive(char* strcPtr, int old_dna, int verboseMode, int recursion);
90 //void swapPtr(char *dst, char *src);
91
92 void parseStruct(char* strcPtr, char* dtPtr, int old_dna, int new_dna, bool fixupPointers);
93 void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char* strcData, char* data, bool fixupPointers);
94 char* getFileElement(short* firstStruct, char* lookupName, char* lookupType, char* data, short** foundPos);
95
96 void swap(char* head, class bChunkInd& ch, bool ignoreEndianFlag);
97 void swapData(char* data, short type, int arraySize, bool ignoreEndianFlag);
98 void swapStruct(int dna_nr, char* data, bool ignoreEndianFlag);
99 void swapLen(char* dataPtr);
100 void swapDNA(char* ptr);
101
102 char* readStruct(char* head, class bChunkInd& chunk);
103 char* getAsString(int code);
104
105 virtual void parseInternal(int verboseMode, char* memDna, int memDnaLength);
106
107public:
108 bFile(const char* filename, const char headerString[7]);
109
110 //todo: make memoryBuffer const char
111 //bFile( const char *memoryBuffer, int len);
112 bFile(char* memoryBuffer, int len, const char headerString[7]);
113 virtual ~bFile();
114
115 bDNA* getFileDNA()
116 {
117 return mFileDNA;
118 }
119
120 virtual void addDataBlock(char* dataBlock) = 0;
121
122 int getFlags() const
123 {
124 return mFlags;
125 }
126
127 void setFileDNAisMemoryDNA()
128 {
129 mFlags |= FD_FILEDNA_IS_MEMDNA;
130 }
131
132 bPtrMap& getLibPointers()
133 {
134 return mLibPointers;
135 }
136
137 void* findLibPointer(void* ptr);
138
139 bool ok();
140
141 virtual void parse(int verboseMode) = 0;
142
143 virtual int write(const char* fileName, bool fixupPointers = false) = 0;
144
145 virtual void writeChunks(FILE* fp, bool fixupPointers);
146
147 virtual void writeDNA(FILE* fp) = 0;
148
149 void updateOldPointers();
150 void resolvePointers(int verboseMode);
151
152 void dumpChunks(bDNA* dna);
153
154 virtual void setFileDNA(int verboseMode, char* buffer, int len);
155
156 int getVersion() const
157 {
158 return mVersion;
159 }
160 //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped
161 void preSwap();
162 void writeFile(const char* fileName);
163};
164} // namespace bParse
165
166#endif //__BFILE_H__
bChunk.h
bCommon.h
bParse::bChunkInd
Definition bChunk.h:59
bParse::bDNA
Definition bDNA.h:32
bParse::bFile::bFile
bFile(const char *filename, const char headerString[7])
Definition bFile.cpp:55
bParse::bFile::mDataPointers
bPtrMap mDataPointers
Definition bFile.h:72
bParse::bFile::mFileLen
int mFileLen
Definition bFile.h:55
bParse::bFile::mMemoryDNA
bDNA * mMemoryDNA
Definition bFile.h:62
bParse::bFile::~bFile
virtual ~bFile()
Definition bFile.cpp:111
bParse::bFile::addDataBlock
virtual void addDataBlock(char *dataBlock)=0
bParse::bFile::swap
void swap(char *head, class bChunkInd &ch, bool ignoreEndianFlag)
Definition bFile.cpp:308
bParse::bFile::m_pointerFixupArray
btAlignedObjectArray< char * > m_pointerFixupArray
Definition bFile.h:64
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:1166
bParse::bFile::parseInternal
virtual void parseInternal(int verboseMode, char *memDna, int memDnaLength)
Definition bFile.cpp:195
bParse::bFile::writeFile
void writeFile(const char *fileName)
Definition bFile.cpp:538
bParse::bFile::parseData
virtual void parseData()=0
bParse::bFile::m_pointerPtrFixupArray
btAlignedObjectArray< char * > m_pointerPtrFixupArray
Definition bFile.h:65
bParse::bFile::setFileDNA
virtual void setFileDNA(int verboseMode, char *buffer, int len)
Definition bFile.cpp:183
bParse::bFile::parseHeader
virtual void parseHeader()
Definition bFile.cpp:124
bParse::bFile::m_chunks
btAlignedObjectArray< bChunkInd > m_chunks
Definition bFile.h:67
bParse::bFile::mDataStart
int mDataStart
Definition bFile.h:60
bParse::bFile::parseStruct
void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers)
Definition bFile.cpp:734
bParse::bFile::getLibPointers
bPtrMap & getLibPointers()
Definition bFile.h:132
bParse::bFile::m_chunkPtrPtrMap
btHashMap< btHashPtr, bChunkInd > m_chunkPtrPtrMap
Definition bFile.h:68
bParse::bFile::dumpChunks
void dumpChunks(bDNA *dna)
Definition bFile.cpp:1458
bParse::bFile::mVersion
int mVersion
Definition bFile.h:56
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:1391
bParse::bFile::readStruct
char * readStruct(char *head, class bChunkInd &chunk)
Definition bFile.cpp:619
bParse::bFile::mLibPointers
bPtrMap mLibPointers
Definition bFile.h:58
bParse::bFile::writeChunks
virtual void writeChunks(FILE *fp, bool fixupPointers)
Definition bFile.cpp:1499
bParse::bFile::getAsString
char * getAsString(int code)
bParse::bFile::mFileBuffer
char * mFileBuffer
Definition bFile.h:54
bParse::bFile::updateOldPointers
void updateOldPointers()
Definition bFile.cpp:1448
bParse::bFile::swapLen
void swapLen(char *dataPtr)
Definition bFile.cpp:334
bParse::bFile::setFileDNAisMemoryDNA
void setFileDNAisMemoryDNA()
Definition bFile.h:127
bParse::bFile::getNextBlock
int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags)
Definition bFile.cpp:1559
bParse::bFile::getFlags
int getFlags() const
Definition bFile.h:122
bParse::bFile::parse
virtual void parse(int verboseMode)=0
bParse::bFile::getFileDNA
bDNA * getFileDNA()
Definition bFile.h:115
bParse::bFile::safeSwapPtr
void safeSwapPtr(char *dst, const char *src)
Definition bFile.cpp:885
bParse::bFile::getFileElement
char * getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos)
Definition bFile.cpp:1024
bParse::bFile::resolvePointersStructRecursive
int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion)
Definition bFile.cpp:1182
bParse::bFile::m_headerString
char m_headerString[7]
Definition bFile.h:51
bParse::bFile::mOwnsBuffer
bool mOwnsBuffer
Definition bFile.h:53
bParse::bFile::resolvePointersMismatch
void resolvePointersMismatch()
Definition bFile.cpp:1100
bParse::bFile::getVersion
int getVersion() const
Definition bFile.h:156
bParse::bFile::write
virtual int write(const char *fileName, bool fixupPointers=false)=0
bParse::bFile::swapStruct
void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag)
Definition bFile.cpp:1052
bParse::bFile::swapData
void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag)
Definition bFile.cpp:854
bParse::bFile::mFlags
int mFlags
Definition bFile.h:74
bParse::bFile::swapDNA
void swapDNA(char *ptr)
Definition bFile.cpp:382
bParse::bFile::findLibPointer
void * findLibPointer(void *ptr)
Definition bFile.cpp:1440
bParse::bFile::ok
bool ok()
Definition bFile.cpp:178
bParse::bFile::mFileDNA
bDNA * mFileDNA
Definition bFile.h:61
bParse::bFile::writeDNA
virtual void writeDNA(FILE *fp)=0
bParse::bFile::preSwap
void preSwap()
Definition bFile.cpp:545
bParse::bFile::getMatchingFileDNA
void getMatchingFileDNA(short *old, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers)
Definition bFile.cpp:941
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition btAlignedObjectArray.h:46
btHashMap
The btHashMap template class implements a generic and lightweight hashmap.
Definition btHashMap.h:220
bParse
Definition btBulletWorldImporter.h:24
bParse::bPtrMap
btHashMap< btHashPtr, bStructHandle * > bPtrMap
Definition bCommon.h:37
bParse::bFileFlags
bFileFlags
Definition bFile.h:27
bParse::FD_ENDIAN_SWAP
@ FD_ENDIAN_SWAP
Definition bFile.h:31
bParse::FD_FILE_64
@ FD_FILE_64
Definition bFile.h:32
bParse::FD_VERSION_VARIES
@ FD_VERSION_VARIES
Definition bFile.h:34
bParse::FD_FILEDNA_IS_MEMDNA
@ FD_FILEDNA_IS_MEMDNA
Definition bFile.h:37
bParse::FD_INVALID
@ FD_INVALID
Definition bFile.h:28
bParse::FD_BROKEN_DNA
@ FD_BROKEN_DNA
Definition bFile.h:36
bParse::FD_OK
@ FD_OK
Definition bFile.h:29
bParse::FD_VOID_IS_8
@ FD_VOID_IS_8
Definition bFile.h:30
bParse::FD_BITS_VARIES
@ FD_BITS_VARIES
Definition bFile.h:33
bParse::FD_DOUBLE_PRECISION
@ FD_DOUBLE_PRECISION
Definition bFile.h:35
bParse::bFileVerboseMode
bFileVerboseMode
Definition bFile.h:41
bParse::FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS
@ FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS
Definition bFile.h:43
bParse::FD_VERBOSE_DUMP_CHUNKS
@ FD_VERBOSE_DUMP_CHUNKS
Definition bFile.h:44
bParse::FD_VERBOSE_DUMP_FILE_INFO
@ FD_VERBOSE_DUMP_FILE_INFO
Definition bFile.h:45
bParse::FD_VERBOSE_EXPORT_XML
@ FD_VERBOSE_EXPORT_XML
Definition bFile.h:42