cache_index.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: BSD-3-Clause
2 // SPDX-FileCopyrightText: Czech Technical University in Prague
3 
4 #include <ctime>
5 #include <functional>
6 
8 #include <ros/time.h>
9 
10 namespace gnss_info
11 {
12 
14 {
15  const time_t nowSec = time.sec;
16  const auto t = *std::gmtime(&nowSec);
17  this->year = t.tm_year + 1900; // struct tm year is relative to year 1900
18  this->month = t.tm_mon + 1;
19  this->day = t.tm_mday;
20 }
21 
22 DayIndex::DayIndex(const uint16_t year, const uint8_t month, const uint8_t day):
23  year(year), month(month), day(day)
24 {
25 }
26 
27 DayIndex::operator ros::Time() const
28 {
29  tm start{};
30  start.tm_year = this->year - 1900;
31  start.tm_mon = this->month - 1;
32  start.tm_mday = this->day;
33  return ros::Time(std::mktime(&start), 0);
34 }
35 
36 bool DayIndex::operator==(const DayIndex& other) const
37 {
38  return this->year == other.year && this->month == other.month && this->day == other.day;
39 }
40 
41 }
42 
44 {
45  return ((std::hash<uint16_t>()(k.year) ^ (std::hash<uint8_t>()(k.month) << 1)) >> 1)
46  ^ (std::hash<uint8_t>()(k.day) << 1);
47 }
std::hash< gnss_info::DayIndex >::operator()
std::size_t operator()(const gnss_info::DayIndex &k) const noexcept
Definition: cache_index.cpp:43
day
day
gnss_info::DayIndex::DayIndex
DayIndex(const ros::Time &time)
Create an index entry for the given time.
Definition: cache_index.cpp:13
year
year
gnss_info::DayIndex::day
uint8_t day
Day (starting with 1).
Definition: cache_index.h:20
gnss_info::DayIndex
Object that can be used as an index into a cache and assigns all times from the same day the same cac...
Definition: cache_index.h:16
time
time
gnss_info::DayIndex::month
uint8_t month
Month (starting with 1).
Definition: cache_index.h:19
gnss_info::DayIndex::year
uint16_t year
Year.
Definition: cache_index.h:18
gnss_info::DayIndex::operator==
bool operator==(const DayIndex &other) const
Compare with another index.
Definition: cache_index.cpp:36
gnss_info
Definition: cache.h:15
start
ROSCPP_DECL void start()
ros::Time
month
month
cache_index.h
t
geometry_msgs::TransformStamped t


gnss_info
Author(s): Martin Pecka
autogenerated on Fri Nov 24 2023 03:50:35