Skip to content

Commit

Permalink
format code with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
jdratlif committed Sep 10, 2022
1 parent 952a59e commit 4817dda
Show file tree
Hide file tree
Showing 32 changed files with 431 additions and 533 deletions.
3 changes: 0 additions & 3 deletions source/exceptions/invalidgamegeniecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: invalidgamegeniecode.cc,v 1.3 2008/12/18 03:23:30 jdratlif Exp $

#include "exceptions/invalidgamegeniecode.hh"

using namespace ggencoder;

13 changes: 5 additions & 8 deletions source/exceptions/invalidgamegeniecode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: invalidgamegeniecode.hh,v 1.8 2008/12/18 03:23:30 jdratlif Exp $

#ifndef GGENCODER_INVALIDGAMEGENIECODEEXCEPTION_HH_
#define GGENCODER_INVALIDGAMEGENIECODEEXCEPTION_HH_
Expand All @@ -32,16 +30,15 @@ namespace ggencoder {
* An exception thrown when a game genie code is invalid.
*/
class InvalidGameGenieCodeException : public std::runtime_error {
public:
public:
/**
* Constructor for an InvalidGameGenieCodeException.
*/
InvalidGameGenieCodeException();
};

inline InvalidGameGenieCodeException::InvalidGameGenieCodeException() :
std::runtime_error("InvalidGameGenieCodeException") {}
}

#endif
inline InvalidGameGenieCodeException::InvalidGameGenieCodeException()
: std::runtime_error("InvalidGameGenieCodeException") {}
} // namespace ggencoder

#endif
7 changes: 2 additions & 5 deletions source/ggencoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: ggencoder.cc,v 1.11 2008/12/18 03:31:46 jdratlif Exp $

#include <QApplication>

Expand All @@ -30,10 +28,9 @@ using namespace ggencoder;

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

GenieDialog dlg;
dlg.show();

return app.exec();
}

3 changes: 0 additions & 3 deletions source/model/comparerawcode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: comparerawcode.cc,v 1.2 2008/12/18 03:23:30 jdratlif Exp $

#include "model/comparerawcode.hh"

using namespace ggencoder;

32 changes: 14 additions & 18 deletions source/model/comparerawcode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Game Genie Encoder/Decoder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* Game Genie Encoder/Decoder is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: comparerawcode.hh,v 1.6 2008/12/18 03:23:30 jdratlif Exp $

#ifndef GGENCODER_COMPARERAWCODE_HH_
#define GGENCODER_COMPARERAWCODE_HH_
Expand All @@ -30,39 +28,37 @@ namespace ggencoder {
* A raw code interface with a compare value.
*/
class CompareRawCode {
protected:
protected:
int compare;
public:

public:
/**
* Checks if this CompareRawCode uses a compare value.
*
* @return true if a compare is used; false otherwise.
*/
bool hasCompare() const;

/**
* Gets the compare value of this CompareRawCode.
*
* @return The compare value.
*/
int getCompare() const;

/**
* Sets the compare value of this CompareRawCode.
*
* @param compare The new compare value.
*/
void setCompare(int compare);
};

inline bool CompareRawCode::hasCompare() const
{ return (compare != -1); }
inline int CompareRawCode::getCompare() const
{ return compare; }
inline void CompareRawCode::setCompare(int compare)
{ this->compare = (compare & 0xFF); };
}

#endif
inline bool CompareRawCode::hasCompare() const { return (compare != -1); }
inline int CompareRawCode::getCompare() const { return compare; }
inline void CompareRawCode::setCompare(int compare) {
this->compare = (compare & 0xFF);
};
} // namespace ggencoder

#endif
11 changes: 4 additions & 7 deletions source/model/gamegeniecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: gamegeniecode.cc,v 1.7 2008/12/18 03:23:30 jdratlif Exp $

#include <cctype>

Expand All @@ -30,16 +28,15 @@ using namespace ggencoder;

int GameGenieCode::toHex(char letter) const {
letter = toupper(letter);

const char *alphabet = getAlphabet();
int count = getAlphabetCount();
int count = getAlphabetCount();

for (int i = 0; i < count; i++) {
if (alphabet[i] == letter) {
return i;
}
}

return -1;
}

34 changes: 15 additions & 19 deletions source/model/gamegeniecode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: gamegeniecode.hh,v 1.9 2008/12/18 03:23:30 jdratlif Exp $

#ifndef GGENCODER_GAMEGENIECODE_HH_
#define GGENCODER_GAMEGENIECODE_HH_
Expand All @@ -32,43 +30,43 @@ namespace ggencoder {
* Interface for a Game Genie code.
*/
class GameGenieCode {
private:
private:
QString code;
public:

public:
/**
* Virtual destructor for a GameGenieCode.
*/
virtual ~GameGenieCode();

/**
* Gets the game genie alphabet.
*
* @return The genie alphabet array.
*/
virtual const char *getAlphabet() const = 0;

/**
* Gets the number of letters in the game genie alphabet.
*
* @return The alphabet letter count.
*/
virtual int getAlphabetCount() const;

/**
* Gets the game genie code.
*
* @return The game genie code.
*/
const QString &getCode() const;

/**
* Sets the game genie code.
*
* @param code The new game genie code.
*/
void setCode(const QString &code);

/**
* Gets the corresponding hex value for a particular game genie letter.
*
Expand All @@ -78,15 +76,13 @@ namespace ggencoder {
*/
virtual int toHex(char letter) const;
};

inline GameGenieCode::~GameGenieCode() {}
inline int GameGenieCode::getAlphabetCount() const
{ return 16; }
inline const QString &GameGenieCode::getCode() const
{ return code; }
inline void GameGenieCode::setCode(const QString &code)
{ this->code = code.toUpper(); }
}
inline int GameGenieCode::getAlphabetCount() const { return 16; }
inline const QString &GameGenieCode::getCode() const { return code; }
inline void GameGenieCode::setCode(const QString &code) {
this->code = code.toUpper();
}
} // namespace ggencoder

#endif

48 changes: 22 additions & 26 deletions source/model/gbgggamegeniecode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,21 @@
* along with Game Genie Encoder/Decoder; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

// $Id: gbgggamegeniecode.cc,v 1.8 2008/12/18 03:23:30 jdratlif Exp $

#include "model/gbgggamegeniecode.hh"

using namespace ggencoder;

const char GBGGGameGenieCode::ALPHABET[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
const char GBGGGameGenieCode::ALPHABET[] = {'0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};

GBGGGameGenieCode GBGGGameGenieCode::create(const QString &code)
throw(InvalidGameGenieCodeException) {
GBGGGameGenieCode GBGGGameGenieCode::create(const QString &code) throw(
InvalidGameGenieCodeException) {
if (isValidCode(code)) {
return GBGGGameGenieCode(code);
}

throw InvalidGameGenieCodeException();
}

Expand All @@ -46,48 +43,47 @@ const char *GBGGGameGenieCode::getAlphabet() const {

bool GBGGGameGenieCode::isValidCode(const QString &code) {
GBGGGameGenieCode temp(code);

const char *alphabet = temp.getAlphabet();
int count = temp.getAlphabetCount();
QString upper = code.toUpper();
int length = upper.length();
int count = temp.getAlphabetCount();

QString upper = code.toUpper();
int length = upper.length();

if ((length != 7) && (length != 11)) {
return false;
}

if (code[3] != '-') {
return false;
}

if (length == 11) {
if (code[7] != '-') {
return false;
}
}

for (int i = 0; i < length; i++) {
if ((i == 3) || (i == 7)) {
continue;
}
bool found = false;
QChar ch = code[i];
char letter = ch.toLatin1();

bool found = false;
QChar ch = code[i];
char letter = ch.toLatin1();

for (int j = 0; j < count; j++) {
if (letter == alphabet[j]) {
found = true;
break;
}
}

if (!found) {
return false;
}
}

return true;
}

Loading

0 comments on commit 4817dda

Please sign in to comment.