3 Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
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:
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.
25 // ----------------------------------------------------- //
34 FD_VERSION_VARIES = 32,
35 FD_DOUBLE_PRECISION = 64,
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,
46 // ----------------------------------------------------- //
50 char m_headerString[7];
63 b3AlignedObjectArray<char *> m_pointerFixupArray;
64 b3AlignedObjectArray<char *> m_pointerPtrFixupArray;
66 b3AlignedObjectArray<bChunkInd> m_chunks;
67 b3HashMap<b3HashPtr, bChunkInd> m_chunkPtrPtrMap;
71 bPtrMap mDataPointers;
75 // ////////////////////////////////////////////////////////////////////////////
78 int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags);
79 void safeSwapPtr(char *dst, const char *src);
81 virtual void parseHeader();
83 virtual void parseData() = 0;
85 void resolvePointersMismatch();
86 void resolvePointersChunk(const bChunkInd &dataChunk, int verboseMode);
88 int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion);
89 //void swapPtr(char *dst, char *src);
91 void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers);
92 void getMatchingFileDNA(short *old, const char *lookupName, const char *lookupType, char *strcData, char *data, bool fixupPointers);
93 char *getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos);
95 void swap(char *head, class bChunkInd &ch, bool ignoreEndianFlag);
96 void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag);
97 void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag);
98 void swapLen(char *dataPtr);
99 void swapDNA(char *ptr);
101 char *readStruct(char *head, class bChunkInd &chunk);
102 char *getAsString(int code);
104 void parseInternal(int verboseMode, char *memDna, int memDnaLength);
107 bFile(const char *filename, const char headerString[7]);
109 //todo: make memoryBuffer const char
110 //bFile( const char *memoryBuffer, int len);
111 bFile(char *memoryBuffer, int len, const char headerString[7]);
119 virtual void addDataBlock(char *dataBlock) = 0;
126 bPtrMap &getLibPointers()
131 void *findLibPointer(void *ptr);
135 virtual void parse(int verboseMode) = 0;
137 virtual int write(const char *fileName, bool fixupPointers = false) = 0;
139 virtual void writeChunks(FILE *fp, bool fixupPointers);
141 virtual void writeDNA(FILE *fp) = 0;
143 void updateOldPointers();
144 void resolvePointers(int verboseMode);
146 void dumpChunks(bDNA *dna);
148 int getVersion() const
152 //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped
154 void writeFile(const char *fileName);
156 } // namespace bParse