blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved. 00003 * Copyright (C) 2006, Novell, Inc. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of 00014 * Vintela, Inc., 00015 * nor Novell, Inc., 00016 * nor the names of its contributors or employees may be used to 00017 * endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 *******************************************************************************/ 00032 00033 00038 #include "blocxx/BLOCXX_config.h" 00039 #include "blocxx/Timeout.hpp" 00040 #include "blocxx/DateTime.hpp" 00041 #include "blocxx/Infinity.hpp" 00042 00043 00044 namespace BLOCXX_NAMESPACE 00045 { 00046 00048 // static 00049 Timeout 00050 Timeout::absolute(const DateTime& dt) 00051 { 00052 return Timeout(E_ABSOLUTE, dt); 00053 } 00054 00056 // static 00057 Timeout 00058 Timeout::relative(float seconds) 00059 { 00060 return Timeout(E_RELATIVE, seconds); 00061 } 00062 00064 // static 00065 Timeout 00066 Timeout::relativeWithReset(float seconds) 00067 { 00068 return Timeout(E_RELATIVE_WITH_RESET, seconds); 00069 } 00070 00072 //static 00073 Timeout Timeout::infinite = relative(INFINITY); 00074 00075 Timeout::ETimeoutType 00076 Timeout::getType() const 00077 { 00078 return m_type; 00079 } 00080 00081 DateTime 00082 Timeout::getAbsolute() const 00083 { 00084 return m_absolute; 00085 } 00086 00087 float 00088 Timeout::getRelative() const 00089 { 00090 return m_seconds; 00091 } 00092 00093 Timeout::Timeout() 00094 { 00095 } 00096 00097 Timeout::Timeout(ETimeoutType type, const DateTime& dt) 00098 : m_type(type) 00099 , m_absolute(dt) 00100 { 00101 } 00102 00103 Timeout::Timeout(ETimeoutType type, float seconds) 00104 : m_type(type) 00105 , m_seconds(seconds) 00106 { 00107 } 00108 00109 bool operator==(const Timeout& x, const Timeout& y) 00110 { 00111 if (x.getType() != y.getType()) 00112 { 00113 return false; 00114 } 00115 if (x.getType() == Timeout::E_ABSOLUTE) 00116 { 00117 return x.getAbsolute() == y.getAbsolute(); 00118 } 00119 else 00120 { 00121 return x.getRelative() == y.getRelative(); 00122 } 00123 } 00124 00125 bool operator!=(const Timeout& x, const Timeout& y) 00126 { 00127 return !(x == y); 00128 } 00129 00130 } // end namespace BLOCXX_NAMESPACE 00131 00132 00133 00134