This it the whole header, it's no big secret, but I'm purty sure I'm not missing anything:
Code:
#ifndef DATABASE_H
#define DATABASE_H
#include "Object.h"
#include <map>
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <string>
#include <vector>
class Database
{
public:
typedef boost::shared_ptr<Object_Manager> Raw_Manager;
typedef boost::weak_ptr<Object_Manager> Data_Observer;
typedef std::map<std::string, Raw_Manager> Manager_Map;
// Function to access a specific manager within the map
Data_Observer Access_Manager(std::string Filename)
{
Manager_Map::iterator it = Database_Manager.find(Filename);
// check if the manager exists in the map
if (it == Database_Manager.end())
{
// if not throw an error
std::cout << "Manager does not exist!" << std::endl;
}
else
{
// if so return a pointer to the manager
return Data_Observer(it->second);
}
}
//Save a manager completely to a file
template <typename T>
void Save_to_File(std::string Filename, Object_Manager Data)
{
std::ofstream ofs(Filename.c_str());
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << Data;
Data.erase();
// archive and stream closed when destructors are called
}
// Load a manager from a file and add it to the list of managers
void Read_File(std::string Filename, Object_Manager Data)
{
// create and open an archive for input
std::ifstream ifs(Filename.c_str(), std::ios::binary);
boost::archive::text_iarchive ia(ifs);
// read class state from archive
ia >> Data;
// create a pointer to the data
new Raw_Manager(Data);
// pair the filename with the manager typ for easy access
Database_Manager.insert(std::make_pair(Filename, Data));
// archive and stream closed when destructors are called
}
private:
Manager_Map Database_Manager;
};
#endif
Here is my current error message:
Code:
c:\documents and settings\home\my documents\visual studio 2005\projects\textgame\textgame\database.h(57) : error C2664: 'boost::shared_ptr<T>::shared_ptr(const boost::shared_ptr<T> &)' : cannot convert parameter 1 from 'Object_Manager' to 'const boost::shared_ptr<T> &'
It points to this line:
Code:
void Read_File(std::string Filename, Object_Manager Data)
{
// create and open an archive for input
std::ifstream ifs(Filename.c_str(), std::ios::binary);
boost::archive::text_iarchive ia(ifs);
// read class state from archive
ia >> Data;
// create a pointer to the data
new Raw_Manager(Data);
// pair the filename with the manager typ for easy access
Database_Manager.insert(std::make_pair(Filename, Data));
// archive and stream closed when destructors are called
}