Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
carma_cooperative_perception::Month Class Reference

#include <month.hpp>

Collaboration diagram for carma_cooperative_perception::Month:
Collaboration graph

Public Member Functions

 Month ()=default
 
uint8_t get_value () const
 
constexpr Month (std::uint8_t month_value)
 Create a Month instance with the specified value. More...
 
constexpr auto operator++ () -> Month &
 Pre-increment operator overload. More...
 
constexpr auto operator++ (int) -> Month
 Post-increment operator overload. More...
 
constexpr auto operator-- () -> Month &
 Pre-decrement operator overload. More...
 
constexpr auto operator-- (int) -> Month
 Post-decrement operator overload. More...
 
constexpr operator unsigned () const
 Conversion function to convert Month instance to unsigned type. More...
 
constexpr auto ok () const -> bool
 Checks if Month instance's value is within valid Gregorian calendar range. More...
 

Private Attributes

std::uint8_t month_value_
 

Friends

constexpr auto operator== (const Month &x, const Month &y) -> bool
 Compare exact equality between two Month instances. More...
 
constexpr auto operator!= (const Month &x, const Month &y) -> bool
 Compare exact inequality between two Month instances. More...
 
constexpr auto operator< (const Month &x, const Month &y) -> bool
 Check if one Month instance is less than another. More...
 
constexpr auto operator<= (const Month &x, const Month &y) -> bool
 Check if one Month instance is less than or equal to another. More...
 
constexpr auto operator> (const Month &x, const Month &y) -> bool
 Check if one Month instance is greater than another. More...
 
constexpr auto operator>= (const Month &x, const Month &y) -> bool
 Check if one Month instance is greater than or equal to another. More...
 
template<typename CharT , typename Traits >
auto operator<< (std::basic_ostream< CharT, Traits > &os, const Month &m) -> std::basic_ostream< CharT, Traits > &
 Output a string representation of Month instance to an output stream. More...
 

Detailed Description

Definition at line 29 of file month.hpp.

Constructor & Destructor Documentation

◆ Month() [1/2]

carma_cooperative_perception::Month::Month ( )
default

◆ Month() [2/2]

constexpr carma_cooperative_perception::Month::Month ( std::uint8_t  month_value)
inlineexplicitconstexpr

Create a Month instance with the specified value.

Parameters
[in]month_valueNumerical value of the month; typically between [1, 12]

Definition at line 41 of file month.hpp.

41: month_value_{month_value} {}

Member Function Documentation

◆ get_value()

uint8_t carma_cooperative_perception::Month::get_value ( ) const
inline

Definition at line 34 of file month.hpp.

34{ return month_value_; }

References month_value_.

◆ ok()

constexpr auto carma_cooperative_perception::Month::ok ( ) const -> bool
inlineconstexpr

Checks if Month instance's value is within valid Gregorian calendar range.

Returns
true if Month instance's value is within [1, 12]; false otherwise

Definition at line 120 of file month.hpp.

121 {
122 constexpr auto jan_value{1U};
123 constexpr auto dec_value{12U};
124
125 return month_value_ >= jan_value && month_value_ <= dec_value;
126 }

References month_value_.

◆ operator unsigned()

constexpr carma_cooperative_perception::Month::operator unsigned ( ) const
inlineexplicitconstexpr

Conversion function to convert Month instance to unsigned type.

Definition at line 113 of file month.hpp.

113{ return static_cast<unsigned>(month_value_); }

References month_value_.

◆ operator++() [1/2]

constexpr auto carma_cooperative_perception::Month::operator++ ( ) -> Month &
inlineconstexpr

Pre-increment operator overload.

Returns
Reference to Month instance being incremented

Definition at line 48 of file month.hpp.

49 {
50 constexpr auto jan_value{1U};
51 constexpr auto dec_value{12U};
52
53 month_value_ = (month_value_ + 1) % (dec_value + 1);
54
55 if (month_value_ == 0) {
56 month_value_ = jan_value;
57 }
58
59 return *this;
60 }

References month_value_.

◆ operator++() [2/2]

constexpr auto carma_cooperative_perception::Month::operator++ ( int  ) -> Month
inlineconstexpr

