More W/Error changes to better support w/what().

v0.27.3
Andreas Huggel 16 years ago
parent 50d9dce7af
commit 18f1cc97b7

@ -115,34 +115,69 @@ namespace Exiv2 {
{
}
//! Specialization for Error
template<>
const char* BasicError<char>::what() const throw()
void BasicError<char>::setMsg()
{
return msg_.c_str();
std::string msg = _(errMsg(code_));
std::string::size_type pos;
pos = msg.find("%0");
if (pos != std::string::npos) {
msg.replace(pos, 2, toString(code_));
}
//! Specialization for WError
template<>
const char* BasicError<wchar_t>::what() const throw()
{
// Todo: Return something more useful
return 0;
if (count_ > 0) {
pos = msg.find("%1");
if (pos != std::string::npos) {
msg.replace(pos, 2, arg1_);
}
//! Specialization for Error
template<>
const wchar_t* BasicError<char>::wwhat() const throw()
{
// Todo: Return something more useful
return 0;
}
if (count_ > 1) {
pos = msg.find("%2");
if (pos != std::string::npos) {
msg.replace(pos, 2, arg2_);
}
}
if (count_ > 2) {
pos = msg.find("%3");
if (pos != std::string::npos) {
msg.replace(pos, 2, arg3_);
}
}
msg_ = msg;
#ifdef EXV_UNICODE_PATH
wmsg_ = s2ws(msg);
#endif
}
//! Specialization for Error
template<>
const wchar_t* BasicError<wchar_t>::wwhat() const throw()
void BasicError<wchar_t>::setMsg()
{
return msg_.c_str();
std::string s = _(errMsg(code_));
std::wstring wmsg(s.begin(), s.end());
std::wstring::size_type pos;
pos = wmsg.find(L"%0");
if (pos != std::wstring::npos) {
wmsg.replace(pos, 2, toBasicString<wchar_t>(code_));
}
if (count_ > 0) {
pos = wmsg.find(L"%1");
if (pos != std::wstring::npos) {
wmsg.replace(pos, 2, arg1_);
}
}
if (count_ > 1) {
pos = wmsg.find(L"%2");
if (pos != std::wstring::npos) {
wmsg.replace(pos, 2, arg2_);
}
}
if (count_ > 2) {
pos = wmsg.find(L"%3");
if (pos != std::wstring::npos) {
wmsg.replace(pos, 2, arg3_);
}
}
wmsg_ = wmsg;
// msg_ = ws2s(wmsg);
}
const char* errMsg(int code)

@ -120,18 +120,18 @@ namespace Exiv2 {
@brief Return the error message as a C-string. The pointer returned by what()
is valid only as long as the BasicError object exists.
*/
EXIV2API virtual const char* what() const throw();
EXV_DLLLOCAL virtual const char* what() const throw();
/*!
@brief Return the error message as a wchar_t-string. The pointer returned by
wwhat() is valid only as long as the BasicError object exists.
*/
EXIV2API virtual const wchar_t* wwhat() const throw();
EXV_DLLLOCAL virtual const wchar_t* wwhat() const throw();
//@}
private:
//! @name Manipulators
//@{
EXV_DLLLOCAL void setMsg();
EXIV2API void setMsg();
//@}
// DATA
@ -140,7 +140,8 @@ namespace Exiv2 {
std::basic_string<charT> arg1_; //!< First argument
std::basic_string<charT> arg2_; //!< Second argument
std::basic_string<charT> arg3_; //!< Third argument
std::basic_string<charT> msg_; //!< Complete error message
std::string msg_; //!< Complete error message
std::wstring wmsg_; //!< Complete error message as a wide string
}; // class BasicError
@ -160,17 +161,6 @@ namespace Exiv2 {
setMsg();
}
template<typename charT>
BasicError<charT>::~BasicError() throw()
{
}
template<typename charT>
int BasicError<charT>::code() const throw()
{
return code_;
}
template<typename charT> template<typename A>
BasicError<charT>::BasicError(int code, const A& arg1)
: code_(code), count_(1), arg1_(toBasicString<charT>(arg1))
@ -198,40 +188,26 @@ namespace Exiv2 {
}
template<typename charT>
void BasicError<charT>::setMsg()
BasicError<charT>::~BasicError() throw()
{
std::string s(exvGettext(errMsg(code_)));
msg_.assign(s.begin(), s.end());
std::string ph("%0");
std::basic_string<charT> tph(ph.begin(), ph.end());
size_t pos = msg_.find(tph);
if (pos != std::basic_string<charT>::npos) {
msg_.replace(pos, 2, toBasicString<charT>(code_));
}
if (count_ > 0) {
ph = "%1";
tph.assign(ph.begin(), ph.end());
pos = msg_.find(tph);
if (pos != std::basic_string<charT>::npos) {
msg_.replace(pos, 2, arg1_);
}
}
if (count_ > 1) {
ph = "%2";
tph.assign(ph.begin(), ph.end());
pos = msg_.find(tph);
if (pos != std::basic_string<charT>::npos) {
msg_.replace(pos, 2, arg2_);
}
}
if (count_ > 2) {
ph = "%3";
tph.assign(ph.begin(), ph.end());
pos = msg_.find(tph);
if (pos != std::basic_string<charT>::npos) {
msg_.replace(pos, 2, arg3_);
template<typename charT>
int BasicError<charT>::code() const throw()
{
return code_;
}
template<typename charT>
const char* BasicError<charT>::what() const throw()
{
return msg_.c_str();
}
template<typename charT>
const wchar_t* BasicError<charT>::wwhat() const throw()
{
return wmsg_.c_str();
}
#ifdef _MSC_VER

Loading…
Cancel
Save