View Single Post
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-25-2015 , 08:52   Re: [INC] DString - Dynamic Strings
Reply With Quote #7

Quote:
Originally Posted by Emp` View Post
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 170creating new object 'DataPack' requires using 'new' before its constructor
C
:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 104cannot find any methods for DString
C
:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : warning 215expression has no effect
C
:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 001expected token";"but found ")"
C:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : error 029invalid expressionassumed zero
C
:\Users\User\Downloads\addons\sourcemod\scripting\include\dstring.inc(24) : fatal error 189too 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 strlenstr );
    if ( 
len )
    {
        
handle.WriteCelllen );
        
handle.WriteStringstr );
    }
    return 
handle;
}

stock int DString_CopyDString handle, const char[] str )
{
    
int len strlenstr );
    if ( !
handle ) return 0;
    
handle.Resettrue );
    
handle.WriteCelllen );
    
handle.WriteStringstr );
    return 
len;
}
stock int DString_FormatDString handle, const char[] strany ... )
{
    
char bufferDSTRING_BUFFERLEN ];
    
VFormatbuffersizeof bufferstr);
    return 
handle.Copyhandlebuffer );
}

stock int DString_AddDString handle, const char[] str )
{
    
int len handle.Length();
    
int len_add strlenstr );
    if ( !
len_add ) return len;
    
int len_new len len_add
    char
[] buffer = new charlen_new ];
    if ( 
len handle.ReadStringbufferlen );
    
strcopybufferlen ], len_addstr );
    return 
handle.Copybuffer );
}
stock int DString_AddExDString handle, const char[] strany ... )
{
    
char bufferDSTRING_BUFFERLEN ];
    
VFormatbuffersizeof bufferstr);
    return 
handle.Addbuffer );
}

stock int DString_ReadDString handlechar[] bufferint buffersize )
{
    
int len handle.Length();
    if ( 
len handle.ReadStringbufferbuffersize );
    return 
len;
}
stock char[] DString_ReadExDString handle )
{
    
int len handle.Length();
    
char[] buffer = new charlen ];
    
handle.Readbufferlen );
    return 
buffer;
}

stock int DString_LengthDString handle )
{
    if ( !
handle ) return 0;
    
handle.Resetfalse );
    if ( !
handle.IsReadable) ) return 0;
    return 
handle.ReadCell();
}
stock void DString_ClearDString handle )
{
    
handle.Resettrue );
}

stock void DString_DeleteDString &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_Lengththis );
        }
    }

    public 
Clear() = DString_Clear;

__________________

Last edited by WildCard65; 06-25-2015 at 08:57.
WildCard65 is offline