Fix test_no_rtti test

extended_type_info system not based on type_id

[SVN r55324]
This commit is contained in:
Robert Ramey
2009-07-31 21:02:48 +00:00
parent 8dd591e640
commit 3274bab1c9
4 changed files with 64 additions and 44 deletions

View File

@@ -12,8 +12,6 @@
# pragma warning (disable : 4786) // too long name, harmless warning
#endif
#include <set>
#define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/basic_serializer.hpp>
#include <boost/archive/detail/basic_serializer_map.hpp>
@@ -25,45 +23,52 @@ namespace boost {
namespace archive {
namespace detail {
bool
basic_serializer_map::type_info_pointer_compare::operator()(
const basic_serializer * lhs, const basic_serializer * rhs
) const {
return *lhs < *rhs;
}
// note: We can't implement this as an associative
// container as such a container might be dependent
// upon the extended_type_info::m_key which might not
// be assigned until later. So we use a "slower" method.
// This not a big deal however as the slower "find" operations
// operations are only called occasionally:
// a) At module unloading
// b) Once per input archive - the value is cached in the archive
// implemenation.
BOOST_ARCHIVE_DECL(bool)
BOOST_ARCHIVE_DECL(void)
basic_serializer_map::insert(const basic_serializer * bs){
return m_map.insert(bs).second;
m_map.push_back(bs);
}
BOOST_ARCHIVE_DECL(void)
basic_serializer_map::erase(const basic_serializer * bs){
map_type::iterator it = m_map.begin();
map_type::iterator it_end = m_map.end();
while(it != it_end){
// note item 9 from Effective STL !!! it++
if(*it == bs)
m_map.erase(it++);
else
it++;
it = std::find(it, it_end, bs);
if(it != it_end){
m_map.erase(it);
}
// note: we can't do this since some of the eti records
// we're pointing to might be expired and the comparison
// won't work. Leave this as a reminder not to "optimize" this.
//it = m_map.find(bs);
//assert(it != m_map.end());
//if(*it == bs)
// m_map.erase(it);
else
assert(false); // this should never occur
}
class equals {
const boost::serialization::extended_type_info * m_eti;
public:
bool operator()(const basic_serializer * bs) const {
return *m_eti == bs->get_eti();
}
equals(const boost::serialization::extended_type_info * eti) :
m_eti(eti)
{}
};
// find the "oldest" matching pointer serializer
BOOST_ARCHIVE_DECL(const basic_serializer *)
basic_serializer_map::find(
const boost::serialization::extended_type_info & eti
) const {
const basic_serializer_arg bs(eti);
map_type::const_iterator it;
it = m_map.find(& bs);
map_type::const_iterator it = m_map.begin();
map_type::const_iterator it_end = m_map.end();
it = std::find_if(it, it_end, equals(& eti));
assert(it != m_map.end());
return *it;
}