FeatureDefDictionary.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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: FeatureDefDictionary.h /main/4 1996/08/21 15:50:25 drk $ */
  24. #ifndef _featureNameDictionary_h
  25. #define _featureNameDictionary_h
  26. #ifndef CDE_NEXT
  27. #else
  28. //#include "StyleSheet/cde_next.h"
  29. #include "dti_cc/CC_Slist.h"
  30. #include "dti_cc/cc_hdict.h"
  31. #include "dti_cc/CC_String.h"
  32. #endif
  33. #include "StyleSheet/Types.h"
  34. #include "StyleSheet/SymTab.h"
  35. #include "StyleSheet/FeatureValue.h"
  36. #include "StyleSheet/Feature.h"
  37. #include "StyleSheet/StyleSheetExceptions.h"
  38. typedef CC_TPtrSlist<FeatureValue> defv_t;
  39. typedef CC_TPtrSlistIterator<FeatureValue> defv_iterator_t;
  40. class TypeValues : public Destructable
  41. {
  42. public:
  43. enum feature_t {real, integer, string, featureset, unit} ;
  44. enum unit_t { INCH=0, PICA=1, POINT=2, CM=3, PIXEL=4, NONE=5 };
  45. TypeValues(char* type, defv_t*);
  46. ~TypeValues();
  47. unsigned int operator==(const TypeValues&);
  48. unsigned check(const FeatureValue*);
  49. friend ostream& operator <<(ostream&, TypeValues&);
  50. ostream& print(ostream&, int tabs) const;
  51. protected:
  52. CC_String f_type;
  53. defv_t* f_default_values;
  54. protected:
  55. };
  56. class FeatureDef;
  57. typedef CC_TPtrSlist<FeatureDef> def_list_t;
  58. typedef CC_TPtrSlistIterator<FeatureDef> def_list_iterator_t;
  59. typedef CC_TPtrSlist<TypeValues> type_values_list_t;
  60. typedef CC_TPtrSlistIterator<TypeValues> type_values_list_iterator_t;
  61. class FeatureDef : public Destructable
  62. {
  63. public:
  64. FeatureDef(const char* name);
  65. virtual ~FeatureDef();
  66. unsigned int operator==(const FeatureDef&);
  67. friend ostream& operator <<(ostream&, FeatureDef&) ;
  68. enum def_type_t { PRIMITIVE, COMPOSITE, REFERENCE, WILDCARD };
  69. virtual unsigned type() const = 0;
  70. virtual const CC_String* name() const { return &f_name; };
  71. virtual ostream& print(ostream&, int tabs) const= 0;
  72. virtual unsigned checkContent(const Feature*) const = 0;
  73. protected:
  74. CC_String f_name;
  75. protected:
  76. };
  77. class FeatureDefComposite : public FeatureDef
  78. {
  79. public:
  80. FeatureDefComposite(const char* name, def_list_t*);
  81. ~FeatureDefComposite();
  82. unsigned checkContent(const Feature*)const ;
  83. const FeatureDef* getComponentDef(const char*) const;
  84. unsigned type() const { return COMPOSITE; };
  85. protected:
  86. def_list_t* f_components;
  87. protected:
  88. virtual ostream& print(ostream&, int tabs) const;
  89. }
  90. ;
  91. class FeatureDefPrimitive: public FeatureDef
  92. {
  93. public:
  94. FeatureDefPrimitive(const char* name, type_values_list_t* tvslist);
  95. ~FeatureDefPrimitive();
  96. unsigned type() const { return PRIMITIVE; };
  97. unsigned checkContent(const Feature*)const ;
  98. protected:
  99. type_values_list_t* f_typeValuesList;
  100. protected:
  101. virtual ostream& print(ostream&, int tabs) const;
  102. }
  103. ;
  104. class FeatureDefReference : public FeatureDef
  105. {
  106. public:
  107. FeatureDefReference(const char* name) : FeatureDef(name) {};
  108. ~FeatureDefReference() {};
  109. unsigned type() const { return REFERENCE; };
  110. unsigned checkContent(const Feature*)const ;
  111. protected:
  112. protected:
  113. virtual ostream& print(ostream&, int tabs) const;
  114. }
  115. ;
  116. class FeatureDefWildCard : public FeatureDef
  117. {
  118. public:
  119. FeatureDefWildCard(const char* name) : FeatureDef(name) {};
  120. ~FeatureDefWildCard() {};
  121. unsigned type() const { return WILDCARD; };
  122. unsigned checkContent(const Feature*)const ;
  123. protected:
  124. protected:
  125. virtual ostream& print(ostream&, int tabs) const;
  126. }
  127. ;
  128. //typedef hashTable<FeatureDef, FeatureDef> featureDefDictionary_t;
  129. //typedef hashTableIterator<FeatureDef, FeatureDef> featureDefDictionary_iterator_t;
  130. class featureDefDictionary : public Destructable
  131. {
  132. protected:
  133. def_list_t* f_def_list;
  134. protected:
  135. const FeatureDef* getDef(const char*);
  136. const FeatureDef* getDef(const Feature*);
  137. //const FeatureDef* getDef(const Feature*, const Feature*);
  138. unsigned _checkSemantics(const Feature* f, const FeatureDef*);
  139. public:
  140. featureDefDictionary();
  141. ~featureDefDictionary();
  142. void addFeatureDefs(def_list_t*);
  143. unsigned checkSemantics(const FeatureSet*);
  144. //format:
  145. //
  146. // featureName
  147. // ComponentName : Type [: Default Values (',' separated)]
  148. // ComponentName : Type [: Default Values (',' separated)]
  149. // featureName
  150. // ComponentName : Type [: Default Values (',' separated)]
  151. // ComponentName : Type [: Default Values (',' separated)]
  152. //
  153. // Example:
  154. // font
  155. // size : Unit
  156. // weight : String : "medium", "bold"
  157. //
  158. friend istream& operator >>(istream&, featureDefDictionary&);
  159. friend ostream& operator <<(ostream&, featureDefDictionary&);
  160. };
  161. #endif