PathTable.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: PathTable.h /main/4 1996/08/21 15:50:37 drk $ */
  24. #ifndef _PathTable_h
  25. #define _PathTable_h
  26. #ifndef CDE_NEXT
  27. #else
  28. #include "dti_cc/CC_Dlist.h"
  29. #include "dti_cc/cc_hdict.h"
  30. #endif
  31. #include <sstream>
  32. #include "Types.h"
  33. #include "SymTab.h"
  34. #include "SSPath.h"
  35. #include "BitVector.h"
  36. class Feature;
  37. class FeatureSet;
  38. #define OP_ONE "?"
  39. #define OP_MANY "*"
  40. typedef unsigned int LetterType;
  41. class EncodedPath
  42. {
  43. int f_size;
  44. int f_patternSize;
  45. LetterType* f_array;
  46. hashTable<LetterType, BitVector> f_SVectors;
  47. LetterType f_wildCard;
  48. LetterType f_unlimitedWildCard;
  49. BitVector* f_copyOfS; // copy of S vector, used in match()
  50. public:
  51. EncodedPath(SSPath* p, unsigned int asPattern = false);
  52. ~EncodedPath();
  53. int length() { return f_size; };
  54. int patternLength() { return f_patternSize; };
  55. unsigned int match(EncodedPath& p, SSPath* Pattern, SSPath* Elements);
  56. }
  57. ;
  58. class basePathFeature
  59. {
  60. protected:
  61. SSPath* f_path;
  62. FeatureSet* f_featureSet;
  63. public:
  64. basePathFeature(SSPath* p=0, FeatureSet* f=0):
  65. f_path(p), f_featureSet(f) {};
  66. ~basePathFeature();
  67. unsigned int operator==(const basePathFeature&) const;
  68. SSPath* path() { return f_path; };
  69. FeatureSet* featureSet() { return f_featureSet; };
  70. void setPath(SSPath* p) { f_path = p; };
  71. void setFeatureSet(FeatureSet* fs) { f_featureSet = fs; };
  72. };
  73. class PathFeature : public basePathFeature
  74. {
  75. unsigned int f_id;
  76. EncodedPath* f_encodedPath;
  77. public:
  78. PathFeature(SSPath* p,FeatureSet* f,EncodedPath* e=0, unsigned int id=0):
  79. basePathFeature(p, f), f_id(id), f_encodedPath(e) {};
  80. ~PathFeature();
  81. EncodedPath* encodedPath() { return f_encodedPath; };
  82. unsigned int id() { return f_id; };
  83. void setEncodedPath(EncodedPath* e) { f_encodedPath = e; };
  84. void setID(int x) { f_id = x; };
  85. unsigned int operator==(const PathFeature&) const;
  86. unsigned int match(SSPath& p);
  87. };
  88. class PathFeatureList : public CC_TPtrDlist<PathFeature>
  89. {
  90. public:
  91. PathFeatureList() {};
  92. virtual ~PathFeatureList();
  93. void appendList(PathFeatureList&);
  94. };
  95. typedef CC_TPtrDlistIterator<PathFeature> PathFeatureListIterator;
  96. // /////////////////////////////////////////////////////////////////////////
  97. //
  98. // class PathTable
  99. //
  100. // /////////////////////////////////////////////////////////////////////////
  101. typedef CC_TPtrDlist<PathFeature>* CC_TPtrDlist_PathFeature_Ptr_T;
  102. class PathTable
  103. {
  104. public:
  105. PathTable();
  106. ~PathTable();
  107. // add a path and associated raw feature set
  108. // this should only be called by the style sheet parser to build this internal
  109. // table
  110. //
  111. // Assume that the paths are passed in in left to right order. i.e.,
  112. // in the order
  113. // "TITLE SECTION"
  114. // "TITLE CHAPTER"
  115. // with the example shown above.
  116. //
  117. //void addPathFeatureSet(Path*, FeatureSet *rawFeatureSet);
  118. void addPathFeatureSet(PathFeature*);
  119. // returns a NULL value if no feature set is available at this point
  120. // this "new"s a new feature set, and the caller is responsible for
  121. // deleting the object
  122. FeatureSet* getFeatureSet(SSPath&);
  123. friend ostream& operator<<(ostream&, PathTable&);
  124. private:
  125. CC_TPtrDlist<PathFeature> f_pathFeatureList;
  126. CC_TPtrDlist_PathFeature_Ptr_T *f_lastSymIndex;
  127. unsigned int f_lastSymIndexCount ;
  128. private:
  129. void initLastSymIndex();
  130. unsigned int findIndex(SSPath&);
  131. FeatureSet* getFeatureSet(int bucketIndex, SSPath&, int& pathId);
  132. };
  133. extern PathTable* gPathTab;
  134. #endif /* _PathTable_h */
  135. /* DO NOT ADD ANY LINES AFTER THIS #endif */