SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 02/07/2012, 04:00 PM   #1
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 70
Reputation: 25
Default [REL]fstream

Simple plugin that adds functionality fstream library to PAWN

What is fstream?
http://www.cplusplus.com/reference/iostream/fstream/


Functions:

fstream:Fopen(filename[], mode, bool:scriptfiles = true)
Opens/creates the file
  • filename[] - file name
  • mode - mode to open, example (ios::in) (ios::out|ios::in)
  • bool:scriptfiles = true - if true files will be opened / created in scriptfiles folder, if false in server folder

Return the ID of file, You can open the 32 files at once. if the error arose will return -1

How to check if file was open correctly?
pawn Code:
new fstream:file = Fopen("file.txt", ios::out);

if(_:file != -1)

//or

if(file != fstream:(-1))



Fclose(fstream:file, bool:clear = true)
Closes the file
  • fstream:file - file id returned by Fopen
  • bool:clear = true - whether or not cleaned after closing the file id, default yes

Returns nothing



Fcopyfmt(fstream:file, fstream:file2)
Copies the contents of one file to another
  • fstream:file - id file, into which something is copied
  • fstream:file2 - id file from which something is copied

Returns nothing



Fgetchar(fstream:file)
gets one character from a file, is equivalent to the get function with no arguments
  • fstream:file - file id

Returns the character from a file



Functions:
Fisopen(fstream:file)
Ftellp(fstream:file)
Ftellg(fstream:file)
Fbad(fstream:file)
Ffail(fstream:file)
Fgood(fstream:file)
Feof(fstream:file)
Fgcount(fstream:file)
Fpeek(fstream:file)
Fsync(fstream:file)
Freadsome(fstream:file, dest[], size)
Fnarrow(fstream:file, c, dfault = NULL)
Fwiden(fstream:file, c)
Fwidth(fstream:file, c = NO_ARG)
Ffill(fstream:file, c = NO_ARG)
Fflags(fstream:file, mask = NO_ARG)
Fsetf(fstream:file, fmtfl, mask = NO_ARG)
Frdstate(fstream:file)
These are the same as in C + +, that is the same act and the same return

Functions:
Fclear(fstream:file, flag = ios::goodbit)
Fseekp(fstream:file, fpos = 0, mode = NO_ARG)
Fseekg(fstream:file, fpos = 0, mode = NO_ARG)
Funget(fstream:file)
Fflush(fstream:file)
Fput(fstream:file, c)
Fget(fstream:file, dest[], size = sizeof dest, delim = '\n')
Fgetline(fstream:file, dest[], size = sizeof dest, delim = '\n')
Fread(fstream:file, dest[], size)
Fignore(fstream:file, size = 1, delim = EOF)
Fputback(fstream:file, fpos)
Funsetf(fstream:file, mask)
Fsetstate(fstream:file, flag)
Same as above but do not return

Fexceptions(fstream:file, except = NO_ARG)
By default, it returns as a C + + with the modified argument does not return

Fwrite(fstream:file, const str[], size = NO_ARG)
Why here is size = NO_ARG? it is clear that's you going to use here strlen, that's why I do this already in the plugin
Function returns nothing


Which means NO_ARG?
Functions in fstream sometimes have the same name but different arguments and action. That is why I added a macro with a value of -2 means use that function without this argument


Example of constans from C++
Code:
ios::showpos
ios::hexfloat
ios::beg
ios::trunc
ios::badbit
Can I use C++ style like
plik.write("text")
plik.ignore(true)
itp.?

Yes but before you have to give F:

pawn Code:
F:plik.write("text");

if(F:plik.ignore(true))
etc.

Update #1:
Thanks to ****** now you can save data to a file in a very simple way:
pawn Code:
new fstream::file("test.txt", ios::out);
file = file + S("string/text here") + 20 + 18.5325 + C('A') + endl;
Fclose(file);
in file will be
Quote:
string/text here2018.5325A
//empty line

and one more example
pawn Code:
file = file + S("Money = ") + GetPlayerMoney(playerid) + endl + S("Score = ") + GetPlayerScore(playerid) + endl;
in file will be
Quote:
Money = 1000
Score = 10
//empty line
S() - if you want to save string in file
C() - if you want to save one char in file
endl - if you want to save enter in file (it's just \n char, fstream change it to \r\n)



DOWNLOAD; Mirror

Source Code; Mirror
__________________
sorry for my bad English

Last edited by Terminator3; 07/07/2012 at 10:09 AM.
Terminator3 is offline   Reply With Quote
Old 02/07/2012, 04:30 PM   #2
Niko_boy
High-roller
 
Niko_boy's Avatar
 
Join Date: Aug 2010
Location: Somewhere i belong
Posts: 1,336
Reputation: 138
Default Re: [REL]fstream

owwa another file system to SA:MP
Cool
__________________
nope[IMG]http://*******/1r0SOkH_[/IMG]
•••[CLOSED]LCS•Freeroam•DM•Stunts•••AutoArena [0.3z][No SkinShot][sixtytiger.com]Want a decent Attack Defend Gamemode?
N/A176.31.229.148:7830Get This! Attack-Defend(v2.3.1)
Niko_boy is offline   Reply With Quote
Old 02/07/2012, 05:52 PM   #3
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 70
Reputation: 25
Default Re: [REL]fstream

Oh, nice, but i do not understand callback _fstream_Fwrite_fix()
for what it's needed?
__________________
sorry for my bad English
Terminator3 is offline   Reply With Quote
Old 02/07/2012, 07:28 PM   #4
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 70
Reputation: 25
Default Re: [REL]fstream

Should not be like that?
pawn Code:
forward
    _fstream_Fwrite_fix();

public
    _fstream_Fwrite_fix()
{
    Fwrite(fstream:(-1), "");
}

because bad id file here is not 0 only -1
__________________
sorry for my bad English
Terminator3 is offline   Reply With Quote
Old 06/07/2012, 07:10 AM   #5
Terminator3
Big Clucker
 
Terminator3's Avatar
 
Join Date: Oct 2009
Posts: 70
Reputation: 25
Default Re: [REL]fstream

@****** is one big problem with your code, Fwrite takes 3 arguments, the last must be -2, with your code 3 argument has a value 16436
Can you fix it because I do not know much about the EMIT


p.s I added
pawn Code:
stock char_tag:
    C(val)
{
    return char_tag:val;
}

stock fstream:
    operator+(
        fstream:fhnd,
        char_tag:val)
{
    Fput(fhnd, val);
    return fhnd;
}
__________________
sorry for my bad English
Terminator3 is offline   Reply With Quote
Old 06/07/2012, 10:19 PM   #6
sampplayer12
Big Clucker
 
sampplayer12's Avatar
 
Join Date: Jun 2012
Location: San Andreas
Posts: 116
Reputation: 19
Default Re: [REL]fstream

Good Work
sampplayer12 is offline   Reply With Quote
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



All times are GMT. The time now is 11:50 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.