Program Listing for File Time.hpp

Return to documentation for file (/tmp/ws/src/fastrtps/include/dds/core/Time.hpp)

/*
 * Copyright 2010, Object Management Group, Inc.
 * Copyright 2010, PrismTech, Corp.
 * Copyright 2010, Real-Time Innovations, Inc.
 * Copyright 2019, Proyectos y Sistemas de Mantenimiento SL (eProsima).
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OMG_DDS_CORE_TIME_HPP_
#define OMG_DDS_CORE_TIME_HPP_

#include <dds/core/types.hpp>

namespace dds {
namespace core {

class Duration;
class Time;

class OMG_DDS_API Time
{
public:

    static const Time invalid();       // {-1, 0xffffffff}

    static const Time from_microsecs(
            int64_t microseconds);

    static const Time from_millisecs(
            int64_t milliseconds);

    static const Time from_secs(
            double seconds);

    Time();

    explicit Time(
            int64_t sec,
            uint32_t nanosec = 0);

    int64_t sec() const;

    void sec(
            int64_t s);

    uint32_t nanosec() const;

    void nanosec(
            uint32_t ns);

    int compare(
            const Time& that) const;

    bool operator >(
            const Time& that) const;

    bool operator >=(
            const Time& that) const;

    bool operator !=(
            const Time& that) const;

    bool operator ==(
            const Time& that) const;
    bool operator <=(
            const Time& that) const;
    bool operator <(
            const Time& that) const;

    Time& operator +=(
            const Duration& a_ti);
    Time& operator -=(
            const Duration& a_ti);

    int64_t to_millisecs() const;

    int64_t to_microsecs() const;

    double to_secs() const;

private:

    int64_t sec_ = 0;
    uint32_t nsec_ = 0;
};

// Time arithmetic operators.
const Time OMG_DDS_API operator +(
        const Time& lhs,
        const Duration& rhs);

const Time OMG_DDS_API operator +(
        const Duration& lhs,
        const Time& rhs);

const Time OMG_DDS_API operator -(
        const Time& lhs,
        const Duration& rhs);

} //namespace core
} //namespace dds

#endif //OMG_DDS_CORE_TIME_HPP_