13 #include "../bscript/berror.h" 14 #include "../bscript/bobject.h" 15 #include "../bscript/executor.h" 16 #include "../bscript/impstr.h" 17 #include "../bscript/objmembers.h" 18 #include "../bscript/objmethods.h" 19 #include "../clib/clib_endian.h" 20 #include "../clib/rawtypes.h" 29 openmode(
std::ios::in ),
40 openmode =
static_cast<ios::openmode
>( 0x0 );
63 return sizeof( *this ) +
_filename.capacity();
73 if ( objmember !=
nullptr )
82 if ( objmethod !=
nullptr )
91 using namespace Bscript;
96 return new BLong( 1 );
104 return new BError(
"Seek requires 2 parameter." );
107 return new BError(
"Invalid parameter" );
109 ios::seekdir seekdir;
112 else if ( type & 0x02 )
117 return new BLong( 0 );
118 return new BLong( 1 );
126 return new BLong( 1 );
132 return new BError(
"Failed to read" );
135 return new BLong( _u32 );
141 return new BError(
"Failed to read" );
144 return new BLong( _s32 );
150 return new BError(
"Failed to read" );
153 return new BLong( _u16 );
159 return new BError(
"Failed to read" );
162 return new BLong( _s16 );
168 return new BError(
"Failed to read" );
169 return new BLong( _u8 );
175 return new BError(
"Failed to read" );
176 return new BLong( _s8 );
181 return new BError(
"GetString requires 1 parameter." );
184 return new BError(
"Invalid parameter" );
186 return new BError(
"Len is negative or 0." );
187 std::vector<unsigned char> _char;
188 _char.resize( value );
189 if ( !
file.
Read( &_char[0], value ) )
190 return new BError(
"Failed to read" );
192 const char* _str =
reinterpret_cast<const char*
>( &_char[0] );
194 while ( len < value && *( _str + len ) )
196 return new String( _str, len );
202 return new BError(
"SetInt32 requires 1 parameter." );
205 return new BError(
"Invalid parameter" );
206 u32 _u32 =
static_cast<u32>( value );
210 return new BError(
"Failed to write" );
211 return new BLong( 1 );
216 return new BError(
"SetSInt32 requires 1 parameter." );
219 return new BError(
"Invalid parameter" );
220 s32 _s32 =
static_cast<s32>( value );
224 return new BError(
"Failed to write" );
225 return new BLong( 1 );
230 return new BError(
"SetInt16 requires 1 parameter." );
233 return new BError(
"Invalid parameter" );
234 u16 _u16 =
static_cast<u16>( value );
238 return new BError(
"Failed to write" );
239 return new BLong( 1 );
244 return new BError(
"SetSInt16 requires 1 parameter." );
247 return new BError(
"Invalid parameter" );
248 s16 _s16 =
static_cast<s16>( value );
252 return new BError(
"Failed to write" );
253 return new BLong( 1 );
258 return new BError(
"SetInt8 requires 1 parameter." );
261 return new BError(
"Invalid parameter" );
262 u8 _u8 =
static_cast<u8>( value );
264 return new BError(
"Failed to write" );
265 return new BLong( 1 );
270 return new BError(
"SetSInt8 requires 1 parameter." );
273 return new BError(
"Invalid parameter" );
274 s8 _s8 =
static_cast<s8>( value );
276 return new BError(
"Failed to write" );
277 return new BLong( 1 );
282 return new BError(
"SetString requires 2 parameters." );
286 return new BError(
"Invalid parameter" );
287 u32 len =
static_cast<u32>( text->
value().length() );
291 return new BError(
"Failed to write" );
292 return new BLong( 1 );
331 Open( filename, mode );
341 if ( _file.is_open() )
345 if ( !_file.is_open() )
352 return _file.is_open();
357 if ( !_file.is_open() )
363 bool BinFile::Seek( std::fstream::pos_type abs_offset, std::ios::seekdir origin )
365 if ( !_file.is_open() )
368 if ( !_file.seekg( abs_offset, origin ) )
375 if ( !_file.read( reinterpret_cast<char*>( buffer ), length ) )
382 if ( !_file.write( reinterpret_cast<char*>( buffer ), length ) )
389 if ( !_file.write( chr, len ) )
396 if ( !_file.is_open() )
397 return std::fstream::pos_type( 0 );
399 std::fstream::pos_type save_pos = _file.tellg();
400 if ( save_pos == std::fstream::pos_type( -1 ) )
403 new Bscript::BError(
"FileSize failed to determine current position." ) );
404 return std::fstream::pos_type( 0 );
406 if ( !_file.seekg( 0, std::ios::end ) )
409 return std::fstream::pos_type( 0 );
411 std::fstream::pos_type size = _file.tellg();
412 if ( size == std::fstream::pos_type( -1 ) )
415 return std::fstream::pos_type( 0 );
417 if ( !_file.seekg( save_pos ) )
420 new Bscript::BError(
"FileSize failed to seek to original position." ) );
421 return std::fstream::pos_type( 0 );
428 if ( !_file.is_open() )
430 return _file.tellg();
435 if ( !_file.is_open() )
442 if ( _file.is_open() )
void setFunctionResult(BObjectImp *imp)
bool WriteBuffer(void *buffer, std::streamsize length)
const std::string & value() const
bool WriteString(const char *chr, unsigned len)
virtual bool operator==(const Bscript::BObjectImp &objimp) const POL_OVERRIDE
bool isa(BObjectType type) const
bool ReadBuffer(void *buffer, std::streamsize length)
char * binary(unsigned int val, int nbits)
ObjMember * getKnownObjMember(const char *token)
ObjMethod * getKnownObjMethod(const char *token)
virtual Bscript::BObjectRef get_member(const char *membername) POL_OVERRIDE
virtual Bscript::BObjectImp * copy() const POL_OVERRIDE
bool Seek(std::fstream::pos_type abs_offset, std::ios::seekdir origin)
std::fstream::pos_type Tell()
std::ios::openmode openmode
virtual std::string getStringRep() const POL_OVERRIDE
static UninitObject * create()
virtual Bscript::BObjectRef get_member_id(const int id) POL_OVERRIDE
std::fstream::pos_type FileSize(Bscript::Executor &exec)
bool Open(const std::string &filename, std::ios::openmode mode)
virtual Bscript::BObjectImp * call_method_id(const int id, Bscript::Executor &ex, bool forcebuiltin=false) POL_OVERRIDE
const String * getStringParam(unsigned param)
virtual size_t sizeEstimate() const POL_OVERRIDE
virtual bool isTrue() const POL_OVERRIDE
virtual Bscript::BObjectImp * call_method(const char *methodname, Bscript::Executor &ex) POL_OVERRIDE
bool getParam(unsigned param, int &value)