Post-increment operator overload.

Parameters
[in]_Dummy parameter used to distinguish from the pre-increment operator
Returns
Copy of Month instance before it was incremented

Definition at line 69 of file month.hpp.

70 {
71 Month previous{*this};
72 ++(*this);
73
74 return previous;
75 }

◆ operator--() [1/2]

constexpr auto carma_cooperative_perception::Month::operator-- ( ) -> Month &
inlineconstexpr

Pre-decrement operator overload.

Returns
Reference to Month instance being decremented

Definition at line 82 of file month.hpp.

83 {
84 constexpr auto dec_value{12U};
85
86 month_value_ = (month_value_ - 1 % (dec_value + 1));
87
88 if (month_value_ == 0) {
89 month_value_ = dec_value;
90 }
91
92 return *this;
93 }

References month_value_.

◆ operator--() [2/2]

constexpr auto carma_cooperative_perception::Month::operator-- ( int  ) -> Month
inlineconstexpr

Post-decrement operator overload.

Parameters
[in]_Dummy parameter used to distinguish from the pre-decrement operator
Returns
Copy of Month instance before it was decremented

Definition at line 102 of file month.hpp.

103 {
104 Month previous{*this};
105 --(*this);
106
107 return previous;
108 }

Friends And Related Function Documentation

◆ operator!=

constexpr auto operator!= ( const Month x,
const Month y 
) -> bool
friend

Compare exact inequality between two Month instances.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is Month instances are not equal; false otherwise

Definition at line 149 of file month.hpp.

◆ operator<

constexpr auto operator< ( const Month x,
const Month y 
) -> bool
friend

Check if one Month instance is less than another.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is x comes before y in the calendar; false otherwise

Definition at line 159 of file month.hpp.

160 {
161 return x.month_value_ < y.month_value_;
162 }

◆ operator<<

template<typename CharT , typename Traits >
auto operator<< ( std::basic_ostream< CharT, Traits > &  os,
const Month m 
) -> std::basic_ostream<CharT, Traits> &
friend

Output a string representation of Month instance to an output stream.

Template Parameters
CharTCharacter type of the specified stream
TraitsCharacter traits of the specified stream
Parameters
[in,out]osOutput stream being written to
[in]mMonth instance being written out
Returns
Reference to specified output stream

Definition at line 215 of file month.hpp.

217 {
218 static constexpr std::array abbreviations{"Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.",
219 "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."};
220 if (!m.ok()) {
221 return os << static_cast<unsigned>(m) << " is not a valid month";
222 }
223
224 return os << abbreviations.at(static_cast<unsigned>(m) - 1);
225 }

◆ operator<=

constexpr auto operator<= ( const Month x,
const Month y 
) -> bool
friend

Check if one Month instance is less than or equal to another.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is x comes before y in the calendar or if instances are equal; false otherwise

Definition at line 172 of file month.hpp.

173 {
174 return x < y || x == y;
175 }

◆ operator==

constexpr auto operator== ( const Month x,
const Month y 
) -> bool
friend

Compare exact equality between two Month instances.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is Month instances are equal; false otherwise

Definition at line 136 of file month.hpp.

137 {
138 return x.month_value_ == y.month_value_;
139 }

◆ operator>

constexpr auto operator> ( const Month x,
const Month y 
) -> bool
friend

Check if one Month instance is greater than another.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is x comes after y in the calendar; false otherwise

Definition at line 185 of file month.hpp.

186 {
187 return x.month_value_ > y.month_value_;
188 }

◆ operator>=

constexpr auto operator>= ( const Month x,
const Month y 
) -> bool
friend

Check if one Month instance is greater than or equal to another.

Parameters
[in]xFirst Month instance
[in]ySecond Month instance
Returns
true is x comes after y in the calendar or if instances are equal; false otherwise

Definition at line 198 of file month.hpp.

199 {
200 return x > y || x == y;
201 }

Member Data Documentation

◆ month_value_

std::uint8_t carma_cooperative_perception::Month::month_value_
private

Definition at line 228 of file month.hpp.

Referenced by get_value(), ok(), operator unsigned(), operator++(), and operator--().


The documentation for this class was generated from the following file: