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_,
47 const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT
48 : m(m_)
49 , wdi(wdi_)
50 {
51 }
52
53 //*************************************************************************
55 //*************************************************************************
56 ETL_NODISCARD
57 ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
58 {
59 return m;
60 }
61
62 //*************************************************************************
64 //*************************************************************************
65 ETL_NODISCARD
66 ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
67 {
68 return wdi;
69 }
70
71 //*************************************************************************
73 //*************************************************************************
74 ETL_NODISCARD
75 ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
76 {
77 return m.ok() && wdi.ok();
78 }
79
80 private:
81
84 };
85
86 //*************************************************************************
88 //*************************************************************************
89 inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday& lhs,
90 const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
91 {
92 return (lhs.month() == rhs.month()) &&
93 (lhs.weekday_indexed() == rhs.weekday_indexed());
94 }
95
96 //*************************************************************************
98 //*************************************************************************
99 inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday& lhs,
100 const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
101 {
102 return !(lhs == rhs);
103 }
104
105 //*************************************************************************
107 //*************************************************************************
109 {
110 public:
111
112 //*************************************************************************
114 //*************************************************************************
115 ETL_CONSTEXPR14 month_weekday_last(const etl::chrono::month& m_,
116 const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT
117 : m(m_)
118 , wdl(wdl_)
119 {
120 }
121
122 //*************************************************************************
124 //*************************************************************************
125 ETL_NODISCARD
126 ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
127 {
128 return m;
129 }
130
131 //*************************************************************************
133 //*************************************************************************
134 ETL_NODISCARD
135 ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
136 {
137 return wdl;
138 }
139
140 //*************************************************************************
142 //*************************************************************************
143 ETL_NODISCARD
144 ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
145 {
146 return m.ok() && wdl.ok();
147 }
148
149 private:
150
153 };
154
155 //*************************************************************************
157 //*************************************************************************
158 inline ETL_CONSTEXPR14 bool operator ==(const etl::chrono::month_weekday_last& lhs,
159 const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
160 {
161 return (lhs.month() == rhs.month()) && (lhs.weekday_last() == rhs.weekday_last());
162 }
163
164 //*************************************************************************
166 //*************************************************************************
167 inline ETL_CONSTEXPR14 bool operator !=(const etl::chrono::month_weekday_last& lhs,
168 const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
169 {
170 return !(lhs == rhs);
171 }
172 }
173
174 //*************************************************************************
176 //*************************************************************************
177#if ETL_USING_8BIT_TYPES
178 template <>
179 struct hash<etl::chrono::month_weekday>
180 {
181 size_t operator()(const etl::chrono::month_weekday& mw) const
182 {
183 etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
184 unsigned int b = mw.weekday_indexed().weekday().c_encoding();
185 unsigned int c = mw.weekday_indexed().index();
186
187 uint8_t buffer[sizeof(a) + sizeof(b) + sizeof(c)];
188
189 memcpy(buffer, &a, sizeof(a));
190 memcpy(buffer + sizeof(a), &b, sizeof(b));
191 memcpy(buffer + sizeof(b), &b, sizeof(c));
192
193 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b) + sizeof(c));
194 }
195 };
196#endif
197
198 //*************************************************************************
200 //*************************************************************************
201#if ETL_USING_8BIT_TYPES
202 template <>
203 struct hash<etl::chrono::month_weekday_last>
204 {
205 size_t operator()(const etl::chrono::month_weekday_last& mw) const
206 {
207 etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
208 unsigned int b = mw.weekday_last().weekday().c_encoding();
209
210 uint8_t buffer[sizeof(a) + sizeof(b)];
211
212 memcpy(buffer, &a, sizeof(a));
213 memcpy(buffer + sizeof(a), &b, sizeof(b));
214
215 return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b));
216 }
217 };
218#endif
219}
220
Construct from month and weekday_last.
Definition month_weekday.h:109
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:115
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition month_weekday.h:126
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:135
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month/day is valid.
Definition month_weekday.h:144
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:75
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:57
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:66
month
Definition month.h:54
weekday_indexed
Definition weekday.h:344
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:389
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 unsigned index() const ETL_NOEXCEPT
Get index.
Definition weekday.h:398
weekday_last
Definition weekday.h:439
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:471
ETL_NODISCARD ETL_CONSTEXPR14 unsigned c_encoding() const ETL_NOEXCEPT
Get the C encoding of the weekday.
Definition weekday.h:212
bitset_ext
Definition absolute.h:39