Leaked source code of windows server 2003
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.

91 lines
1.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: symt.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // SYMTMBN.H: Symbol and symbol table handling declarations
  12. //
  13. #ifndef _SYMT_H_
  14. #define _SYMT_H_
  15. #include "zstrt.h"
  16. ////////////////////////////////////////////////////////////////////
  17. // template TMPSYMTBL: a symbol table
  18. //
  19. // Names ares ZSREFs based upon strings interned into
  20. // the internal string table using "intern()".
  21. //
  22. // Objects are smart pointers which destroy themselves
  23. // when assigned to or upon destruction of the symbol table.
  24. //
  25. // Public functions:
  26. //
  27. // add(): adds an association between an OBJ * and
  28. // its name string
  29. // find(): returns an OBJ * or NULL
  30. // intern(): registers a string in the symbol table's
  31. // string table.
  32. ////////////////////////////////////////////////////////////////////
  33. class GOBJMBN;
  34. template<class OBJ>
  35. class TMPSYMTBL :
  36. public map<ZSREF, REFPOBJ<OBJ>, less<ZSREF> >
  37. {
  38. typedef REFPOBJ<GOBJMBN> ROBJ;
  39. typedef map<ZSREF, REFPOBJ<OBJ>, less<ZSREF> > TSYMMAP;
  40. public:
  41. TMPSYMTBL () {};
  42. ~ TMPSYMTBL ()
  43. {
  44. clear();
  45. };
  46. void add ( SZC szc, OBJ * pobj )
  47. {
  48. ZSREF zsr = _stszstr.Zsref(szc);
  49. (*this)[zsr] = pobj;
  50. pobj->SetName(zsr);
  51. }
  52. OBJ * find ( SZC szc )
  53. {
  54. iterator it = TSYMMAP::find(_stszstr.Zsref(szc));
  55. return it == end()
  56. ? NULL
  57. : (*it).second.Pobj();
  58. }
  59. ZSREF intern ( SZC szc )
  60. {
  61. return _stszstr.Zsref(szc);
  62. }
  63. bool remove ( SZC szc )
  64. {
  65. iterator it = TSYMMAP::find(_stszstr.Zsref(szc));
  66. if ( it != end() )
  67. {
  68. erase(it);
  69. return true;
  70. }
  71. return false;
  72. }
  73. protected:
  74. // The ensemble of strings
  75. STZSTR _stszstr;
  76. HIDE_UNSAFE(TMPSYMTBL);
  77. };
  78. #endif