plist_pvt.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #ifndef _PLIST_PVT_H
  42. #define _PLIST_PVT_H
  43. /*
  44. * FILE: plist_pvt.h
  45. *
  46. * DESCRIPTION:
  47. *
  48. * This file contains private definitions for the property list
  49. * utility implementation.
  50. */
  51. #include "base/pool.h"
  52. /* Forward declarations */
  53. typedef struct PLValueStruct_s PLValueStruct_t;
  54. typedef struct PLSymbol_s PLSymbol_t;
  55. typedef struct PLSymbolTable_s PLSymbolTable_t;
  56. typedef struct PListStruct_s PListStruct_t;
  57. /*
  58. * TYPE: PLValueStruct_t
  59. *
  60. * DESCRIPTION:
  61. *
  62. * This type represents a property value. It is dynamically
  63. * allocated when a new property is added to a property list.
  64. * It contains a reference to a property list that contains
  65. * information about the property value, and a reference to
  66. * the property value data.
  67. */
  68. #include <stddef.h>
  69. struct PLValueStruct_s {
  70. pb_entry pv_pbentry; /* used for pblock compatibility */
  71. pb_param pv_pbparam; /* property name and value pointers */
  72. PLValueStruct_t *pv_next; /* property name hash collision link */
  73. PListStruct_t *pv_type; /* property value type reference */
  74. int pv_pi; /* property index */
  75. int pv_flags; /* bit flags */
  76. };
  77. #define pv_name pv_pbparam.name
  78. #define pv_value pv_pbparam.value
  79. /* pv_flags definitions */
  80. #define PVF_MALLOC 0x1 /* allocated via MALLOC */
  81. /* Offset to pv_pbparam in PLValueStruct_t */
  82. #define PVPBOFFSET offsetof(struct PLValueStruct_s,pv_pbparam)
  83. /* Convert pb_param pointer to PLValueStruct_t pointer */
  84. #define PATOPV(p) ((PLValueStruct_t *)((char *)(p) - PVPBOFFSET))
  85. /*
  86. * TYPE: PLSymbolTable_t
  87. *
  88. * DESCRIPTION:
  89. *
  90. * This type represents a symbol table that maps property names
  91. * to properties. It is dynamically allocated the first time a
  92. * property is named.
  93. */
  94. #define PLSTSIZES {7, 19, 31, 67, 123, 257, 513}
  95. #define PLMAXSIZENDX (sizeof(plistHashSizes)/sizeof(plistHashSizes[0]))
  96. struct PLSymbolTable_s {
  97. int pt_sizendx; /* pt_hash size, as an index in PLSTSIZES */
  98. int pt_nsyms; /* number of symbols in table */
  99. PLValueStruct_t *pt_hash[1];/* variable-length array */
  100. };
  101. /*
  102. * TYPE: PListStruct_t
  103. *
  104. * DESCRIPTION:
  105. *
  106. * This type represents the top-level of a property list structure.
  107. * It is dynamically allocated when a property list is created, and
  108. * freed when the property list is destroyed. It references a
  109. * dynamically allocated array of pointers to property value
  110. * structures (PLValueStruct_t).
  111. */
  112. #define PLIST_DEFSIZE 8 /* default initial entries in pl_ppval */
  113. #define PLIST_DEFGROW 16 /* default incremental entries for pl_ppval */
  114. struct PListStruct_s {
  115. pblock pl_pb; /* pblock subset of property list head */
  116. PLSymbolTable_t *pl_symtab; /* property name to index symbol table */
  117. pool_handle_t *pl_mempool; /* associated memory pool handle */
  118. int pl_maxprop; /* maximum number of properties */
  119. int pl_resvpi; /* number of reserved property indices */
  120. int pl_lastpi; /* last allocated property index */
  121. int pl_cursize; /* current size of pl_ppval in entries */
  122. };
  123. #define pl_initpi pl_pb.hsize /* number of pl_ppval entries initialized */
  124. #define pl_ppval pl_pb.ht /* pointer to array of value pointers */
  125. /* Convert pblock pointer to PListStruct_t pointer */
  126. #define PBTOPL(p) ((PListStruct_t *)(p))
  127. #define PLSIZENDX(i) (plistHashSizes[i])
  128. #define PLHASHSIZE(i) (sizeof(PLSymbolTable_t) + \
  129. (PLSIZENDX(i) - 1)*sizeof(PLValueStruct_t *))
  130. extern int plistHashSizes[7];
  131. extern int PListHashName(PLSymbolTable_t *symtab, const char *pname);
  132. #endif /* _PLIST_PVT_H */