/contrib/groff/src/roff/troff/dictionary.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 92 lines · 57 code · 13 blank · 22 comment · 0 complexity · f00f3e4409a29e6b3f8d8843ad1d132b MD5 · raw file

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3. Written by James Clark (jjc@jclark.com)
  4. This file is part of groff.
  5. groff is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 2, or (at your option) any later
  8. version.
  9. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License along
  14. with groff; see the file COPYING. If not, write to the Free Software
  15. Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
  16. // there is no distinction between name with no value and name with NULL value
  17. // null names are not permitted (they will be ignored).
  18. struct association {
  19. symbol s;
  20. void *v;
  21. association() : v(0) {}
  22. };
  23. class dictionary;
  24. class dictionary_iterator {
  25. dictionary *dict;
  26. int i;
  27. public:
  28. dictionary_iterator(dictionary &);
  29. int get(symbol *, void **);
  30. };
  31. class dictionary {
  32. int size;
  33. int used;
  34. double threshold;
  35. double factor;
  36. association *table;
  37. void rehash(int);
  38. public:
  39. dictionary(int);
  40. void *lookup(symbol s, void *v=0); // returns value associated with key
  41. void *lookup(const char *);
  42. // if second parameter not NULL, value will be replaced
  43. void *remove(symbol);
  44. friend class dictionary_iterator;
  45. };
  46. class object {
  47. int rcount;
  48. public:
  49. object();
  50. virtual ~object();
  51. void add_reference();
  52. void remove_reference();
  53. };
  54. class object_dictionary;
  55. class object_dictionary_iterator {
  56. dictionary_iterator di;
  57. public:
  58. object_dictionary_iterator(object_dictionary &);
  59. int get(symbol *, object **);
  60. };
  61. class object_dictionary {
  62. dictionary d;
  63. public:
  64. object_dictionary(int);
  65. object *lookup(symbol nm);
  66. void define(symbol nm, object *obj);
  67. void rename(symbol oldnm, symbol newnm);
  68. void remove(symbol nm);
  69. int alias(symbol newnm, symbol oldnm);
  70. friend class object_dictionary_iterator;
  71. };
  72. inline int object_dictionary_iterator::get(symbol *sp, object **op)
  73. {
  74. return di.get(sp, (void **)op);
  75. }