Ini file reader

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

Ini file reader

#1 Post by martinrame »

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.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

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.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#3 Post by martinrame »

Thanks, let me try it.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#4 Post by martinrame »

My .ini file contents is this:

Code: Select all

[default]
HttpPort=80
DicomPort=104
I'm trying to read it with this:

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;
  }
But allways I'm getting "Section not valid", what I'm doing wrong?[/code]

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#5 Post by Jörg Riesmeier »

The class supports more than one hierarchical level (i.e. subsections and so on), see parameter "maxLevel" of the constructor.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#6 Post by martinrame »

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?

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#7 Post by Jörg Riesmeier »

As far as I can see, you have to specify a maxLevel of "1".

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#8 Post by martinrame »

Well, I changed my code to this:

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. :(

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#9 Post by Jörg Riesmeier »

Have you already tried to use upper case characters for the section names and keywords, i.e. "DEFAULT" and "HTTPPORT"?

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#10 Post by martinrame »

Thanks Jörg, making everything upper case it worked.

Now I'll have to figure out how to use the file in normal mixed Upper/Lower case and read it into a string, then UpperCase it, and use OFConfigFile with that string.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#11 Post by Jörg Riesmeier »

As far as I know, and I'm not the developer of OFConfigFile, you have to use upper case characters only in the program, i.e. not necessarily in the config file.

martinrame
Posts: 347
Joined: Mon, 2009-02-23, 19:57

#12 Post by martinrame »

Yes!, you are right. Problem solved, then!.

Post Reply

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 1 guest