FDO Rasters - Changing the Raster Data Model

Frank Warmerdam warmerdam at pobox.com
Thu Sep 7 15:17:39 EDT 2006


Folks,

I'm seriously working on the FDO GDAL provider and have lots of good
stuff implemented and working now.

However, a few things have come up which I'm unsure about.  One of those
is the correct handling of the FdoRasterDataModel object in the code.

The FdoRfpBandRaster::GetDataModel() method maintains an internal
FdoRasterDataModel object, and returns a pointer to it from the method.

But in UnitTests like RfpRasterConversion.cpp we see lots of examples like
this:

	// change the data model and tile size
	FdoPtr<FdoRasterDataModel> dataModel = m_raster->GetDataModel();
	dataModel->SetDataModelType(FdoRasterDataModelType_Gray);
	dataModel->SetBitsPerPixel(8);
	dataModel->SetTileSizeX(256);
	dataModel->SetTileSizeY(256);
	m_raster->SetDataModel(dataModel);

My understanding is that the above code will effectively be modifying
the internal copy of the data model kept by the raster each time a
method like SetDataModelType(), or SetTileSizeX() is called.  Is that
right?  This generally seems like an unsafe practice.  For instance,
if the data model is changed to use some unsupported value such as 1 for
SetBitsPerPixel(), then the internal data model has already been changed
even if the validation done in SetDataModel() refused to assign the 'new'
data model due to the unsupported form.

It seems like the GetDataModel() method ought to return a copy of the
internal data model, or the user ought to be responsible for making a
copy before making any alterations.

Is there a subtle cloning of the data model object happening in here
somewhere that I'm not aware of?

--

Next, what is the best way to clone an object like the FdoRasterDataModel?
It didn't seem have an obvious copy constructor or assignment operator.

In my StreamReader constructor, I decided I ought to make a copy of the
data model so that even if the application code alters the data model
after creating the stream and before destroying it, that the stream would
continue to use the data model in force at the point it was created.  To
do this I used the following to create a copy of the data model.

     // Make a local copy of the data model.
     m_dataModel = FdoRasterDataModel::Create();
     *m_dataModel = *model_in;

In this case, I happen to know that a shallow copy on the FdoRasterDataModel
is safe, so it works.  But is this really the right way?

Forgive me for my possibly lame questions.  I have a certain rather limited
style of C++ coding I use in GDAL and I understand exactly what is happening
within that.  But in more "modern" projects such as FDO I'm not always certain
if I'm doing things in the right way or whether I'm understanding some of the
C++ mechanisms that come into play.

For reference. the source files reflected here can be found at:

Unit test (search for "SetDataModel(":

https://fdogdal.osgeo.org/source/browse/fdogdal/trunk/Providers/GDAL/Src/UnitTest/RfpRasterConversion.cpp?rev=2&view=markup

Implementation of GetDataModel(), search for GetDataModel:

https://fdogdal.osgeo.org/source/browse/fdogdal/trunk/Providers/GDAL/Src/Provider/FdoRfpBandRaster.cpp?rev=2&view=markup

FdoRasterDataModel class declaration:

https://fdocore.osgeo.org/source/browse/fdocore/trunk/Fdo/Unmanaged/Inc/Fdo/Raster/RasterDataModel.h?rev=317&view=markup

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org





More information about the Fdo-internals mailing list