Pol  Revision:cb584c9
berror.cpp
Go to the documentation of this file.
1 
7 #include "berror.h"
8 
9 #include "contiter.h"
10 #include "impstr.h"
11 
12 namespace Pol
13 {
14 namespace Bscript
15 {
16 unsigned int BError::creations_ = 0;
17 unsigned int BError::creations()
18 {
19  return creations_;
20 }
21 
23 {
24  ++creations_;
25 }
26 
27 BError::BError( const BError& other ) : BStruct( other, OTError )
28 {
29  ++creations_;
30 }
31 
32 BError::BError( std::istream& is, unsigned size ) : BStruct( is, size, OTError )
33 {
34  ++creations_;
35 }
36 
37 BError::BError( const char* err ) : BStruct( OTError )
38 {
39  ++creations_;
40  addMember( "errortext", new String( err ) );
41 }
42 
43 BError::BError( const std::string& err ) : BStruct( OTError )
44 {
45  ++creations_;
46  addMember( "errortext", new String( err ) );
47 }
48 
49 
50 BObjectImp* BError::copy( void ) const
51 {
52  return new BError( *this );
53 }
54 
55 char BError::packtype() const
56 {
57  return 'e';
58 }
59 
60 const char* BError::typetag() const
61 {
62  return "error";
63 }
64 
65 const char* BError::typeOf() const
66 {
67  return "Error";
68 }
69 
71 {
72  return OTError;
73 }
74 
75 BObjectImp* BError::unpack( std::istream& is )
76 {
77  unsigned size;
78  char colon;
79  if ( !( is >> size >> colon ) )
80  {
81  return new BError( "Unable to unpack struct elemcount" );
82  }
83  if ( (int)size <= 0 )
84  {
85  return new BError(
86  "Unable to unpack struct elemcount. Length given must be positive integer!" );
87  }
88  if ( colon != ':' )
89  {
90  return new BError( "Unable to unpack struct elemcount. Bad format. Colon not found!" );
91  }
92  return new BError( is, size );
93 }
94 
95 
96 bool BError::isTrue() const
97 {
98  return false;
99 }
103 bool BError::operator==( const BObjectImp& imp ) const
104 {
105  return ( imp.isa( OTError ) || imp.isa( OTUninit ) );
106 }
107 
108 bool BError::operator<( const BObjectImp& imp ) const
109 {
110  if ( imp.isa( OTError ) || imp.isa( OTUninit ) )
111  return false; // Because it's equal can't be lesser
112 
113  return true;
114 }
115 
117 {
118  return new ContIterator();
119 }
120 
122 {
123  return BObjectRef( this );
124 }
125 
126 BObjectImp* BError::array_assign( BObjectImp* /*idx*/, BObjectImp* /*target*/, bool /*copy*/ )
127 {
128  return this;
129 }
130 }
131 }
unsigned char u8
Definition: rawtypes.h:25
bool isa(BObjectType type) const
Definition: bobject.h:353
virtual ContIterator * createIterator(BObject *pIterVal) POL_OVERRIDE
Definition: berror.cpp:116
virtual const char * typeOf() const POL_OVERRIDE
Definition: berror.cpp:65
void addMember(const char *name, BObjectRef val)
Definition: bstruct.cpp:305
static unsigned int creations()
Definition: berror.cpp:17
virtual const char * typetag() const POL_OVERRIDE
Definition: berror.cpp:60
virtual bool operator<(const BObjectImp &objimp) const POL_OVERRIDE
Definition: berror.cpp:108
virtual BObjectImp * array_assign(BObjectImp *idx, BObjectImp *target, bool copy) POL_OVERRIDE
Definition: berror.cpp:126
static unsigned int creations_
Definition: berror.h:61
virtual char packtype() const POL_OVERRIDE
Definition: berror.cpp:55
virtual u8 typeOfInt() const POL_OVERRIDE
Definition: berror.cpp:70
virtual BObjectRef OperSubscript(const BObject &obj) POL_OVERRIDE
Definition: berror.cpp:121
virtual bool operator==(const BObjectImp &objimp) const POL_OVERRIDE
Definition: berror.cpp:103
virtual BObjectImp * copy() const POL_OVERRIDE
Definition: berror.cpp:50
Definition: berror.cpp:12
virtual bool isTrue() const POL_OVERRIDE
Definition: berror.cpp:96
static BObjectImp * unpack(std::istream &is)
Definition: berror.cpp:75