@@ -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,119 @@ 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{
177- // head recursion to print path from root to target
178-
179- if (! setting.isRoot ())
178+ if (!setting.isRoot ())
180179 {
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 () << ' ]' ;
180+ __writeSettingPath (setting.getParent (), o);
181+ o << ' .' ;
190182 }
183+ o << setting.getName ();
191184}
192185
193186// ---------------------------------------------------------------------------
194187
195- static std::string __makeSettingExceptionErrorString (char const *path,
196- char const *derivedType)
188+ static std::string __constructSettingPath (const Setting &setting)
197189{
198- std::stringstream sstr ;
199- sstr << derivedType << " : " << path ;
200- return sstr .str ();
190+ std::stringstream ss ;
191+ __writeSettingPath (setting, ss) ;
192+ return ss .str ();
201193}
202194
203195// ---------------------------------------------------------------------------
204196
205- SettingException::SettingException (char const *derivedType,
206- const Setting &setting)
197+ static std::string __constructSettingPath (const Setting &setting, int idx)
207198{
208- std::stringstream sstr;
209- __constructPath (setting, sstr);
199+ std::stringstream ss;
200+ __writeSettingPath (setting, ss);
201+ ss << " .[" << idx << ' ]' ;
202+ return ss.str ();
203+ }
210204
211- _path = ::strdup (sstr.str ().c_str ());
212- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
205+ // ---------------------------------------------------------------------------
206+
207+ static std::string __constructSettingPath (const Setting &setting, const char *name)
208+ {
209+ std::stringstream ss;
210+ __writeSettingPath (setting, ss);
211+ ss << " .[" << name << ' ]' ;
212+ return ss.str ();
213213}
214214
215215// ---------------------------------------------------------------------------
216216
217- SettingException::SettingException (char const *derivedType,
218- const Setting &setting,
219- int idx)
217+ static std::string __constructErrorMessage (char const *derivedType, std::string const & path)
220218{
221- std::stringstream sstr;
222- __constructPath (setting, sstr);
223- sstr << " .[" << idx << " ]" ;
219+ std::stringstream ss;
220+ ss << derivedType << " : " << path;
221+ return ss.str ();
222+ }
223+
224+ // ---------------------------------------------------------------------------
224225
225- _path = ::strdup (sstr.str ().c_str ());
226- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
226+ SettingException::SettingException (char const *derivedType, std::string path)
227+ : ConfigException(__constructErrorMessage(derivedType, path))
228+ , _path(std::move(path))
229+ {
227230}
228231
229232// ---------------------------------------------------------------------------
230233
231234SettingException::SettingException (char const *derivedType,
232- const Setting &setting,
233- const char *name )
235+ const Setting &setting)
236+ : SettingException(derivedType, __constructSettingPath(setting) )
234237{
235- std::stringstream sstr;
236- __constructPath (setting, sstr);
237- sstr << ' . ' << name;
238+ }
239+
240+ // ---------------------------------------------------------------------------
238241
239- _path = ::strdup (sstr.str ().c_str ());
240- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
242+ SettingException::SettingException (char const *derivedType,
243+ const Setting &setting,
244+ int idx)
245+ : SettingException(derivedType, __constructSettingPath(setting, idx))
246+ {
241247}
242248
243249// ---------------------------------------------------------------------------
244250
245251SettingException::SettingException (char const *derivedType,
246- const char *path)
252+ const Setting &setting,
253+ const char *name)
254+ : SettingException(derivedType, __constructSettingPath(setting, name))
247255{
248- _path = ::strdup (path);
249- _errorMessage = __makeSettingExceptionErrorString (_path, derivedType);
250256}
251257
252258// ---------------------------------------------------------------------------
253259
254260SettingException::SettingException (const Setting &setting)
261+ : SettingException(" setting exception" , setting)
255262{
256- std::stringstream sstr;
257- __constructPath (setting, sstr);
258-
259- _path = ::strdup (sstr.str ().c_str ());
260- _errorMessage =
261- __makeSettingExceptionErrorString (_path, " setting exception" );
262263}
263264
264265// ---------------------------------------------------------------------------
265266
266267SettingException::SettingException (const Setting &setting, int idx)
268+ : SettingException(" setting exception" , setting, idx)
267269{
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" );
275270}
276271
277272// ---------------------------------------------------------------------------
278273
279274SettingException::SettingException (const Setting &setting, const char *name)
275+ : SettingException(" setting exception" , setting, name)
280276{
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" );
288277}
289278
290279// ---------------------------------------------------------------------------
291280
292281SettingException::SettingException (const char *path)
282+ : SettingException(" setting exception" , path)
293283{
294- _path = ::strdup (path);
295- _errorMessage =
296- __makeSettingExceptionErrorString (_path, " setting exception" );
297284}
298285
299286// ---------------------------------------------------------------------------
300287
301- const char * SettingException::getPath () const
288+ std::string const & SettingException::getPath () const
302289{
303290 return (_path);
304291}
@@ -307,17 +294,16 @@ const char *SettingException::getPath() const
307294
308295SettingException::SettingException (const SettingException &other)
309296 : ConfigException(other)
297+ , _path(other._path)
310298{
311- _path = ::strdup (other._path );
312299}
313300
314301// ---------------------------------------------------------------------------
315302
316303SettingException &SettingException::operator =(const SettingException &other)
317304{
318305 ConfigException::operator =(other);
319- ::free (_path);
320- _path = ::strdup (other._path );
306+ _path = other._path ;
321307
322308 return (*this );
323309}
@@ -326,7 +312,6 @@ SettingException &SettingException::operator=(const SettingException &other)
326312
327313SettingException::~SettingException () throw ()
328314{
329- ::free (_path);
330315}
331316
332317// ---------------------------------------------------------------------------
@@ -384,9 +369,9 @@ SettingNameException::SettingNameException(const Setting &setting,
384369
385370// ---------------------------------------------------------------------------
386371
387- const char *FileIOException::what () const throw()
372+ FileIOException::FileIOException ()
373+ : ConfigException(" FileIOException" )
388374{
389- return (" FileIOException" );
390375}
391376
392377// ---------------------------------------------------------------------------
@@ -1111,7 +1096,7 @@ std::string Setting::getPath() const
11111096{
11121097 std::stringstream path;
11131098
1114- __constructPath (*this , path);
1099+ __writeSettingPath (*this , path);
11151100
11161101 return (path.str ());
11171102}
0 commit comments