From 53c125a9b3df0ec282c4e06372ec3cf16132f2b8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 2 Nov 2007 02:02:52 +0000 Subject: [PATCH] made entry not require exceptions --- include/libtorrent/entry.hpp | 27 +++++++++++++++++++++++++++ src/entry.cpp | 2 ++ 2 files changed, 29 insertions(+) diff --git a/include/libtorrent/entry.hpp b/include/libtorrent/entry.hpp index 7fd6c8c53..1c25cc7c7 100755 --- a/include/libtorrent/entry.hpp +++ b/include/libtorrent/entry.hpp @@ -161,8 +161,10 @@ namespace libtorrent // is a dictionary, otherwise they will throw entry& operator[](char const* key); entry& operator[](std::string const& key); +#ifndef BOOST_NO_EXCEPTIONS const entry& operator[](char const* key) const; const entry& operator[](std::string const& key) const; +#endif entry* find_key(char const* key); entry const* find_key(char const* key) const; @@ -221,55 +223,80 @@ namespace libtorrent copy(e); } + inline entry::integer_type& entry::integer() { 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"); +#endif + TORRENT_ASSERT(m_type == int_t); return *reinterpret_cast(data); } 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"); +#endif + TORRENT_ASSERT(m_type == int_t); return *reinterpret_cast(data); } inline entry::string_type& entry::string() { 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"); +#endif + TORRENT_ASSERT(m_type == string_t); return *reinterpret_cast(data); } 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"); +#endif + TORRENT_ASSERT(m_type == string_t); return *reinterpret_cast(data); } inline entry::list_type& entry::list() { 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"); +#endif + TORRENT_ASSERT(m_type == list_t); return *reinterpret_cast(data); } 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"); +#endif + TORRENT_ASSERT(m_type == list_t); return *reinterpret_cast(data); } inline entry::dictionary_type& entry::dict() { 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"); +#endif + TORRENT_ASSERT(m_type == dictionary_t); return *reinterpret_cast(data); } 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"); +#endif + TORRENT_ASSERT(m_type == dictionary_t); return *reinterpret_cast(data); } diff --git a/src/entry.cpp b/src/entry.cpp index 50c6967cc..88800713c 100755 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -126,6 +126,7 @@ namespace libtorrent return &i->second; } +#ifndef BOOST_NO_EXCEPTIONS const entry& entry::operator[](char const* key) const { dictionary_type::const_iterator i = dict().find(key); @@ -138,6 +139,7 @@ namespace libtorrent { return (*this)[key.c_str()]; } +#endif entry::entry(dictionary_type const& v) {