Expression.h 3.9 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: Expression.h /main/4 1996/08/21 15:50:17 drk $ */
  24. #ifndef _Expression_h
  25. #define _Expression_h
  26. /* **************************************************************
  27. Defines the tree for evaluating expressions given as feature values
  28. in the Style Sheet
  29. * ************************************************************** */
  30. #include "SymTab.h"
  31. #ifndef CDE_NEXT
  32. typedef dlist_array<Symbol> f_items_t;
  33. #else
  34. #include "dti_cc/cc_povec.h"
  35. typedef dlist_array<Symbol> f_items_t;
  36. #endif
  37. class FeatureValue;
  38. class TermNode;
  39. // /////////////////////////////////////////////////////////////////////////
  40. // class Expression
  41. //
  42. // holds root of expression tree
  43. // /////////////////////////////////////////////////////////////////////////
  44. class Expression
  45. {
  46. public:
  47. Expression(TermNode *root);
  48. Expression(const Expression&);
  49. virtual ~Expression();
  50. virtual FeatureValue *evaluate() const;
  51. ostream &print(ostream &) const;
  52. private:
  53. TermNode* f_root;
  54. };
  55. class TermNode
  56. {
  57. public:
  58. virtual ~TermNode();
  59. virtual FeatureValue *evaluate() const = 0;
  60. virtual ostream &print(ostream &) const = 0;
  61. virtual TermNode *clone() const = 0;
  62. };
  63. class VariableNode: public TermNode
  64. {
  65. // for single name variables eg: "DEFAULT_FONT"
  66. public:
  67. VariableNode(const Symbol& name);
  68. virtual FeatureValue *evaluate() const;
  69. ostream &print(ostream &) const;
  70. virtual TermNode *clone() const;
  71. private:
  72. Symbol f_name;
  73. };
  74. class CompositeVariableNode : public TermNode
  75. {
  76. // for feature path variables (font.size)
  77. // eg: font: { size: font.size }
  78. public:
  79. CompositeVariableNode();
  80. CompositeVariableNode(size_t capac); /* if we know how many items to expect */
  81. ~CompositeVariableNode();
  82. virtual FeatureValue *evaluate() const ;
  83. ostream &print(ostream &) const;
  84. virtual TermNode *clone() const;
  85. void prependItem(const Symbol& item);
  86. void appendItem(const Symbol& item);
  87. const Symbol* convertableToVariable();
  88. private:
  89. //dlist_array<Symbol> f_items;
  90. f_items_t f_items;
  91. };
  92. class BinaryOperatorNode: public TermNode
  93. {
  94. public:
  95. enum operatorType { PLUS, MINUS, TIMES, DIVIDE };
  96. BinaryOperatorNode(operatorType, TermNode* left, TermNode* right);
  97. ~BinaryOperatorNode();
  98. virtual TermNode *clone() const;
  99. virtual FeatureValue *evaluate() const;
  100. ostream &print(ostream &) const;
  101. private:
  102. operatorType f_operator ;
  103. TermNode *f_left;
  104. TermNode *f_right;
  105. };
  106. class SgmlAttributeNode: public TermNode
  107. {
  108. public:
  109. SgmlAttributeNode(const Symbol& name);
  110. SgmlAttributeNode();
  111. virtual FeatureValue *evaluate() const ;
  112. ostream &print(ostream &) const;
  113. virtual TermNode *clone() const;
  114. private:
  115. Symbol f_name;
  116. };
  117. class ConstantNode: public TermNode
  118. {
  119. public:
  120. ConstantNode(FeatureValue*);
  121. ~ConstantNode();
  122. virtual FeatureValue *evaluate() const;
  123. ostream &print(ostream &) const;
  124. virtual TermNode *clone() const;
  125. private:
  126. FeatureValue *f_value;
  127. };
  128. ostream &operator <<(ostream &, const Expression &);
  129. ostream &operator <<(ostream &, const TermNode &);
  130. #endif /* _Expression_h */
  131. /* DO NOT ADD ANY LINES AFTER THIS #endif */