00001 #ifndef OMG_DDS_CORE_DURATION_HPP_ 00002 #define OMG_DDS_CORE_DURATION_HPP_ 00003 00004 /* Copyright 2010, Object Management Group, Inc. 00005 * Copyright 2010, PrismTech, Corp. 00006 * Copyright 2010, Real-Time Innovations, Inc. 00007 * All rights reserved. 00008 * 00009 * Licensed under the Apache License, Version 2.0 (the "License"); 00010 * you may not use this file except in compliance with the License. 00011 * You may obtain a copy of the License at 00012 * 00013 * http://www.apache.org/licenses/LICENSE-2.0 00014 * 00015 * Unless required by applicable law or agreed to in writing, software 00016 * distributed under the License is distributed on an "AS IS" BASIS, 00017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00018 * See the License for the specific language governing permissions and 00019 * limitations under the License. 00020 */ 00021 00022 #include <dds/core/corefwd.hpp> 00023 00024 00025 namespace dds { namespace core { 00026 00030 class Duration { 00031 public: 00032 static const Duration zero(); // {0, 0} 00033 static const Duration infinite(); // {0x7fffffff, 0x7fffffff} 00034 public: 00038 Duration(); 00039 00043 explicit Duration(int32_t sec, uint32_t nanosec = 0); 00044 00045 ~Duration(); 00046 00047 public: 00048 static const Duration from_microseconds(int64_t microseconds); 00049 static const Duration from_milliseconds(int64_t milliseconds); 00050 static const Duration from_seconds(double seconds); 00051 00052 public: 00053 int32_t sec() const; 00054 void sec(int32_t s); 00055 00056 uint32_t nanosec() const; 00057 void nanosec(uint32_t ns); 00058 00065 void reset(int32_t s, uint32_t ns); 00066 00067 public: 00068 int compare(const Duration& that) const; 00069 00070 bool operator >(const Duration& that) const; 00071 bool operator >=(const Duration& that) const; 00072 00073 bool operator ==(const Duration& that) const; 00074 00075 bool operator <=(const Duration& that) const; 00076 bool operator <(const Duration& that) const; 00077 00078 public: 00079 Duration& operator+=(const Duration &a_ti); 00080 Duration& operator-=(const Duration &a_ti); 00081 00082 public: 00083 void set_in_milliseconds(int64_t millisec); 00084 int64_t get_in_milliseconds() const; 00085 00086 void set_in_microseconds(int64_t microsec); 00087 int64_t get_in_microseconds() const; 00088 00089 void set_in_seconds(double seconds); 00090 double get_in_seconds() const; 00091 00092 private: 00093 uint32_t sec_; 00094 uint32_t nsec_; 00095 }; 00096 00097 // Duration arithmetic operators. 00098 const Duration operator +(const Duration& lhs, 00099 const Duration& rhs); 00100 const Duration operator -(const Duration& lhs, 00101 const Duration& rhs); 00102 const Duration operator *(uint32_t lhs, 00103 const Duration& rhs); 00104 const Duration operator *(const Duration& lhs, 00105 uint32_t rhs); 00106 const Duration operator /(uint32_t lhs, 00107 const Duration& rhs); 00108 const Duration operator /(const Duration& lhs, 00109 uint32_t rhs); 00110 00111 } } /* namespace dds / namespace core */ 00112 #endif /* OMG_DDS_CORE_DURATION_HPP_ */ 00113
1.7.1