b3DNA.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. bParse
  3. Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef __BDNA_H__
  14. #define __BDNA_H__
  15. #include "b3Common.h"
  16. namespace bParse
  17. {
  18. struct bNameInfo
  19. {
  20. char *m_name;
  21. bool m_isPointer;
  22. int m_dim0;
  23. int m_dim1;
  24. };
  25. class bDNA
  26. {
  27. public:
  28. bDNA();
  29. ~bDNA();
  30. void init(char *data, int len, bool swap = false);
  31. int getArraySize(char *str);
  32. int getArraySizeNew(short name)
  33. {
  34. const bNameInfo &nameInfo = m_Names[name];
  35. return nameInfo.m_dim0 * nameInfo.m_dim1;
  36. }
  37. int getElementSize(short type, short name)
  38. {
  39. const bNameInfo &nameInfo = m_Names[name];
  40. int size = nameInfo.m_isPointer ? mPtrLen * nameInfo.m_dim0 * nameInfo.m_dim1 : mTlens[type] * nameInfo.m_dim0 * nameInfo.m_dim1;
  41. return size;
  42. }
  43. int getNumNames() const
  44. {
  45. return m_Names.size();
  46. }
  47. char *getName(int ind);
  48. char *getType(int ind);
  49. short *getStruct(int ind);
  50. short getLength(int ind);
  51. int getReverseType(short type);
  52. int getReverseType(const char *type);
  53. int getNumStructs();
  54. //
  55. bool lessThan(bDNA *other);
  56. void initCmpFlags(bDNA *memDNA);
  57. bool flagNotEqual(int dna_nr);
  58. bool flagEqual(int dna_nr);
  59. bool flagNone(int dna_nr);
  60. int getPointerSize();
  61. void dumpTypeDefinitions();
  62. private:
  63. enum FileDNAFlags
  64. {
  65. FDF_NONE = 0,
  66. FDF_STRUCT_NEQU,
  67. FDF_STRUCT_EQU
  68. };
  69. void initRecurseCmpFlags(int i);
  70. b3AlignedObjectArray<int> mCMPFlags;
  71. b3AlignedObjectArray<bNameInfo> m_Names;
  72. b3AlignedObjectArray<char *> mTypes;
  73. b3AlignedObjectArray<short *> mStructs;
  74. b3AlignedObjectArray<short> mTlens;
  75. b3HashMap<b3HashInt, int> mStructReverse;
  76. b3HashMap<b3HashString, int> mTypeLookup;
  77. int mPtrLen;
  78. };
  79. } // namespace bParse
  80. #endif //__BDNA_H__