Raised This Month: $ Target: $400
 0% 

[INC] DString - Dynamic Strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 06-24-2015 , 15:31   Re: [INC] DString - Dynamic Strings
Reply With Quote #1

Quote:
Originally Posted by Eun View Post
I appreciate your changes.
But there are some problems:

I guess you should not limit the Developer to an "arbitrarily high" buffer. Thats not the use case of this Module. This Module should give you the theoretical possibility to use string with an unspecified length.
You just limited it to 4084

The buffer was especially designed just for AddEx, since we cannot be dynamic on Formatting issues.

Additionaly you never should fill buffers in a Length call. Length operations should be as little as possible.

However, I added the MethodMap.
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.

Edit: Attachment outdated, see post below.
Attached Files
File Type: inc dstring.inc (2.9 KB, 216 views)

Last edited by Emp`; 07-31-2016 at 15:09. Reason: attachment outdated
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-25-2015 , 08:52   Re: [INC] DString - Dynamic Strings
Reply With Quote #2

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
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode