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<> 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_));
} }
if (count_ > 0) {
//! Specialization for WError pos = msg.find("%1");
template<> if (pos != std::string::npos) {
const char* BasicError<wchar_t>::what() const throw() msg.replace(pos, 2, arg1_);
{
// Todo: Return something more useful
return 0;
} }
}
//! Specialization for Error if (count_ > 1) {
template<> pos = msg.find("%2");
const wchar_t* BasicError<char>::wwhat() const throw() if (pos != std::string::npos) {
{ msg.replace(pos, 2, arg2_);
// Todo: Return something more useful }
return 0; }
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<> 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) 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() @brief Return the error message as a C-string. The pointer returned by what()
is valid only as long as the BasicError object exists. 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 @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. 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: private:
//! @name Manipulators //! @name Manipulators
//@{ //@{
EXV_DLLLOCAL void setMsg(); EXIV2API void setMsg();
//@} //@}
// DATA // DATA
@ -140,7 +140,8 @@ namespace Exiv2 {
std::basic_string<charT> arg1_; //!< First argument std::basic_string<charT> arg1_; //!< First argument
std::basic_string<charT> arg2_; //!< Second argument std::basic_string<charT> arg2_; //!< Second argument
std::basic_string<charT> arg3_; //!< Third 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 }; // class BasicError
@ -160,17 +161,6 @@ namespace Exiv2 {
setMsg(); 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> template<typename charT> template<typename A>
BasicError<charT>::BasicError(int code, const A& arg1) BasicError<charT>::BasicError(int code, const A& arg1)
: code_(code), count_(1), arg1_(toBasicString<charT>(arg1)) : code_(code), count_(1), arg1_(toBasicString<charT>(arg1))
@ -198,40 +188,26 @@ namespace Exiv2 {
} }
template<typename charT> 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"; template<typename charT>
tph.assign(ph.begin(), ph.end()); int BasicError<charT>::code() const throw()
pos = msg_.find(tph); {
if (pos != std::basic_string<charT>::npos) { return code_;
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>
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 #ifdef _MSC_VER

Loading…
Cancel
Save