Loading...
Searching...
No Matches
month_weekday.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2025 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_IN_CHRONO_H
#error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
#endif
namespace etl
{
namespace chrono
{
class month_weekday
{
public:
//*************************************************************************
//*************************************************************************
ETL_CONSTEXPR14 month_weekday(const etl::chrono::month& m_, const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT
: m(m_)
, wdi(wdi_)
{
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
{
return m;
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
{
return wdi;
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
{
return m.ok() && wdi.ok();
}
private:
etl::chrono::month m;
etl::chrono::weekday_indexed wdi;
};
//*************************************************************************
//*************************************************************************
inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::month_weekday& lhs, const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
{
return (lhs.month() == rhs.month()) && (lhs.weekday_indexed() == rhs.weekday_indexed());
}
//*************************************************************************
//*************************************************************************
inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::month_weekday& lhs, const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT
{
return !(lhs == rhs);
}
//*************************************************************************
//*************************************************************************
class month_weekday_last
{
public:
//*************************************************************************
//*************************************************************************
ETL_CONSTEXPR14 month_weekday_last(const etl::chrono::month& m_, const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT
: m(m_)
, wdl(wdl_)
{
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
{
return m;
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
{
return wdl;
}
//*************************************************************************
//*************************************************************************
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
{
return m.ok() && wdl.ok();
}
private:
etl::chrono::month m;
etl::chrono::weekday_last wdl;
};
//*************************************************************************
//*************************************************************************
inline ETL_CONSTEXPR14 bool operator==(const etl::chrono::month_weekday_last& lhs, const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
{
return (lhs.month() == rhs.month()) && (lhs.weekday_last() == rhs.weekday_last());
}
//*************************************************************************
//*************************************************************************
inline ETL_CONSTEXPR14 bool operator!=(const etl::chrono::month_weekday_last& lhs, const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT
{
return !(lhs == rhs);
}
} // namespace chrono
//*************************************************************************
//*************************************************************************
#if ETL_USING_8BIT_TYPES
template <>
struct hash<etl::chrono::month_weekday>
{
size_t operator()(const etl::chrono::month_weekday& mw) const
{
etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
unsigned int b = mw.weekday_indexed().weekday().c_encoding();
unsigned int c = mw.weekday_indexed().index();
uint8_t buffer[sizeof(a) + sizeof(b) + sizeof(c)];
memcpy(buffer, &a, sizeof(a));
memcpy(buffer + sizeof(a), &b, sizeof(b));
memcpy(buffer + sizeof(a) + sizeof(b), &c, sizeof(c));
return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b) + sizeof(c));
}
};
#endif
//*************************************************************************
//*************************************************************************
#if ETL_USING_8BIT_TYPES
template <>
struct hash<etl::chrono::month_weekday_last>
{
size_t operator()(const etl::chrono::month_weekday_last& mw) const
{
etl::chrono::month::rep a = static_cast<etl::chrono::month::rep>(static_cast<unsigned>(mw.month()));
unsigned int b = mw.weekday_last().weekday().c_encoding();
uint8_t buffer[sizeof(a) + sizeof(b)];
memcpy(buffer, &a, sizeof(a));
memcpy(buffer + sizeof(a), &b, sizeof(b));
return etl::private_hash::generic_hash<size_t>(buffer, buffer + sizeof(a) + sizeof(b));
}
};
#endif
} // namespace etl
etl::chrono::month_weekday_last
Construct from month and weekday_last.
Definition month_weekday.h:102
etl::chrono::month_weekday_last::month_weekday_last
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::chrono::month_weekday_last::month
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition month_weekday.h:117
etl::chrono::month_weekday_last::weekday_last
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:125
etl::chrono::month_weekday_last::ok
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month/day is valid.
Definition month_weekday.h:133
etl::chrono::month_weekday
Definition month_weekday.h:40
etl::chrono::month_weekday::ok
ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT
Returns true if the month/day is valid.
Definition month_weekday.h:71
etl::chrono::month_weekday::month_weekday
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::chrono::month_weekday::month
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month month() const ETL_NOEXCEPT
Returns the month.
Definition month_weekday.h:55
etl::chrono::month_weekday::weekday_indexed
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT
Returns the weekday_indexed.
Definition month_weekday.h:63
etl::chrono::month
month
Definition month.h:54
etl::chrono::weekday_indexed
weekday_indexed
Definition weekday.h:338
etl::chrono::weekday_indexed::weekday
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:362
etl::chrono::weekday_indexed::index
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 unsigned index() const ETL_NOEXCEPT
Get index.
Definition weekday.h:370
etl::chrono::weekday_last
weekday_last
Definition weekday.h:409
etl::chrono::weekday_last::weekday
ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday weekday() const ETL_NOEXCEPT
Get weekday.
Definition weekday.h:441
etl::chrono::weekday::c_encoding
ETL_NODISCARD ETL_CONSTEXPR14 unsigned c_encoding() const ETL_NOEXCEPT
Get the C encoding of the weekday.
Definition weekday.h:210
etl::chrono::operator==
ETL_CONSTEXPR14 bool operator==(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Equality operator.
Definition day.h:166
etl::chrono::operator!=
ETL_CONSTEXPR14 bool operator!=(const etl::chrono::day &d1, const etl::chrono::day &d2) ETL_NOEXCEPT
Inequality operator.
Definition day.h:174
etl
Definition absolute.h:40