mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-29 16:09:30 +00:00
Started new reporter, "console", which will replace "basic" when done.
Introduced Option template as part of this.
This commit is contained in:
parent
f276a0588c
commit
fe98123d0b
9 changed files with 258 additions and 6 deletions
64
include/internal/catch_option.hpp
Normal file
64
include/internal/catch_option.hpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Created by Phil on 02/12/2012.
|
||||
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
|
||||
|
||||
#include "catch_common.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
// An optional type
|
||||
template<typename T>
|
||||
class Option {
|
||||
public:
|
||||
Option() : nullableValue( NULL ) {}
|
||||
Option( T const& _value )
|
||||
: nullableValue( new( storage ) T( _value ) )
|
||||
{}
|
||||
Option( Option const& _other )
|
||||
: nullableValue( _other ? new( storage ) T( *_other ) : NULL )
|
||||
{}
|
||||
|
||||
~Option() {
|
||||
reset();
|
||||
}
|
||||
|
||||
Option& operator= ( Option const& _other ) {
|
||||
reset();
|
||||
if( _other )
|
||||
nullableValue = new( storage ) T( *_other );
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
if( nullableValue )
|
||||
nullableValue->~T();
|
||||
nullableValue = NULL;
|
||||
}
|
||||
T& operator*() { return *nullableValue; }
|
||||
const T& operator*() const { return *nullableValue; }
|
||||
T* operator->() { return nullableValue; }
|
||||
const T* operator->() const { return nullableValue; }
|
||||
|
||||
bool some() const { return nullableValue != NULL; }
|
||||
bool none() const { return nullableValue == NULL; }
|
||||
|
||||
bool operator !() const { return nullableValue == NULL; }
|
||||
operator SafeBool::type() const {
|
||||
return SafeBool::makeSafe( some() );
|
||||
}
|
||||
|
||||
private:
|
||||
T* nullableValue;
|
||||
char storage[sizeof(T)];
|
||||
};
|
||||
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
|
Loading…
Add table
Add a link
Reference in a new issue