made entry not require exceptions

This commit is contained in:
Arvid Norberg 2007-11-02 02:02:52 +00:00
parent cb9fbea5f7
commit 53c125a9b3
2 changed files with 29 additions and 0 deletions

View File

@ -161,8 +161,10 @@ namespace libtorrent
// is a dictionary, otherwise they will throw // is a dictionary, otherwise they will throw
entry& operator[](char const* key); entry& operator[](char const* key);
entry& operator[](std::string const& key); entry& operator[](std::string const& key);
#ifndef BOOST_NO_EXCEPTIONS
const entry& operator[](char const* key) const; const entry& operator[](char const* key) const;
const entry& operator[](std::string const& key) const; const entry& operator[](std::string const& key) const;
#endif
entry* find_key(char const* key); entry* find_key(char const* key);
entry const* find_key(char const* key) const; entry const* find_key(char const* key) const;
@ -221,55 +223,80 @@ namespace libtorrent
copy(e); copy(e);
} }
inline entry::integer_type& entry::integer() inline entry::integer_type& entry::integer()
{ {
if (m_type == undefined_t) construct(int_t); if (m_type == undefined_t) construct(int_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != int_t) throw type_error("invalid type requested from entry"); if (m_type != int_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == int_t);
return *reinterpret_cast<integer_type*>(data); return *reinterpret_cast<integer_type*>(data);
} }
inline entry::integer_type const& entry::integer() const inline entry::integer_type const& entry::integer() const
{ {
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != int_t) throw type_error("invalid type requested from entry"); if (m_type != int_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == int_t);
return *reinterpret_cast<const integer_type*>(data); return *reinterpret_cast<const integer_type*>(data);
} }
inline entry::string_type& entry::string() inline entry::string_type& entry::string()
{ {
if (m_type == undefined_t) construct(string_t); if (m_type == undefined_t) construct(string_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != string_t) throw type_error("invalid type requested from entry"); if (m_type != string_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == string_t);
return *reinterpret_cast<string_type*>(data); return *reinterpret_cast<string_type*>(data);
} }
inline entry::string_type const& entry::string() const inline entry::string_type const& entry::string() const
{ {
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != string_t) throw type_error("invalid type requested from entry"); if (m_type != string_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == string_t);
return *reinterpret_cast<const string_type*>(data); return *reinterpret_cast<const string_type*>(data);
} }
inline entry::list_type& entry::list() inline entry::list_type& entry::list()
{ {
if (m_type == undefined_t) construct(list_t); if (m_type == undefined_t) construct(list_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != list_t) throw type_error("invalid type requested from entry"); if (m_type != list_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == list_t);
return *reinterpret_cast<list_type*>(data); return *reinterpret_cast<list_type*>(data);
} }
inline entry::list_type const& entry::list() const inline entry::list_type const& entry::list() const
{ {
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != list_t) throw type_error("invalid type requested from entry"); if (m_type != list_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == list_t);
return *reinterpret_cast<const list_type*>(data); return *reinterpret_cast<const list_type*>(data);
} }
inline entry::dictionary_type& entry::dict() inline entry::dictionary_type& entry::dict()
{ {
if (m_type == undefined_t) construct(dictionary_t); if (m_type == undefined_t) construct(dictionary_t);
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != dictionary_t) throw type_error("invalid type requested from entry"); if (m_type != dictionary_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == dictionary_t);
return *reinterpret_cast<dictionary_type*>(data); return *reinterpret_cast<dictionary_type*>(data);
} }
inline entry::dictionary_type const& entry::dict() const inline entry::dictionary_type const& entry::dict() const
{ {
#ifndef BOOST_NO_EXCEPTIONS
if (m_type != dictionary_t) throw type_error("invalid type requested from entry"); if (m_type != dictionary_t) throw type_error("invalid type requested from entry");
#endif
TORRENT_ASSERT(m_type == dictionary_t);
return *reinterpret_cast<const dictionary_type*>(data); return *reinterpret_cast<const dictionary_type*>(data);
} }

View File

@ -126,6 +126,7 @@ namespace libtorrent
return &i->second; return &i->second;
} }
#ifndef BOOST_NO_EXCEPTIONS
const entry& entry::operator[](char const* key) const const entry& entry::operator[](char const* key) const
{ {
dictionary_type::const_iterator i = dict().find(key); dictionary_type::const_iterator i = dict().find(key);
@ -138,6 +139,7 @@ namespace libtorrent
{ {
return (*this)[key.c_str()]; return (*this)[key.c_str()];
} }
#endif
entry::entry(dictionary_type const& v) entry::entry(dictionary_type const& v)
{ {