plist_pvt.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifndef _PLIST_PVT_H
  39. #define _PLIST_PVT_H
  40. /*
  41. * FILE: plist_pvt.h
  42. *
  43. * DESCRIPTION:
  44. *
  45. * This file contains private definitions for the property list
  46. * utility implementation.
  47. */
  48. #include "base/pool.h"
  49. /* Forward declarations */
  50. typedef struct PLValueStruct_s PLValueStruct_t;
  51. typedef struct PLSymbol_s PLSymbol_t;
  52. typedef struct PLSymbolTable_s PLSymbolTable_t;
  53. typedef struct PListStruct_s PListStruct_t;
  54. /*
  55. * TYPE: PLValueStruct_t
  56. *
  57. * DESCRIPTION:
  58. *
  59. * This type represents a property value. It is dynamically
  60. * allocated when a new property is added to a property list.
  61. * It contains a reference to a property list that contains
  62. * information about the property value, and a reference to
  63. * the property value data.
  64. */
  65. #include <stddef.h>
  66. struct PLValueStruct_s {
  67. pb_entry pv_pbentry; /* used for pblock compatibility */
  68. pb_param pv_pbparam; /* property name and value pointers */
  69. PLValueStruct_t *pv_next; /* property name hash collision link */
  70. PListStruct_t *pv_type; /* property value type reference */
  71. int pv_pi; /* property index */
  72. int pv_flags; /* bit flags */
  73. };
  74. #define pv_name pv_pbparam.name
  75. #define pv_value pv_pbparam.value
  76. /* pv_flags definitions */
  77. #define PVF_MALLOC 0x1 /* allocated via MALLOC */
  78. /* Offset to pv_pbparam in PLValueStruct_t */
  79. #define PVPBOFFSET offsetof(struct PLValueStruct_s,pv_pbparam)
  80. /* Convert pb_param pointer to PLValueStruct_t pointer */
  81. #define PATOPV(p) ((PLValueStruct_t *)((char *)(p) - PVPBOFFSET))
  82. /*
  83. * TYPE: PLSymbolTable_t
  84. *
  85. * DESCRIPTION:
  86. *
  87. * This type represents a symbol table that maps property names
  88. * to properties. It is dynamically allocated the first time a
  89. * property is named.
  90. */
  91. #define PLSTSIZES {7, 19, 31, 67, 123, 257, 513}
  92. #define PLMAXSIZENDX (sizeof(plistHashSizes)/sizeof(plistHashSizes[0]))
  93. struct PLSymbolTable_s {
  94. int pt_sizendx; /* pt_hash size, as an index in PLSTSIZES */
  95. int pt_nsyms; /* number of symbols in table */
  96. PLValueStruct_t *pt_hash[1];/* variable-length array */
  97. };
  98. /*
  99. * TYPE: PListStruct_t
  100. *
  101. * DESCRIPTION:
  102. *
  103. * This type represents the top-level of a property list structure.
  104. * It is dynamically allocated when a property list is created, and
  105. * freed when the property list is destroyed. It references a
  106. * dynamically allocated array of pointers to property value
  107. * structures (PLValueStruct_t).
  108. */
  109. #define PLIST_DEFSIZE 8 /* default initial entries in pl_ppval */
  110. #define PLIST_DEFGROW 16 /* default incremental entries for pl_ppval */
  111. struct PListStruct_s {
  112. pblock pl_pb; /* pblock subset of property list head */
  113. PLSymbolTable_t *pl_symtab; /* property name to index symbol table */
  114. pool_handle_t *pl_mempool; /* associated memory pool handle */
  115. int pl_maxprop; /* maximum number of properties */
  116. int pl_resvpi; /* number of reserved property indices */
  117. int pl_lastpi; /* last allocated property index */
  118. int pl_cursize; /* current size of pl_ppval in entries */
  119. };
  120. #define pl_initpi pl_pb.hsize /* number of pl_ppval entries initialized */
  121. #define pl_ppval pl_pb.ht /* pointer to array of value pointers */
  122. /* Convert pblock pointer to PListStruct_t pointer */
  123. #define PBTOPL(p) ((PListStruct_t *)(p))
  124. #define PLSIZENDX(i) (plistHashSizes[i])
  125. #define PLHASHSIZE(i) (sizeof(PLSymbolTable_t) + \
  126. (PLSIZENDX(i) - 1)*sizeof(PLValueStruct_t *))
  127. extern int plistHashSizes[7];
  128. extern int PListHashName(PLSymbolTable_t *symtab, const char *pname);
  129. #endif /* _PLIST_PVT_H */