ATLAS Offline Software
Loading...
Searching...
No Matches
ALFA_ConfigParams Class Reference

#include <ALFA_ConfigParams.h>

Collaboration diagram for ALFA_ConfigParams:

Public Types

using StringStringMap = std::map<std::string, std::string, std::less<> >

Public Member Functions

bool IsKey (const char *szKey) const
const char * GetParameter (const char *szKey) const
int Init (const char *szFile, const char *szSection)
void UnInitialize ()

Private Attributes

bool m_bIsValid {}
std::string m_strSection {"invalid"}
StringStringMap m_mapParams

Detailed Description

Definition at line 14 of file ALFA_ConfigParams.h.

Member Typedef Documentation

◆ StringStringMap

using ALFA_ConfigParams::StringStringMap = std::map<std::string, std::string, std::less<> >

Definition at line 17 of file ALFA_ConfigParams.h.

Member Function Documentation

◆ GetParameter()

const char * ALFA_ConfigParams::GetParameter ( const char * szKey) const

Definition at line 71 of file ALFA_ConfigParams.cxx.

72{
73 if(!m_bIsValid) return nullptr;
74
75 char szbuff[256];
76 memset(szbuff,0,sizeof(szbuff));
77 if(szKey) strncpy(szbuff,szKey,sizeof(szbuff)-1);
78 //strlwr(szbuff);
79
80 StringStringMap::const_iterator iter;
81 if((iter=m_mapParams.find(szbuff))!=m_mapParams.end()){
82 return (*iter).second.c_str();
83 }
84 else return nullptr;
85}
StringStringMap m_mapParams

◆ Init()

int ALFA_ConfigParams::Init ( const char * szFile,
const char * szSection )

Definition at line 25 of file ALFA_ConfigParams.cxx.

26{
27 bool bRes=false;
28 FILE* pfile=nullptr;
29 char szbuff[256],szsec[256];
30 char* ppv;
31
33
34 if((pfile=fopen(szFile,"r"))==nullptr) return false;
35
36 //read section
37 memset(szsec,0,sizeof(szsec));
38 if(szSection) strncpy(szsec,szSection,sizeof(szsec)-1);
39 //strlwr(szsec);
40 m_strSection=szsec;
41
42 while(!feof(pfile)){
43 fgets(szbuff,sizeof(szbuff),pfile);
44 if(*(szbuff+strlen(szbuff)-1)=='\n') *(szbuff+strlen(szbuff)-1)=0;
45 if(strcmp(szbuff,szsec) != 0) continue; //if(strcmp(strlwr(szbuff),szsec)) continue;
46 else{ bRes=true; break; }
47 }
48
49 if(!bRes){
50 fclose(pfile);
51 return 0;
52 }
53
54 while(!feof(pfile)){
55 fgets(szbuff,sizeof(szbuff),pfile);
56 if(*szbuff==0 || *szbuff==' ' || *szbuff=='\n' || *szbuff==';') continue;
57 if(*szbuff=='[') break;
58 if((ppv=strchr(szbuff,'='))==nullptr) continue;
59
60 if(*(szbuff+strlen(szbuff)-1)=='\n') *(szbuff+strlen(szbuff)-1)=0;
61 *ppv=0; ppv++;
62 m_mapParams.insert(StringStringMap::value_type(szbuff,ppv));
63 }
64
65 fclose(pfile);
66 if(!m_mapParams.empty()) m_bIsValid=true;
67
68 return m_mapParams.size();
69}

◆ IsKey()

bool ALFA_ConfigParams::IsKey ( const char * szKey) const

Definition at line 87 of file ALFA_ConfigParams.cxx.

88{
89 if(!m_bIsValid) return false;
90
91 char szbuff[256];
92 memset(szbuff,0,sizeof(szbuff));
93 if(szKey) strncpy(szbuff,szKey,sizeof(szbuff)-1);
94 //strlwr(szbuff);
95
96 StringStringMap::const_iterator iter;
97 return (iter=m_mapParams.find(szbuff))!=m_mapParams.end();
98}

◆ UnInitialize()

void ALFA_ConfigParams::UnInitialize ( )

Definition at line 18 of file ALFA_ConfigParams.cxx.

19{
20 m_bIsValid=false;
21 m_strSection="invalid";
22 m_mapParams.clear();
23}

Member Data Documentation

◆ m_bIsValid

bool ALFA_ConfigParams::m_bIsValid {}
private

Definition at line 19 of file ALFA_ConfigParams.h.

19{};

◆ m_mapParams

StringStringMap ALFA_ConfigParams::m_mapParams
private

Definition at line 21 of file ALFA_ConfigParams.h.

◆ m_strSection

std::string ALFA_ConfigParams::m_strSection {"invalid"}
private

Definition at line 20 of file ALFA_ConfigParams.h.

20{"invalid"};

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