Quote:
Originally Posted by Emp`
The attached version now packs a length cell, removing the length cap from before.
DSTRING_BUFFERLEN is now only used with VFormat. (ie. Format and AddEx functions)
Per WildCard65, length is a property and no longer uses the buffer. Also, added double inclusion block and changed function name cases.
Furthermore, DString inherits the DataPack methodmap, demonstrating dual methodmap usage.
|
Emp, your include has a compile error with the property, it expects a new line after naming the property, but it got a '{'
Edit: Another thing, your methodmap is also useless, in it's current position it's referencing no function so it f***s the compiler.
After moving the methodmap to under all the functions it references, it has more compile errors.
Errors after moving methodmap:
PHP Code:
dstringtest.sp
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(20) : error 170: creating new object 'DataPack' requires using 'new' before its constructor
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 104: cannot find any methods for DString
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : warning 215: expression has no effect
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 001: expected token: ";", but found ")"
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 029: invalid expression, assumed zero
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : fatal error 189: too many error messages on one line
Done
C:\Users\User\Downloads\addons\sourcemod\scripting>C:\Users\User\Downloads\addons\sourcemod\scripting\ff2Rename.bat dstringtest.sp
Above errors caused by doing: new DString() which is replaced with: DString_Create
PHP Code:
/**************************************************************************
* *
* DString - Dynamic Strings *
* Author: Eun *
* Version: 1.0.1 Emp`s changes *
* *
**************************************************************************/
#if defined _DSTRING_INCLUDED
#endinput
#endif
#define _DSTRING_INCLUDED
#if !defined DSTRING_BUFFERLEN
#define DSTRING_BUFFERLEN 4048
#endif
stock DString DString_Create( const char[] str = "" )
{
DString handle = view_as < DString > DataPack();
int len = strlen( str );
if ( len )
{
handle.WriteCell( len );
handle.WriteString( str );
}
return handle;
}
stock int DString_Copy( DString handle, const char[] str )
{
int len = strlen( str );
if ( !handle ) return 0;
handle.Reset( true );
handle.WriteCell( len );
handle.WriteString( str );
return len;
}
stock int DString_Format( DString handle, const char[] str, any ... )
{
char buffer[ DSTRING_BUFFERLEN ];
VFormat( buffer, sizeof buffer, str, 3 );
return handle.Copy( handle, buffer );
}
stock int DString_Add( DString handle, const char[] str )
{
int len = handle.Length();
int len_add = strlen( str );
if ( !len_add ) return len;
int len_new = len + len_add
char[] buffer = new char[ len_new ];
if ( len ) handle.ReadString( buffer, len );
strcopy( buffer[ len ], len_add, str );
return handle.Copy( buffer );
}
stock int DString_AddEx( DString handle, const char[] str, any ... )
{
char buffer[ DSTRING_BUFFERLEN ];
VFormat( buffer, sizeof buffer, str, 3 );
return handle.Add( buffer );
}
stock int DString_Read( DString handle, char[] buffer, int buffersize )
{
int len = handle.Length();
if ( len ) handle.ReadString( buffer, buffersize );
return len;
}
stock char[] DString_ReadEx( DString handle )
{
int len = handle.Length();
char[] buffer = new char[ len ];
handle.Read( buffer, len );
return buffer;
}
stock int DString_Length( DString handle )
{
if ( !handle ) return 0;
handle.Reset( false );
if ( !handle.IsReadable( 1 ) ) return 0;
return handle.ReadCell();
}
stock void DString_Clear( DString handle )
{
handle.Reset( true );
}
stock void DString_Delete( DString &handle )
{
delete handle;
}
methodmap DString < DataPack
{
public DString() = DString_Create;
public Copy() = DString_Copy;
public Format() = DString_Format;
public Add() = DString_Add;
public AddEx() = DString_AddEx;
public Read() = DString_Read;
public ReadEx() = DString_ReadEx;
property int Length
{
public get()
{
return DString_Length( this );
}
}
public Clear() = DString_Clear;
}
__________________