diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2007-07-03 04:20:36 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2007-07-03 04:20:36 +0000 |
commit | 65cc463f1d91fe99acf1c4dd9bce7e0038593022 (patch) | |
tree | 95644c3c42a4a23db50dc42722cdeb4489427e14 /pokemod/Author.cpp | |
parent | 9102febc37475af113681eaaee02ecc2ea04b4da (diff) | |
download | sigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.tar.gz sigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.tar.xz sigen-65cc463f1d91fe99acf1c4dd9bce7e0038593022.zip |
Fixed Logging, minor fixes, got rid of NatureEffect, and started migration from wxGTK to Qt
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@22 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Author.cpp')
-rw-r--r-- | pokemod/Author.cpp | 474 |
1 files changed, 221 insertions, 253 deletions
diff --git a/pokemod/Author.cpp b/pokemod/Author.cpp index 20d34db3..b2c2d912 100644 --- a/pokemod/Author.cpp +++ b/pokemod/Author.cpp @@ -1,253 +1,221 @@ -/////////////////////////////////////////////////////////////////////////////
-// Name: pokemod/Author.cpp
-// Purpose: Define an author of a PokéMod
-// Author: Ben Boeckel
-// Modified by: Ben Boeckel
-// Created: Wed Feb 28 20:42:17 2007
-// Copyright: ©2007 Nerdy Productions
-// Licence:
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-/////////////////////////////////////////////////////////////////////////////
-
-#include "Author.h"
-
-PokeGen::PokeMod::Author::Author(const unsigned _id) :
- name(""),
- email(""),
- role("")
-{
- LogCtor("Author", id);
- id = _id;
-}
-
-PokeGen::PokeMod::Author::Author(Ini &ini, const unsigned _id)
-{
- LogCtorIni("Author", id);
- ImportIni(ini, _id);
- if (id == UINT_MAX)
- LogIdError("Author");
-}
-
-PokeGen::PokeMod::Author::~Author()
-{
- LogDtor("Author", id, name);
-}
-
-void PokeGen::PokeMod::Author::Validate()
-{
- LogValidateStart("Author", id, name);
- if (name == "")
- {
- LogVarNotSet("Author", id, "name");
- isValid = false;
- }
- if (email == "")
- {
- LogVarNotSet("Author", id, "email", name);
- }
- else if (!IsValidEmail())
- {
- LogVarNotValid("Author", id, "email", name);
- isValid = false;
- }
- if (role == "")
- {
- LogVarNotSet("Author", id, "role", name);
- isValid = false;
- }
- LogValidateOver("Author", id, isValid, name);
-}
-
-#ifdef PG_DEBUG_WINDOW
-void PokeGen::PokeMod::Author::Validate(const wxListBox &output)
-{
- LogValidateStart("Author", id, name);
- if (name == "")
- {
- LogVarNotSet("Author", "name", id);
- output.Append(ConsoleLogVarNotSet("Author", "name", id)));
- isValid = false;
- }
- if (email == "")
- {
- LogVarNotSet("Author", "email", id, name);
- output.Append(ConsoleLogVarNotSetW("Author", "email", id)));
- }
- else if (!IsValidEmail())
- {
- LogVarNotValid("Author", "email", id, name);
- output.Append(ConsoleLogVarNotValid("Author", "email", id, name));
- isValid = false;
- }
- if (role == "")
- {
- LogValNotSet("Author", "role", id, name);
- output.Append(ConsoleLogValNotSet("Author", "role", id, name)));
- isValid = false;
- }
- LogValidateOver("Author", isValid, id, name);
- }
-#endif
-
- void PokeGen::PokeMod::Author::ImportIni(Ini &ini, const unsigned _id)
- {
- LogImportStart("Author");
- String curName;
- if (_id == UINT_MAX)
- {
- ini.GetValue("id", id);
- if (id == UINT_MAX)
- LogIdNotFound("Author");
- }
- else
- id = _id;
- ini.GetValue("name", name);
- ini.GetValue("email", email);
- ini.GetValue("role", role);
- LogImportOver("Author", id, name);
- }
-
- void PokeGen::PokeMod::Author::ExportIni(std::ofstream &fout) const
- {
- LogExportStart("Author", id, name);
- Ini exAuthor("author");
- exAuthor.AddField("id", id);
- exAuthor.AddField("name", name);
- exAuthor.AddField("email", email);
- exAuthor.AddField("role", role);
- exAuthor.Export(fout);
- LogExportOver("Author", id, name);
- }
-
- void PokeGen::PokeMod::Author::SetName(const String &n)
- {
- LogSetVar("Author", id, "name", n, name);
- name = n;
- }
-
- void PokeGen::PokeMod::Author::SetEmail(const String &e)
- {
- LogSetVar("Author", id, "email", e, name);
- email = e;
- }
-
- void PokeGen::PokeMod::Author::SetRole(const String &r)
- {
- LogSetVar("Author", id, "role", r, name);
- role = r;
- }
-
- PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetName() const
- {
- LogFetchVar("Author", id, "name", name);
- return name;
- }
-
- PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetEmail() const
- {
- LogFetchVar("Author", id, "email", email, name);
- return email;
- }
-
- PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetRole() const
- {
- LogFetchVar("Author", id, "role", role, name);
- return role;
- }
-
- bool PokeGen::PokeMod::Author::IsValidEmail() const
- {
- bool valid = true;
- Log(String("Author: Validating email of %d (%s)", id, name.c_str()), PM_DEBUG_DEBUG);
- EmailCheck stage = EM_NAME;
- int count = 0;
- for (unsigned i = 0; (i < email.length()) && valid; ++i)
- {
- switch (stage)
- {
- case EM_NAME:
- switch (email[i])
- {
- // Only allow alphanumerics and '%-_.' in the name
- case 'a' ... 'z':
- case 'A' ... 'Z':
- case '0' ... '9':
- case '%':
- case '-':
- case '_':
- case '.':
- ++count;
- break;
- // Move to the next part if '@' is encountered
- case '@':
- if (!count)
- valid = false;
- count = 0;
- stage = EM_HOST;
- break;
- // Not valid if anything else is encountered
- default:
- valid = false;
- }
- break;
- case EM_HOST:
- switch (email[i])
- {
- // Only allow alphanumerics and '%-_.' in the host
- case 'a' ... 'z':
- case 'A' ... 'Z':
- case '0' ... '9':
- case '-':
- ++count;
- break;
- // Move to the next part if '.' is encountered
- case '.':
- if (!count)
- valid = false;
- count = 0;
- stage = EM_DOMAIN;
- break;
- // Not valid if anything else is encountered
- default:
- valid = false;
- }
- break;
- case EM_DOMAIN:
- switch (email[i])
- {
- // Only allow alphanumerics and '%-_.' in the host
- case 'a' ... 'z':
- case 'A' ... 'Z':
- ++count;
- break;
- // Move to the next domain extension if '.' is encountered
- case '.':
- if (!count)
- valid = false;
- count = 0;
- break;
- // Not valid if anything else is encountered
- default:
- valid = false;
- }
- }
- }
- // Make sure the domain was entered and the extension is in the valid range
- if ((stage != EM_DOMAIN) || (count < 2) || (4 < count))
- valid = false;
- Log(String("Author: Validated email of %d (%s) as %s", id, name.c_str(), valid ? "valid" : "invalid"), PM_DEBUG_DEBUG);
- return valid;
- }
-
+///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/Author.cpp +// Purpose: Define an author of a PokéMod +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Wed Feb 28 20:42:17 2007 +// Copyright: ©2007 Nerdy Productions +// Licence: +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program 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 this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +///////////////////////////////////////////////////////////////////////////// + +#include "Author.h" + +PokeGen::PokeMod::Author::Author(const unsigned _id) : + name(""), + email(""), + role("") +{ + LogCtor("Author", id); + id = _id; +} + +PokeGen::PokeMod::Author::Author(Ini &ini, const unsigned _id) +{ + LogCtorIni("Author", id); + ImportIni(ini, _id); + if (id == UINT_MAX) + LogIdError("Author"); +} + +PokeGen::PokeMod::Author::~Author() +{ + LogDtor("Author", id, name); +} + +void PokeGen::PokeMod::Author::Validate() +{ + LogValidateStart("Author", id, name); + if (name == "") + { + LogVarNotSet("Author", id, "name"); + isValid = false; + } + if (email == "") + { + LogVarNotSet("Author", id, "email", name); + } + else if (!IsValidEmail()) + { + LogVarNotValid("Author", id, "email", name); + isValid = false; + } + if (role == "") + { + LogVarNotSet("Author", id, "role", name); + isValid = false; + } + LogValidateOver("Author", id, isValid, name); +} + +void PokeGen::PokeMod::Author::ImportIni(Ini &ini, const unsigned _id) +{ + LogImportStart("Author"); + String curName; + if (_id == UINT_MAX) + { + ini.GetValue("id", id); + if (id == UINT_MAX) + LogIdNotFound("Author"); + } + else + id = _id; + ini.GetValue("name", name); + ini.GetValue("email", email); + ini.GetValue("role", role); + LogImportOver("Author", id, name); +} + +void PokeGen::PokeMod::Author::ExportIni(std::ofstream &fout) const +{ + LogExportStart("Author", id, name); + Ini exAuthor("author"); + exAuthor.AddField("id", id); + exAuthor.AddField("name", name); + exAuthor.AddField("email", email); + exAuthor.AddField("role", role); + exAuthor.Export(fout); + LogExportOver("Author", id, name); +} + +void PokeGen::PokeMod::Author::SetName(const String &n) +{ + LogSetVar("Author", id, "name", n, name); + name = n; +} + +void PokeGen::PokeMod::Author::SetEmail(const String &e) +{ + LogSetVar("Author", id, "email", e, name); + email = e; +} + +void PokeGen::PokeMod::Author::SetRole(const String &r) +{ + LogSetVar("Author", id, "role", r, name); + role = r; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetName() const +{ + LogFetchVar("Author", id, "name", name); + return name; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetEmail() const +{ + LogFetchVar("Author", id, "email", email, name); + return email; +} + +PokeGen::PokeMod::String PokeGen::PokeMod::Author::GetRole() const +{ + LogFetchVar("Author", id, "role", role, name); + return role; +} + +bool PokeGen::PokeMod::Author::IsValidEmail() const +{ + bool valid = true; + Log::Write(String("Author: Validating email of %d (%s)", id, name.c_str()), PM_DEBUG_DEBUG | PM_DEBUG_VALIDATION); + EmailCheck stage = EM_NAME; + int count = 0; + for (unsigned i = 0; (i < email.length()) && valid; ++i) + { + switch (stage) + { + case EM_NAME: + switch (email[i]) + { + // Only allow alphanumerics and '%-_.' in the name + case 'a' ... 'z': + case 'A' ... 'Z': + case '0' ... '9': + case '%': + case '-': + case '_': + case '.': + ++count; + break; + // Move to the next part if '@' is encountered + case '@': + if (!count) + valid = false; + count = 0; + stage = EM_HOST; + break; + // Not valid if anything else is encountered + default: + valid = false; + } + break; + case EM_HOST: + switch (email[i]) + { + // Only allow alphanumerics and '%-_.' in the host + case 'a' ... 'z': + case 'A' ... 'Z': + case '0' ... '9': + case '-': + ++count; + break; + // Move to the next part if '.' is encountered + case '.': + if (!count) + valid = false; + count = 0; + stage = EM_DOMAIN; + break; + // Not valid if anything else is encountered + default: + valid = false; + } + break; + case EM_DOMAIN: + switch (email[i]) + { + // Only allow alphanumerics and '%-_.' in the host + case 'a' ... 'z': + case 'A' ... 'Z': + ++count; + break; + // Move to the next domain extension if '.' is encountered + case '.': + if (!count) + valid = false; + count = 0; + break; + // Not valid if anything else is encountered + default: + valid = false; + } + } + } + // Make sure the domain was entered and the extension is in the valid range + if ((stage != EM_DOMAIN) || (count < 2) || (4 < count)) + valid = false; + Log::Write(String("Author: Validated email of %d (%s) as %s", id, name.c_str(), valid ? "valid" : "invalid"), PM_DEBUG_DEBUG | PM_DEBUG_VALIDATION); + return valid; +} |