Public Member Functions | Public Attributes | Private Attributes

cfg_Base Class Reference
[Parser for config files; validation]

#include <cfg.h>

Inheritance diagram for cfg_Base:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 cfg_Base ()
virtual ~cfg_Base ()
void Convert (const pf_ValueList &a_parsedList, val_RuleVec &a_rules)
val_ValueFindRule (const string &a_varName, val_RuleVec &a_rules) const
bool WasParsed (const void *a_item, val_RuleVec &a_rules)
void CheckMandatory (val_RuleVec &a_rules)
virtual void ConvertGroup (const string &a_grpName, const pf_Group &a_group)
void ConvertFileHeader (const pf_File &a_parsedFile)

Public Attributes

string m_fileType
UInt32_t m_fileVersion
ivd_Time32_t m_fileDate
string m_fileUser

Private Attributes

 log_CLASSID_m

Detailed Description

Definition at line 39 of file cfg.h.


Constructor & Destructor Documentation

cfg_Base::cfg_Base (  ) 

Definition at line 46 of file cfg.cpp.

  : m_fileVersion(0),
    m_fileDate(0) {

    // Empty
}

virtual cfg_Base::~cfg_Base (  )  [inline, virtual]

Definition at line 45 of file cfg.h.

{};


Member Function Documentation

void cfg_Base::CheckMandatory ( val_RuleVec a_rules  ) 

Definition at line 135 of file cfg.cpp.

References dbg_NORM, ie_MISSING_VAR, ie_TOO_MANY_VAR, ivd_Error, log_DBG_INT_m, log_FUNC_m, val_RuleVec::rules, and val_RuleVec::size().

