proton/timestamp.hpp

Go to the documentation of this file.
00001 #ifndef PROTON_TIMESTAMP_HPP
00002 #define PROTON_TIMESTAMP_HPP
00003 
00004 /*
00005  * Licensed to the Apache Software Foundation (ASF) under one
00006  * or more contributor license agreements.  See the NOTICE file
00007  * distributed with this work for additional information
00008  * regarding copyright ownership.  The ASF licenses this file
00009  * to you under the Apache License, Version 2.0 (the
00010  * "License"); you may not use this file except in compliance
00011  * with the License.  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,
00016  * software distributed under the License is distributed on an
00017  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00018  * KIND, either express or implied.  See the License for the
00019  * specific language governing permissions and limitations
00020  * under the License.
00021  */
00022 
00023 #include "./duration.hpp"
00024 
00025 #include <proton/type_compat.h>
00026 
00029 
00030 namespace proton {
00031 
00035 class timestamp : private internal::comparable<timestamp> {
00036   public:
00038     typedef int64_t numeric_type;
00039 
00041     PN_CPP_EXTERN static timestamp now();
00042 
00044     explicit timestamp(numeric_type ms = 0) : ms_(ms) {}
00045 
00047     timestamp& operator=(numeric_type ms) { ms_ = ms; return *this; }
00048 
00050     numeric_type milliseconds() const { return ms_; }
00051 
00052   private:
00053     numeric_type ms_;
00054 };
00055 
00058 inline bool operator==(timestamp x, timestamp y) { return x.milliseconds() == y.milliseconds(); }
00059 inline bool operator<(timestamp x, timestamp y) { return x.milliseconds() < y.milliseconds(); }
00060 
00061 inline timestamp operator+(timestamp ts, duration d) { return timestamp(ts.milliseconds() + d.milliseconds()); }
00062 inline timestamp operator-(timestamp ts, duration d) { return timestamp(ts.milliseconds() - d.milliseconds()); }
00063 inline duration operator-(timestamp t0, timestamp t1) { return duration(t0.milliseconds() - t1.milliseconds()); }
00064 inline timestamp operator+(duration d, timestamp ts) { return ts + d; }
00066 
00068 PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, timestamp);
00069 
00070 } // proton
00071 
00072 #endif // PROTON_TIMESTAMP_HPP

Generated on 17 Jan 2019 for Qpid Proton C++ by  doxygen 1.6.1