Branch data Line data Source code
1 : : /* 2 : : * Copyright (C) 2026 by Thun Lu. All rights reserved. 3 : : * Author: Thun Lu <thun.lu@zohomail.cn> 4 : : * Repo: https://github.com/thun-res/vlink 5 : : * _ __ __ _ __ 6 : : * | | / / / / (_) ____ / /__ 7 : : * | | / / / / / / / __ \ / //_/ 8 : : * | |/ / / /___ / / / / / / / ,< 9 : : * |___/ /_____/ /_/ /_/ /_/ /_/|_| 10 : : * 11 : : * Licensed under the Apache License, Version 2.0 (the "License"); 12 : : * you may not use this file except in compliance with the License. 13 : : * You may obtain a copy of the License at 14 : : * 15 : : * http://www.apache.org/licenses/LICENSE-2.0 16 : : * 17 : : * Unless required by applicable law or agreed to in writing, software 18 : : * distributed under the License is distributed on an "AS IS" BASIS, 19 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 : : * See the License for the specific language governing permissions and 21 : : * limitations under the License. 22 : : */ 23 : : 24 : : #include "./extension/status.h" 25 : : 26 : : #include <string> 27 : : 28 : : #include "./extension/status_detail.h" 29 : : 30 : : namespace vlink { 31 : : 32 : : namespace Status { 33 : : 34 : : template <typename T> 35 : 13 : static void write_if_type(std::ostream& ostream, const Base& status) noexcept { 36 : : #if defined(NDEBUG) || defined(__ANDROID__) 37 : : const auto* target = static_cast<const T*>(&status); 38 : : #else 39 [ + - ]: 13 : const auto* target = dynamic_cast<const T*>(&status); 40 : : #endif 41 : : 42 [ + - ]: 13 : if VLIKELY (target) { 43 : 13 : ostream << *target; 44 : 13 : return; 45 : : } 46 : : 47 : : ostream << "Unknown"; // LCOV_EXCL_LINE GCOVR_EXCL_LINE 48 : : } 49 : : 50 : : // Base 51 : 132 : Base::Base() = default; 52 : : 53 : 132 : Base::~Base() = default; 54 : : 55 : 15 : std::ostream& operator<<(std::ostream& ostream, const Base& status) noexcept { 56 : : try { 57 [ + - + + : 15 : switch (status.get_type()) { + + + + + + + + + + ] 58 : 1 : case kUnknown: 59 [ + - ]: 1 : ostream << "Unknown"; 60 : 1 : break; 61 : 2 : case kPublicationMatched: 62 : 2 : write_if_type<PublicationMatched>(ostream, status); 63 : 2 : break; 64 : 1 : case kOfferedDeadlineMissed: 65 : 1 : write_if_type<OfferedDeadlineMissed>(ostream, status); 66 : 1 : break; 67 : 1 : case kOfferedIncompatibleQos: 68 : 1 : write_if_type<OfferedIncompatibleQos>(ostream, status); 69 : 1 : break; 70 : 1 : case kLivelinessLost: 71 : 1 : write_if_type<LivelinessLost>(ostream, status); 72 : 1 : break; 73 : 2 : case kSubscriptionMatched: 74 : 2 : write_if_type<SubscriptionMatched>(ostream, status); 75 : 2 : break; 76 : 1 : case kRequestedDeadlineMissed: 77 : 1 : write_if_type<RequestedDeadlineMissed>(ostream, status); 78 : 1 : break; 79 : 1 : case kLivelinessChanged: 80 : 1 : write_if_type<LivelinessChanged>(ostream, status); 81 : 1 : break; 82 : 2 : case kSampleRejected: 83 : 2 : write_if_type<SampleRejected>(ostream, status); 84 : 2 : break; 85 : 1 : case kRequestedIncompatibleQos: 86 : 1 : write_if_type<RequestedIncompatibleQos>(ostream, status); 87 : 1 : break; 88 : 1 : case kSampleLost: 89 : 1 : write_if_type<SampleLost>(ostream, status); 90 : 1 : break; 91 : 1 : default: 92 [ + - ]: 1 : ostream << "Unknown"; 93 : 1 : break; 94 : : } 95 : : } catch (std::exception&) { // LCOV_EXCL_LINE GCOVR_EXCL_LINE 96 : : ostream << "Unknown"; // LCOV_EXCL_LINE GCOVR_EXCL_LINE 97 : : } // LCOV_EXCL_LINE GCOVR_EXCL_LINE 98 : : 99 : 15 : return ostream; 100 : : } 101 : : 102 : : // Unknown 103 : 36 : Type Unknown::get_type() const { return kUnknown; } 104 : : 105 [ + - ]: 8 : std::string Unknown::get_string() const { return "Unknown"; } 106 : : 107 : 1 : std::ostream& operator<<(std::ostream& ostream, const Unknown& status) noexcept { 108 : 1 : ostream << status.get_string(); 109 : : 110 : 1 : return ostream; 111 : : } 112 : : 113 : : // BasePtr 114 : 4 : std::ostream& operator<<(std::ostream& ostream, const BasePtr& status) noexcept { 115 [ + + ]: 4 : if VUNLIKELY (!status) { 116 : 1 : ostream << "null"; 117 : 1 : return ostream; 118 : : } 119 : : 120 : 3 : ostream << *status; 121 : : 122 : 3 : return ostream; 123 : : } 124 : : 125 : : } // namespace Status 126 : : 127 : : } // namespace vlink