Ini file reader
Moderator: Moderator Team
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
Ini file reader
Hi, I need to add INI file reading support for an utility I'm creating, that uses dcmtk.
Before implementing it by myself, I would like to ask if the library has this feature already implemented.
Thanks in advance.
Before implementing it by myself, I would like to ask if the library has this feature already implemented.
Thanks in advance.
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
What about OFConfigFile? It's probably not the best solution but it is used for the association negotion profiles in dcmnet and some dcmpstat tools.
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
My .ini file contents is this:
I'm trying to read it with this:
But allways I'm getting "Section not valid", what I'm doing wrong?[/code]
Code: Select all
[default]
HttpPort=80
DicomPort=104
Code: Select all
FILE *lFile = fopen("mycfgfile.ini", "rb");
if(lFile)
{
OFConfigFile *iniFile = new OFConfigFile(lFile);
iniFile->select_section("default");
if(iniFile->section_valid(1))
{
DCMWLM_INFO("-->" << iniFile->get_entry("HttpPort") << "<--");
}
else
{
DCMWLM_INFO("-->Section not valid<--");
}
delete iniFile;
}
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
The class supports more than one hierarchical level (i.e. subsections and so on), see parameter "maxLevel" of the constructor.
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
Yes, I know that. Also OFConfigFile_MaxLevel, by default is 2, so it should read my file without problems.
Please, tell me if my understanding of this class is right or not.
1) iniFile->select_section("default");
Here I'm choosing to read all keys inside [default] section.
2) if(iniFile->section_valid(1))
Here I'm checking if the section number 1 is valid. This allways returns False in my example. I also tried with (0) and (2), but i'm getting the same result.
3) iniFile->get_entry("HttpPort")
Here, if the cursor were at section [default], I should be able to get the value of HttPort variable.
This reasoning is ok?
Please, tell me if my understanding of this class is right or not.
1) iniFile->select_section("default");
Here I'm choosing to read all keys inside [default] section.
2) if(iniFile->section_valid(1))
Here I'm checking if the section number 1 is valid. This allways returns False in my example. I also tried with (0) and (2), but i'm getting the same result.
3) iniFile->get_entry("HttpPort")
Here, if the cursor were at section [default], I should be able to get the value of HttPort variable.
This reasoning is ok?
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
Well, I changed my code to this:
...but I'm getting the same results.
Code: Select all
FILE *lFile = fopen("ModalityWorklistServer.ini", "rb");
if(lFile)
{
DCMWLM_INFO("-->1<--");
OFConfigFile iniFile(lFile, 1);
iniFile.set_section(1, "default");
if(! iniFile.section_valid(1) )
{
DCMWLM_INFO("-->Section not valid<--");
}
else
{
DCMWLM_INFO("-->" << iniFile.get_entry("HttpPort") << "<--");
}
DCMWLM_INFO("-->3<--");
fclose(lFile);
}
...but I'm getting the same results.
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
-
- ICSMED DICOM Services
- Posts: 2217
- Joined: Fri, 2004-10-29, 21:38
- Location: Oldenburg, Germany
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
Who is online
Users browsing this forum: Google [Bot] and 1 guest