Skip to content
Snippets Groups Projects
Commit 6dae5967 authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Added mvd::ToStdString() and mvd::FromStdString(); Replaced bad...

ENH: Added mvd::ToStdString() and mvd::FromStdString(); Replaced bad conversions by safe To/FromStdString() functions.
parent ae400996
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@
//
// System includes (sorted by alphabetic order)
#include <string>
//
// ITK includes (sorted by alphabetic order)
......@@ -160,6 +161,34 @@ QStringList&
AppendToQStringList( QStringList& qsl,
const StringVector& sv );
/**
* \brief Convert and copy an STL std::string to a QString.
*
* The 8-bit data is converted to Unicode using the
* QString::fromAscii() method.
*
* \param str The 8-bit STL string to convert.
*
* \return The Unicode converted QString.
*/
inline
QString
FromStdString( const std::string& str );
/**
* \brief Convert and copy a QString to a STL std::string.
*
* The Unicode data is converted to 8-bit using the QString::toAscii()
* method.
*
* \param str The Unicode string to convert.
*
* \return The 8-bit converted STL std::string.
*/
inline
std::string
ToStdString( const QString& str );
} // end namespace 'mvd'.
/*****************************************************************************/
......@@ -269,6 +298,22 @@ AppendToQStringList( QStringList& qsl, const StringVector& sv )
return qsl;
}
/*******************************************************************************/
inline
QString
FromStdString( const std::string& str )
{
return QString( str.c_str() );
}
/*******************************************************************************/
inline
std::string
ToStdString( const QString& str )
{
return std::string( str.toAscii().constData() );
}
/*******************************************************************************/
} // end namespace 'mvd'
......
......@@ -25,8 +25,6 @@
//
// System includes (sorted by alphabetic order)
#include <cerrno>
#include <exception>
//
// ITK includes (sorted by alphabetic order)
......@@ -73,22 +71,7 @@ DatasetModel
if( !pathDir.exists() )
{
/*
qDebug() << "System error: " << errno << " -- '" << strerror( errno ) << "'";
QString message(
QString( "'%1': %2 '%3'" )
.arg( path )
.arg( errno )
.arg( strerror( errno ) )
);
qDebug() << "std::invalid_argument(" << message << ")";
throw std::invalid_argument( message.toAscii().constData() );
*/
throw SystemError( QString( "('%1')" ).arg( path ).toAscii().constData() );
throw SystemError( ToStdString( QString( "('%1')" ).arg( path ) ) );
}
if( !pathDir.exists( name ) )
......@@ -97,7 +80,7 @@ DatasetModel
if( !pathDir.mkpath( name ) )
{
throw SystemError( QString( "('%1')" ).arg( name ).toAscii().constData() );
throw SystemError( ToStdString( QString( "('%1')" ).arg( name ) ) );
}
// TODO: write empty descriptor.xml
......
......@@ -78,7 +78,7 @@ QuicklookModel
VectorImageModel * viModel = qobject_cast< VectorImageModel* >( parent() );
// get the filename and use it to compose the quicklook filename
const char* filename = static_cast<const char*>(viModel->GetFilename().toAscii());
const char* filename = viModel->GetFilename().toAscii().constData();
std::string fnameNoExt = itksys::SystemTools::GetFilenameWithoutExtension( filename );
std::string path = itksys::SystemTools::GetFilenamePath( filename );
......
......@@ -63,8 +63,8 @@ SystemError::whatString( int err, const std::string& msg )
#if 0
// Use Qt's tr() in order for the text string to be translated.
// N.B.: strerror() string may use system locales.
return
( msg.empty()
return ToStdString(
msg.empty()
? tr( "System error %1: '%2'." )
.arg( err )
.arg( strerror( err ) )
......@@ -74,7 +74,7 @@ SystemError::whatString( int err, const std::string& msg )
.arg( strerror( err ) )
.arg( msg )
).toAscii().constData();
);
#else
std::stringstream sstream( std::ios_base::out );
......
......@@ -96,7 +96,7 @@ VectorImageModel
// Get the largest possible region of the image
m_ImageFileReader = DefaultImageFileReaderType::New();
m_ImageFileReader->SetFileName( m_Filename.toAscii().constData() );
m_ImageFileReader->SetFileName( ToStdString( m_Filename ) );
m_ImageFileReader->UpdateOutputInformation();
// Build overviews if necessary
......@@ -124,7 +124,7 @@ VectorImageModel
//m_ImageFileReader->GetAvailableResolutions(m_AvailableLod);
std::string tempfilename(m_Filename.toAscii().constData());
std::string tempfilename( ToStdString( m_Filename ) );
filter->SetInputFileName(tempfilename);
filter->SetNbOfResolutions(m_ImageFileReader->GetAvailableResolutions().size());
......@@ -629,7 +629,7 @@ VectorImageModel
try
{
fileReader->SetFileName( static_cast<const char*>(lodFilename.toAscii()) );
fileReader->SetFileName( ToStdString( lodFilename ) );
fileReader->UpdateOutputInformation();
m_ImageFileReader = fileReader;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment