Source code of Windows XP (NT5)
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.

191 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. persist.h
  5. Abstract:
  6. General structure persistence functions, structure and definitions.
  7. Author:
  8. Aghajanyan Souren 27-Mar-2001
  9. Revision History:
  10. --*/
  11. #ifndef _PERSIST_H_
  12. #define _PERSIST_H_
  13. #define BYVALUE TRUE
  14. #define BYREF FALSE
  15. #define END_OF_STRUCT (BYTE*)0xffffffff
  16. typedef enum tagPersistResultsEnum{
  17. Persist_Success = 0,
  18. Persist_BadParameters,
  19. Persist_Fail,
  20. Persist_WrongSignature,
  21. Persist_WrongVersion
  22. } PersistResultsEnum;
  23. typedef struct {
  24. DWORD dwSignature;
  25. DWORD dwVersion;
  26. DWORD dwReserved;
  27. } PERSIST_HEADER, * PPERSIST_HEADER;
  28. typedef enum tagStringType{
  29. NoStr,
  30. AnsiStr,
  31. UnicodeStr
  32. }StringType;
  33. typedef struct tagFIELD_DESCRIPTION{
  34. BYTE * Offset;
  35. StringType IsString;
  36. DWORD Size;
  37. BOOL byValue;
  38. UINT * ArraySizeFieldOffset;
  39. struct tagFIELD_DESCRIPTION * FieldDescription;
  40. //
  41. //For structures with variable size
  42. //struct VariableSizeStruct{
  43. // ......
  44. // UINT uiNumberOfItem;
  45. // ITEM items[1];
  46. //};
  47. //Where InitialNumberOfItemInArrayForVariableStructMember is
  48. //number of element in items array initialy
  49. //
  50. UINT InitialNumberOfItem;
  51. }FIELD_DESCRIPTION, *PFIELD_DESCRIPTION;
  52. typedef struct tagSTRUCT_DEFINITION{
  53. DWORD dwVersion;
  54. DWORD dwReserved;
  55. PFIELD_DESCRIPTION FieldDescriptions;
  56. }STRUCT_DEFINITION, *PSTRUCT_DEFINITION;
  57. #define GET_STRUCT_MEMBER_OFFSET(structname, fieldname) ((BYTE *)&((structname *)NULL)->fieldname)
  58. #define GET_STRUCT_MEMBER_BYVALUE_FROM_OFFSET(type, structptr, offset) ((type)(((BYTE *)structptr) + ((DWORD)offset)))
  59. #define GET_STRUCT_MEMBER_BYREF_FROM_OFFSET(type, structptr, offset) ((type)*((DWORD *)(((BYTE *)structptr) + ((DWORD)offset))))
  60. #define GET_TYPE_DEFINITION_FROM_NAME(name, version) g_DefinitionOf_##name##_##version
  61. #define GET_TYPE_DESCRIPTION_FROM_NAME(name, version) g_DescriptionOf_##name##_##version
  62. #define PERSIST_BEGIN_DECLARE_STRUCT(name, version) FIELD_DESCRIPTION GET_TYPE_DESCRIPTION_FROM_NAME(name, version)[] = {
  63. #define PERSIST_END_DECLARE_STRUCT(name, version) {END_OF_STRUCT, NoStr, 0, 0, 0, 0}};\
  64. STRUCT_DEFINITION GET_TYPE_DEFINITION_FROM_NAME(name, version) = {version, 0, GET_TYPE_DESCRIPTION_FROM_NAME(name, version)};
  65. #define PERSISTENCE_IMPLEMENTATION(name) name;
  66. #define PERSIST_FIELD(structname, type, version, fieldname, isString, byValue, arraySizeVar) \
  67. {\
  68. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  69. (isString), \
  70. sizeof(type), \
  71. (byValue), \
  72. GET_STRUCT_MEMBER_OFFSET(structname, arraySizeVar), \
  73. GET_TYPE_DESCRIPTION_FROM_NAME(type, version), \
  74. 0, \
  75. }
  76. #define PERSIST_FIELD_BY_VALUE(structname, type, fieldname) \
  77. {\
  78. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  79. NoStr, \
  80. sizeof(type), \
  81. TRUE, \
  82. NULL, \
  83. NULL, \
  84. 0, \
  85. }
  86. #define PERSIST_FIELD_STRINGW(structname, fieldname) \
  87. {\
  88. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  89. UnicodeStr, \
  90. 0, \
  91. BYREF, \
  92. NULL, \
  93. NULL, \
  94. 0, \
  95. }
  96. #define PERSIST_STRUCT_BY_VALUE_VARIABLE_LENGTH(structname, type, fieldname, arraySizeVar, InitialNumberOfItem) \
  97. {\
  98. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  99. NoStr, \
  100. sizeof(type), \
  101. TRUE, \
  102. (UINT *)GET_STRUCT_MEMBER_OFFSET(structname, arraySizeVar), \
  103. NULL, \
  104. InitialNumberOfItem, \
  105. }
  106. #define PERSIST_FIELD_NESTED_TYPE(structname, type, version, fieldname, byValue) \
  107. {\
  108. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  109. NoStr, \
  110. sizeof(type), \
  111. (byValue), \
  112. NULL, \
  113. GET_TYPE_DESCRIPTION_FROM_NAME(type, version), \
  114. 0, \
  115. }
  116. #define PERSIST_FIELD_NESTED_TYPE_CYCLE(structname, type, version, fieldname, byValue, arraySizeVar) \
  117. {\
  118. GET_STRUCT_MEMBER_OFFSET(structname, fieldname), \
  119. NoStr, \
  120. sizeof(type), \
  121. (byValue), \
  122. (UINT *)GET_STRUCT_MEMBER_OFFSET(structname, arraySizeVar), \
  123. GET_TYPE_DESCRIPTION_FROM_NAME(type, version), \
  124. 0, \
  125. }
  126. PersistResultsEnum
  127. PersistStore(
  128. IN BYTE ** pBuffer,
  129. IN UINT *Size,
  130. IN BYTE * pStructure,
  131. IN PSTRUCT_DEFINITION StructDefinitionPtr
  132. );
  133. PersistResultsEnum
  134. PersistLoad(
  135. IN BYTE * pBuffer,
  136. IN UINT Size,
  137. IN BYTE * pStructure,
  138. IN PSTRUCT_DEFINITION StructDefinitionPtr
  139. );
  140. VOID
  141. PersistReleaseMemory(
  142. IN BYTE * pStructure,
  143. IN PFIELD_DESCRIPTION pFieldsDescription
  144. );
  145. BOOL
  146. CompareStructures(
  147. IN BYTE * pStructure1,
  148. IN BYTE * pStructure2,
  149. IN PFIELD_DESCRIPTION pFieldsDescription
  150. );
  151. #define PERSIST_STORE(pBufferPtr, SizePtr, structname, version, pStructurePtr) PersistStore(pBufferPtr, SizePtr, (BYTE*)pStructurePtr, &(GET_TYPE_DEFINITION_FROM_NAME(structname, version)))
  152. #define PERSIST_LOAD(pBufferPtr, Size, structname, version, pStructurePtr) PersistLoad(pBufferPtr, Size, (BYTE*)pStructurePtr, &(GET_TYPE_DEFINITION_FROM_NAME(structname, version)))
  153. #define PERSIST_RELEASE_STRUCT_MEMORY(structname, version, pStructurePtr) PersistReleaseMemory((BYTE*)pStructurePtr, GET_TYPE_DEFINITION_FROM_NAME(structname, version).FieldDescriptions)
  154. #define PERSIST_RELEASE_BUFFER(pBuffer) FreeMem(pBuffer)
  155. #define PERSIST_COMPARE_STRUCTURES(structname, version, pStructurePtr1, pStructurePtr2) CompareStructures((BYTE*)pStructurePtr1, (BYTE*)pStructurePtr2, GET_TYPE_DEFINITION_FROM_NAME(structname, version).FieldDescriptions)
  156. #endif