File Class

JS - Reference
JS Syntax
Leohtml Class
File Class
Get_tmp_file Function
Line Class
Tag Class
Lexer Class
Rebuilt_file Function
For accessing file this class can be used. This class is not a simple interface to a file. The class was developed for accessing a real file or simulating a file in the memory.
Leo<HTML> is massively using this feature and as the result of this it does not need temporary files.
So don't be supriced and study this class intensively.


Class: File



File( String name, String openmode, Bool nocreate = false, Bool realfile = true);

File( File other_file );


Null open( String name, String openmode, Bool nocreate = false, Bool realfile = true );

Bool is_valid();

String get_name();

Null trunc();

Bool eof();

Null clear();

Null flush();

Integer tellg();

Integer tellp();

Null seekg( Integer pos );

Null seekp( Integer pos );

Integer get();

Null put( Integer c );

String read( Integer n );

Null write( String s);

Null write( String s, Interger n);

String getline();

Null append( File other_file );

Null reference( File other_file );

At this class a file consists of two parts: the real file and a pointer to the file. There can only exist one file but several pointers to the file.
The File class is a pointer to a file. If you copy the File class you do not copy the file, you will only copy the pointer to the file. Consequently you can use the File class as function parameter.

The second feature of the File File class is the possibility to create virtual file, that does not exist in the file system, but is created in the memory. That's ideal for temporary files.
The access and the creation of temorary files is faster as at real files. But the disadvantage is that such a virtual file only exists during the execution of Leo<HTML> . When the compiler finished execution all datas are lost.

The Get_tmp_file Function returns unique file names for temporary files.

There are three Constructors:

A new instance of this class will be created. This class will be invalid as long as a file will be opend with the open() function, or a other file class will be referenced by using the reference() function.

File( String name, String openmode, Bool nocreate = false, Bool realfile = true)
Open or create a file. The parameters are equal to the open() function. There you will find their description too.

File( File other_file )
Copy the other File class. This means not copying the real file. Only the poiter to the file dublicated.

Null open( String name, String openmode, nocreate = false, realfile = true )
This function opens a file.

String name
The name of the file.

String openmode
The openmode of the file. It's a character string. These are the characters that can be used and it's meaning:
r   Open file for read access.
w   Open file for write access.
a   Open for writing and append data to the file.
t   If file exist erase the data.

Bool nocreate
If the parameter is true, opening a file will fail if the file does not exists. The default value is false.

Bool realfile
If the parameter is true a real file would be used. If not, a virtual file will be used.

Bool is_valid()
If the class and it's file are valid, the function will return true

String get_name()
The function returns the name of the file. This will even work after the class becomes invalid, after is_valid returns false.

function open_file( name ) { 
  var file = new File( name, "r", true, true ); 
  if( ! file.is_valid() ) { 
    message( "cannot open file", file.get_name() ); 
  // .... 

Null trunc()
Erase the data of the file.

Bool eof()
Returns true if the end of the file has been reached. It will return true until clear() has benn called.

Null flush()
Flushes the buffer and writes all data to the file.

Integer tellg()
Returns the Position of the read pointer of the file.

Integer tellp()
Returns the Position of the write pointer of the file.

Null seekg( Integer pos )
Moves the read pointer to the position in the file.

Null seekp( Integer pos )
Moves the write pointer to the position in the file.

Integer get()
Returns the next character of the file.

put( Integer c )
Writes the character to the file.

String read( Integer n )
Reads n characters from the file.

Null write( String s )
Writes the string s to the file.

Null write( String s, Integer n )
Writes n characters of the string s to the file.

String getline()
Reads a line from the file.

Null append( File other_file )
Appends the given file to the current file.

Null reference( File other_file )
The function copies the other file pointer data to this class. In other words, it copies the other_file to this class. It's the same like opening the file of the other class once again.

var file1 = new File( "foo.txt", "rw" ); 
// fisrt method 
var file2 = new File( "foo.txt", "rw" ); 
// second method 
var file2 = new File(); 
file2.reference( file1 ); 

Again: this won't copy the real file, only the pointer on the file.
After using this function you'll have to check if the file is valid by using is_valid().

Ein Beispiel für die benutztung der Line Klasse findest du hier: Example

This page was created by King Leo . Page generator was Leo<HTML> version 0.99.0 .