| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 CalcAdd = '+', | 44 CalcAdd = '+', |
| 45 CalcSubtract = '-', | 45 CalcSubtract = '-', |
| 46 CalcMultiply = '*', | 46 CalcMultiply = '*', |
| 47 CalcDivide = '/' | 47 CalcDivide = '/' |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 enum CalculationPermittedValueRange { | 50 enum CalculationPermittedValueRange { |
| 51 CalculationRangeAll, | 51 CalculationRangeAll, |
| 52 CalculationRangeNonNegative | 52 CalculationRangeNonNegative |
| 53 }; | 53 }; |
| 54 |
| 55 enum CalcExpressionNodeType { |
| 56 CalcExpressionNodeUndefined, |
| 57 CalcExpressionNodeNumber, |
| 58 CalcExpressionNodeLength, |
| 59 CalcExpressionNodeBinaryOperation |
| 60 }; |
| 54 | 61 |
| 55 class CalcExpressionNode { | 62 class CalcExpressionNode { |
| 56 public: | 63 public: |
| 64 CalcExpressionNode() |
| 65 : m_type(CalcExpressionNodeUndefined) |
| 66 { |
| 67 } |
| 68 |
| 57 virtual ~CalcExpressionNode() | 69 virtual ~CalcExpressionNode() |
| 58 { | 70 { |
| 59 } | 71 } |
| 60 | 72 |
| 61 virtual float evaluate(float maxValue) const = 0; | 73 virtual float evaluate(float maxValue) const = 0; |
| 74 virtual bool operator==(const CalcExpressionNode&) const = 0; |
| 75 |
| 76 CalcExpressionNodeType type() const { return m_type; } |
| 77 |
| 78 protected: |
| 79 CalcExpressionNodeType m_type; |
| 62 }; | 80 }; |
| 63 | 81 |
| 64 class CalculationValue : public RefCounted<CalculationValue> { | 82 class CalculationValue : public RefCounted<CalculationValue> { |
| 65 public: | 83 public: |
| 66 static PassRefPtr<CalculationValue> create(PassOwnPtr<CalcExpressionNode> va
lue, CalculationPermittedValueRange); | 84 static PassRefPtr<CalculationValue> create(PassOwnPtr<CalcExpressionNode> va
lue, CalculationPermittedValueRange); |
| 67 float evaluate(float maxValue) const; | 85 float evaluate(float maxValue) const; |
| 86 |
| 87 bool operator==(const CalculationValue& o) const |
| 88 { |
| 89 return m_value == o.m_value || *(m_value.get()) == *(o.m_value.get()); |
| 90 } |
| 68 | 91 |
| 69 private: | 92 private: |
| 70 CalculationValue(PassOwnPtr<CalcExpressionNode> value, CalculationPermittedV
alueRange range) | 93 CalculationValue(PassOwnPtr<CalcExpressionNode> value, CalculationPermittedV
alueRange range) |
| 71 : m_value(value) | 94 : m_value(value) |
| 72 , m_isNonNegative(range == CalculationRangeNonNegative) | 95 , m_isNonNegative(range == CalculationRangeNonNegative) |
| 73 { | 96 { |
| 74 } | 97 } |
| 75 | 98 |
| 76 OwnPtr<CalcExpressionNode> m_value; | 99 OwnPtr<CalcExpressionNode> m_value; |
| 77 bool m_isNonNegative; | 100 bool m_isNonNegative; |
| 78 }; | 101 }; |
| 79 | 102 |
| 80 class CalcExpressionNumber : public CalcExpressionNode { | 103 class CalcExpressionNumber : public CalcExpressionNode { |
| 81 public: | 104 public: |
| 82 explicit CalcExpressionNumber(float value) | 105 explicit CalcExpressionNumber(float value) |
| 83 : m_value(value) | 106 : m_value(value) |
| 84 { | 107 { |
| 108 m_type = CalcExpressionNodeNumber; |
| 85 } | 109 } |
| 86 | 110 |
| 111 bool operator==(const CalcExpressionNumber& o) const |
| 112 { |
| 113 return m_value == o.m_value; |
| 114 } |
| 115 |
| 116 virtual bool operator==(const CalcExpressionNode& o) const |
| 117 { |
| 118 return type() == o.type() && *this == static_cast<const CalcExpressionNu
mber&>(o); |
| 119 } |
| 120 |
| 87 virtual float evaluate(float) const | 121 virtual float evaluate(float) const |
| 88 { | 122 { |
| 89 return m_value; | 123 return m_value; |
| 90 } | 124 } |
| 91 | 125 |
| 92 private: | 126 private: |
| 93 float m_value; | 127 float m_value; |
| 94 }; | 128 }; |
| 95 | 129 |
| 96 class CalcExpressionLength : public CalcExpressionNode { | 130 class CalcExpressionLength : public CalcExpressionNode { |
| 97 public: | 131 public: |
| 98 explicit CalcExpressionLength(Length length) | 132 explicit CalcExpressionLength(Length length) |
| 99 : m_length(length) | 133 : m_length(length) |
| 100 { | 134 { |
| 135 m_type = CalcExpressionNodeLength; |
| 101 } | 136 } |
| 102 | 137 |
| 138 bool operator==(const CalcExpressionLength& o) const |
| 139 { |
| 140 return m_length == o.m_length; |
| 141 } |
| 142 |
| 143 virtual bool operator==(const CalcExpressionNode& o) const |
| 144 { |
| 145 return type() == o.type() && *this == static_cast<const CalcExpressionLe
ngth&>(o); |
| 146 } |
| 147 |
| 103 virtual float evaluate(float maxValue) const | 148 virtual float evaluate(float maxValue) const |
| 104 { | 149 { |
| 105 return floatValueForLength(m_length, maxValue); | 150 return floatValueForLength(m_length, maxValue); |
| 106 } | 151 } |
| 107 | 152 |
| 108 private: | 153 private: |
| 109 Length m_length; | 154 Length m_length; |
| 110 }; | 155 }; |
| 111 | 156 |
| 112 class CalcExpressionBinaryOperation : public CalcExpressionNode { | 157 class CalcExpressionBinaryOperation : public CalcExpressionNode { |
| 113 public: | 158 public: |
| 114 CalcExpressionBinaryOperation(PassOwnPtr<CalcExpressionNode> leftSide, PassO
wnPtr<CalcExpressionNode> rightSide, CalcOperator op) | 159 CalcExpressionBinaryOperation(PassOwnPtr<CalcExpressionNode> leftSide, PassO
wnPtr<CalcExpressionNode> rightSide, CalcOperator op) |
| 115 : m_leftSide(leftSide) | 160 : m_leftSide(leftSide) |
| 116 , m_rightSide(rightSide) | 161 , m_rightSide(rightSide) |
| 117 , m_operator(op) | 162 , m_operator(op) |
| 118 { | 163 { |
| 164 m_type = CalcExpressionNodeBinaryOperation; |
| 119 } | 165 } |
| 120 | 166 |
| 167 bool operator==(const CalcExpressionBinaryOperation& o) const |
| 168 { |
| 169 return m_operator == o.m_operator && *m_leftSide == *o.m_leftSide && *m_
rightSide == *o.m_rightSide; |
| 170 } |
| 171 |
| 172 virtual bool operator==(const CalcExpressionNode& o) const |
| 173 { |
| 174 return type() == o.type() && *this == static_cast<const CalcExpressionBi
naryOperation&>(o); |
| 175 } |
| 176 |
| 177 |
| 121 virtual float evaluate(float) const; | 178 virtual float evaluate(float) const; |
| 122 | 179 |
| 123 private: | 180 private: |
| 124 OwnPtr<CalcExpressionNode> m_leftSide; | 181 OwnPtr<CalcExpressionNode> m_leftSide; |
| 125 OwnPtr<CalcExpressionNode> m_rightSide; | 182 OwnPtr<CalcExpressionNode> m_rightSide; |
| 126 CalcOperator m_operator; | 183 CalcOperator m_operator; |
| 127 }; | 184 }; |
| 128 | 185 |
| 129 } // namespace WebCore | 186 } // namespace WebCore |
| 130 | 187 |
| 131 #endif // CalculationValue_h | 188 #endif // CalculationValue_h |
| OLD | NEW |