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.


Detailed Description

Definition at line 227 of file pf.h.


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

Constructor & Destructor Documentation

pf_File::pf_File (  ) 

Definition at line 376 of file pf.cpp.

00377     : pf_Component(0),
00378       m_buffer(NULL),
00379       m_bufSize(0) {
00380     //Empty
00381 }

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

Definition at line 383 of file pf.cpp.

00387     : pf_Component(0),
00388       m_header    ( a_header ),
00389       m_common    ( a_common ),
00390       m_sections  ( a_sections ),
00391       parsed      ( true ) {
00392     // Empty
00393 }

pf_File::~pf_File (  )  [virtual]

Definition at line 395 of file pf.cpp.

00395                   {
00396     // Empty
00397 }


Member Function Documentation

void pf_File::Parse ( const cmn_Path a_filePath  ) 

Definition at line 403 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(), and mif_CfgRep::ParseToFile().

00403                                              {
00404     log_FUNC_A_m(Parse,
00405         "a_filePath: " << a_filePath
00406     );
00407 
00408     cmn_MutexLock l(g_parse_x);
00409 
00410     // ReadFile allocates new buffer.
00411     // Indicate that it must be deleted in Cleanup()
00412     m_deleteBuffer = true;
00413     ReadFile(a_filePath);
00414     UseBuffer(m_buffer, m_bufSize);
00415     DoParse();
00416 }

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 418 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().

00418                                               {
00419     log_FUNC_m(WriteFile);
00420 
00421     cmn_File cfgFile(a_fname);
00422     ostringstream cfgStr;
00423     cfgStr << *this;
00424     cfgFile.OpenF(fom_WRITE | fom_CREATE_NEW);
00425     cfgFile.WriteF(cfgStr.str().c_str(), cfgStr.str().size());
00426     cfgFile.CloseF();
00427 }

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 429 of file pf.cpp.

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

00429                                                                 {
00430     log_FUNC_m(Parse);
00431 
00432     cmn_MutexLock l(g_parse_x);
00433 
00434     m_deleteBuffer = false;
00435     m_buffer = a_buffer;
00436     m_bufSize = a_bufSize;
00437     UseBuffer(m_buffer, m_bufSize);
00438     DoParse();
00439 }

Here is the call graph for this function:

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

Definition at line 399 of file pf.cpp.

References m_garbageCollector.

Referenced by yyparse().

00399                                            {
00400     return this->m_garbageCollector;
00401 }

Here is the caller graph for this function:

void pf_File::Cleanup (  ) 

Definition at line 509 of file pf.cpp.

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

Referenced by DoParse().

00509                       {
00510     unsigned int i;
00511     for (i = 0; i < m_garbageCollector.size(); i++) {
00512         delete m_garbageCollector[i];
00513     }
00514     m_garbageCollector.clear();
00515 
00516     lexCleanup();
00517     yy_delete_buffer(m_yaccBuf);
00518 
00519     if (m_deleteBuffer) {
00520         delete [] m_buffer; m_buffer = NULL;
00521     }
00522 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 501 of file pf.cpp.

References parse_errln, parse_errtoken, parsed, and pError.

Referenced by yyerror().

00501                                                   {
00502     parsed = false;
00503     pError = true;
00504     parse_errln = a_line;
00505     //string parse_errmsg;
00506     parse_errtoken = a_text;
00507 }

Here is the caller graph for this function:

string pf_File::GetFileType ( void   )  const

Definition at line 524 of file pf.cpp.

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

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

00524                                   {
00525     return m_fileHeader.simple.val;
00526 }

Here is the caller graph for this function:

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

Definition at line 478 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().

00478                                               {
00479     log_FUNC_A_m(ReadFile, "a_fname: " << a_fname);
00480 
00481     cmn_File fileToParse(a_fname);
00482     fileToParse.OpenF(fom_READ | fom_OPEN_EXISTING);
00483 
00484     ivd_FileInfo_t fileInfo;
00485     fileToParse.StatF(fileInfo);
00486 
00487     log_DBG_m(dbg_LOW, "File size: " << fileInfo.size);
00488 
00489     m_bufSize = static_cast<size_t>(fileInfo.size) + 2;
00490     m_buffer = new char[m_bufSize];
00491 
00492     fileToParse.ReadF(m_buffer, m_bufSize);
00493 
00494     // flex requires last 2 characters to be 0
00495     m_buffer[m_bufSize-2] = 0;
00496     m_buffer[m_bufSize-1] = 0;
00497 
00498     fileToParse.CloseF();
00499 }

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 441 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().

00441                                                               {
00442     log_FUNC_m(UseBuffer);
00443 
00444     m_yaccBuf = yy_scan_buffer(m_buffer, m_bufSize);
00445     if (m_yaccBuf == NULL) {
00446         throw ivd_Error(
00447             ie_PARSER_ERROR,
00448             "NULL from yy_scan_buffer(). Most probably missing two terminating zeroes.",
00449             true);
00450     }
00451 }

Here is the call graph for this function:

Here is the caller graph for this function:

void pf_File::DoParse (  )  [private]

Definition at line 453 of file pf.cpp.

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

Referenced by Parse().

00453                       {
00454     log_FUNC_m(DoParse);
00455 
00456     g_file_p = this;
00457     int result = yyparse();
00458 
00459     Cleanup();
00460 
00461     if ( result == 0) {
00462         parsed = true;
00463         log_DBG_m(dbg_DETAIL, "Parsed OK");
00464     }
00465     else {
00466         parsed = false;
00467         ostringstream sstr;
00468         sstr
00469             << "Syntax error in line " << parse_errln
00470             << " at token \"" << parse_errtoken << "\".";
00471         throw ivd_Error(
00472             ie_PARSER_ERROR, sstr.str(),
00473             true
00474             );
00475     };
00476 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 254 of file pf.h.

Definition at line 255 of file pf.h.

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

Definition at line 261 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 262 of file pf.h.

Referenced by MarkError().

Definition at line 263 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 264 of file pf.h.

Definition at line 265 of file pf.h.

Referenced by DoParse(), and MarkError().

Definition at line 273 of file pf.h.

Referenced by Cleanup(), and GetGCVec().

bool pf_File::m_deleteBuffer [private]

Definition at line 275 of file pf.h.

Referenced by Cleanup(), and Parse().

char* pf_File::m_buffer [private]

Definition at line 276 of file pf.h.

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

size_t pf_File::m_bufSize [private]

Definition at line 277 of file pf.h.

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

Definition at line 278 of file pf.h.

Referenced by Cleanup(), and UseBuffer().

Reimplemented from pf_Component.

Definition at line 280 of file pf.h.


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

Generated on Mon Feb 27 19:43:47 2012 for OPENARCHIVE by  doxygen 1.5.6