/* * libfud * Copyright 2024 Dominick Allen * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FUD_STATUS_HPP #define FUD_STATUS_HPP #include namespace fud { // NOLINTNEXTLINE(performance-enum-size) enum class [[nodiscard]] FudStatus : int32_t { /** \brief Indisputable success. */ Success = 0, /** \brief Either partially succeeding, or failing in a recoverable way. */ Partial, /** \brief Typically a major failure in an underlying system call. */ Failure, /** \brief An argument passed in was a null pointer and is invalid. */ NullPointer, /** \brief An argument passed in is in an invalid state or mismatches with other arguments. */ ArgumentInvalid, /** \brief An handle to a managed object is not valid. */ HandleInvalid, /** \brief An object is uninitialized or no longer valid. */ ObjectInvalid, /** \brief A utf sequence in a string is invalid. */ Utf8Invalid, /** \brief A string is not terminated or has a length field exceeding its capacity. */ StringInvalid, /** \brief The requested operation on the object is not valid for its current state. */ OperationInvalid, /** \brief An object which is to be initialized has already been initialized. */ AlreadyInitialized, /** \brief A format string is invalid. */ FormatInvalid, /** \brief A string being parsed as a number is out of range for the requested type. */ RangeError, /** \brief The given index is not in range of a randomly accessible container. */ IndexInvalid, /** \brief An object in a container already exists in the requested slot for a new object. */ Exists, /** \brief An object in a container does not exist in the requested slot for an existing object. */ NotFound, /** \brief A container is empty when something was expected to be present. */ Empty, /** \brief A container is full when attempting to add something to it. */ Full, /** \brief An operation requiring elevated permissions failed. */ PermissionDenied, /** \brief Two or more objects overlap when they are expected to be distinct. */ Aliased, /** \brief An requested allocation could not be completed. */ AllocFailure, /** \brief An requested deallocation could not be completed. */ DeallocFailure, /** \brief The function is not implemented, but is planned to be implemented. */ NotImplemented, /** \brief The function or desired mode of action for a function is not supported. */ NotSupported }; constexpr const char* FudStatusToString(FudStatus status) { switch (status) { case FudStatus::Success: return "Success"; case FudStatus::Partial: return "Partial"; case FudStatus::Failure: return "Failure"; case FudStatus::NullPointer: return "NullPointer"; case FudStatus::ArgumentInvalid: return "ArgumentInvalid"; case FudStatus::HandleInvalid: return "HandleInvalid"; case FudStatus::ObjectInvalid: return "ObjectInvalid"; case FudStatus::StringInvalid: return "StringInvalid"; case FudStatus::OperationInvalid: return "OperationInvalid"; case FudStatus::Utf8Invalid: return "Utf8Invalid"; case FudStatus::RangeError: return "RangeError"; case FudStatus::FormatInvalid: return "FormatInvalid"; case FudStatus::AlreadyInitialized: return "AlreadyInitialized"; case FudStatus::IndexInvalid: return "IndexInvalid"; case FudStatus::Exists: return "Exists"; case FudStatus::NotFound: return "NotFound"; case FudStatus::Empty: return "Empty"; case FudStatus::Full: return "Full"; case FudStatus::PermissionDenied: return "PermissionDenied"; case FudStatus::Aliased: return "Aliased"; case FudStatus::AllocFailure: return "AllocFailure"; case FudStatus::DeallocFailure: return "DeallocFailure"; case FudStatus::NotImplemented: return "NotImplemented"; case FudStatus::NotSupported: return "NotSupported"; default: return "Unknown"; } } constexpr bool anyAreNull() { return false; } template constexpr bool anyAreNull(const T* pointer) { return pointer == nullptr; } template constexpr bool anyAreNull(T pointer, Ts... pointers) { if (pointer == nullptr) { return true; } return anyAreNull(pointers...); } } // namespace fud #endif