Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

261 lines
14 KiB

  1. //========= Copyright � 1996-2004, Valve LLC, All rights reserved. ============
  2. //
  3. // Purpose: Sets of columns in queries
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef COLUMNSET_H
  8. #define COLUMNSET_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. namespace GCSDK
  13. {
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Sets of columns in queries
  16. //-----------------------------------------------------------------------------
  17. class CColumnSet
  18. {
  19. public:
  20. CColumnSet( const CRecordInfo *pRecordInfo );
  21. CColumnSet( const CRecordInfo *pRecordInfo, int nColumn );
  22. CColumnSet( const CColumnSet & rhs );
  23. CColumnSet & operator=( const CColumnSet & rhs );
  24. const CColumnSet operator+( const CColumnSet & rhs ) const;
  25. CColumnSet & operator+=( const CColumnSet & rhs );
  26. bool BAddColumn( int nColumn );
  27. bool BRemoveColumn( int nColumn );
  28. bool IsSet( int nColumn ) const;
  29. bool IsEmpty() const { return m_vecColumns.Count() == 0;}
  30. uint32 GetColumnCount() const;
  31. int GetColumn( int nIndex ) const;
  32. const CColumnInfo & GetColumnInfo( int nIndex ) const;
  33. const CRecordInfo *GetRecordInfo() const { return m_pRecordInfo; }
  34. // putting column sets in messages
  35. void AddToMessage( CGCMsgBase *pMsg ) const;
  36. bool BParseFromMessage( CGCMsgBase *pMsg );
  37. void MakeEmpty();
  38. void MakeFull();
  39. void MakeInsertable();
  40. void MakeNoninsertable();
  41. void MakePrimaryKey();
  42. void MakeInverse( const CColumnSet & columnSet );
  43. template< typename TSchClass >
  44. static CColumnSet Empty();
  45. template< typename TSchClass >
  46. static CColumnSet Full();
  47. template< typename TSchClass >
  48. static CColumnSet Insertable();
  49. template< typename TSchClass >
  50. static CColumnSet Noninsertable();
  51. template< typename TSchClass >
  52. static CColumnSet PrimaryKey();
  53. static CColumnSet Inverse( const CColumnSet & columnSet );
  54. #ifdef DBGFLAG_VALIDATE
  55. void Validate( CValidator &validator, const char *pchName );
  56. #endif
  57. private:
  58. CUtlVector<int> m_vecColumns;
  59. const CRecordInfo *m_pRecordInfo;
  60. };
  61. // Usage notes:
  62. // The fields in a column set are order-dependent, and must match the order of the fields in
  63. // the query used to generate the data. The code that reads values doesn't do any fancy
  64. // name-matching and will copy values to incorrect locations silently if there is a
  65. // disagreement between the fields in the query and the fields in the column set.
  66. //
  67. // Examples:
  68. // // This is broken.
  69. // query = "SELECT * FROM Items";
  70. // columnSet = CSET_12_COL( CSchItem, individual_field_names );
  71. //
  72. // // This is fixed.
  73. // query = "SELECT * FROM Items";
  74. // columnSet = CSET_FULL( ... );
  75. #define FOR_EACH_COLUMN_IN_SET( columnSet, iterName ) for( uint32 iterName = 0; iterName < (columnSet).GetColumnCount(); iterName++ )
  76. #define CSET_EMPTY( schClass ) CColumnSet::Empty<schClass>()
  77. #define CSET_FULL( schClass ) CColumnSet::Full<schClass>()
  78. #define CSET_INSERTABLE( schClass ) CColumnSet::Insertable<schClass>()
  79. #define CSET_NONINSERTABLE( schClass ) CColumnSet::Noninsertable<schClass>()
  80. #define CSET_PK( schClass ) CColumnSet::PrimaryKey<schClass>()
  81. #define CSET_1_COL( schClass, col1 ) \
  82. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 )
  83. #define CSET_2_COL( schClass, col1, col2 ) \
  84. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  85. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 )
  86. #define CSET_3_COL( schClass, col1, col2, col3 ) \
  87. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  88. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  89. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 )
  90. #define CSET_4_COL( schClass, col1, col2, col3, col4 ) \
  91. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  92. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  93. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  94. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 )
  95. #define CSET_5_COL( schClass, col1, col2, col3, col4, col5 ) \
  96. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  97. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  98. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  99. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  100. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 )
  101. #define CSET_6_COL( schClass, col1, col2, col3, col4, col5, col6 ) \
  102. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  103. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  104. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  105. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  106. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  107. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 )
  108. #define CSET_7_COL( schClass, col1, col2, col3, col4, col5, col6, col7 ) \
  109. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  110. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  111. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  112. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  113. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  114. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  115. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 )
  116. #define CSET_8_COL( schClass, col1, col2, col3, col4, col5, col6, col7, col8 ) \
  117. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  118. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  119. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  120. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  121. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  122. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  123. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 ) + \
  124. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col8 )
  125. #define CSET_9_COL( schClass, col1, col2, col3, col4, col5, col6, col7, col8, col9 ) \
  126. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  127. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  128. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  129. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  130. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  131. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  132. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 ) + \
  133. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col8 ) + \
  134. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col9 )
  135. #define CSET_10_COL( schClass, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10 ) \
  136. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  137. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  138. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  139. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  140. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  141. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  142. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 ) + \
  143. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col8 ) + \
  144. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col9 ) + \
  145. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col10 )
  146. #define CSET_11_COL( schClass, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11 ) \
  147. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  148. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  149. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  150. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  151. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  152. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  153. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 ) + \
  154. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col8 ) + \
  155. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col9 ) + \
  156. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col10 ) + \
  157. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col11 )
  158. #define CSET_12_COL( schClass, col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12 ) \
  159. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col1 ) + \
  160. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col2 ) + \
  161. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col3 ) + \
  162. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col4 ) + \
  163. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col5 ) + \
  164. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col6 ) + \
  165. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col7 ) + \
  166. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col8 ) + \
  167. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col9 ) + \
  168. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col10 ) + \
  169. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col11 ) + \
  170. CColumnSet( GSchemaFull().GetSchema( schClass::k_iTable ).GetRecordInfo(), schClass::col12 )
  171. //-----------------------------------------------------------------------------
  172. // Purpose: Returns an empty Column Set for a schema class
  173. //-----------------------------------------------------------------------------
  174. template< typename TSchClass >
  175. CColumnSet CColumnSet::Empty()
  176. {
  177. CColumnSet set( GSchemaFull().GetSchema( TSchClass::k_iTable ).GetRecordInfo() );
  178. return set;
  179. }
  180. //-----------------------------------------------------------------------------
  181. // Purpose: Returns a Column Set for a schema class which contains every field
  182. //-----------------------------------------------------------------------------
  183. template< typename TSchClass >
  184. CColumnSet CColumnSet::Full()
  185. {
  186. CColumnSet set( GSchemaFull().GetSchema( TSchClass::k_iTable ).GetRecordInfo() );
  187. set.MakeFull();
  188. return set;
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Purpose: Returns a Column Set for a schema class which contains every
  192. // insertable field
  193. //-----------------------------------------------------------------------------
  194. template< typename TSchClass >
  195. CColumnSet CColumnSet::Insertable()
  196. {
  197. CColumnSet set( GSchemaFull().GetSchema( TSchClass::k_iTable ).GetRecordInfo() );
  198. set.MakeInsertable();
  199. return set;
  200. }
  201. //-----------------------------------------------------------------------------
  202. // Purpose: Returns a Column Set for a schema class which contains every
  203. // noninsertable field
  204. //-----------------------------------------------------------------------------
  205. template< typename TSchClass >
  206. CColumnSet CColumnSet::Noninsertable()
  207. {
  208. CColumnSet set( GSchemaFull().GetSchema( TSchClass::k_iTable ).GetRecordInfo() );
  209. set.MakeNoninsertable();
  210. return set;
  211. }
  212. //-----------------------------------------------------------------------------
  213. // Purpose: Returns a Column Set for a schema class which contains every
  214. // primary key field
  215. //-----------------------------------------------------------------------------
  216. template< typename TSchClass >
  217. CColumnSet CColumnSet::PrimaryKey()
  218. {
  219. CColumnSet set( GSchemaFull().GetSchema( TSchClass::k_iTable ).GetRecordInfo() );
  220. set.MakePrimaryKey();
  221. return set;
  222. }
  223. } // namespace GCSDK
  224. #endif // COLUMNSET_H