Problem about IFeatureReader & IFeatureReaderImp in Managed FDO

Xuewei Ren xren at hannastrategies.com
Wed Sep 6 03:58:12 EDT 2006


In function XmlSerialize, can you pass reader argument that is the
instance of IFeatureReaderImpl? You mentioned that you implemented
IFeatureReader called MyFeatureReader. You must have passed the instance
of your own class as the reader argument in this function. I believe
that causes the problem. From the code, we can find out that this
function assumes that IFeatureReaderImpl is the only implementation for
IFeatureReader. Because of this assumption, the original code did the
static_cast from IFeatureReader to IFeatureReaderImpl. This is actually
not correct. Hope this can be corrected soon.

 

The workaround might be to pass an instance of IFeatureReaderImpl for
the reader argument.

 

Cheers,

 

Xuewei

 

 

________________________________

From: song yafeng-Heman [mailto:yfsong at hslcn.com] 
Sent: Tuesday, September 05, 2006 9:38 PM
To: dev at fdo.osgeo.org
Cc: Xuewei Ren; xue kai-Constantine
Subject: Problem about IFeatureReader & IFeatureReaderImp in Managed FDO

 

Hi everyone.

 

I met a problem about IFeatureReader when I was writing C# code.

I rewrite the class MyFeatureReader derived from IFeatureReader in C#
which is the same as the class in GmlWriteTest.cpp in unit test of FDO
with the same name.

Then I use XmlFeatureSerializer.XmlSerialize(featureReader,
featureWriter, flags), but always meet errors.

I debug in the mgFdo, find error occurs here (in the red).

 

[code]

System::Void
NAMESPACE_FDO_XML::XmlFeatureSerializer::XmlSerialize(NAMESPACE_FDO_COMM
ANDS_FEATURE::IFeatureReader* reader,
NAMESPACE_FDO_XML::XmlFeatureWriter* writer,
NAMESPACE_FDO_XML::XmlFeatureFlags* flags)

{

//The original code.

 
//EXCEPTION_HANDLER(FdoXmlFeatureSerializer::XmlSerialize(static_cast<NA
MESPACE_FDO_COMMANDS_FEATURE::IFeatureReaderImp*>(reader)->GetImpObj(),
writer->GetImpObj(), flags->GetImpObj()))               

 

//The full code same as the original code

         NAMESPACE_FDO_COMMANDS_FEATURE::IFeatureReaderImp* readerImp =
static_cast<NAMESPACE_FDO_COMMANDS_FEATURE::IFeatureReaderImp*>(reader);

         GisPtr<FdoIFeatureReader> uReader = readerImp->GetImpObj();

         GisPtr<FdoXmlFeatureWriter> uWriter = writer->GetImpObj();

         GisPtr<FdoXmlFeatureFlags> uFlags = flags->GetImpObj();

         try 

         { 

                   FdoXmlFeatureSerializer::XmlSerialize(uReader,
uWriter, uFlags); 

         } 

         catch(GisException* e) 

         { 

                   NAMESPACE_COMMON::Exception* mgE =
NAMESPACE_COMMON::Exception::Create(e); 

                   e->Release(); 

                   throw mgE; 

         }

}

[/code]

 

Because the reader is derived from IFearureReader, cast it to a
IFeatureReaderImp is not a right operation. Then use GetImpObj() will
get wrong pointer. This wrong point cause the error later.  

 

Is this a bug or I make some mistakes in my code?

 

A bit of help would be greatly appreciated.

Thanks

 

Kino

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/fdo-internals/attachments/20060906/8ad5e950/attachment.html


More information about the Fdo-internals mailing list