Referenced by cfg_Library::cfg_Library(), cfg_PMClient::cfg_PMClient(), cfg_PMFileExpiration::cfg_PMFileExpiration(), cfg_PMTree::cfg_PMTree(), cfg_RMHost::cfg_RMHost(), cfg_DirHL7Info::Init(), cfg_DirCollocationInfo::Init(), cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), and cfg_PMCfg::Refresh().

                                                 {
    log_FUNC_m(CheckMandatory);

    /*
    For each unparsed element default value is applied
    or if option is mandatory exception is thrown
    */

    for (UInt32_t i = 0 ; i < a_rules.size() ; i++){
        if (a_rules.rules[i]->m_numParsed == 0) {
            // options was not parsed
            if (a_rules.rules[i]->m_minNumOfVal == 1) {
                // This option is mandatory! Parsing will fail
                throw ivd_Error(ie_MISSING_VAR, a_rules.rules[i]->GetName());
            }
            else {
                //apply default values for simple value (list?, group?)
                if (a_rules.rules[i]->m_useDefault) {
                    log_DBG_INT_m(dbg_NORM,
                        "Option " << a_rules.rules[i]->GetName() <<
                        " was not parsed. Will use default value");
                    a_rules.rules[i]->Conv(a_rules.rules[i]->m_default);
                }
            }
        }
        else if (a_rules.rules[i]->m_numParsed > a_rules.rules[i]->m_maxNumOfVal) {
            // too many valuse parsed
            throw ivd_Error(ie_TOO_MANY_VAR,a_rules.rules[i]->GetName());
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cfg_Base::Convert ( const pf_ValueList a_parsedList,
val_RuleVec a_rules 
)

Definition at line 53 of file cfg.cpp.

References val_Value::Add(), val_Value::AddRange(), pf_List::At(), pf_ValueList::At(), val_Value::Conv(), ConvertGroup(), dbg_DETAIL, dbg_LOW, FindRule(), ivd_BaseException::GetContext(), ivd_BaseException::GetError(), val_Value::GetName(), pf_Value::group, pf_Group::grpType, ie_DATA_CORRUPTION, ie_NYI, pf_Elem::isRange, ivd_Error, pf_Component::lineNum, pf_Value::list, log_DBG_INT_m, log_DBG_m, log_FUNC_m, val_Value::m_numParsed, pf_ValueBase::name, PF_COMMENT, PF_GROUP, PF_INCLFILE, PF_LIST, PF_RANGE, PF_SIMPLE, pf_Value::simple, pf_List::size(), pf_ValueList::size(), pf_Elem::toVal, pf_Value::type, and pf_Elem::val.

Referenced by cfg_DriveType::cfg_DriveType(), cfg_DriveVendor::cfg_DriveVendor(), cfg_Library::cfg_Library(), cfg_PMClient::cfg_PMClient(), cfg_PMFileExpiration::cfg_PMFileExpiration(), cfg_PMTree::cfg_PMTree(), cfg_RMHost::cfg_RMHost(), ConvertFileHeader(), cfg_DirHL7Info::Init(), cfg_DirCollocationInfo::Init(), cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), cfg_PMCfg::Refresh(), cfg_LibraryFile::Refresh(), cfg_HL7Info::Refresh(), cfg_DriveSettings::Refresh(), cfg_CollocationInfo::Refresh(), and cfg_CliBase::Refresh().

                                                                             {
    log_FUNC_m(Convert);


    for (unsigned int i = 0; i < a_parsedList.size(); i++) {
        const pf_Value  &varValue = a_parsedList.At(i);
        string          varName = varValue.name;
        log_DBG_m(dbg_DETAIL,"variable " << varName);

        if (varValue.type == PF_COMMENT) {
            //log_DBG_m(dbg_DETAIL, "Skipping comment.");
            continue;
        }
        try {
            if (varValue.type == PF_GROUP) {
                log_DBG_INT_m(dbg_DETAIL,
                    "Converting Group: " << varValue.group->grpType );

                // varValue.name is GroupName
                // *(varValue.group).grpType is GroupType
                ConvertGroup(varValue.name, *(varValue.group) );
            }
            else {
                val_Value *valRule = FindRule(varName, a_rules);
                valRule->m_numParsed++;

                log_DBG_m(dbg_DETAIL, "Parsing : " <<  valRule->GetName()
                                     << " varValue.type: " << varValue.type
                                     << " varValue.simple.val> " << varValue.simple.val);

                switch (varValue.type) {
                    case PF_SIMPLE:
                        valRule->Conv(varValue.simple.val);
                        break;
                    case PF_RANGE:
                        valRule->Conv(
                            varValue.simple.val,
                            varValue.simple.toVal);
                        break;
                    case PF_LIST:
                        {
                            for (UInt32_t j=0; j < varValue.list.size(); j++) {
                                if (varValue.list.At(j).isRange) {
                                    valRule->AddRange(
                                        varValue.list.At(j).val,
                                        varValue.list.At(j).toVal
                                    );
                                }
                                else {
                                    valRule->Add(varValue.list.At(j).val);
                                }
                            };
                        }
                        break;
                    case PF_INCLFILE:
                        throw ivd_Error(ie_NYI);
                    /*
                        Comment has already been taken care of above.
                    case PF_COMMENT:
                        break;
                    */
                    default:
                        log_FUNC_m(Convert);
                        throw ivd_Error(ie_DATA_CORRUPTION,
                                "Unexpected variable type", true);
                        break;
                }
            }
        }
        catch (ivd_Error e) {
            log_FUNC_m(Convert);
            log_DBG_m(dbg_LOW,"Error at line number " << varValue.lineNum);
            ostringstream newErrorText;
            newErrorText
                << e.GetContext()
                << " at line number:" << varValue.lineNum;

            throw ivd_Error(e.GetError(), newErrorText.str());
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cfg_Base::ConvertFileHeader ( const pf_File a_parsedFile  ) 

Definition at line 189 of file cfg.cpp.

References val_RuleVec::Add(), cfg_MAX_FILE_DATE, cfg_MAX_FILE_USER, cfg_MAX_FILE_VERSION, cfg_MIN_FILE_DATE, cfg_MIN_FILE_USER, cfg_MIN_FILE_VERSION, Convert(), dbg_NORM, pf_File::GetFileType(), log_DBG_m, log_FUNC_m, m_fileDate, m_fileType, m_fileUser, m_fileVersion, and pf_File::m_header.

Referenced by cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), cfg_PMCfg::Refresh(), cfg_LibraryFile::Refresh(), cfg_HL7Info::Refresh(), cfg_DriveSettings::Refresh(), and cfg_CollocationInfo::Refresh().

                                                            {
    static const string c_fileVersion   ("Version");
    static const string c_fileDate      ("Date");
    static const string c_fileUser      ("User");

    log_FUNC_m(ConvertFileHeader);

    val_RuleVec  rules;

    rules.Add(new val_Integer(c_fileVersion,
        val_Limit(cfg_MIN_FILE_VERSION, cfg_MAX_FILE_VERSION)), this->m_fileVersion);

    // Lower limit is set to 0 to allow having empty string as entry for the
    // modification time in the header (converted to Epoch).
    rules.Add(new val_Date(c_fileDate,
        val_Limit(cfg_MIN_FILE_DATE, cfg_MAX_FILE_DATE)), this->m_fileDate);
    rules.Add(new val_StrictString(c_fileUser,
        val_Limit(cfg_MIN_FILE_USER, cfg_MAX_FILE_USER)), this->m_fileUser);

    Convert(a_parsedFile.m_header, rules);

    m_fileType = a_parsedFile.GetFileType();

    log_DBG_m(dbg_NORM,
        "File header -> type: " << m_fileType <<
        ", ver: " << m_fileVersion <<
        ", date: " << m_fileDate <<
        ", user: " << m_fileUser );
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void cfg_Base::ConvertGroup ( const string &  a_grpName,
const pf_Group a_group 
) [inline, virtual]

Reimplemented in cfg_CollocationInfo, cfg_DriveVendor, cfg_DriveSettings, cfg_HL7Info, cfg_LibraryFile, cfg_PMCfg, and cfg_RMDrive.

Definition at line 52 of file cfg.h.

References ie_NO_SUBGROUP, and ivd_Error.

Referenced by Convert().

Here is the caller graph for this function:

val_Value * cfg_Base::FindRule ( const string &  a_varName,
val_RuleVec a_rules 
) const

Definition at line 168 of file cfg.cpp.

References dbg_DETAIL, ie_UNKNOWN_VAR, ivd_Error, log_DBG_m, log_FUNC_m, val_RuleVec::rules, val_RuleVec::size(), and strcasecmp.

Referenced by Convert().

                                                                                 {

    for (UInt32_t i = 0; i < a_rules.size(); i++) {
        if( strcasecmp(
                a_rules.rules[i]->GetName().c_str(),
                a_varName.c_str()) == 0 ) {
            return a_rules.rules[i];
        }
    }

    {
        log_FUNC_m(FindRule);

        log_DBG_m(dbg_DETAIL,"did NOT found rule for variable: " << a_varName );
        // Variable not found
        throw ivd_Error(ie_UNKNOWN_VAR, "Name: " + a_varName, true);
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool cfg_Base::WasParsed ( const void *  a_item,
val_RuleVec a_rules 
)

Member Data Documentation

Definition at line 60 of file cfg.h.

Referenced by ConvertFileHeader().

Definition at line 61 of file cfg.h.

Referenced by ConvertFileHeader().

Definition at line 59 of file cfg.h.

Referenced by ConvertFileHeader().


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