MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/TriangleMeshDistance / BasicResult

Class BasicResult

tests/catch.hpp:6885–6927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6883
6884 template<typename T = void>
6885 class BasicResult : public ResultValueBase<T> {
6886 public:
6887 template<typename U>
6888 explicit BasicResult( BasicResult<U> const &other )
6889 : ResultValueBase<T>( other.type() ),
6890 m_errorMessage( other.errorMessage() )
6891 {
6892 assert( type() != ResultBase::Ok );
6893 }
6894
6895 template<typename U>
6896 static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; }
6897 static auto ok() -> BasicResult { return { ResultBase::Ok }; }
6898 static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; }
6899 static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; }
6900
6901 explicit operator bool() const { return m_type == ResultBase::Ok; }
6902 auto type() const -> ResultBase::Type { return m_type; }
6903 auto errorMessage() const -> std::string { return m_errorMessage; }
6904
6905 protected:
6906 void enforceOk() const override {
6907
6908 // Errors shouldn't reach this point, but if they do
6909 // the actual error message will be in m_errorMessage
6910 assert( m_type != ResultBase::LogicError );
6911 assert( m_type != ResultBase::RuntimeError );
6912 if( m_type != ResultBase::Ok )
6913 std::abort();
6914 }
6915
6916 std::string m_errorMessage; // Only populated if resultType is an error
6917
6918 BasicResult( ResultBase::Type type, std::string const &message )
6919 : ResultValueBase<T>(type),
6920 m_errorMessage(message)
6921 {
6922 assert( m_type != ResultBase::Ok );
6923 }
6924
6925 using ResultValueBase<T>::ResultValueBase;
6926 using ResultBase::m_type;
6927 };
6928
6929 enum class ParseResultType {
6930 Matched, NoMatch, ShortCircuitAll, ShortCircuitSame

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected