Embedded Template Library 1.0
Loading...
Searching...
No Matches
month_weekday.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2025 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_IN_CHRONO_H
32 #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
33#endif
34
35namespace etl
36{
37 namespace chrono
38 {
40 {
41 public:
42
43 //*************************************************************************
45 //*************************************************************************
46 ETL_CONSTEXPR14 month_weekday(const etl::chrono::month& m_, const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT
47 : m(m_)
48 , wdi(wdi_)
49 {
50 }
51
52 //*************************************************************************
54 //*************************************************************************
55 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
56 {
57 return m;
58 }
59
60 //*************************************************************************
62 //*************************************************************************
63 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
64 {
65 return wdi;
66 }
67
68 //*************************************************************************
70 //*************************************************************************
71 ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
72 {
73 return m.ok() && wdi.ok();
74 }
75
76 private:
77
80 };
81
82 //*************************************************************************
84 //*************************************************************************
85 inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::month_weekday& lhs, const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
86 {
87 return (lhs.month() == rhs.month()) && (lhs.weekday_indexed() == rhs.weekday_indexed());
88 }
89
90 //*************************************************************************
92 //*************************************************************************
93 inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::month_weekday& lhs, const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
94 {
95 return !(lhs == rhs);
96 }
97
98 //*************************************************************************
100 //*************************************************************************
102 {
103 public:
104
105 //*************************************************************************
107 //*************************************************************************
108 ETL_CONSTEXPR14 month_weekday_last(const etl::chrono::month& m_, const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT
109 : m(m_)
110 , wdl(wdl_)
111 {
112 }
113
114 //*************************************************************************
116 //*************************************************************************
117 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
118 {
119 return m;
120 }
121
122 //*************************************************************************
124 //*************************************************************************
125 ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
126 {
127 return wdl;
128 }
129
130 //*************************************************************************
132 //*************************************************************************
133 ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
134 {
135 return m.ok() && wdl.ok();
136 }
137
138 private:
139
142 };
143
144 //*************************************************************************
146 //*************************************************************************
147 inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::month_weekday_last& lhs, const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
148 {
149 return (lhs.month() == rhs.month()) && (lhs.weekday_last() == rhs.weekday_last());
150 }
151
152 //*************************************************************************
154 //*************************************************************************
155 inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::month_weekday_last& lhs, const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
156 {
157 return !(lhs == rhs);
158 }
159 } // namespace chrono
160
161 //*************************************************************************
163 //*************************************************************************
164#if ETL_USING_8BIT_TYPES
165 template <>
166 struct hash<etl::chrono::month_weekday>
167 {
168 size_t operator()(const etl::chrono::month_weekday& mw) const
169 {
170 etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
171 unsigned int b = mw.weekday_indexed().weekday().c_encoding();
172 unsigned int c = mw.weekday_indexed().index();
173
174 uint8_t buffer[sizeof(a) + sizeof(b) + sizeof(c)];
175
176 memcpy(buffer, &a, sizeof(a));
177 memcpy(buffer + sizeof(a), &b, sizeof(b));
178 memcpy(buffer + sizeof(a) + sizeof(b), &c, sizeof(c));
179
180 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b) + sizeof(c));
181 }
182 };
183#endif
184
185 //*************************************************************************
187 //*************************************************************************
188#if ETL_USING_8BIT_TYPES
189 template <>
190 struct hash<etl::chrono::month_weekday_last>
191 {
192 size_t operator()(const etl::chrono::month_weekday_last& mw) const
193 {
194 etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
195 unsigned int b = mw.weekday_last().weekday().c_encoding();
196
197 uint8_t buffer[sizeof(a) + sizeof(b)];
198
199 memcpy(buffer, &a, sizeof(a));
200 memcpy(buffer + sizeof(a), &b, sizeof(b));
201
202 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b));
203 }
204 };
205#endif
206} // namespace etl
Construct from month and weekday_last.
Definition month_weekday.h:102
ETL_CONSTEXPR14 month_weekday_last(const etl::chrono::month &m_, const etl::chrono::weekday_last &wdl_) ETL_NOEXCEPT
Construct from month and weekday_indexed.
Definition month_weekday.h:108
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition month_weekday.h:117
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:125
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month/day is valid.
Definition month_weekday.h:133
Definition month_weekday.h:40
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month/day is valid.
Definition month_weekday.h:71
ETL_CONSTEXPR14 month_weekday(const etl::chrono::month &m_, const etl::chrono::weekday_indexed &wdi_) ETL_NOEXCEPT
Construct from month and weekday_indexed.
Definition month_weekday.h:46
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition month_weekday.h:55
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:63
month
Definition month.h:54
weekday_indexed
Definition weekday.h:338
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:362
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 unsigned index() const ETL_NOEXCEPT
Get index.
Definition weekday.h:370
weekday_last
Definition weekday.h:409
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:441
ETL_NODISCARD ETL_CONSTEXPR14 unsigned c_encoding() const ETL_NOEXCEPT
Get the C encoding of the weekday.
Definition weekday.h:210
ETL_CONSTEXPR14 bool operator==(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Equality operator.
Definition day.h:166
ETL_CONSTEXPR14 bool operator!=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Inequality operator.
Definition day.h:174
bitset_ext
Definition absolute.h:40