From 9fa33dd2e440ad74dae9578a48869230aad6f2e0 Mon Sep 17 00:00:00 2001 From: Luc Hermitte <luc.hermitte@c-s.fr> Date: Tue, 26 Jun 2012 20:46:57 +0200 Subject: [PATCH] BUG: static storage objects have troubles to be deallocated with the plugin architecture --- Code/IO/otbGDALImageIO.cxx | 15 ++-- Code/IO/otbImageMetadataInterfaceBase.cxx | 5 +- .../OssimAdapters/otbMetaDataKey.cxx | 55 +++++++------- .../OssimAdapters/otbMetaDataKey.h | 73 ++++++++----------- 4 files changed, 66 insertions(+), 82 deletions(-) diff --git a/Code/IO/otbGDALImageIO.cxx b/Code/IO/otbGDALImageIO.cxx index 795e694975..13912961f8 100644 --- a/Code/IO/otbGDALImageIO.cxx +++ b/Code/IO/otbGDALImageIO.cxx @@ -682,7 +682,7 @@ void GDALImageIO::InternalReadImageInformation() int blockSizeY = 0; dataset->GetRasterBand(1)->GetBlockSize(&blockSizeX, &blockSizeY); - + if(blockSizeX > 0 && blockSizeY > 0) { itk::EncapsulateMetaData<unsigned int>(dict, MetaDataKey::TileHintX, blockSizeX); @@ -1116,9 +1116,9 @@ void GDALImageIO::Write(const void* buffer) if( gdalDriverShortName.compare("JPEG") == 0 ) { option[0] = const_cast<char *>("QUALITY=95"); - + } - + GDALDataset* hOutputDS = driver->CreateCopy( realFileName.c_str(), m_Dataset->GetDataSet(), FALSE, option, NULL, NULL ); GDALClose(hOutputDS); @@ -1272,7 +1272,7 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) unsigned int nbPixelPerTile = ReferenceTileSizeInBytes / m_BytePerPixel / m_NbBands; unsigned int idealTileDimension = static_cast<unsigned int>( vcl_sqrt(static_cast<float>(nbPixelPerTile)) ); - + // Set tileDimension to the nearest power of two and aligned to // 16 pixels (needed by tiff spec) unsigned int tileDimension = 16; @@ -1415,12 +1415,13 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) /* -------------------------------------------------------------------- */ std::string svalue = ""; - std::vector<std::string> keys = dict.GetKeys(); - MetaDataKey key; + std::vector<std::string> keys = dict.GetKeys(); + std::string const metadataKey = MetaDataKey::MetadataKey; for (unsigned int itkey = 0; itkey < keys.size(); ++itkey) { - if (keys[itkey].compare(0, key.MetadataKey.length(), key.MetadataKey) == 0) + /// \todo Why not <tt>keys[itkey] == MetadataKey::MetadataKey</tt> ? + if (keys[itkey].compare(0, metadataKey.length(), metadataKey) == 0) { itk::ExposeMetaData<std::string>(dict, keys[itkey], svalue); unsigned int equalityPos = svalue.find_first_of('='); diff --git a/Code/IO/otbImageMetadataInterfaceBase.cxx b/Code/IO/otbImageMetadataInterfaceBase.cxx index a7eb462d88..6b92497930 100644 --- a/Code/IO/otbImageMetadataInterfaceBase.cxx +++ b/Code/IO/otbImageMetadataInterfaceBase.cxx @@ -432,7 +432,7 @@ ImageMetadataInterfaceBase::GetYPixelSpacing() const } return 0; - + } @@ -455,12 +455,11 @@ ImageMetadataInterfaceBase::PrintSelf(std::ostream& os, itk::Indent indent, cons // by the ExposeMetaData method MetaDataDictionaryType dict2 = dict; - MetaDataKey key; for (unsigned int itkey = 0; itkey < keys.size(); ++itkey) { - switch (key.GetKeyType(keys[itkey])) + switch (MetaDataKey::GetKeyType(keys[itkey])) { case MetaDataKey::TSTRING: itk::ExposeMetaData<std::string>(dict2, keys[itkey], svalue); diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.cxx b/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.cxx index c096977d96..0598e9f974 100644 --- a/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.cxx +++ b/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.cxx @@ -23,44 +23,43 @@ namespace otb { +namespace MetaDataKey +{ +char const* DriverShortNameKey = "DriverShortName"; +char const* DriverLongNameKey = "DriverLongName"; -const std::string MetaDataKey::DriverShortNameKey = "DriverShortName"; -const std::string MetaDataKey::DriverLongNameKey = "DriverLongName"; - -const std::string MetaDataKey::ProjectionRefKey = "ProjectionRef"; - -const std::string MetaDataKey::GCPProjectionKey = "GCPProjection"; -const std::string MetaDataKey::GCPParametersKey = "GCP_"; -const std::string MetaDataKey::GCPCountKey = "GCPCount"; +char const* ProjectionRefKey = "ProjectionRef"; -const std::string MetaDataKey::GeoTransformKey = "GeoTransform"; +char const* GCPProjectionKey = "GCPProjection"; +char const* GCPParametersKey = "GCP_"; +char const* GCPCountKey = "GCPCount"; -const std::string MetaDataKey::MetadataKey = "Metadata_"; -const std::string MetaDataKey::SubMetadataKey = "SubMetadata_"; +char const* GeoTransformKey = "GeoTransform"; -const std::string MetaDataKey::UpperLeftCornerKey = "UpperLeftCorner"; -const std::string MetaDataKey::UpperRightCornerKey = "UpperRightCorner"; -const std::string MetaDataKey::LowerLeftCornerKey = "LowerLeftCorner"; -const std::string MetaDataKey::LowerRightCornerKey = "LowerRightCorner"; +char const* MetadataKey = "Metadata_"; +char const* SubMetadataKey = "SubMetadata_"; -const std::string MetaDataKey::ColorTableNameKey = "ColorTableName"; -const std::string MetaDataKey::ColorEntryCountKey = "ColorEntryCount"; -const std::string MetaDataKey::ColorEntryAsRGBKey = "ColorEntryAsRGB"; +char const* UpperLeftCornerKey = "UpperLeftCorner"; +char const* UpperRightCornerKey = "UpperRightCorner"; +char const* LowerLeftCornerKey = "LowerLeftCorner"; +char const* LowerRightCornerKey = "LowerRightCorner"; -const std::string MetaDataKey::OSSIMKeywordlistKey = "OSSIMKeywordlist"; -const std::string MetaDataKey::OSSIMKeywordlistDelimiterKey = "OSSIMKeywordlistDelimiter"; +char const* ColorTableNameKey = "ColorTableName"; +char const* ColorEntryCountKey = "ColorEntryCount"; +char const* ColorEntryAsRGBKey = "ColorEntryAsRGB"; -const std::string MetaDataKey::VectorDataKeywordlistKey = "VectorDataKeywordlist"; -const std::string MetaDataKey::VectorDataKeywordlistDelimiterKey = "VectorDataKeywordlistDelimiter"; +char const* OSSIMKeywordlistKey = "OSSIMKeywordlist"; +char const* OSSIMKeywordlistDelimiterKey = "OSSIMKeywordlistDelimiter"; -const std::string MetaDataKey::ResolutionFactor = "ResolutionFactor"; -const std::string MetaDataKey::CacheSizeInBytes = "CacheSizeInBytes"; +char const* VectorDataKeywordlistKey = "VectorDataKeywordlist"; +char const* VectorDataKeywordlistDelimiterKey = "VectorDataKeywordlistDelimiter"; -const std::string MetaDataKey::TileHintX = "TileHintX"; -const std::string MetaDataKey::TileHintY = "TileHintY"; +char const* ResolutionFactor = "ResolutionFactor"; +char const* CacheSizeInBytes = "CacheSizeInBytes"; -MetaDataKey::MetaDataKey() {} -MetaDataKey::~MetaDataKey() {} +char const* TileHintX = "TileHintX"; +char const* TileHintY = "TileHintY"; +} const MetaDataKey::KeyTypeDef Types[] = { diff --git a/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.h b/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.h index feec97cbd1..f75a533cbe 100644 --- a/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.h +++ b/Code/UtilitiesAdapters/OssimAdapters/otbMetaDataKey.h @@ -26,55 +26,45 @@ namespace otb { -/** \class MetaDataKey - * - * \brief Creation of an otb::MetaDataKey class that defines the - * key of metadata used in the metadata dictionary. - * +/** \namespace MetaDataKey + * Definition of the key of metadata used in the metadata dictionary. */ -class ITK_EXPORT MetaDataKey +namespace MetaDataKey { -public: - - typedef MetaDataKey Self; - - MetaDataKey(); - virtual ~MetaDataKey(); + extern char const* DriverShortNameKey; + extern char const* DriverLongNameKey; - static const std::string DriverShortNameKey; - static const std::string DriverLongNameKey; + extern char const* ProjectionRefKey; - static const std::string ProjectionRefKey; + extern char const* GCPProjectionKey; + extern char const* GCPParametersKey; + extern char const* GCPCountKey; - static const std::string GCPProjectionKey; - static const std::string GCPParametersKey; - static const std::string GCPCountKey; + extern char const* GeoTransformKey; - static const std::string GeoTransformKey; + extern char const* MetadataKey; + extern char const* SubMetadataKey; - static const std::string MetadataKey; - static const std::string SubMetadataKey; + extern char const* UpperLeftCornerKey; + extern char const* UpperRightCornerKey; + extern char const* LowerLeftCornerKey; + extern char const* LowerRightCornerKey; - static const std::string UpperLeftCornerKey; - static const std::string UpperRightCornerKey; - static const std::string LowerLeftCornerKey; - static const std::string LowerRightCornerKey; + extern char const* ColorTableNameKey; + extern char const* ColorEntryCountKey; + extern char const* ColorEntryAsRGBKey; - static const std::string ColorTableNameKey; - static const std::string ColorEntryCountKey; - static const std::string ColorEntryAsRGBKey; + extern char const* OSSIMKeywordlistKey; + extern char const* OSSIMKeywordlistDelimiterKey; - static const std::string OSSIMKeywordlistKey; - static const std::string OSSIMKeywordlistDelimiterKey; + extern char const* VectorDataKeywordlistKey; + extern char const* VectorDataKeywordlistDelimiterKey; - static const std::string VectorDataKeywordlistKey; - static const std::string VectorDataKeywordlistDelimiterKey; + extern char const* ResolutionFactor; + extern char const* CacheSizeInBytes; - static const std::string ResolutionFactor; - static const std::string CacheSizeInBytes; - - static const std::string TileHintX; - static const std::string TileHintY; + extern char const* TileHintX; + extern char const* TileHintY; enum KeyType @@ -112,12 +102,7 @@ public: typedef std::vector<double> VectorType; typedef itk::VariableLengthVector<double> VariableLengthVectorType; - -private: - MetaDataKey(const Self &); //purposely not implemented - void operator =(const Self&); //purposely not implemented - -}; +} /** \class OTB_GCP * @@ -154,7 +139,7 @@ public: ~OTB_GCP(); OTB_GCP(const OTB_GCP &pGcp); - + void operator =(const OTB_GCP& pGcp); void Print(std::ostream& os) const; -- GitLab