problem with overwriting Class

Charma Motoko_Kusanagi at web.de
Mon May 28 02:06:26 PDT 2007


Hello,
I have a problem with overwriting a class. I want to make a class from BufferedFile in which i can use all it's functions but i want the starting position to be shifted to a given position (Vfpos) and to go to a given maximum (Vfsize). For example i got a 100kb-file and i want it to start from position 10kb and load maximum of 20kb, i want it to act as if there is a 20kb-file only and it should go from 10-30 with positions 0-20. I started overwriting the read-functions and adding stuff so that it doesn't read more than the wanted area and so on. My problem is with the position(ulong offset) function. For some reason I can't correctly overwrite it...
I got this code...

class Vfile : BufferedFile
{
	uint Vfpos; // in my case this is 41
	uint Vfsize; // and this is 17
	
	ulong position() // this one works perfectly!
	{
		return ( super.seek(0, SeekPos.Current) - Vfpos );
	}
	
	void position(ulong newpos)
	{
		if( newpos > Vfsize )
		{
			...
		}
		else
		{
			std.stdio.writefln("New pos:", Vfpos+newpos );
			// now this doesn'T work
			std.stdio.writefln("super-seek: ", super.seek( Vfpos+newpos, SeekPos.Set ) );
			// this one doesn't work either
			// super.position(Vfpos + newpos);
			std.stdio.writefln("My new pos: ", super.position() );
		}
...
}

Vfile bla = new Vfile(..);
writefln( bla.position() );
bla.postition(9)
writefln( bla.position() );

this would give something like:
41 <-- my starting position
New pos: 50
super-seek: 50
My new pos: 41
41

the function super.seek(...) DOES return the correct new position but i can't understand why the position is allways changed back to the first...
Please help!!



More information about the Digitalmars-d mailing list