Advertisement
dcomicboy

databasemgr

Dec 3rd, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.65 KB | None | 0 0
  1. //----------------------------------------------------------------------------------------------------
  2. // IDatabaseMgr.h
  3. //
  4. // Provides the definition for the IDatabaseMgr interface. This interface is used to load and manage
  5. // game databases. Each database contains a collection of categories. Each category represents a
  6. // type of entry, and contains a collection of records. Each record is an instance of a category
  7. // and holds a list of attributes. Each attribute is of a certain type and contains an array of values.
  8. // The database manager handles referencing of databases so that if multiple game objects are using
  9. // the same database it will only be loaded and stored once. This interface only supports read access
  10. // to databases. The IDatabaseCreator should be used for creating databases and saving them to disk.
  11. //
  12. //----------------------------------------------------------------------------------------------------
  13.  
  14. #ifndef __IDATABASEMGR_H__
  15. #define __IDATABASEMGR_H__
  16.  
  17. //handles for the different database objects
  18. class CDatabase;
  19. class CCategory;
  20. class CRecord;
  21. class CAttribute;
  22.  
  23. typedef CDatabase* HDATABASE;
  24. typedef const CCategory* HCATEGORY;
  25. typedef const CRecord* HRECORD;
  26. typedef const CAttribute* HATTRIBUTE;
  27.  
  28. //handles for the different database creator objects
  29. class CDatabaseCreator;
  30. class CCategoryCreator;
  31. class CRecordCreator;
  32. class CAttributeCreator;
  33.  
  34. typedef CDatabaseCreator* HDATABASECREATOR;
  35. typedef CCategoryCreator* HCATEGORYCREATOR;
  36. typedef CRecordCreator* HRECORDCREATOR;
  37. typedef CAttributeCreator* HATTRIBUTECREATOR;
  38.  
  39. //defnition for an invalid database index
  40. #define INVALID_GAME_DATABASE_INDEX 0xFFFFFFFF
  41.  
  42. //forward declarations
  43. class ILTInStream;
  44.  
  45. //An enumeration that specifies the different attribute types that are available
  46. enum EAttributeType
  47. {
  48. eAttributeType_Invalid,
  49. eAttributeType_Bool,
  50. eAttributeType_Float,
  51. eAttributeType_Int32,
  52. eAttributeType_String,
  53. eAttributeType_WString,
  54. eAttributeType_Vector2,
  55. eAttributeType_Vector3,
  56. eAttributeType_Vector4,
  57. eAttributeType_RecordLink,
  58. eAttributeType_Struct,
  59. };
  60.  
  61. //an enumeration that specifies the different usages a property can have. For example, a string
  62. //can be used as just a string or the name of an animation, a filename, or a reference to a ClientFX
  63. //This is only provided for informational purposes and does not effect database access at all
  64. enum EAttributeUsage
  65. {
  66. //the standard default attribute usage, no special usage
  67. eAttributeUsage_Default,
  68. //this attribute is intended to serve as a reference to a file resource
  69. eAttributeUsage_Filename,
  70. //this attribute is intended to serve as a reference to a client fx
  71. eAttributeUsage_ClientFX,
  72. //this attribute is intended to serve as a reference to a model animation
  73. eAttributeUsage_Animation,
  74. };
  75.  
  76. //IDatabaseMgr interface for managing game databases
  77. class IDatabaseMgr
  78. {
  79. public:
  80.  
  81. //------------------------------------
  82. // Database Management
  83. //------------------------------------
  84.  
  85. //Given the name of a database this will determine if the database is loaded, and if it is
  86. //it will return a new handle to that database. This handle must be released with ReleaseDatabase
  87. //otherwise it will be leaked. This will return NULL if the database has not already been loaded.
  88. virtual HDATABASE OpenExistingDatabase(const char* pszFileName) = 0;
  89.  
  90. //given the name of a database that this will be referred to as and an ILTInStream that is opened
  91. //for read access to the database to be read, this will load the database from the file and
  92. //return a handle to the new database. If the database already exists, it will not be read
  93. //again and instead a reference to the existing database will be returned. This returned handle
  94. //must be released with ReleaseDatabase otherwise it will result in a leak. The caller is responsible
  95. //for closing the passed in file stream.
  96. virtual HDATABASE OpenNewDatabase(const char* pszFileName, ILTInStream& InFile) = 0;
  97.  
  98. //given an ILTInStream to an unpacked file, this will load the database from the stream and
  99. //return a handle. This method does not perform any reference counting on databases, so calling
  100. //twice with the same stream will result in two separate instances. The returned handle must be
  101. //released with ReleaseDatabase otherwise it will result in a leak. The caller is responsible for
  102. //closing the passed in stream.
  103. virtual HDATABASE OpenUnpackedDatabase(ILTInStream& UnpackedFile, ILTInStream& ConstraintFile) = 0;
  104.  
  105. //this will convert a database that was created for writing over to a database that can be used
  106. //for reading. This is a costly operation and therefore should not be done at runtime. This will
  107. //return NULL if the conversion operation fails. It also takes a name that this database can be
  108. //identified by when using OpenExistingDatabase. If a database with that name is already opened,
  109. //it will use that database in place of converting. The returned handle must be freed with
  110. //ReleaseDatabase.
  111. virtual HDATABASE ConvertDatabase(HDATABASECREATOR hCreator, const char* pszDatabaseName) = 0;
  112.  
  113. //this will swap the values of two databases. Note that the values in the first database (hDatabase1)
  114. //must all be present in the second database (hDatabase2), meaning that the first is a subset of the
  115. //second. If this is not the case, this will return false. To restore the databases to their original
  116. //states, simply call this a second time.
  117. virtual bool SwapDatabaseValues(HDATABASE hDatabase1, HDATABASE hDatabase2) = 0;
  118.  
  119. //this will return the name of the database, or NULL if the provided database
  120. //is invalid. Note that this returned string must not be referenced after the database has been
  121. //released.
  122. virtual const char* GetDatabaseName(HDATABASE hDatabase) = 0;
  123.  
  124. //called to release a reference to the database. Once this call is made, none of the category,
  125. //record, or attribute handles that were obtained from this database are valid and must not be used.
  126. virtual void ReleaseDatabase(HDATABASE hDatabase) = 0;
  127.  
  128. //------------------------------------
  129. // Category Management
  130. //------------------------------------
  131.  
  132. //given a database and the name of a category, this will return a handle to the category within
  133. //the database or NULL if it cannot be found.
  134. virtual HCATEGORY GetCategory(HDATABASE hDatabase, const char* pszCategoryName) = 0;
  135.  
  136. //given a database, this will return the number of categories that exist within the database,
  137. //or 0 if the database is invalid
  138. virtual uint32 GetNumCategories(HDATABASE hDatabase) = 0;
  139.  
  140. //given a database and an index, this will return a handle to the category within
  141. //the database or NULL if the index is out of range or the database invalid.
  142. virtual HCATEGORY GetCategoryByIndex(HDATABASE hDatabase, uint32 nIndex) = 0;
  143.  
  144. //given a category, this will return the parent database of the category. This is guaranteed to
  145. //be valid as long as the category handle is valid.
  146. virtual HDATABASE GetCategoryParent(HCATEGORY hCategory) = 0;
  147.  
  148. //given a category, this will return the index of the category in the parent database. This
  149. //will return INVALID_GAME_DATABASE_INDEX if the category is invalid.
  150. virtual uint32 GetCategoryIndex(HCATEGORY hCategory) = 0;
  151.  
  152. //given a category this will return the name of the category, or NULL if the provided category
  153. //is invalid. Note that this returned string must not be referenced after the database has been
  154. //released.
  155. virtual const char* GetCategoryName(HCATEGORY hCategory) = 0;
  156.  
  157. //------------------------------------
  158. // Record Management
  159. //------------------------------------
  160.  
  161. //given a category, this allows for obtaining a record from the category by a string name. This
  162. //will return NULL if the category is invalid or the record cannot be found.
  163. virtual HRECORD GetRecord(HCATEGORY hCategory, const char* pszRecordName) = 0;
  164.  
  165. //allows for a more condensed form of access to an individual record given only a database. This
  166. //will return NULL if it cannot match any of the parameters in the hierarchy to get to the record.
  167. virtual HRECORD GetRecord( HDATABASE hDatabase, const char* pszCategory,
  168. const char* pszRecord) = 0;
  169.  
  170. //given a category, this returns how many records it contains, or 0 if the category
  171. //is invalid.
  172. virtual uint32 GetNumRecords(HCATEGORY hCategory) = 0;
  173.  
  174. //given a category, this allows for obtaining a record from the category by an index. This will return
  175. //NULL if the category is invalid or if the index is out of range
  176. virtual HRECORD GetRecordByIndex(HCATEGORY hCategory, uint32 nIndex) = 0;
  177.  
  178. //given a record, this will return the parent category of the record. This is guaranteed to
  179. //be valid as long as the record handle is valid.
  180. virtual HCATEGORY GetRecordParent(HRECORD hRecord) = 0;
  181.  
  182. //given a record, this will return the index of the record in the parent category. This
  183. //will return INVALID_GAME_DATABASE_INDEX if the record is invalid.
  184. virtual uint32 GetRecordIndex(HRECORD hRecord) = 0;
  185.  
  186. //given a record, this will return the record name, or NULL if the provided record
  187. //is invalid. Note that this returned string must not be referenced after the database has been
  188. //released.
  189. virtual const char* GetRecordName(HRECORD hRecord) = 0;
  190.  
  191. //------------------------------------
  192. // Attribute Management
  193. //------------------------------------
  194.  
  195. //given a record this will get an attribute by name. This will return NULL if the record is invalid
  196. //or if the attribute cannot be found.
  197. virtual HATTRIBUTE GetAttribute(HRECORD hRecord, const char* pszAttributeName) = 0;
  198.  
  199. //allows for a more condensed form of access to an individual attribute given only a database. This
  200. //will return NULL if it cannot match any of the parameters in the hierarchy to get to the attribute.
  201. virtual HATTRIBUTE GetAttribute( HDATABASE hDatabase, const char* pszCategory,
  202. const char* pszRecord, const char* pszAttribute) = 0;
  203.  
  204. //allows for a more condensed form of access to an individual attribute given only a database. This
  205. //will return NULL if it cannot match any of the parameters in the hierarchy to get to the attribute.
  206. virtual HATTRIBUTE GetAttribute( HCATEGORY hCategory, const char* pszRecord,
  207. const char* pszAttribute) = 0;
  208.  
  209. //given a record this will return how many attributes it contains
  210. virtual uint32 GetNumAttributes(HRECORD hRecord) = 0;
  211.  
  212. //given a record and an index, this will return the appropriate attribute, or NULL if the record
  213. //is invalid or the index out of range
  214. virtual HATTRIBUTE GetAttributeByIndex(HRECORD hRecord, uint32 nIndex) = 0;
  215.  
  216. //given an attribute, this will return the parent record of the attribute. This is guaranteed to
  217. //be valid as long as the attribute handle is valid.
  218. virtual HRECORD GetAttributeParent(HATTRIBUTE hAttribute) = 0;
  219.  
  220. //given an attribute, this will return the index of the attribute in the parent record. This
  221. //will return INVALID_GAME_DATABASE_INDEX if the attribute is invalid.
  222. virtual uint32 GetAttributeIndex(HATTRIBUTE hAttribute) = 0;
  223.  
  224. //given an attribute, this will return the attribute name, or NULL if the provided attribute
  225. //is invalid. Note that this returned string must not be referenced after the database has been
  226. //released.
  227. virtual const char* GetAttributeName(HATTRIBUTE hAttribute) = 0;
  228.  
  229. //------------------------------------
  230. // Value Management
  231. //------------------------------------
  232.  
  233. //given an attribute this will determine how many values it contains. All valid attributes are
  234. //guaranteed to contain at least one value. An invalid attribute handle will return 0
  235. virtual uint32 GetNumValues(HATTRIBUTE hAttribute) = 0;
  236.  
  237. //provides access to the type of the attribute. This will return eAttributeType_Invalid if the
  238. //attribute handle is invalid.
  239. virtual EAttributeType GetAttributeType(HATTRIBUTE hAttribute) = 0;
  240.  
  241. //provides access to the usage of this attribute. This can be used to get more information about
  242. //how the field is supposed to be used and is provided for informational purposes only. This will return
  243. //the default usage if the provided attribute is invalid
  244. virtual EAttributeUsage GetAttributeUsage(HATTRIBUTE hAttribute) = 0;
  245.  
  246. //provides access to an integer value. This will return the default should the attribute
  247. //be invalid, the value index out of range, or the attribute type is different than expected.
  248. virtual int32 GetInt32(HATTRIBUTE hAttribute, uint32 nValueIndex, int32 nDefault) = 0;
  249.  
  250. //provides access to a floating point value. This will return the default should the attribute
  251. //be invalid, the value index out of range, or the attribute type is different than expected.
  252. virtual float GetFloat(HATTRIBUTE hAttribute, uint32 nValueIndex, float fDefault) = 0;
  253.  
  254. //provides access to a string value. This will return the default should the attribute
  255. //be invalid, the value index out of range, or the attribute type is different than expected.
  256. virtual const char* GetString(HATTRIBUTE hAttribute, uint32 nValueIndex, const char* pszDefault) = 0;
  257.  
  258. //provides access to a unicode string value. This will return the default should the attribute
  259. //be invalid, the value index out of range, or the attribute type is different than expected.
  260. virtual const wchar_t* GetWString(HATTRIBUTE hAttribute, uint32 nValueIndex, const wchar_t* pszDefault) = 0;
  261.  
  262. //provides access to a vector 3 value. This will return the default should the attribute
  263. //be invalid, the value index out of range, or the attribute type is different than expected.
  264. virtual LTVector2 GetVector2(HATTRIBUTE hAttribute, uint32 nValueIndex, const LTVector2& vDefault) = 0;
  265.  
  266. //provides access to a vector 3 value. This will return the default should the attribute
  267. //be invalid, the value index out of range, or the attribute type is different than expected.
  268. virtual LTVector GetVector3(HATTRIBUTE hAttribute, uint32 nValueIndex, const LTVector& vDefault) = 0;
  269.  
  270. //provides access to a vector 4 value. This will return the default should the attribute
  271. //be invalid, the value index out of range, or the attribute type is different than expected.
  272. virtual LTVector4 GetVector4(HATTRIBUTE hAttribute, uint32 nValueIndex, const LTVector4& vDefault) = 0;
  273.  
  274. //provides access to a boolean value. This will return the default should the attribute
  275. //be invalid, or the value index out of range.
  276. virtual bool GetBool(HATTRIBUTE hAttribute, uint32 nValueIndex, bool bDefault) = 0;
  277.  
  278. //provides access to a record link value. This will return the default should the attribute
  279. //be invalid, or the value index out of range.
  280. virtual HRECORD GetRecordLink(HATTRIBUTE hAttribute, uint32 nValueIndex, HRECORD hDefault) = 0;
  281. };
  282.  
  283.  
  284. #endif
  285.  
  286.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement