Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Y
YAT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Control System
Libraries
YAT
Commits
11271048
Commit
11271048
authored
Feb 19, 2024
by
Stéphane Poirier
Browse files
Options
Downloads
Patches
Plain Diff
[Duration] new conversion method 'as' and other adjustements
parent
7eb22016
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/yat/time/Time.h
+56
-30
56 additions, 30 deletions
include/yat/time/Time.h
src/time/Time.cpp
+0
-11
0 additions, 11 deletions
src/time/Time.cpp
with
56 additions
and
41 deletions
include/yat/time/Time.h
+
56
−
30
View file @
11271048
...
...
@@ -114,6 +114,12 @@ inline int64 int64FromHLPair(long lHigh, unsigned long ulLow)
//! Number of nanoseconds per second.
#define NANOSEC_PER_SEC 1000000000LL
//! Number of nanoseconds per millisecond.
#define NANOSEC_PER_MILLISEC 1000000L
//! Number of nanoseconds per millisecond.
#define NANOSEC_PER_MICROSEC 1000
//! Number of microseconds per day - High part.
#define MICROSEC_PER_DAY_H 20L
//! Number of microseconds per day - Low part.
...
...
@@ -859,6 +865,7 @@ public:
};
public
:
//! default c-tor
Duration
()
:
m_nanos
(
0
)
{
}
//! c-tor
...
...
@@ -879,14 +886,11 @@ public:
//! Get duration fields
void
get
(
Fields
*
fields_p
)
const
;
//! duration in seconds
double
total_secs
()
const
;
//! return a pair with number of seconds and nanoseconds
std
::
pair
<
uint32
,
uint32
>
secs_nanos
()
const
;
//! sets raw value: total number of nanoseconds
void
set
(
uint64
ns
)
{
m_nanos
=
ns
;
}
void
raw_value
(
uint64
ns
)
{
m_nanos
=
ns
;
}
//! gets the duration raw value
uint64
raw_value
()
const
{
return
m_nanos
;
}
//! sets secs and remnants nanosecs
void
set
(
uint32
secs
,
uint32
nanos
);
...
...
@@ -894,8 +898,13 @@ public:
//! gets seconds & nanosecs through pointers
void
get
(
uint32
*
secs_p
,
uint32
*
nsecs_p
)
const
;
//! gets raw value: total number of nanoseconds
uint64
get
()
const
{
return
m_nanos
;
}
//! get as requested duration sub-type
template
<
class
T
>
T
&
as
()
{
throw
yat
::
Exception
(
"BAD_CAST"
,
"Can't convert duration to the requested type"
,
"Duration::get<T>"
);
}
//! Assignement operators
Duration
operator
+
(
const
Duration
&
other
);
...
...
@@ -932,6 +941,7 @@ public:
//! \name Deprecated methods
//@{
void
get
(
DurationFields
*
pDF
)
const
;
double
total_secs
()
const
;
void
total_micros
(
int64
microsecs
)
{
m_nanos
=
1000
*
llabs
(
microsecs
);
}
int64
total_micros
()
const
{
return
m_nanos
/
1000
;
}
uint16
days
()
const
;
...
...
@@ -957,25 +967,19 @@ class YAT_DECL Seconds : public Duration
{
public:
//! construct a seconds duration
Seconds
(
uint32
secs
)
{
set
(
uint64
(
secs
)
*
1000000000LL
);
}
Seconds
(
double
secs
)
{
set
(
secs
);
}
//! construct a seconds duration
Seconds
(
int
secs
)
{
set
(
uint64
(
abs
(
secs
))
*
1000000000LL
);
}
//! construct a seconds duration
Seconds
(
double
secs
)
//! set duration in seconds
void
set
(
double
secs
)
{
if
(
fabs
(
secs
)
<=
DURATION_MAX_SECS
)
set
(
uint64
(
fabs
(
secs
)
*
1000000000LL
));
Duration
::
raw_value
(
uint64
(
fabs
(
secs
)
*
NANOSEC_PER_SEC
+
0.5
));
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Seconds::Seconds"
);
}
//! return the number of seconds as a floating point value
double
get
()
const
{
return
double
(
raw_value
())
/
NANOSEC_PER_SEC
;
}
};
//==================================================================================================
...
...
@@ -985,13 +989,18 @@ class YAT_DECL Millisecs : public Duration
{
public:
//! construct a milliseconds duration
Millisecs
(
uint64
ms
)
Millisecs
(
uint64
ms
)
{
set
(
ms
);
}
//! set duration in milliseconds
void
set
(
uint64
ms
)
{
if
(
ms
<=
DURATION_MAX_MILLIS
)
set
(
ms
*
1000000LL
);
Duration
::
raw_value
(
ms
*
NANOSEC_PER_MILLISEC
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Millisecs::Millisecs"
);
}
uint64
get
()
const
{
return
uint64
(
double
(
raw_value
())
/
NANOSEC_PER_MILLISEC
+
0.5
);
}
};
//==================================================================================================
...
...
@@ -1001,13 +1010,18 @@ class YAT_DECL Microsecs : public Duration
{
public:
//! construct a microseconds duration
Microsecs
(
uint64
us
)
Microsecs
(
uint64
us
)
{
set
(
us
);
}
//! set duration in microseconds
void
set
(
uint64
us
)
{
if
(
us
<=
DURATION_MAX_MICROS
)
set
(
us
*
1000LL
);
Duration
::
raw_value
(
us
*
NANOSEC_PER_MICROSEC
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Microsecs::Microsecs"
);
}
uint64
get
()
const
{
return
uint64
(
double
(
raw_value
())
/
NANOSEC_PER_MICROSEC
+
0.5
);
}
};
//==================================================================================================
...
...
@@ -1017,15 +1031,27 @@ class YAT_DECL Nanosecs : public Duration
{
public:
//! construct a nanosseconds duration
Nanosecs
(
uint64
ns
)
Nanosecs
(
uint64
ns
)
{
set
(
ns
);
}
//! set duration in nanoseconds
void
set
(
uint64
ns
)
{
if
(
ns
<=
DURATION_MAX_NANOS
)
set
(
ns
);
Duration
::
raw_value
(
ns
);
else
throw
Exception
(
"OVERFLOW"
,
"Overflow error"
,
"Nanosecs::Nanosecs"
);
}
uint64
get
()
const
{
return
raw_value
();
}
};
//==============================================================================
template
<
>
inline
Seconds
&
Duration
::
as
()
{
return
static_cast
<
Seconds
&>
(
*
this
);
}
template
<
>
inline
Millisecs
&
Duration
::
as
()
{
return
static_cast
<
Millisecs
&>
(
*
this
);
}
template
<
>
inline
Microsecs
&
Duration
::
as
()
{
return
static_cast
<
Microsecs
&>
(
*
this
);
}
template
<
>
inline
Nanosecs
&
Duration
::
as
()
{
return
static_cast
<
Nanosecs
&>
(
*
this
);
}
//==================================================================================================
// MeanDuration
//==================================================================================================
...
...
@@ -1035,7 +1061,7 @@ public:
MeanDuration
()
:
m_count
(
0
),
m_mean
()
{}
void
add
(
const
Duration
&
d
)
{
++
m_count
;
m_mean
.
set
(
(
m_mean
.
get
()
*
(
m_count
-
1
)
+
d
.
get
()
)
/
m_count
);
}
{
++
m_count
;
m_mean
.
raw_value
(
(
m_mean
.
raw_value
()
*
(
m_count
-
1
)
+
d
.
raw_value
()
)
/
m_count
);
}
std
::
size_t
n
()
const
{
return
m_count
;
}
const
Duration
&
get
()
const
{
return
m_mean
;
}
...
...
This diff is collapsed.
Click to expand it.
src/time/Time.cpp
+
0
−
11
View file @
11271048
...
...
@@ -1769,17 +1769,6 @@ void Duration::get(uint32* secs_p, uint32* nsecs_p) const
throw
Exception
(
"INVALID_PTR"
,
"received invalid pointer"
,
"Duration::get"
);
}
//----------------------------------------------------------------------------
// Duration::secs_nanos
//----------------------------------------------------------------------------
std
::
pair
<
uint32
,
uint32
>
Duration
::
secs_nanos
()
const
{
uint32
secs
,
nanos
;
nanos
=
m_nanos
%
NANOSEC_PER_SEC
;
secs
=
uint32
(
m_nanos
/
NANOSEC_PER_SEC
);
return
std
::
make_pair
(
secs
,
nanos
);
}
//----------------------------------------------------------------------------
// Duration::set
//----------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment