[svn-r8269] Purpose:

Cleaning up warnings

Description:
    Many exception constructors have warnings about reference to temporary
    location because of the parameter initialization, for example,
    "const string& var = 0."

Solution:
    Changed "string&" parameters to pass by value for these constructors.
    Consequently, passing string by value also takes care of char pointers
    so the overloaded constructors for char pointers are then removed.
    Also, instead of setting Exception::detailMessage to null string, I
    set it to DEFAULT_MSG ("No detailed information provided") by default.

Platforms:
    SunOS 5.7 (arabica)
    Linux 2.4 (eirene)
    IA-64 (titan)
This commit is contained in:
Binh-Minh Ribler 2004-03-21 21:56:59 -05:00
parent 7fb0362eed
commit 9e3178fedf
7 changed files with 34 additions and 70 deletions

View File

@ -116,7 +116,7 @@ class H5_DLLCPP CommonFG {
StrType openStrType( const char* name ) const;
// for H5File and Group to throw appropriate exception
virtual void throwException(const string& func_name, const string& msg) const = 0;
virtual void throwException(const string func_name, const string msg) const = 0;
CommonFG();
virtual ~CommonFG();

View File

@ -22,32 +22,13 @@ namespace H5 {
#endif // H5_NO_STD
#endif
const string Exception::DEFAULT_MSG("No detailed information provided");
// Default constructor
Exception::Exception() : detailMessage(""), funcName("") {}
// Constructor taking only a detailed message as string object
//Exception::Exception(const string& message) : detailMessage(message) {}
// Constructor taking a function name and a detailed message as string objects
Exception::Exception(const string& func_name, const string& message) : detailMessage(message), funcName(func_name) {}
// Constructor taking a detailed message as character string
// digital alpha (gondolin) produces compilation error at static_cast<string>
// so I replaced this constructor by the one below it
//Exception::Exception( const char* message) : detailMessage(static_cast<string>(message)) {}
//Exception::Exception(const char* message)
//{
//detailMessage = string(message);
//}
// Constructor taking a function name and a detailed message as character
// strings
Exception::Exception(const char* func_name, const char* message)
{
detailMessage = string(message);
if (func_name != NULL)
funcName = string(func_name);
}
Exception::Exception(const string func_name, const string message) : detailMessage(message), funcName(func_name) {}
// copy constructor
Exception::Exception( const Exception& orig )
@ -153,7 +134,7 @@ const char* Exception::getCFuncName() const
// Prints the error stack in a default manner.
void Exception::printError( FILE* stream ) const
{
herr_t ret_value = H5Eprint( H5E_DEFAULT, NULL ); // print to stderr
herr_t ret_value = H5Eprint( H5E_DEFAULT, stream ); // print to stderr
if( ret_value < 0 )
throw Exception( "Exception::printError", "H5Eprint failed" );
}
@ -161,53 +142,43 @@ void Exception::printError( FILE* stream ) const
Exception::~Exception() {}
FileIException::FileIException():Exception(){}
FileIException::FileIException(const string& func_name, const string& message) : Exception(func_name, message) {}
FileIException::FileIException(const char* func_name, const char* message) : Exception(func_name, message) {}
FileIException::FileIException(const string func_name, const string message) : Exception(func_name, message) {}
FileIException::~FileIException() {}
GroupIException::GroupIException():Exception(){}
GroupIException::GroupIException(const string& func_name, const string& message) : Exception(func_name, message) {}
GroupIException::GroupIException(const char* func_name, const char* message) : Exception(func_name, message) {}
GroupIException::GroupIException(const string func_name, const string message) : Exception(func_name, message) {}
GroupIException::~GroupIException() {}
DataSpaceIException::DataSpaceIException():Exception(){}
DataSpaceIException::DataSpaceIException(const string& func_name, const string& message) : Exception(func_name, message) {}
DataSpaceIException::DataSpaceIException(const char* func_name, const char* message) : Exception(func_name, message) {}
DataSpaceIException::DataSpaceIException(const string func_name, const string message) : Exception(func_name, message) {}
DataSpaceIException::~DataSpaceIException() {}
DataTypeIException::DataTypeIException():Exception(){}
DataTypeIException::DataTypeIException(const string& func_name, const string& message) : Exception(func_name, message) {}
DataTypeIException::DataTypeIException(const char* func_name, const char* message) : Exception(func_name, message) {}
DataTypeIException::DataTypeIException(const string func_name, const string message) : Exception(func_name, message) {}
DataTypeIException::~DataTypeIException() {}
PropListIException::PropListIException():Exception(){}
PropListIException::PropListIException(const string& func_name, const string& message) : Exception(func_name, message) {}
PropListIException::PropListIException(const char* func_name, const char* message) : Exception(func_name, message) {}
PropListIException::PropListIException(const string func_name, const string message) : Exception(func_name, message) {}
PropListIException::~PropListIException() {}
DataSetIException::DataSetIException():Exception(){}
DataSetIException::DataSetIException(const string& func_name, const string& message) : Exception(func_name, message) {}
DataSetIException::DataSetIException(const char* func_name, const char* message) : Exception(func_name, message) {}
DataSetIException::DataSetIException(const string func_name, const string message) : Exception(func_name, message) {}
DataSetIException::~DataSetIException() {}
AttributeIException::AttributeIException():Exception(){}
AttributeIException::AttributeIException(const string& func_name, const string& message) : Exception(func_name, message) {}
AttributeIException::AttributeIException(const char* func_name, const char* message) : Exception(func_name, message) {}
AttributeIException::AttributeIException(const string func_name, const string message) : Exception(func_name, message) {}
AttributeIException::~AttributeIException() {}
ReferenceException::ReferenceException():Exception(){}
ReferenceException::ReferenceException(const string& func_name, const string& message) : Exception(func_name, message) {}
ReferenceException::ReferenceException(const char* func_name, const char* message) : Exception(func_name, message) {}
ReferenceException::ReferenceException(const string func_name, const string message) : Exception(func_name, message) {}
ReferenceException::~ReferenceException() {}
LibraryIException::LibraryIException():Exception(){}
LibraryIException::LibraryIException(const string& func_name, const string& message) : Exception(func_name, message) {}
LibraryIException::LibraryIException(const char* func_name, const char* message) : Exception(func_name, message) {}
LibraryIException::LibraryIException(const string func_name, const string message) : Exception(func_name, message) {}
LibraryIException::~LibraryIException() {}
IdComponentException::IdComponentException(): Exception() {}
IdComponentException::IdComponentException(const string& func_name, const string& message) : Exception(func_name, message) {}
IdComponentException::IdComponentException(const char* func_name, const char* message) : Exception(func_name, message) {}
IdComponentException::IdComponentException(const string func_name, const string message) : Exception(func_name, message) {}
IdComponentException::~IdComponentException() {}
#ifndef H5_NO_NAMESPACE

View File

@ -32,8 +32,7 @@ class H5_DLLCPP Exception {
// Creates an exception with a function name where the failure occurs
// and an optional detailed message
Exception( const string& func_name, const string& message = 0);
Exception( const char* func_name, const char* message = NULL);
Exception(const string func_name, const string message = DEFAULT_MSG);
// copy constructor
Exception( const Exception& orig);
@ -85,85 +84,79 @@ class H5_DLLCPP Exception {
#endif
string detailMessage;
string funcName;
protected:
// Default value for detailMessage
static const string DEFAULT_MSG;
};
class H5_DLLCPP FileIException : public Exception {
public:
FileIException();
FileIException( const string& func_name, const string& message = NULL);
FileIException( const char* func_name, const char* message = NULL);
FileIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~FileIException();
};
class H5_DLLCPP GroupIException : public Exception {
public:
GroupIException();
GroupIException( const string& func_name, const string& message=NULL);
GroupIException( const char* func_name, const char* message = NULL);
GroupIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~GroupIException();
};
class H5_DLLCPP DataSpaceIException : public Exception {
public:
DataSpaceIException();
DataSpaceIException(const string& func_name, const string& message=NULL);
DataSpaceIException(const char* func_name, const char* message = NULL);
DataSpaceIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~DataSpaceIException();
};
class H5_DLLCPP DataTypeIException : public Exception {
public:
DataTypeIException();
DataTypeIException(const string& func_name, const string& message = NULL);
DataTypeIException(const char* func_name, const char* message = NULL);
DataTypeIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~DataTypeIException();
};
class H5_DLLCPP PropListIException : public Exception {
public:
PropListIException();
PropListIException(const string& func_name, const string& message=NULL);
PropListIException(const char* func_name, const char* message = NULL);
PropListIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~PropListIException();
};
class H5_DLLCPP DataSetIException : public Exception {
public:
DataSetIException();
DataSetIException(const string& func_name, const string& message=NULL);
DataSetIException(const char* func_name, const char* message = NULL);
DataSetIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~DataSetIException();
};
class H5_DLLCPP AttributeIException : public Exception {
public:
AttributeIException();
AttributeIException(const string& func_name, const string& message=NULL);
AttributeIException(const char* func_name, const char* message = NULL);
AttributeIException(const string func_name, const string message = DEFAULT_MSG);
virtual ~AttributeIException();
};
class H5_DLLCPP ReferenceException : public Exception {
public:
ReferenceException();
ReferenceException(const string& func_name, const string& message=NULL);
ReferenceException(const char* func_name, const char* message = NULL);
ReferenceException(const string func_name, const string message=DEFAULT_MSG);
virtual ~ReferenceException();
};
class H5_DLLCPP LibraryIException : public Exception {
public:
LibraryIException();
LibraryIException(const string& func_name, const string& message=NULL);
LibraryIException(const char* func_name, const char* message = NULL);
LibraryIException(const string func_name, const string message=DEFAULT_MSG);
virtual ~LibraryIException();
};
class H5_DLLCPP IdComponentException : public Exception {
public:
IdComponentException();
IdComponentException(const string& func_name, const string& message=NULL);
IdComponentException(const char* func_name, const char* message = NULL);
IdComponentException(const string func_name, const string message=DEFAULT_MSG);
virtual ~IdComponentException();
};

View File

@ -185,7 +185,7 @@ void H5File::p_close() const
// exception can be thrown for file or group. The func_name is a member
// function of CommonFG and "H5File::" will be inserted to indicate the
// function called is an implementation of H5File
void H5File::throwException(const string& func_name, const string& msg) const
void H5File::throwException(const string func_name, const string msg) const
{
string full_name = func_name;
full_name.insert(0, "H5File::");

View File

@ -40,7 +40,7 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG {
virtual hid_t getLocId() const;
// Throw file exception
virtual void throwException(const string& func_name, const string& msg) const;
virtual void throwException(const string func_name, const string msg) const;
// Determines if a file, specified by its name, is in HDF5 format

View File

@ -138,7 +138,7 @@ void Group::p_close() const
}
// Throw file exception
void Group::throwException(const string& func_name, const string& msg) const
void Group::throwException(const string func_name, const string msg) const
{
string full_name = func_name;
full_name.insert(0, "Group::");

View File

@ -47,7 +47,7 @@ class H5_DLLCPP Group : public H5Object, public CommonFG {
virtual hid_t getLocId() const;
// Throw group exception
virtual void throwException(const string& func_name, const string& msg) const;
virtual void throwException(const string func_name, const string msg) const;
// Used by the API to appropriately close a group