PLearn 0.1
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes
PLearn::BufferedIntVecFile Class Reference

#include <BufferedIntVecFile.h>

Inheritance diagram for PLearn::BufferedIntVecFile:
Inheritance graph
[legend]
Collaboration diagram for PLearn::BufferedIntVecFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BufferedIntVecFile (int buflen_=DEFAULT_BUFLEN)
 Default constructor, you must then call open.
 BufferedIntVecFile (const string &the_filename, bool readwrite=false, int buflen_=DEFAULT_BUFLEN)
virtual void open (const string &the_filename, bool readwrite=false)
 The copy constructor opens the file a second time in readonly mode only.
virtual void close ()
virtual int get (int i) const
virtual void put (int i, int value)
virtual int operator[] (int i) const
virtual void append (int value)
virtual ~BufferedIntVecFile ()

Protected Types

typedef IntVecFile inherited

Protected Member Functions

virtual void getBuf (int bufstart_)
virtual void flush ()

Protected Attributes

int bufstart
const int buflen
intbuf
bool bufmod

Static Protected Attributes

static const int DEFAULT_BUFLEN = 65536

Detailed Description

Definition at line 45 of file BufferedIntVecFile.h.


Member Typedef Documentation

Definition at line 51 of file BufferedIntVecFile.h.


Constructor & Destructor Documentation

PLearn::BufferedIntVecFile::BufferedIntVecFile ( int  buflen_ = DEFAULT_BUFLEN) [inline]

Default constructor, you must then call open.

Definition at line 60 of file BufferedIntVecFile.h.

      : IntVecFile(), bufstart(-1), buflen(buflen_), bufmod(false)
      { buf= new int[buflen]; }
PLearn::BufferedIntVecFile::BufferedIntVecFile ( const string &  the_filename,
bool  readwrite = false,
int  buflen_ = DEFAULT_BUFLEN 
) [inline]

Definition at line 63 of file BufferedIntVecFile.h.

      : IntVecFile(the_filename, readwrite), bufstart(-1), buflen(buflen_), bufmod(false)
      { buf= new int[buflen]; }
PLearn::BufferedIntVecFile::~BufferedIntVecFile ( ) [virtual]

Definition at line 84 of file BufferedIntVecFile.cc.

{
    close();
    if(buf) delete[] buf;
}

Member Function Documentation

virtual void PLearn::BufferedIntVecFile::append ( int  value) [inline, virtual]

Reimplemented from PLearn::IntVecFile.

Definition at line 77 of file BufferedIntVecFile.h.

{ put(length(),value); }
void PLearn::BufferedIntVecFile::close ( ) [virtual]

Reimplemented from PLearn::IntVecFile.

Definition at line 60 of file BufferedIntVecFile.cc.

References PLearn::flush().

Here is the call graph for this function:

void PLearn::BufferedIntVecFile::flush ( ) [protected, virtual]

Definition at line 98 of file BufferedIntVecFile.cc.

References PLearn::byte_order(), PLearn::TVec< T >::copyFrom(), PLearn::TVec< T >::data(), PLearn::endianswap(), PLearn::TVec< T >::length(), and PLearn::min().

{
/*
    if(bufmod)
        for(int i= 0; i < buflen && i+bufstart < length(); ++i)
            inherited::put(i+bufstart, buf[i]);
*/

    if(bufmod)
    {
        int len= min(buflen, length()-bufstart);
        seek_to_index(bufstart);
        if (byte_order() != endianness_) 
        {
            TVec<int> new_vec(len);
            new_vec.copyFrom(buf, len);
            endianswap(new_vec.data(), new_vec.length());
            fwrite(new_vec.data(), sizeof(int), new_vec.length(), f);
        }
        else 
        {
            fwrite(buf, sizeof(int), len, f);
        }
    }

    bufmod= false;
}

Here is the call graph for this function:

int PLearn::BufferedIntVecFile::get ( int  i) const [virtual]

Reimplemented from PLearn::IntVecFile.

Definition at line 66 of file BufferedIntVecFile.cc.

{
    if(bufstart < 0 || bufstart > i || i >= bufstart+buflen)
        const_cast<BufferedIntVecFile*>(this)->getBuf(i);
    return buf[i-bufstart];
}
void PLearn::BufferedIntVecFile::getBuf ( int  bufstart_) [protected, virtual]

Definition at line 90 of file BufferedIntVecFile.cc.

References PLearn::flush(), and i.

{
    flush();
    bufstart= bufstart_;
    for(int i= 0; i < buflen && i+bufstart < length(); ++i)
        buf[i]= inherited::get(i+bufstart);
}

Here is the call graph for this function:

void PLearn::BufferedIntVecFile::open ( const string &  the_filename,
bool  readwrite = false 
) [virtual]

The copy constructor opens the file a second time in readonly mode only.

Reimplemented from PLearn::IntVecFile.

Definition at line 52 of file BufferedIntVecFile.cc.

References PLearn::flush().

{
    flush();
    inherited::open(the_filename, readwrite);
    bufstart= -1;
    bufmod= false;
}

Here is the call graph for this function:

virtual int PLearn::BufferedIntVecFile::operator[] ( int  i) const [inline, virtual]

Reimplemented from PLearn::IntVecFile.

Definition at line 76 of file BufferedIntVecFile.h.

References i.

{ return get(i); }
void PLearn::BufferedIntVecFile::put ( int  i,
int  value 
) [virtual]

Reimplemented from PLearn::IntVecFile.

Definition at line 73 of file BufferedIntVecFile.cc.

{
    if(bufstart < 0 || bufstart > i || i >= bufstart+buflen)
        getBuf(i);
    bufmod= true;
    buf[i-bufstart]= value;
    if(i>=length_)
        length_ = i+1;
}

Member Data Documentation

int* PLearn::BufferedIntVecFile::buf [mutable, protected]

Definition at line 55 of file BufferedIntVecFile.h.

Definition at line 54 of file BufferedIntVecFile.h.

Definition at line 56 of file BufferedIntVecFile.h.

Definition at line 53 of file BufferedIntVecFile.h.

const int PLearn::BufferedIntVecFile::DEFAULT_BUFLEN = 65536 [static, protected]

Definition at line 49 of file BufferedIntVecFile.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines