polserver/pol-core/bscript/berror.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

129 lines
2.2 KiB
C++

/** @file
*
* @par History
*/
#include "bscript/berror.h"
#include "bscript/bcontiter.h"
#include "bscript/bstring.h"
namespace Pol::Bscript
{
unsigned int BError::creations_ = 0;
unsigned int BError::creations()
{
return creations_;
}
BError::BError() : BStruct( OTError )
{
++creations_;
}
BError::BError( const BError& other ) : BStruct( other, OTError )
{
++creations_;
}
BError::BError( std::istream& is, unsigned size ) : BStruct( is, size, OTError )
{
++creations_;
}
BError::BError( const char* err ) : BStruct( OTError )
{
++creations_;
addMember( "errortext", new String( err ) );
}
BError::BError( const std::string& err ) : BStruct( OTError )
{
++creations_;
addMember( "errortext", new String( err ) );
}
BObjectImp* BError::copy() const
{
return new BError( *this );
}
char BError::packtype() const
{
return 'e';
}
const char* BError::typetag() const
{
return "error";
}
const char* BError::typeOf() const
{
return "Error";
}
u8 BError::typeOfInt() const
{
return OTError;
}
BObjectImp* BError::unpack( std::istream& is )
{
unsigned size;
char colon;
if ( !( is >> size >> colon ) )
{
return new BError( "Unable to unpack struct elemcount" );
}
if ( (int)size <= 0 )
{
return new BError(
"Unable to unpack struct elemcount. Length given must be positive integer!" );
}
if ( colon != ':' )
{
return new BError( "Unable to unpack struct elemcount. Bad format. Colon not found!" );
}
return new BError( is, size );
}
bool BError::isTrue() const
{
return false;
}
/**
* An error is equal to any other error or uninit
*/
bool BError::operator==( const BObjectImp& imp ) const
{
return ( imp.isa( OTError ) || imp.isa( OTUninit ) );
}
bool BError::operator<( const BObjectImp& imp ) const
{
if ( imp.isa( OTError ) || imp.isa( OTUninit ) )
return false; // Because it's equal can't be lesser
return true;
}
ContIterator* BError::createIterator( BObject* /*pIterVal*/ )
{
return new ContIterator();
}
BObjectRef BError::OperSubscript( const BObject& /*obj*/ )
{
return BObjectRef( this );
}
BObjectImp* BError::array_assign( BObjectImp* /*idx*/, BObjectImp* /*target*/, bool /*copy*/ )
{
return this;
}
} // namespace Pol::Bscript