/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/sys/Time.h

00001 #ifndef _sys_Time_h
00002 #define _sys_Time_h
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  * 
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  * 
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include <stdint.h>
00026 #include <limits>
00027 #include <iosfwd>
00028 
00029 namespace qpid {
00030 namespace sys {
00031 
00032 class Duration;
00033 
00066 class AbsTime {
00067     static int64_t max() { return std::numeric_limits<int64_t>::max(); }
00068     int64_t time_ns;
00069     
00070     friend class Duration;
00071         
00072 public:
00073     inline AbsTime() {}
00074     inline AbsTime(const AbsTime& time0, const Duration& duration);
00075     // Default assignment operation fine
00076     // Default copy constructor fine
00077          
00078     static AbsTime now();
00079     inline static AbsTime FarFuture();
00080     bool operator==(const AbsTime& t) const { return t.time_ns == time_ns; }
00081     template <class S> void serialize(S& s) { s(time_ns); }
00082 
00083     friend bool operator<(const AbsTime& a, const AbsTime& b);
00084     friend bool operator>(const AbsTime& a, const AbsTime& b);
00085     friend std::ostream& operator << (std::ostream&, const AbsTime&);
00086 };
00087 
00088 std::ostream& operator << (std::ostream&, const AbsTime&);
00089 
00096 class Duration {
00097     static int64_t max() { return std::numeric_limits<int64_t>::max(); }
00098     int64_t nanosecs;
00099 
00100     friend class AbsTime;
00101 
00102 public:
00103     inline Duration(int64_t time0);
00104     inline explicit Duration(const AbsTime& time0);
00105     inline explicit Duration(const AbsTime& start, const AbsTime& finish);
00106     inline operator int64_t() const;
00107 };
00108 
00109 std::ostream& operator << (std::ostream&, const Duration&);
00110 
00111 AbsTime::AbsTime(const AbsTime& t, const Duration& d) :
00112     time_ns(d == Duration::max() ? max() : t.time_ns+d.nanosecs)
00113 {}
00114 
00115 AbsTime AbsTime::FarFuture() { AbsTime ff; ff.time_ns = max(); return ff;}
00116 
00117 inline AbsTime now() { return AbsTime::now(); }
00118 
00119 inline bool operator<(const AbsTime& a, const AbsTime& b) { return a.time_ns < b.time_ns; }
00120 inline bool operator>(const AbsTime& a, const AbsTime& b) { return a.time_ns > b.time_ns; }
00121 
00122 Duration::Duration(int64_t time0) :
00123     nanosecs(time0)
00124 {}
00125 
00126 Duration::Duration(const AbsTime& time0) :
00127     nanosecs(time0.time_ns)
00128 {}
00129 
00130 Duration::Duration(const AbsTime& start, const AbsTime& finish) :
00131     nanosecs(finish.time_ns - start.time_ns)
00132 {}
00133 
00134 Duration::operator int64_t() const
00135 { return nanosecs; }
00136 
00138 const Duration TIME_SEC  = 1000*1000*1000;
00140 const Duration TIME_MSEC = 1000*1000;
00142 const Duration TIME_USEC = 1000;
00144 const Duration TIME_NSEC = 1;
00145 
00147 const Duration TIME_INFINITE = std::numeric_limits<int64_t>::max();
00148 
00150 const AbsTime FAR_FUTURE = AbsTime::FarFuture();
00151 
00152 }}
00153 
00154 #endif  

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7