[fdo-dev] Pre-conditions and unsafe constuctions
Mateusz Loskot
mateusz at loskot.net
Thu Dec 7 10:53:50 EST 2006
Hi,
Here is another construction I'd like to get some explanation about.
In function FdoRdbmsMySqlConnection::NewSchemaManager(), there is
following construction:
FdoSmPhMySqlMgrP physMgr =
schMgr->GetPhysicalSchema()->SmartCast<FdoSmPhMySqlMgr>();
According to my understanding of the SmartCast<T>() implemen,
it is acceptable to return NULL from this call.
Next, FdoSmPhMgrP (FdoPtr-based type) is initialized with NULL.
Again, FdoPtr<T>::operator-> will throw "encrypted" exception not
explaining the real problem: Type of FdpoSmPhMgr is not castable
to FdoSmPhMySqlMgr type, what in turn means a real design
problem occured.
Why SmartCast<T>() function, if present anyway, does not check for
NULL and throw domain-related error like "Types are unrelated and can
not be downcasted" or similar?
Otherwise, I can't see the real benefits of SmartCast<T>() and even it
makes code error prone, because it allows chain-calls of operator->()
without having real control on pointers validation.
I'm just curious about rationale of these constructions and I wonder if
I am allowed to not to use SmartCast and DownCast functions in PostGIS
provider but use dynamic_cast and throw some FDO exception if types are
unrelated so not castable.
Am I allowed?
Cheers
--
Mateusz Loskot
http://mateusz.loskot.net
More information about the Fdo_dev
mailing list