Home | History | Annotate | Download | only in BulletFileLoader
      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 __BDNA_H__
     17 #define __BDNA_H__
     18 
     19 
     20 #include "bCommon.h"
     21 
     22 namespace bParse {
     23 
     24 	struct	bNameInfo
     25 	{
     26 		char*	m_name;
     27 		bool	m_isPointer;
     28 		int		m_dim0;
     29 		int		m_dim1;
     30 	};
     31 
     32 	class bDNA
     33 	{
     34 	public:
     35 		bDNA();
     36 		~bDNA();
     37 
     38 		void init(char *data, int len, bool swap=false);
     39 
     40 		int getArraySize(char* str);
     41 		int getArraySizeNew(short name)
     42 		{
     43 			const bNameInfo& nameInfo = m_Names[name];
     44 			return nameInfo.m_dim0*nameInfo.m_dim1;
     45 		}
     46 		int getElementSize(short type, short name)
     47 		{
     48 			const bNameInfo& nameInfo = m_Names[name];
     49 			int size = nameInfo.m_isPointer ? mPtrLen*nameInfo.m_dim0*nameInfo.m_dim1 : mTlens[type]*nameInfo.m_dim0*nameInfo.m_dim1;
     50 			return size;
     51 		}
     52 
     53 		int	getNumNames() const
     54 		{
     55 			return m_Names.size();
     56 		}
     57 
     58 		char *getName(int ind);
     59 		char *getType(int ind);
     60 		short *getStruct(int ind);
     61 		short getLength(int ind);
     62 		int getReverseType(short type);
     63 		int getReverseType(const char *type);
     64 
     65 
     66 		int getNumStructs();
     67 
     68 		//
     69 		bool lessThan(bDNA* other);
     70 
     71 		void initCmpFlags(bDNA *memDNA);
     72 		bool flagNotEqual(int dna_nr);
     73 		bool flagEqual(int dna_nr);
     74 		bool flagNone(int dna_nr);
     75 
     76 
     77 		int getPointerSize();
     78 
     79 		void	dumpTypeDefinitions();
     80 
     81 
     82 	private:
     83 		enum FileDNAFlags
     84 		{
     85 			FDF_NONE=0,
     86 			FDF_STRUCT_NEQU,
     87 			FDF_STRUCT_EQU
     88 		};
     89 
     90 		void initRecurseCmpFlags(int i);
     91 
     92 		btAlignedObjectArray<int>			mCMPFlags;
     93 
     94 		btAlignedObjectArray<bNameInfo>			m_Names;
     95 		btAlignedObjectArray<char*>			mTypes;
     96 		btAlignedObjectArray<short*>			mStructs;
     97 		btAlignedObjectArray<short>			mTlens;
     98 		btHashMap<btHashInt, int>			mStructReverse;
     99 		btHashMap<btHashString,int>	mTypeLookup;
    100 
    101 		int							mPtrLen;
    102 
    103 
    104 
    105 
    106 	};
    107 }
    108 
    109 
    110 #endif//__BDNA_H__
    111