[Insight-developers] ExceptionObject Borland Compile errors
Niels Dekker
niels-xtk at xs4all.nl
Thu May 29 04:29:21 EDT 2008
Luis Ibanez wrote:
> Following Brad's suggestion [...]
> An interface/facade class was added that simply provides the
> Register()/UnRegister() API expected by the SmartPointer.
>
> See changes in the following links (.h and .cxx)
> http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkExceptionObject.h?root=Insight&r1=1.37&r2=1.38&sortby=date
> http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkExceptionObject.cxx?root=Insight&r1=1.12&r2=1.13&sortby=date
>
> This class is then used in the .cxx file as the base class
> of the ExceptionData class. The Register/UnRegister methods
> are now overloaded in ReferenceCountedExceptionData and are
> delegated to its second parent, the LightObject.
Thanks for helping me out, Luis! I'm sorry I wasn't at my computer
anymore last evening. Actually I did send a revised version yesterday,
to Brad and Bill, but I wasn't sure if it was allowed to CC it to the
mailing list. Are attachments allowed, on the mailing list?
Anyway, my revision was far less sophisticated than yours: it had just
one helper class ("ExceptionData"), that contains *both* the exception
data and the Register()/UnRegister() methods, as well as the reference
counter itself. (It didn't use LightObject anymore.) The class
definition of ExceptionData would need to be in itkExceptionObject.h, to
make Borland happy. Brad mailed me that it should work. But
unfortunately Bill mailed me that Borland stilll didn't like it. Bill,
can you please tell us what Borland complained about?
So I'm sorry I didn't CC my revision to you as well, but honestly I do
like your fix slightly more than mine. :-) Especially because it still
uses LightObject, which does reference counting in a thread safe way.
Two little remarks:
itkExceptionObject.cxx now says:
const ExceptionObject::ReferenceCountedExceptionData *
ExceptionObject::GetExceptionData() const
{
const ReferenceCountedExceptionData * thisData =
dynamic_cast< const ReferenceCountedExceptionData *>(
this->m_ExceptionData.GetPointer() );
return thisData;
}
I think that dynamic_cast only makes sense if you check afterwards
whether or not it's successful. But I think that this runtime checking
isn't really necessary this time. So you might as well do static_cast.
You added some c_str() calls:
m_ExceptionData = ReferenceCountedExceptionData::ConstNew(
IsNull ? "" : this->GetExceptionData()->m_File.c_str(),
IsNull ? 0 : this->GetExceptionData()->m_Line,
IsNull ? "" : this->GetExceptionData()->m_Description.c_str(),
s);
Did you do so because of compiler complaints? Anyway, this has the
effect of converting the arguments from std::string to char-pointer, and
then back to std::string again. Instead I think it would be preferable
to stick with std::string:
m_ExceptionData = ReferenceCountedExceptionData::ConstNew(
IsNull ? std::string() : this->GetExceptionData()->m_File,
IsNull ? 0 : this->GetExceptionData()->m_Line,
IsNull ? std::string() : this->GetExceptionData()->m_Description,
s);
As you see, I replaced the literal ("") by std::string(), to avoid those
possible compilers complaints. What do you think?
Kind regards,
Niels
More information about the Insight-developers
mailing list