polserver/pol-core/bscript/bboolean.cpp
turleypol 1463b76c7c
Includes are now all relative to pol-core basefolder (#906)
* all except pol

* pol and includes under defines

* something weird has happened

* remove own folder from include searchpath

* fixed remaining, adapted include style for external headers

* missing include
2026-07-25 23:01:18 +02:00

58 lines
1 KiB
C++

#include "bscript/bboolean.h"
#include "bscript/berror.h"
#include <fmt/compile.h>
#include <fmt/format.h>
#include <istream>
namespace Pol::Bscript
{
using namespace fmt::literals;
#if BOBJECTIMP_DEBUG
BBoolean::BBoolean( bool bval ) : BObjectImp( OTBoolean ), bval_( bval ) {}
BBoolean::BBoolean( const BBoolean& B ) : BBoolean( B.bval_ ) {}
#endif
BObjectImp* BBoolean::unpack( std::istream& is )
{
int lv;
if ( is >> lv )
{
return new BBoolean( lv != 0 );
}
return new BError( "Error extracting Boolean value" );
}
void BBoolean::packonto( std::string& str ) const
{
fmt::format_to( std::back_inserter( str ), "b{}"_cf, bval_ ? 1 : 0 );
}
BObjectImp* BBoolean::copy() const
{
return new BBoolean( *this );
}
size_t BBoolean::sizeEstimate() const
{
return sizeof( BBoolean );
}
bool BBoolean::isTrue() const
{
return bval_;
}
bool BBoolean::operator==( const BObjectImp& objimp ) const
{
return bval_ == objimp.isTrue();
}
std::string BBoolean::getStringRep() const
{
return bval_ ? "true" : "false";
}
} // namespace Pol::Bscript