keyring.cc

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #include <fstream>
00024 
00025 #include "keyring.h"
00026 #include "utils.h"
00027 #include "fnames.h"
00028 #include "exceptions.h"
00029 
00030 using std::ifstream;
00031 using std::ofstream;
00032 
00033 void Keyring::read()
00034 {
00035   ifstream in;
00036 
00037   // clear keyring first
00038   keys.clear();
00039 
00040   try
00041   {
00042     U7open(in, KEYRINGDAT);
00043   }
00044   catch(exult_exception &e) {
00045     // maybe an old savegame, just leave the keyring empty
00046     return;
00047   }
00048 
00049   do {
00050     int val = Read2(in);
00051     if (in.good())
00052       addkey(val);
00053   } while (in.good());
00054 
00055   in.close();
00056 }
00057 
00058 void Keyring::write()
00059 {
00060   ofstream out;
00061 
00062   U7open(out, KEYRINGDAT);
00063 
00064   std::set<int>::iterator iter;
00065 
00066   for (iter = keys.begin(); iter != keys.end(); ++iter)
00067     Write2(out, *iter);
00068 
00069   out.close();
00070 }
00071 
00072 void Keyring::clear()
00073 {
00074   keys.clear();
00075 }
00076 
00077 void Keyring::addkey(int qual)
00078 {
00079   keys.insert(qual);
00080 }
00081 
00082 bool Keyring::checkkey(int qual)
00083 {
00084   return (keys.find(qual) != keys.end());
00085 }

Generated on Mon Jul 9 14:42:51 2007 for ExultEngine by  doxygen 1.5.1