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
 
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 39 of file month.hpp.

39: month_value_{month_value} {}

Member Function Documentation

◆ 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 118 of file month.hpp.

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

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 111 of file month.hpp.

111{ 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 46 of file month.hpp.

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

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 67 of file month.hpp.

68 {
69 Month previous{*this};
70 ++(*this);
71
72 return previous;
73 }

◆ 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 80 of file month.hpp.

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

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 100 of file month.hpp.

101 {
102 Month previous{*this};
103 --(*this);
104
105 return previous;
106 }

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 147 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 157 of file month.hpp.

158 {
159 return x.month_value_ < y.month_value_;
160 }

◆ 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 213 of file month.hpp.

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

◆ 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 170 of file month.hpp.

171 {
172 return x < y || x == y;
173 }

◆ 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 134 of file month.hpp.

135 {
136 return x.month_value_ == y.month_value_;
137 }

◆ 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 183 of file month.hpp.

184 {
185 return x.month_value_ > y.month_value_;
186 }

◆ 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 196 of file month.hpp.

197 {
198 return x > y || x == y;
199 }

Member Data Documentation

◆ month_value_

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

Definition at line 226 of file month.hpp.

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


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