Line data Source code
1 : /* 2 : * Copyright (C) 2020-2024 MEmilio 3 : * 4 : * Authors: Carlotta Gerstein, Martin J. Kuehn 5 : * 6 : * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de> 7 : * 8 : * Licensed under the Apache License, Version 2.0 (the "License"); 9 : * you may not use this file except in compliance with the License. 10 : * You may obtain a copy of the License at 11 : * 12 : * http://www.apache.org/licenses/LICENSE-2.0 13 : * 14 : * Unless required by applicable law or agreed to in writing, software 15 : * distributed under the License is distributed on an "AS IS" BASIS, 16 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 : * See the License for the specific language governing permissions and 18 : * limitations under the License. 19 : */ 20 : 21 : #ifndef MIO_ABM_MASK_H 22 : #define MIO_ABM_MASK_H 23 : 24 : #include "abm/mask_type.h" 25 : #include "abm/time.h" 26 : #include "memilio/io/default_serialize.h" 27 : 28 : namespace mio 29 : { 30 : namespace abm 31 : { 32 : /** 33 : * @brief Reduces the probability that a Person becomes infected. 34 : * Every Person has a Mask that reduces the probability of becoming infected when wearing this Mask. 35 : */ 36 : class Mask 37 : { 38 : public: 39 : /** 40 : * @brief Construct a new Mask of a certain type. 41 : * @param[in] type The type of the Mask. 42 : * @param[in] t The TimePoint of the Mask's initial usage. 43 : */ 44 : Mask(MaskType type, TimePoint t); 45 : 46 : /** 47 : * @brief Get the MaskType of this Mask. 48 : */ 49 2133 : MaskType get_type() const 50 : { 51 2133 : return m_type; 52 : } 53 : 54 : /** 55 : * @brief Get the length of time this Mask has been used. 56 : * @param[in] curr_time The current TimePoint. 57 : */ 58 : const TimeSpan get_time_used(TimePoint curr_time) const; 59 : 60 : /** 61 : * @brief Change the type of the Mask and reset the time it was used. 62 : * @param[in] new_mask_type The type of the new Mask. 63 : * @param[in] t The TimePoint of mask change. 64 : */ 65 : void change_mask(MaskType new_mask_type, TimePoint t); 66 : 67 : /// This method is used by the default serialization feature. 68 18 : auto default_serialize() 69 : { 70 36 : return Members("Mask").add("mask_type", m_type).add("time_first_used", m_time_first_usage); 71 : } 72 : 73 : private: 74 : MaskType m_type; ///< Type of the Mask. 75 : TimePoint m_time_first_usage; ///< TimePoint of the Mask's initial usage. 76 : }; 77 : } // namespace abm 78 : 79 : /// @brief Creates an instance of abm::Mask for default serialization. 80 : template <> 81 : struct DefaultFactory<abm::Mask> { 82 9 : static abm::Mask create() 83 : { 84 9 : return abm::Mask(abm::MaskType::Count, abm::TimePoint()); 85 : } 86 : }; 87 : 88 : } // namespace mio 89 : 90 : #endif