File indexing completed on 2024-05-12 15:39:11
0001 /* 0002 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 1. Redistributions of source code must retain the above copyright 0008 * notice, this list of conditions and the following disclaimer. 0009 * 2. Redistributions in binary form must reproduce the above copyright 0010 * notice, this list of conditions and the following disclaimer in the 0011 * documentation and/or other materials provided with the distribution. 0012 * 0013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 0014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0015 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 0017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0018 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0019 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 0020 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 0021 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 0026 #ifndef SMILTime_h 0027 #define SMILTime_h 0028 0029 #if ENABLE(SVG) 0030 0031 #include <algorithm> 0032 0033 namespace WebCore 0034 { 0035 0036 class SMILTime 0037 { 0038 public: 0039 SMILTime() : m_time(0) { } 0040 SMILTime(double time) : m_time(time) { } 0041 SMILTime(const SMILTime &o) : m_time(o.m_time) { } 0042 0043 static SMILTime unresolved() 0044 { 0045 return unresolvedValue; 0046 } 0047 static SMILTime indefinite() 0048 { 0049 return indefiniteValue; 0050 } 0051 0052 SMILTime &operator=(const SMILTime &o) 0053 { 0054 m_time = o.m_time; 0055 return *this; 0056 } 0057 double value() const 0058 { 0059 return m_time; 0060 } 0061 0062 bool isFinite() const 0063 { 0064 return m_time < indefiniteValue; 0065 } 0066 bool isIndefinite() const 0067 { 0068 return m_time == indefiniteValue; 0069 } 0070 bool isUnresolved() const 0071 { 0072 return m_time == unresolvedValue; 0073 } 0074 0075 private: 0076 static const double unresolvedValue; 0077 static const double indefiniteValue; 0078 0079 double m_time; 0080 }; 0081 0082 inline bool operator==(const SMILTime &a, const SMILTime &b) 0083 { 0084 return a.isFinite() && a.value() == b.value(); 0085 } 0086 inline bool operator!=(const SMILTime &a, const SMILTime &b) 0087 { 0088 return !operator==(a, b); 0089 } 0090 inline bool operator>(const SMILTime &a, const SMILTime &b) 0091 { 0092 return a.value() > b.value(); 0093 } 0094 inline bool operator<(const SMILTime &a, const SMILTime &b) 0095 { 0096 return a.value() < b.value(); 0097 } 0098 inline bool operator>=(const SMILTime &a, const SMILTime &b) 0099 { 0100 return a.value() > b.value() || operator==(a, b); 0101 } 0102 inline bool operator<=(const SMILTime &a, const SMILTime &b) 0103 { 0104 return a.value() < b.value() || operator==(a, b); 0105 } 0106 0107 inline SMILTime max(const SMILTime &a, const SMILTime &b) 0108 { 0109 return std::max(a.value(), b.value()); 0110 } 0111 inline SMILTime min(const SMILTime &a, const SMILTime &b) 0112 { 0113 return std::min(a.value(), b.value()); 0114 } 0115 SMILTime operator+(const SMILTime &, const SMILTime &); 0116 SMILTime operator-(const SMILTime &, const SMILTime &); 0117 // So multiplying times does not make too much sense but SMIL defines it for duration * repeatCount 0118 SMILTime operator*(const SMILTime &, const SMILTime &); 0119 } 0120 0121 #endif 0122 #endif