added type() to alerts, to not require rtti support

This commit is contained in:
Arvid Norberg 2009-10-30 03:21:25 +00:00
parent cd0fc85b5f
commit 380dbd5600
3 changed files with 246 additions and 338 deletions

View File

@ -4723,12 +4723,35 @@ is its synopsis:
virtual ~alert();
virtual int type() const = 0;
virtual std::string message() const = 0;
virtual char const* what() const = 0;
virtual int category() const = 0;
virtual std::auto_ptr<alert> clone() const = 0;
};
``type()`` returns an integer that is unique to this alert type. It can be
compared against a specific alert by querying a static constant called ``alert_type``
in the alert. It can be used to determine the run-time type of an alert* in
order to cast to that alert type and access specific members.
e.g::
std::auto_ptr<alert> a = ses.pop_alert();
switch (a->type())
{
case read_piece_alert::alert_type:
{
read_piece_alert* p = (read_piece_alert*)a.get();
// use p
break;
}
case file_renamed_alert::alert_type:
{
// etc...
}
}
``what()`` returns a string literal describing the type of the alert. It does
not include any information that might be bundled with the alert.
@ -4844,7 +4867,7 @@ mappings.
``mapping`` refers to the mapping index of the port map that failed, i.e.
the index returned from add_mapping_.
``type`` is 0 for NAT-PMP and 1 for UPnP.
``map_type`` is 0 for NAT-PMP and 1 for UPnP.
``error`` tells you what failed.
::
@ -4879,7 +4902,7 @@ the index returned from add_mapping_.
// ...
int mapping;
int external_port;
int type;
int map_type;
};
portmap_log_alert
@ -4895,7 +4918,7 @@ for debugging the UPnP or NAT-PMP implementation.
struct portmap_log_alert: alert
{
//...
int type;
int map_type;
std::string msg;
};

View File

@ -69,8 +69,10 @@ namespace libtorrent {
{
public:
#ifndef TORRENT_NO_DEPRECATE
// only here for backwards compatibility
enum severity_t { debug, info, warning, critical, fatal, none };
#endif
enum category_t
{
@ -95,6 +97,7 @@ namespace libtorrent {
// a timestamp is automatically created in the constructor
ptime timestamp() const;
virtual int type() const = 0;
virtual char const* what() const = 0;
virtual std::string message() const = 0;
virtual int category() const = 0;
@ -158,6 +161,8 @@ namespace libtorrent {
unhandled_alert() {}
};
#ifndef BOOST_NO_TYPEID
namespace detail {
struct void_;
@ -206,6 +211,9 @@ namespace libtorrent {
}
};
#endif // BOOST_NO_TYPEID
} // namespace libtorrent
#endif // TORRENT_ALERT_HPP_INCLUDED

File diff suppressed because it is too large Load Diff