2
0

Object.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef OBJ_H_
  2. #define OBJ_H_
  3. #include "FileIO.h"
  4. #include "Base.h"
  5. namespace gameplay
  6. {
  7. /**
  8. * Object is the abstract base class of all the objects that can be written in the GamePlay Binary file.
  9. */
  10. class Object
  11. {
  12. public:
  13. // TypeID's
  14. enum TypeID
  15. {
  16. SCENE_ID = 1,
  17. NODE_ID = 2,
  18. ANIMATIONS_ID = 3,
  19. ANIMATION_ID = 4,
  20. ANIMATIONCHANNEL_ID = 5,
  21. NODEINSTANCE_ID = 8,
  22. MODEL_ID = 11,
  23. MATERIAL_ID = 16,
  24. EFFECT_ID = 17,
  25. CAMERA_ID = 32,
  26. LIGHT_ID = 33,
  27. MESH_ID = 34,
  28. MESHPART_ID = 35,
  29. MESHSKIN_ID = 36,
  30. FONT_ID = 128,
  31. };
  32. /**
  33. * Constructor.
  34. */
  35. Object(void);
  36. /**
  37. * Destructor.
  38. */
  39. virtual ~Object(void);
  40. /**
  41. * Returns the Object TypeID.
  42. */
  43. virtual unsigned int getTypeId(void) const;
  44. /**
  45. * Returns the string element name of the object.
  46. * Used for printing the gameplayfile as text.
  47. */
  48. virtual const char* getElementName(void) const = 0;
  49. /**
  50. * Writes this object to the file stream as binary.
  51. */
  52. virtual void writeBinary(FILE* file);
  53. /**
  54. * Writes this object to the file stream as text.
  55. */
  56. virtual void writeText(FILE* file) = 0;
  57. /**
  58. * Returns this object's id string.
  59. */
  60. const std::string& getId() const;
  61. /**
  62. * Sets this object's id string.
  63. */
  64. void setId(const char* id);
  65. /**
  66. * Sets this object's id string.
  67. */
  68. void setId(const std::string& id);
  69. /**
  70. * Prints an XML start element with the name of this object to the text file stream.
  71. * Also prints the id as an attribute if the id length is greater than zero.
  72. */
  73. void fprintElementStart(FILE* file);
  74. /**
  75. * Prints an XML end element with the name of this object to the text file stream.
  76. */
  77. void fprintElementEnd(FILE* file);
  78. /**
  79. * Writes the xref of this object to the binary file stream.
  80. */
  81. void writeBinaryXref(FILE* file);
  82. /**
  83. * Returns the file position that this object was written to.
  84. * An offset of zero means this object has not been written yet.
  85. */
  86. unsigned int getFilePosition();
  87. /**
  88. * Writes out a list of objects to a binary file stream.
  89. */
  90. template <class T>
  91. static void writeBinaryObjects(std::list<T> list, FILE* file)
  92. {
  93. // First write the size of the list
  94. write((unsigned int)list.size(), file);
  95. // Then write each element
  96. typename std::list<T>::const_iterator i;
  97. for (i = list.begin(); i != list.end(); ++i)
  98. {
  99. (*i)->writeBinary(file);
  100. }
  101. }
  102. /**
  103. * Writes out a vector of objects to a binary file stream.
  104. */
  105. template <class T>
  106. static void writeBinaryObjects(std::vector<T> vector, FILE* file)
  107. {
  108. // First write the size of the vector
  109. write((unsigned int)vector.size(), file);
  110. // Then write each element
  111. typename std::vector<T>::const_iterator i;
  112. for (i = vector.begin(); i != vector.end(); ++i)
  113. {
  114. (*i)->writeBinary(file);
  115. }
  116. }
  117. private:
  118. /**
  119. * Saves where this object was written to in the binary file.
  120. */
  121. void saveFilePosition(FILE* file);
  122. private:
  123. std::string _id;
  124. long _fposition;
  125. };
  126. }
  127. #endif