Raised This Month: $23 Target: $400
 5% 

[INC] DString - Dynamic Strings


Post New Thread Reply   
 
Thread Tools Display Modes
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 07-09-2015 , 20:26   Re: [INC] DString - Dynamic Strings
Reply With Quote #21

Quote:
Originally Posted by WildCard65 View Post
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 View Post
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_Createstr ); }

    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;
    public Clone() = 
DString_Clone;
}

stock DString DString_Create( const char[] str "" )
{
    
DString handle view_as DString > new DataPack();
    
int len strlenstr );
    if ( 
len )
    {
        
handle.WriteCelllen );
        
handle.WriteStringstr );
    }
    return 
handle;
}

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

stock int DString_AddDString handle, const char[] str )
{
    if ( !
handle ) return 0;
    
int len_base handle.Length;
    if ( !
len_base ) return handle.Copystr );
    
int len_add strlenstr );
    if ( !
len_add ) return len_base;
    for ( 
char[] buffer = new charlen_base ]; handle.IsReadable); handle.ReadStringbufferlen_base ) ) { }
    
handle.WriteStringstr );
    
handle.Resetfalse );
    
int len_new len_base len_add;
    
handle.WriteCelllen_new );
    return 
len_new;
}
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_temp;
    for ( 
int len handle.Length len_temp len len_temp += strlenbufferlen_temp ] ) )
        
handle.ReadStringbufferlen_temp ], buffersize );
    return 
len_temp;
}
stock char[] DString_ReadExDString handle )
{
    
int len handle.Length;
    if ( !
len len++;
    
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 DString DString_CloneDString handle )
{
    return 
handle ? new DStringhandle.ReadEx() ) : null;
}

stock void DString_DeleteDString &handle )
{
    
delete handle;

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`
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 07-31-2016 , 15:06   Re: [INC] DString - Dynamic Strings
Reply With Quote #22

Update per:
Quote:
Originally Posted by BAILOPAN View Post
Removing () = binding
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 2048
#endif

methodmap DString DataPack
{
    public 
DString( const char[] str "" )
    {
        
DString handle view_as DString > ( new DataPack() );
        
int len strlenstr );
        if ( 
len )
        {
            
handle.WriteCelllen );
            
handle.WriteStringstr );
        }
        return 
handle;
    }

    
property int Length
    
{
        public 
get()
        {
            if ( !
this ) return 0;
            
this.Resetfalse );
            if ( !
this.IsReadable) ) return 0;
            return 
this.ReadCell();
        }
    }

    public 
int Copy( const char[] str )
    {
        if ( !
this ) return 0;
        
this.Resettrue );
        
int len strlenstr );
        if ( 
len )
        {
            
this.WriteCelllen );
            
this.WriteStringstr );
        }
        return 
len;
    }
    public 
int Format( const char[] strany ... )
    {
        
char bufferDSTRING_BUFFERLEN ];
        
VFormatbuffersizeof bufferstr);
        return 
this.Copybuffer );
    }

    public 
int Add( const char[] str )
    {
        if ( !
this ) return 0;
        
int len_base this.Length;
        if ( !
len_base ) return this.Copystr );
        
int len_add strlenstr );
        if ( !
len_add ) return len_base;
        
int len_read;
        
char[] buffer = new charlen_base ];
        while ( 
this.IsReadable) && len_read len_base )
        {
            
this.ReadStringbufferlen_base );
            
len_read += strlenbuffer );
        }
        
this.WriteStringstr );
        
this.Resetfalse );
        
int len_new len_base len_add;
        
this.WriteCelllen_new );
        return 
len_new;
    }
    public 
int AddEx( const char[] strany ... )
    {
        
char bufferDSTRING_BUFFERLEN ];
        
VFormatbuffersizeof bufferstr);
        return 
this.Addbuffer );
    }

    public 
int Readchar[] bufferint buffersize )
    {
        
int len_read;
        for ( 
int len this.Length this.IsReadable) && len_read len && buffersize len_read len_read += strlenbufferlen_read ] ) )
            
this.ReadStringbufferlen_read ], buffersize len_read );
        return 
len_read;
    }
    public 
char[] ReadEx()
    {
        
char bufferDSTRING_BUFFERLEN ];
        
this.Readbuffersizeof buffer );
        return 
buffer;
    }

    public 
void Clear() { this.Resettrue ); }
    public 
DString Clone()
    {
        if ( !
this )
            return 
null;

        
int len this.Length;
        if ( !
len len++;
        
char[] buffer = new charlen ];
        
this.Readbufferlen );
        return new 
DStringbuffer );
    }

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`
Reply


Thread Tools
Display Modes

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 13:35.


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