@@ -49,34 +49,36 @@ static const char **__include_func(config_t *config,
4949// ---------------------------------------------------------------------------
5050
5151ConfigException::ConfigException ()
52+ : std::runtime_error(" " )
5253{
5354}
5455
5556// ---------------------------------------------------------------------------
5657
5758ConfigException::ConfigException (std::string const &errorMessage)
58- : _errorMessage (errorMessage)
59+ : std::runtime_error (errorMessage)
5960{
6061}
6162
6263// ---------------------------------------------------------------------------
6364
6465ConfigException::ConfigException (ConfigException const &other)
65- : _errorMessage (other._errorMessage )
66+ : std::runtime_error (other.what() )
6667{
6768}
6869
6970// ---------------------------------------------------------------------------
7071
71- ConfigException::~ConfigException () throw ( )
72+ ConfigException& ConfigException:: operator =(ConfigException const &other )
7273{
74+ std::runtime_error::operator =(other);
75+ return (*this );
7376}
7477
7578// ---------------------------------------------------------------------------
7679
77- const char * ConfigException::what () const throw()
80+ ConfigException::~ConfigException () throw ()
7881{
79- return _errorMessage.c_str ();
8082}
8183
8284// ---------------------------------------------------------------------------
@@ -171,134 +173,126 @@ static int __toTypeCode(Setting::Type type)
171173
172174// ---------------------------------------------------------------------------
173175
174- static void __constructPath (const Setting &setting,
175- std::stringstream &path)
176+ static void __writeSettingPath (const Setting &setting, std::ostream &o)
176177{
177178 // head recursion to print path from root to target
178179
179- if (! setting.isRoot ())
180+ if (!setting.isRoot ())
180181 {
181- __constructPath (setting.getParent (), path);
182- if (path.tellp () > 0 )
183- path << ' .' ;
184-
185- const char *name = setting.getName ();
186- if (name)
187- path << name;
188- else
189- path << ' [' << setting.getIndex () << ' ]' ;
182+ __writeSettingPath (setting.getParent (), o);
183+ o << ' .' ;
190184 }
185+ const char *name = setting.getName ();
186+
187+ if (name)
188+ o << name;
189+ else
190+ o << ' [' << setting.getIndex () << ' ]' ;
191191}
192192
193193// ---------------------------------------------------------------------------
194194
195- static std::string __makeSettingExceptionErrorString (char const *path,
196- char const *derivedType)
195+ static std::string __constructSettingPath (const Setting &setting)
197196{
198- std::stringstream sstr ;
199- sstr << derivedType << " : " << path ;
200- return sstr .str ();
197+ std::stringstream ss ;
198+ __writeSettingPath (setting, ss) ;
199+ return ss .str ();
201200}
202201
203202// ---------------------------------------------------------------------------
204203
205- SettingException::SettingException (char const *derivedType,
206- const Setting &setting)
204+ static std::string __constructSettingPath (const Setting &setting, int idx)
207205{
208- std::stringstream sstr;
209- __constructPath (setting, sstr);
206+ std::stringstream ss;
207+ __writeSettingPath (setting, ss);
208+ ss << " .[" << idx << ' ]' ;
209+ return ss.str ();
210+ }
211+
212+ // ---------------------------------------------------------------------------
210213
211- _path = ::strdup (sstr.str ().c_str ());
212- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
214+ static std::string __constructSettingPath (const Setting &setting, const char *name)
215+ {
216+ std::stringstream ss;
217+ __writeSettingPath (setting, ss);
218+ ss << " .[" << name << ' ]' ;
219+ return ss.str ();
213220}
214221
215222// ---------------------------------------------------------------------------
216223
217- SettingException::SettingException (char const *derivedType,
218- const Setting &setting,
219- int idx)
224+ static std::string __constructErrorMessage (char const *derivedType, std::string const & path)
220225{
221- std::stringstream sstr;
222- __constructPath (setting, sstr);
223- sstr << " .[" << idx << " ]" ;
226+ std::stringstream ss;
227+ ss << derivedType << " : " << path;
228+ return ss.str ();
229+ }
230+
231+ // ---------------------------------------------------------------------------
224232
225- _path = ::strdup (sstr.str ().c_str ());
226- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
233+ SettingException::SettingException (char const *derivedType, std::string path)
234+ : ConfigException(__constructErrorMessage(derivedType, path))
235+ , _path(std::move(path))
236+ {
227237}
228238
229239// ---------------------------------------------------------------------------
230240
231241SettingException::SettingException (char const *derivedType,
232- const Setting &setting,
233- const char *name )
242+ const Setting &setting)
243+ : SettingException(derivedType, __constructSettingPath(setting) )
234244{
235- std::stringstream sstr;
236- __constructPath (setting, sstr);
237- sstr << ' . ' << name;
245+ }
246+
247+ // ---------------------------------------------------------------------------
238248
239- _path = ::strdup (sstr.str ().c_str ());
240- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
249+ SettingException::SettingException (char const *derivedType,
250+ const Setting &setting,
251+ int idx)
252+ : SettingException(derivedType, __constructSettingPath(setting, idx))
253+ {
241254}
242255
243256// ---------------------------------------------------------------------------
244257
245258SettingException::SettingException (char const *derivedType,
246- const char *path)
259+ const Setting &setting,
260+ const char *name)
261+ : SettingException(derivedType, __constructSettingPath(setting, name))
247262{
248- _path = ::strdup (path);
249- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
250263}
251264
252265// ---------------------------------------------------------------------------
253266
254267SettingException::SettingException (const Setting &setting)
268+ : SettingException(" setting exception" , setting)
255269{
256- std::stringstream sstr;
257- __constructPath (setting, sstr);
258-
259- _path = ::strdup (sstr.str ().c_str ());
260- _errorMessage =
261- __makeSettingExceptionErrorString (_path, " setting exception" );
262270}
263271
264272// ---------------------------------------------------------------------------
265273
266274SettingException::SettingException (const Setting &setting, int idx)
275+ : SettingException(" setting exception" , setting, idx)
267276{
268- std::stringstream sstr;
269- __constructPath (setting, sstr);
270- sstr << " .[" << idx << " ]" ;
271-
272- _path = ::strdup (sstr.str ().c_str ());
273- _errorMessage =
274- __makeSettingExceptionErrorString (_path, " setting exception" );
275277}
276278
277279// ---------------------------------------------------------------------------
278280
279281SettingException::SettingException (const Setting &setting, const char *name)
282+ : SettingException(" setting exception" , setting, name)
280283{
281- std::stringstream sstr;
282- __constructPath (setting, sstr);
283- sstr << ' .' << name;
284-
285- _path = ::strdup (sstr.str ().c_str ());
286- _errorMessage =
287- __makeSettingExceptionErrorString (_path, " setting exception" );
288284}
289285
290286// ---------------------------------------------------------------------------
291287
292288SettingException::SettingException (const char *path)
289+ : SettingException(" setting exception" , path)
293290{
294- _path = ::strdup (path);
295- _errorMessage =
296- __makeSettingExceptionErrorString (_path, " setting exception" );
297291}
298292
299293// ---------------------------------------------------------------------------
300294
301- const char * SettingException::getPath () const
295+ std::string const & SettingException::getPath () const
302296{
303297 return (_path);
304298}
@@ -307,17 +301,16 @@ const char *SettingException::getPath() const
307301
308302SettingException::SettingException (const SettingException &other)
309303 : ConfigException(other)
304+ , _path(other._path)
310305{
311- _path = ::strdup (other._path );
312306}
313307
314308// ---------------------------------------------------------------------------
315309
316310SettingException &SettingException::operator =(const SettingException &other)
317311{
318312 ConfigException::operator =(other);
319- ::free (_path);
320- _path = ::strdup (other._path );
313+ _path = other._path ;
321314
322315 return (*this );
323316}
@@ -326,7 +319,6 @@ SettingException &SettingException::operator=(const SettingException &other)
326319
327320SettingException::~SettingException () throw ()
328321{
329- ::free (_path);
330322}
331323
332324// ---------------------------------------------------------------------------
@@ -384,9 +376,9 @@ SettingNameException::SettingNameException(const Setting &setting,
384376
385377// ---------------------------------------------------------------------------
386378
387- const char *FileIOException::what () const throw()
379+ FileIOException::FileIOException ()
380+ : ConfigException(" FileIOException" )
388381{
389- return (" FileIOException" );
390382}
391383
392384// ---------------------------------------------------------------------------
@@ -1111,7 +1103,7 @@ std::string Setting::getPath() const
11111103{
11121104 std::stringstream path;
11131105
1114- __constructPath (*this , path);
1106+ __writeSettingPath (*this , path);
11151107
11161108 return (path.str ());
11171109}
0 commit comments