+#include <GameServ/DataLayer/File/FileArmorDAO.h>\r
+using GameServ::DataLayer::File::FileArmorDAO;\r
+#include <GameServ/GameLayer/GameObjects/ArmorGO.h>\r
+using GameServ::GameLayer::GameObjects::ArmorGO;\r
+\r
+#include <GameServ/DataLayer/DataLayerExceptions.h>\r
+using GameServ::DataLayer::Exceptions::ResourceException;\r
+using GameServ::DataLayer::Exceptions::DataLayerException;\r
+\r
+#include <GameServ/DataLayer/File/FileId.h>\r
+using GameServ::DataLayer::File::FileId;\r
+\r
+#include <boost/shared_ptr.hpp>\r
+#include <boost/format.hpp>\r
+#include <boost/algorithm/string.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+using boost::shared_ptr;\r
+using boost::format;\r
+using boost::str;\r
+using boost::algorithm::to_upper;\r
+using boost::lexical_cast;\r
+#include <boost/tokenizer.hpp>\r
+typedef boost::tokenizer<boost::char_separator<char> > \r
+ tokenizer;\r
+\r
+#include <string>\r
+using std::string;\r
+\r
+#include <fstream>\r
+using std::ifstream;\r
+using std::getline;\r
+using std::ofstream;\r
+using std::endl;\r
+\r
+#include <map>\r
+using std::map;\r
+\r
+// TODO: Switch filename to be loaded from a config file\r
+FileArmorDAO::FileArmorDAO() : mFilename("data/items/masteritems.dat")\r
+{\r
+ Initialize(GetArmorFilePath());\r
+}\r
+\r
+FileArmorDAO::FileArmorDAO(const string &filename)\r
+{\r
+ Initialize(filename);\r
+}\r
+\r
+FileArmorDAO::~FileArmorDAO()\r
+{\r
+}\r
+\r
+void FileArmorDAO::Initialize(const string &filename)\r
+{\r
+ mFilename = filename;\r
+ LoadArmorCache();\r
+}\r
+\r
+string FileArmorDAO::GetArmorFilePath() const\r
+{\r
+ return mFilename;\r
+}\r
+\r
+shared_ptr<ArmorGO> FileArmorDAO::GetById(const string &Id) const\r
+{\r
+ string line;\r
+ ifstream infile;\r
+ infile.open(GetArmorFilePath().c_str());\r
+\r
+ if (infile.fail())\r
+ {\r
+ throw ResourceException(str(format("Unable to open file %1%") % GetArmorFilePath()), __FILE__, __LINE__);\r
+ }\r
+\r
+\r
+ while (getline(infile, line))\r
+ {\r
+ shared_ptr<ArmorGO> spArmor = CreateArmorFromLine(line);\r
+ if (spArmor->Id() == Id)\r
+ {\r
+ return spArmor;\r
+ }\r
+ }\r
+ return shared_ptr<ArmorGO>();\r
+}\r
+\r
+shared_ptr<ArmorGO> FileArmorDAO::CreateArmorFromLine(const string &line) const\r
+{\r
+ assert(!line.empty());\r
+ shared_ptr<ArmorGO> spArmor;\r
+ spArmor = shared_ptr<ArmorGO>(new ArmorGO());\r
+ boost::char_separator<char> sep(" ", 0, boost::keep_empty_tokens);\r
+ tokenizer tokens(line, sep);\r
+ tokenizer::iterator tok_iter = tokens.begin();\r
+\r
+\r
+\r
+ return spArmor;\r
+}\r
+bool FileArmorDAO::IdExists(const string &Id) const\r
+{\r
+ map<string, shared_ptr<ArmorGO> >::const_iterator iter;\r
+ iter = spArmorCache.find(Id);\r
+ return (iter != spArmorCache.end());\r
+}\r
+\r
+void FileArmorDAO::LoadArmorCache(void)\r
+{\r
+}
\ No newline at end of file