0

Hi all...
can anyone explain how i can read from a config file and retrieve its value in a cpp file...
I am writing down the cfg file...

<APM>

[APM_SAYHELLO]
Formatter.Type = String
Formatter.Val  = AtlLogPlainTextFormatter
Filter.Type    = String
Filter.Val     = LEVEL_DDEBUG
ComponentLevelFilter.Type = String
ComponentLevelFilter.Val = true 
ComponentsEnabled.Type = NumList
ComponentsEnabled.Val = {1,2}
SizeLimit.Type = Number
SizeLimit.Val  = 10000
CentralLoggerCompo.Type = StringList
CentralLoggerCompo.Val = {CMP1, CMP3, CMP5} 


[APM_SAYHOWRU]
Formatter.Type = String
Formatter.Val  = AtlLogPlainTextFormatter
Filter.Type    = String
Filter.Val     = LEVEL_DDEBUG
ComponentLevelFilter.Type = String
ComponentLevelFilter.Val = true 
ComponentsEnabled.Type = NumList
ComponentsEnabled.Val = {1,2}
SizeLimit.Type = Number
SizeLimit.Val  = 10000
CentralLoggerCompo.Type = StringList
CentralLoggerCompo.Val = {CMP2, CMP4, CMP6} 


<XR>
[XR_ONE]
    EventId_0.Type        = Number
    EventId_0.Val         = 0
    EventName_0.Type      = String
    EventName_0.Val       = RTB0_RECP_RDY_LO
    EventChannel_0.Type   = String
    EventChannel_0.Val    = RT
    EventOwners_0.Type    = StringList 
    EventOwners_0.Val     = {XRVxActor1, XREngDbg}
    EventDataType_0.Type  = String
    EventDataType_0.Val   = null


[XR_TWO]
    EventId_1.Type        = Number
    EventId_1.Val         = 1
    EventName_1.Type      = String
    EventName_1.Val       = RTB0_RECP_RDY_HI
    EventChannel_1.Type   = String
    EventChannel_1.Val    = RT
    EventOwners_1.Type    = StringList
    EventOwners_1.Val     = {XRVxActor1, XREngDbg}
    EventDataType_1.Type  = String
    EventDataType_1.Val   = null

<MGR>
[MGR_SYS]
  BootTimeout.Type         = String
  BootTimeout.Val          = 200.0
  ResetTimeout.Type        = String
  ResetTimeout.Val         = 200.0
  ShutdownTimeout.Type     = String
  ShutdownTimeout.Val      = 300.0
  ShutdownCompleteTimeout.Type = String
  ShutdownCompleteTimeout.Val  = 300.0


 [MGR_SUBSYS]
  BootTimeout.Type         = String
  BootTimeout.Val          = 300.0
  ResetTimeout.Type        = String
  ResetTimeout.Val         = 300.0
  ShutdownTimeout.Type     = String
  ShutdownTimeout.Val      = 30.0
  ShutdownCompleteTimeout.Type = String
  ShutdownCompleteTimeout.Val  = 300.0

--------------------------------------------------------------------------------
and the cpp file, in which i need to read it is...

#include "ConfigInterface.h"

CI(string file, string comp)    //constructor
{
_file_name = file;
_comp_name = comp;
init();
}

void * CI::getval(string event, string event_data)
{ 
 setresult(event, event_data);
 return result ;
}

// processing to read the config file here.


void CI::init()
{
//need to work on.......

}

void CI::setresult(string event, string event_data)
{

// need to work on.......

}



/****************** Main ******************************/
//  from where i'll read the config file
int main()
{

CI MGRConfig("MyConfigData.cfg", "MGR"); // creating object of CI class and providing config file name and section name i wnat to read.
int *sysMgrTimeOut = (int*)MGRConfig.getval("MGR_SYS", "ResetTimeout"); // i have type casted the value bcoz getval will return void*, in fact that's why it is returning void*, so that we can convert it in any type.
cout<<*sysMgrTimeOut; // Now it should print 200.0 as per the confg file.

// same way it can get read any value from config file for any events fo any component. got it.. :)


return 0;
}



-------------------------------------------------------------------------------
and the header file is:

//ConfigInterface.h

//i can add any function/varibale/member in private section for my //processing. 


class CI
{

private:
// the config file i need to read.
string _file_name;  

// component i need to read from config file. e.g <XR>string _comp_name  

// requested events in getval. e.g [XR_ONE]
string _events;     
// requested events_data getval. e.g EventId_0
string _events_data;
 // function to set the requested value.
void setval(string event, string event_data);

void * result;
void init();        
// in this function i need to do all processing to read the config 
//file and set the value for diffrent events data of diffrent //components

public:
CI(string file, string comp);   //constructor
void * getval(string event, string event_data); 
// should be return void pointer on the value so that it can be //convert into any data type later.

};

Edited by Reverend Jim: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by phoenix911
0

please add the CODE-tags to the respective areas... it makes things easier to read :) thanx

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.