Fix Coverity 10050
[u/mrichter/AliRoot.git] / TTherminator / Therminator / ReadPar.cxx
CommitLineData
2e967919 1/******************************************************************************
2 * T H E R M I N A T O R *
3 * THERMal heavy-IoN generATOR *
4 * version 1.0 *
5 * *
6 * Authors of the model: Wojciech Broniowski, Wojciech.Broniowski@ifj.edu.pl, *
7 * Wojciech Florkowski, Wojciech.Florkowski@ifj.edu.pl *
8 * Authors of the code: Adam Kisiel, kisiel@if.pw.edu.pl *
9 * Tomasz Taluc, ttaluc@if.pw.edu.pl *
10 * Code designers: Adam Kisiel, Tomasz Taluc, Wojciech Broniowski, *
11 * Wojciech Florkowski *
12 * *
13 * For the detailed description of the program and furhter references *
14 * to the description of the model plesase refer to: nucl-th/0504047, *
15 * accessibile at: http://www.arxiv.org/nucl-th/0504047 *
16 * *
17 * Homepage: http://hirg.if.pw.edu.pl/en/therminator/ *
18 * *
19 * This code can be freely used and redistributed. However if you decide to *
20 * make modifications to the code, please contact the authors, especially *
21 * if you plan to publish the results obtained with such modified code. *
22 * Any publication of results obtained using this code must include the *
23 * reference to nucl-th/0504047 and the published version of it, when *
24 * available. *
25 * *
26 *****************************************************************************/
27#include "THGlobal.h"
28#include "ReadPar.h"
29#include <iostream>
30#include <fstream>
31#include <sstream>
32#include <iosfwd>
d9e5a3f9 33#include <stdlib.h>
2e967919 34
35ReadPar::ReadPar()
36{
37 fname = 0;
38}
39
40ReadPar::ReadPar(const char *aFName)
41{
42 fname = strdup(aFName);
43 readFile(aFName);
44}
45
d9e5a3f9 46ReadPar::~ReadPar()
47{
48 if (fname)
49 free(fname);
50}
51
2e967919 52int ReadPar::readFile(const char *aFName) throw (int)
53{
54 option read_opt;
55 STR buf_str;
56 char buff[200];
57 char dummy[200];
58
59 std::ifstream infile(aFName);
60 std::istringstream *instream;
61
62 if (!infile.is_open())
63 throw RP_Exception_NoParFile;
64
65 while (!infile.eof())
66 {
67 infile.getline(buff, 200);
68 instream = new std::istringstream(buff);
69 memset(dummy,0,200);
70 *instream >> dummy;
71
72 PRINT_DEBUG_3("Read " << dummy);;
73 read_opt.keyword = dummy;
74 memset(dummy,0,200);
75 *instream >> dummy;
76
77 PRINT_DEBUG_3("Read " << dummy);
78 if (strstr(dummy,"="))
79 {
80 dummy[0]='\0';
81
82 memset(dummy,0,200);
83 *instream >> dummy;
84 PRINT_DEBUG_3("Read " << dummy);
85
86 read_opt.value = dummy;
87 options.push_back(read_opt);
88 }
89 }
90 infile.close();
91
92 return 0;
93}
94
95int ReadPar::printOptions()
96{
97 VOPT::iterator c;
98
99 for (c=options.begin(); c != options.end(); c++)
100 PRINT_DEBUG_3("Keyword: " << c->keyword << " Value: " << c->value);
101
102 return 0;
103}
104
105STR ReadPar::getPar(const char *name) throw(STR)
106{
107 VOPT::iterator c;
108 STR pname(name);
109
110 for (c=options.begin(); c != options.end(); c++)
111 if (c->keyword == pname)
112 {
113 PRINT_DEBUG_2("Returning value " << c->value << " for keyword " << c->keyword);
114 return c->value;
115 }
116 throw *(new STR(name));
117
118 return TString("");
119}
120
121
122