// -*- C++ -*-
#ifndef SAVELOAD_H
#define SAVELOAD_H

#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>

#include <string>

namespace GG {
    class Wnd;
}

// This function saves any GG::Wnd-derived class to XML archive "ar", saving it with the name "name".
void SaveWnd(const GG::Wnd* wnd, const std::string& name, boost::archive::xml_oarchive& ar);

// This function loads a GG::Wnd-derived class from XML archive "ar", creating a new object on the heap.  The object's
// GG::Wnd* pointer is stored in wnd.
void LoadWnd(GG::Wnd*& wnd, const std::string& name, boost::archive::xml_iarchive& ar);

// Since the above function will only accept a GG::Wnd*, this one is provided to more conveniently accept GG::Wnd
// subclass pointers.
template <class T>
void LoadWnd(T*& wnd, const std::string& name, boost::archive::xml_iarchive& ar)
{
    GG::Wnd* wnd_as_base = wnd;
    LoadWnd(wnd_as_base, name, ar);
    wnd = dynamic_cast<T*>(wnd_as_base);
    assert(wnd);
}

#endif
