Public Member Functions | Public Attributes | Private Attributes

cmn_FastFileSearch Class Reference
[Classes for large file i/o, relative file, and DataBase]

<Description:> A more elaborate class description that describes all aspects of class usage etc. More...

#include <cmn_FastFileSearch.h>

Collaboration diagram for cmn_FastFileSearch:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 cmn_FastFileSearch (cmn_FastSearch *a_fastSearch_p, cmn_File *a_file_p, ivd_FileBufSize_t a_buffSize=4096)
virtual ~cmn_FastFileSearch ()
ivd_FilePosition_t Find (ivd_FilePosition_t a_start)
void SetFile (cmn_File *a_file_p)

Public Attributes

 log_CLASSID_m
 Description of a class member.

Private Attributes

cmn_FastSearchm_fastSearch_p
 pointer to fast search instance
cmn_Filem_file_p
 file that need to be searched
ivd_FileBufSize_t m_buffSize
 size of buffer where search is perform
char * m_buffer_p

Detailed Description

<Description:> A more elaborate class description that describes all aspects of class usage etc.

Author:
Dejan Volk Lupo, HERMES SoftLab
See also:
<reference>

Definition at line 46 of file cmn_FastFileSearch.h.


Constructor & Destructor Documentation

cmn_FastFileSearch::cmn_FastFileSearch ( cmn_FastSearch a_fastSearch_p,
cmn_File a_file_p,
ivd_FileBufSize_t  a_buffSize = 4096 
)

Definition at line 53 of file cmn_FastFileSearch.cpp.

References cmn_Num2Str(), ivd_NULLCHK_m, m_buffer_p, m_buffSize, and cmn_FastSearch::SetBuffer().

                    :
                    m_fastSearch_p(a_fastSearch_p),
                    m_file_p(a_file_p),
                    m_buffSize(a_buffSize)
{
    m_buffer_p = new char[m_buffSize];
    ivd_NULLCHK_m(m_buffer_p, "void[" + cmn_Num2Str(m_buffSize) + "]");

    a_fastSearch_p->SetBuffer(m_buffer_p, m_buffSize);
}

Here is the call graph for this function:

cmn_FastFileSearch::~cmn_FastFileSearch (  )  [virtual]

Definition at line 70 of file cmn_FastFileSearch.cpp.

References m_buffer_p.

                                        {
    //TODO who will delete m_fastSearch_p
    // DO not delete m_file_p 
    delete [] m_buffer_p;
}


Member Function Documentation

ivd_FilePosition_t cmn_FastFileSearch::Find ( ivd_FilePosition_t  a_start  ) 

Definition at line 79 of file cmn_FastFileSearch.cpp.

References cmn_FastSearch::Find(), m_buffer_p, m_buffSize, m_fastSearch_p, m_file_p, cmn_File::ReadF(), cmn_File::SeekF(), and cmn_FastSearch::SetBuffer().

Referenced by fio_StartTransaction_t::FindStart().

                                                {

    ivd_FilePosition_t p = a_start;

    m_file_p->SeekF(a_start);

    int   left = 0;
    char *d    = m_buffer_p;

    ivd_FileBufSize_t byteToRead = m_buffSize;
    ivd_FileBufSize_t read       = m_file_p->ReadF(d, byteToRead);


    while (read == byteToRead) {
        left = m_fastSearch_p->Find();
        if (left >= 0) {
            return p + left; // the pattern is found
        }
        left *= -1; // make it positive
        byteToRead = m_buffSize - left;
        memcpy(d, d + byteToRead, left);  // copy from the end of the buffer what was not checked
        p += byteToRead; // first byte in buffer represent this file offset
        read = m_file_p->ReadF(d + left, byteToRead); // read next amount of data
    }
    // check rest data, buffer is shorter now
    m_fastSearch_p->SetBuffer(m_buffer_p, read + left); 
    left = m_fastSearch_p->Find();
    if (left >= 0) {
        return p + left; // the pattern is found
    }
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmn_FastFileSearch::SetFile ( cmn_File a_file_p  )  [inline]

Definition at line 82 of file cmn_FastFileSearch.h.

{ m_file_p = a_file_p; };


Member Data Documentation

Description of a class member.

See also:
<reference>
<reference> Macro to add class name member s_className.

Definition at line 77 of file cmn_FastFileSearch.h.

Definition at line 65 of file cmn_FastFileSearch.h.

Referenced by cmn_FastFileSearch(), Find(), and ~cmn_FastFileSearch().

size of buffer where search is perform

Definition at line 63 of file cmn_FastFileSearch.h.

Referenced by cmn_FastFileSearch(), and Find().

pointer to fast search instance

Definition at line 57 of file cmn_FastFileSearch.h.

Referenced by Find().

file that need to be searched

Definition at line 60 of file cmn_FastFileSearch.h.

Referenced by Find().


The documentation for this class was generated from the following files: