Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

snesgamegeniecode.cc

Go to the documentation of this file.
00001 /*
00002  * Game Genie Encoder/Decoder
00003  * Copyright (C) 2004-2005 emuWorks
00004  * http://games.technoplaza.net/
00005  *
00006  * This file is part of Game Genie Encoder/Decoder.
00007  *
00008  * Game Genie Encoder/Decoder is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Game Genie Encoder/Decoder is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Game Genie Encoder/Decoder; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00021  */
00022  
00023 // $Id: snesgamegeniecode.cc,v 1.4 2005/07/30 02:36:45 technoplaza Exp $
00024 
00025 #include "snesgamegeniecode.hh"
00026 #include "../exceptions/invalidgamegeniecode.hh"
00027 
00028 using namespace emuWorks;
00029 
00030 const char SNESGameGenieCode::ALPHABET[] = {
00031     'D', 'F', '4', '7', '0', '9', '1', '5',
00032     '6', 'B', 'C', '8', 'A', '2', '3', 'E'
00033 };
00034 
00035 SNESGameGenieCode SNESGameGenieCode::create(QString &code) {
00036     if (isValidCode(code)) {
00037         return SNESGameGenieCode(code);
00038     }
00039     
00040     throw InvalidGameGenieCodeException();
00041 }
00042 
00043 bool SNESGameGenieCode::isValidCode(QString &code) {
00044     SNESGameGenieCode temp(code);
00045     
00046     const char *alphabet = temp.getAlphabet();
00047     int count = temp.getAlphabetCount();
00048     
00049     QString upper = code.toUpper();
00050     int length = upper.length();
00051     
00052     if (length != 9) {
00053         return false;
00054     }
00055     
00056     if (code[4] != '-') {
00057         return false;
00058     }
00059     
00060     for (int i = 0; i < length; i++) {
00061         if (i == 4) {
00062             continue;
00063         }
00064         
00065         bool found = false;
00066         QChar ch = code[i];
00067         char letter = ch.toAscii();
00068         
00069         for (int j = 0; j < count; j++) {
00070             if (letter == alphabet[j]) {
00071                 found = true;
00072                 break;
00073             }
00074         }
00075         
00076         if (!found) {
00077             return false;
00078         }
00079     }
00080     
00081     return true;
00082 }
00083 
00084 const char *SNESGameGenieCode::getAlphabet() {
00085     return ALPHABET;
00086 }
00087 

Generated on Sat Jul 30 15:01:51 2005 for Game Genie Encoder/Decoder by  doxygen 1.4.4