Public Member Functions | Public Attributes | Private Member Functions | Private Attributes

pf_File Class Reference
[Parser for config files; validation]

#include <pf.h>

Inheritance diagram for pf_File:
Inheritance graph
[legend]
Collaboration diagram for pf_File:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 pf_File ()
 pf_File (const pf_ValueList &a_header, const pf_Section &a_common, const pf_SectionList &a_sections)
virtual ~pf_File ()
void Parse (const cmn_Path &a_filePath)
void WriteFile (const cmn_Path &a_fname)
void Parse (char *a_buffer, const unsigned int a_bufSize)
 Parses from a memory buffer.
vector< pf_Component * > & GetGCVec ()
void Cleanup ()
void MarkError (long a_line, string a_text)
string GetFileType () const

Public Attributes

pf_Value m_fileCookie
pf_Value m_fileHeader
pf_ValueList m_header
pf_Section m_common
pf_SectionList m_sections
bool parsed
bool pError
int parse_errln
string parse_errmsg
string parse_errtoken

Private Member Functions

void ReadFile (const cmn_Path &a_fname)
void UseBuffer (char *a_buffer, const size_t a_bufSize)
void DoParse ()

Private Attributes

vector< pf_Component * > m_garbageCollector
bool m_deleteBuffer
char * m_buffer
size_t m_bufSize
YY_BUFFER_STATE m_yaccBuf
 log_CLASSID_m

Detailed Description

Definition at line 241 of file pf.h.


Constructor & Destructor Documentation

pf_File::pf_File (  ) 

Definition at line 390 of file pf.cpp.

    : pf_Component(0),
      m_buffer(NULL),
      m_bufSize(0) {
    //Empty
}

pf_File::pf_File ( const pf_ValueList a_header,
const pf_Section a_common,
const pf_SectionList a_sections 
)

Definition at line 397 of file pf.cpp.

    : pf_Component(0),
      m_header    ( a_header ),
      m_common    ( a_common ),
      m_sections  ( a_sections ),
      parsed      ( true ) {
    // Empty
}

pf_File::~pf_File (  )  [virtual]

Definition at line 409 of file pf.cpp.

                  {
    // Empty
}


Member Function Documentation

void pf_File::Cleanup (  ) 

Definition at line 523 of file pf.cpp.

References lexCleanup(), m_buffer, m_deleteBuffer, m_garbageCollector, m_yaccBuf, and yy_delete_buffer().

