Quote:
Originally Posted by WildCard65
DString_Create works, what I believe the cause is where you put the methodmap. If you look at where DataPack has it's methodmap located, I suggest you try to make your version of the include match it.
|
You are describing more of a compile error, but it is producing a run time error. No compile error makes me think that it is seeing the functions fine, even with the methodmap before the DString functions. Did it work when you moved it below the stock functions?
Quote:
Originally Posted by Eun
Well mine has a Methodmap as well.
You can use the map or use the tradional syntax.
|
My version uses a lot less datapack functions (it's a faster script) by storing strings instead of individual cells. You don't want to waste extra time on reading/writing strings.
Also, your methodmaps are recreating some functions, whereas mine point to the stock DString functions.
Lastly, your DString methodmap is not inheriting the DataPack methodmap, so you are not taking advantage of the DataPack methods.
Code with the Create method updated and a Clone method:
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
methodmap DString < DataPack
{
public DString( const char[] str = "" ) { return DString_Create( str ); }
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;
public Clone() = DString_Clone;
}
stock DString DString_Create( const char[] str = "" )
{
DString handle = view_as < DString > new DataPack();
int len = strlen( str );
if ( len )
{
handle.WriteCell( len );
handle.WriteString( str );
}
return handle;
}
stock int DString_Copy( DString handle, const char[] str )
{
if ( !handle ) return 0;
handle.Reset( true );
int len = strlen( str );
if ( len )
{
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( buffer );
}
stock int DString_Add( DString handle, const char[] str )
{
if ( !handle ) return 0;
int len_base = handle.Length;
if ( !len_base ) return handle.Copy( str );
int len_add = strlen( str );
if ( !len_add ) return len_base;
for ( char[] buffer = new char[ len_base ]; handle.IsReadable( 1 ); handle.ReadString( buffer, len_base ) ) { }
handle.WriteString( str );
handle.Reset( false );
int len_new = len_base + len_add;
handle.WriteCell( len_new );
return len_new;
}
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_temp;
for ( int len = handle.Length ; len_temp < len ; len_temp += strlen( buffer[ len_temp ] ) )
handle.ReadString( buffer[ len_temp ], buffersize );
return len_temp;
}
stock char[] DString_ReadEx( DString handle )
{
int len = handle.Length;
if ( !len ) len++;
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 DString DString_Clone( DString handle )
{
return handle ? new DString( handle.ReadEx() ) : null;
}
stock void DString_Delete( DString &handle )
{
delete handle;
}