#ifndef ASSETIARCHIVE_H #define ASSETIARCHIVE_H #include #include #include #include #include template< class AssetManagerType, class AssetType > class asset_iarchive : public boost::archive::text_iarchive_impl< asset_iarchive > { friend class CubesDemo; typedef boost::archive::text_iarchive_impl< asset_iarchive > archive_base_t; private: AssetManagerType* TheAssetManager; osBool RootAssetLoaded; public: asset_iarchive(AssetManagerType* theAssetManager, std::istream& is, unsigned int flags = 0) :archive_base_t(is, flags) ,TheAssetManager(theAssetManager) ,RootAssetLoaded(false) {} ~asset_iarchive() { } public: template bool load_object_ptr_custom(T& t) { BOOST_STATIC_ASSERT(boost::is_pointer::value); if (boost::is_base_of::type >::value) { if (!RootAssetLoaded) { RootAssetLoaded = true; return false; } else { AssetManagerType::ResourceID ResourceId; operator&(ResourceId); AssetType* a = TheAssetManager->FindAsset(ResourceId); if (!a) { a = TheAssetManager->LoadAsset(ResourceId); } t = static_cast(a); return true; } } else { return false; } } }; #include #include #include #include "AssetManager.hpp" #include "Asset.hpp" namespace boost { namespace archive { template class basic_text_iarchive< asset_iarchive > ; template class text_iarchive_impl< asset_iarchive > ; template class detail::archive_pointer_iserializer< asset_iarchive > ; } // namespace archive } // namespace boost #define BOOST_ARCHIVE_CUSTOM_IARCHIVE_TYPES asset_iarchive #endif//ASSETIARCHIVE_H