Referenced by DoParse().

                      {
    unsigned int i;
    for (i = 0; i < m_garbageCollector.size(); i++) {
        delete m_garbageCollector[i];
    }
    m_garbageCollector.clear();

    lexCleanup();
    yy_delete_buffer(m_yaccBuf);

    if (m_deleteBuffer) {
        delete [] m_buffer; m_buffer = NULL;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pf_File::DoParse (  )  [private]

Definition at line 467 of file pf.cpp.

References Cleanup(), dbg_DETAIL, ie_PARSER_ERROR, ivd_Error, log_DBG_m, log_FUNC_m, parse_errln, parse_errtoken, parsed, and yyparse().

Referenced by Parse().

                      {
    log_FUNC_m(DoParse);

    g_file_p = this;
    int result = yyparse();

    Cleanup();

    if ( result == 0) {
        parsed = true;
        log_DBG_m(dbg_DETAIL, "Parsed OK");
    }
    else {
        parsed = false;
        ostringstream sstr;
        sstr
            << "Syntax error in line " << parse_errln
            << " at token \"" << parse_errtoken << "\".";
        throw ivd_Error(
            ie_PARSER_ERROR, sstr.str(),
            true
            );
    };
}

Here is the call graph for this function:

Here is the caller graph for this function:

string pf_File::GetFileType ( void   )  const

Definition at line 538 of file pf.cpp.

References m_fileHeader, pf_Value::simple, and pf_Elem::val.

Referenced by cfg_Base::ConvertFileHeader(), and mif_CfgRep::ParseToFile().

                                  {
    return m_fileHeader.simple.val;
}

Here is the caller graph for this function:

vector< pf_Component * > & pf_File::GetGCVec (  ) 

Definition at line 413 of file pf.cpp.

References m_garbageCollector.

Referenced by yyparse().

                                           {
    return this->m_garbageCollector;
}

Here is the caller graph for this function:

void pf_File::MarkError ( long  a_line,
string  a_text 
)

Definition at line 515 of file pf.cpp.

References parse_errln, parse_errtoken, parsed, and pError.

Referenced by yyerror().

                                                  {
    parsed = false;
    pError = true;
    parse_errln = a_line;
    //string parse_errmsg;
    parse_errtoken = a_text;
}

Here is the caller graph for this function:

void pf_File::Parse ( const cmn_Path a_filePath  ) 

Definition at line 417 of file pf.cpp.

References DoParse(), log_FUNC_A_m, m_buffer, m_bufSize, m_deleteBuffer, ReadFile(), and UseBuffer().

Referenced by i_BackEndAgent_i::i_BackEndAgent_i(), i_ResourceManager_i::i_ResourceManager_i(), la_SCSILibrary::Open(), Parse(), i_PartitionManager_i::ParseConfig(), ParseDrive(), i_ResourceManager_i::ParsePMConfig(), ParseSystem(), mif_CfgRep::ParseToFile(), cfg_CollocationInfo::ReadCollocationInfo(), and cfg_HL7Info::ReadHL7Info().

                                             {
    log_FUNC_A_m(Parse,
        "a_filePath: " << a_filePath
    );

    cmn_MutexLock l(g_parse_x);

    // ReadFile allocates new buffer.
    // Indicate that it must be deleted in Cleanup()
    m_deleteBuffer = true;
    ReadFile(a_filePath);
    UseBuffer(m_buffer, m_bufSize);
    DoParse();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pf_File::Parse ( char *  a_buffer,
const unsigned int  a_bufSize 
)

Parses from a memory buffer.

Warning:
Buffer must include two bytes at the end. a_bufSize must include those bytes.

Definition at line 443 of file pf.cpp.

References DoParse(), log_FUNC_m, m_buffer, m_bufSize, m_deleteBuffer, Parse(), and UseBuffer().

Here is the call graph for this function:

void pf_File::ReadFile ( const cmn_Path a_fname  )  [private]

Definition at line 492 of file pf.cpp.

References cmn_File::CloseF(), dbg_LOW, fom_OPEN_EXISTING, fom_READ, log_DBG_m, log_FUNC_A_m, m_buffer, m_bufSize, cmn_File::OpenF(), cmn_File::ReadF(), and cmn_File::StatF().

Referenced by Parse().

                                              {
    log_FUNC_A_m(ReadFile, "a_fname: " << a_fname);

    cmn_File fileToParse(a_fname);
    fileToParse.OpenF(fom_READ | fom_OPEN_EXISTING);

    ivd_FileInfo_t fileInfo;
    fileToParse.StatF(fileInfo);

    log_DBG_m(dbg_LOW, "File size: " << fileInfo.size);

    m_bufSize = static_cast<size_t>(fileInfo.size) + 2;
    m_buffer = new char[m_bufSize];

    fileToParse.ReadF(m_buffer, m_bufSize);

    // flex requires last 2 characters to be 0
    m_buffer[m_bufSize-2] = 0;
    m_buffer[m_bufSize-1] = 0;

    fileToParse.CloseF();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pf_File::UseBuffer ( char *  a_buffer,
const size_t  a_bufSize 
) [private]

Definition at line 455 of file pf.cpp.

References ie_PARSER_ERROR, ivd_Error, log_FUNC_m, m_buffer, m_bufSize, m_yaccBuf, NULL, and yy_scan_buffer().

Referenced by Parse().

                                                              {
    log_FUNC_m(UseBuffer);

    m_yaccBuf = yy_scan_buffer(m_buffer, m_bufSize);
    if (m_yaccBuf == NULL) {
        throw ivd_Error(
            ie_PARSER_ERROR,
            "NULL from yy_scan_buffer(). Most probably missing two terminating zeroes.",
            true);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pf_File::WriteFile ( const cmn_Path a_fname  ) 

Definition at line 432 of file pf.cpp.

References cmn_File::CloseF(), fom_CREATE_NEW, fom_WRITE, log_FUNC_m, cmn_File::OpenF(), and cmn_File::WriteF().

Referenced by mif_CfgRep::Upload().

                                              {
    log_FUNC_m(WriteFile);

    cmn_File cfgFile(a_fname);
    ostringstream cfgStr;
    cfgStr << *this;
    cfgFile.OpenF(fom_WRITE | fom_CREATE_NEW);
    cfgFile.WriteF(cfgStr.str().c_str(), cfgStr.str().size());
    cfgFile.CloseF();
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from pf_Component.

Definition at line 294 of file pf.h.

char* pf_File::m_buffer [private]

Definition at line 290 of file pf.h.

Referenced by Cleanup(), Parse(), ReadFile(), and UseBuffer().

size_t pf_File::m_bufSize [private]

Definition at line 291 of file pf.h.

Referenced by Parse(), ReadFile(), and UseBuffer().

bool pf_File::m_deleteBuffer [private]

Definition at line 289 of file pf.h.

Referenced by Cleanup(), and Parse().

Definition at line 268 of file pf.h.

Definition at line 269 of file pf.h.

Referenced by GeneratePFStructure(), GetFileType(), operator<<(), and yyparse().

Definition at line 287 of file pf.h.

Referenced by Cleanup(), and GetGCVec().

Definition at line 292 of file pf.h.

Referenced by Cleanup(), and UseBuffer().

Definition at line 277 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 278 of file pf.h.

Definition at line 279 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 275 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 276 of file pf.h.

Referenced by MarkError().


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