Safir SDK Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AceTimeConverter.h
Go to the documentation of this file.
1/******************************************************************************
2*
3* Copyright Saab AB, 2006-2013 (http://safirsdkcore.com)
4*
5* Created by: Erik Adolfsson / sterad
6*
7*******************************************************************************
8*
9* This file is part of Safir SDK Core.
10*
11* Safir SDK Core is free software: you can redistribute it and/or modify
12* it under the terms of version 3 of the GNU General Public License as
13* published by the Free Software Foundation.
14*
15* Safir SDK Core is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22*
23******************************************************************************/
24#ifndef __DOUF_ACE_TIME_CONVERTER_H
25#define __DOUF_ACE_TIME_CONVERTER_H
26
27#ifndef SAFIR_NO_DEPRECATED
28
29#include <ace/Time_Value.h>
32
33//disable warnings in boost
34#if defined _MSC_VER
35 #pragma warning (push)
36 #pragma warning (disable : 4127)
37#endif
38
39#include <boost/date_time/posix_time/posix_time.hpp>
40
41//and enable the warnings again
42#if defined _MSC_VER
43 #pragma warning (pop)
44#endif
45
46namespace Safir
47{
48namespace Time
49{
50
58 {
59 public:
60
67 static ACE_Time_Value ToAceTime(const Safir::Dob::Typesystem::Si64::Second time);
68
75 static ACE_Time_Value ToAceTime(const boost::posix_time::time_duration & duration);
76
83 static ACE_Time_Value ToAceTime(const boost::posix_time::ptime & time);
84
91 static Safir::Dob::Typesystem::Si64::Second ToDouble(const ACE_Time_Value & time);
92
99 static boost::posix_time::ptime ToPtime(const ACE_Time_Value & utcTime);
100
101 };
102
103 inline ACE_Time_Value AceTimeConverter::ToAceTime(const boost::posix_time::time_duration & duration)
104 {
105 if (boost::posix_time::time_duration::num_fractional_digits() == 6)
106 {
107 return ACE_Time_Value(static_cast<time_t>(duration.total_seconds()),
108 static_cast<suseconds_t>(duration.fractional_seconds()));
109 }
110 else
111 {
112 return ACE_Time_Value(static_cast<time_t>(duration.total_seconds()),
113 static_cast<suseconds_t>(duration.fractional_seconds()
114 * pow(1.0, boost::posix_time::time_duration::num_fractional_digits() -6)));
115 }
116 }
117
119 {
120 return ACE_Time_Value(static_cast<suseconds_t>(time),
121 static_cast<suseconds_t>((time - Safir::Dob::Typesystem::Int64(time)) * pow (10.0,6)));
122 }
123
124 inline ACE_Time_Value AceTimeConverter::ToAceTime(const boost::posix_time::ptime & time)
125 {
126 return ToAceTime(TimeProvider::ToDouble(time));
127 }
128
130 {
131 return time.sec() + (time.usec() / pow (10.0,6));
132 }
133
134 inline boost::posix_time::ptime AceTimeConverter::ToPtime(const ACE_Time_Value & time)
135 {
136 return TimeProvider::ToPtime(ToDouble(time));
137 }
138
139
140} // namespace Time
141} // namespace Safir
142
143#endif
144#endif //__DOUF_ACE_TIME_CONVERTER_H
This namespace contains all the functionality and definitions of the SAFIR SDK.
Definition Backdoor.h:31
DotsC_Int64 Int64
64 bit integer type.
Definition Defs.h:69
Float64 Second
64 bit representation of Second.
Definition Defs.h:197
The AceTimeConverter class provides functions to convert to/from ACE time.
Definition AceTimeConverter.h:58
static Safir::Dob::Typesystem::Si64::Second ToDouble(const ACE_Time_Value &time)
Convert specified ACE time to a Double.
Definition AceTimeConverter.h:129
static ACE_Time_Value ToAceTime(const Safir::Dob::Typesystem::Si64::Second time)
Get specified time in ACE Time representation.
Definition AceTimeConverter.h:118
static boost::posix_time::ptime ToPtime(const ACE_Time_Value &utcTime)
Get specified ACE time in boost::posix_time::ptime representation.
Definition AceTimeConverter.h:134
static boost::posix_time::ptime ToPtime(const Safir::Dob::Typesystem::Si64::Second utcTime)
Get specified UTC time in boost::posix_time::ptime representation.
Definition TimeProvider.h:105
static Safir::Dob::Typesystem::Si64::Second ToDouble(const boost::posix_time::ptime &utcTime)
Convert specified UTC time to a Double.
Definition TimeProvider.h:130