DDS-PSM-C++  1.0
ISO C++ API for OpenSplice DDS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Duration.hpp
Go to the documentation of this file.
1 #ifndef OMG_DDS_CORE_DURATION_HPP_
2 #define OMG_DDS_CORE_DURATION_HPP_
3 
4 /* Copyright 2010, Object Management Group, Inc.
5  * Copyright 2010, PrismTech, Corp.
6  * Copyright 2010, Real-Time Innovations, Inc.
7  * All rights reserved.
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #include <dds/core/types.hpp>
23 
24 namespace dds { namespace core {
25 
30  public:
31  static const Duration zero(); // {0, 0}
32  static const Duration infinite(); // {0x7fffffff, 0x7fffffff}
33  public:
37  Duration();
38 
42  explicit Duration(int32_t sec, uint32_t nanosec = 0);
43 
44  ~Duration();
45 
46  public:
47  static const Duration from_microsecs(int64_t microseconds);
48  static const Duration from_millisecs(int64_t milliseconds);
49  static const Duration from_secs(double seconds);
50 
51  public:
52  int32_t sec() const;
53  void sec(int32_t s);
54 
55  uint32_t nanosec() const;
56  void nanosec(uint32_t ns);
57 
58  public:
59  int compare(const Duration& that) const;
60 
61  bool operator >(const Duration& that) const;
62  bool operator >=(const Duration& that) const;
63 
64  bool operator ==(const Duration& that) const;
65 
66  bool operator <=(const Duration& that) const;
67  bool operator <(const Duration& that) const;
68 
69  public:
70  Duration& operator+=(const Duration &a_ti);
71  Duration& operator-=(const Duration &a_ti);
72 
73  const Duration operator +(const Duration& other) const;
74  const Duration operator -(const Duration& other) const;
75  public:
81  int64_t to_millisecs() const;
82 
88  int64_t to_microsecs() const;
89 
95  double to_secs() const;
96 
97  private:
98  uint32_t sec_;
99  uint32_t nsec_;
100  };
101 
102  const Duration operator *(uint32_t lhs,
103  const Duration& rhs);
104 
105  const Duration operator *(const Duration& lhs,
106  uint32_t rhs);
107 
108 
109  const Duration operator /(const Duration& lhs,
110  uint32_t rhs);
111 
112 } } /* namespace dds / namespace core */
113 #endif /* OMG_DDS_CORE_DURATION_HPP_ */
114