![]() |
Race Class ReferenceDatabase table Race.
More...
|
Public Member Functions | |
Race (Database &, long num) | |
Race (Database &, const std::string &) | |
~Race () | |
bool | Exists () |
Check if the object already exists in database. | |
void | Save () |
Save the object in database. | |
long | GetNum () |
Get integer primary key from object. | |
void | SetName (const std::string &) |
const std::string & | GetName () |
void | SetSightRange (double) |
double | GetSightRange () |
void | SetHearing (double) |
double | GetHearing () |
Static Public Member Functions | |
static int | DisplayRaces (InSocket *) |
Static Private Member Functions | |
static db::Race * | GetRace (Database &, long num) |
static db::Race * | GetRace (Database &, const std::string &) |
Private Attributes | |
db::Race * | m_race |
Static Private Attributes | |
static races_t | m_cache |
Definition at line 34 of file Race.h.
Race::Race | ( | Database & | , | |
long | num | |||
) |
Race::Race | ( | Database & | , | |
const std::string & | ||||
) |
bool Race::Exists | ( | ) | [virtual] |
Check if the object already exists in database.
Implements Object.
Definition at line 81 of file Race.cpp.
References m_race.
Referenced by Create::OnLine(), and Player::SightRange().
void Race::Save | ( | ) | [virtual] |
long Race::GetNum | ( | ) | [virtual] |
void Race::SetName | ( | const std::string & | ) |
Definition at line 101 of file Race.cpp.
References m_cache, and m_race.
Referenced by Create::OnLine().
00102 { 00103 for (std::map<std::string,db::Race *>::iterator it = m_cache.begin(); it != m_cache.end(); it++) 00104 { 00105 std::string name = (*it).first; 00106 if (name == m_race -> name) 00107 { 00108 m_cache.erase(it); 00109 break; 00110 } 00111 } 00112 m_race -> name = x; 00113 m_cache[x] = m_race; 00114 }
const std::string & Race::GetName | ( | ) |
Definition at line 117 of file Race.cpp.
References m_race.
Referenced by Create::OnLine().
00118 { 00119 return m_race -> name; 00120 }
void Race::SetSightRange | ( | double | ) |
Definition at line 123 of file Race.cpp.
References m_race.
Referenced by Create::OnLine().
00124 { 00125 m_race -> sightrange = x; 00126 }
double Race::GetSightRange | ( | ) |
Definition at line 129 of file Race.cpp.
References m_race.
Referenced by Create::OnLine(), and Player::SightRange().
00130 { 00131 return m_race -> sightrange; 00132 }
void Race::SetHearing | ( | double | ) |
Definition at line 135 of file Race.cpp.
References m_race.
Referenced by Create::OnLine().
00136 { 00137 m_race -> hearing = x; 00138 }
double Race::GetHearing | ( | ) |
Definition at line 141 of file Race.cpp.
References m_race.
Referenced by Create::OnLine().
00142 { 00143 return m_race -> hearing; 00144 }
int Race::DisplayRaces | ( | InSocket * | ) | [static] |
Definition at line 147 of file Race.cpp.
Referenced by Create::Execute(), and Login::OnLine().
00148 { 00149 Database& db = from -> GetDatabase(); 00150 Query q(db); 00151 int n = 0; 00152 q.get_result("select * from race order by name"); 00153 while (q.fetch_row()) 00154 { 00155 db::Race r(&db, &q); 00156 from -> Send(Utility::l2string(r.num) + ") " + r.name + "\n"); 00157 n = MAX(n, r.num); 00158 } 00159 q.free_result(); 00160 return n; 00161 }
db::Race * Race::GetRace | ( | Database & | , | |
long | num | |||
) | [static, private] |
Definition at line 50 of file Race.cpp.
References m_cache.
00051 { 00052 for (std::map<std::string,db::Race *>::iterator it = m_cache.begin(); it != m_cache.end(); it++) 00053 { 00054 db::Race *p = (*it).second; 00055 if (p -> num == num) 00056 return p; 00057 } 00058 db::Race *p = new db::Race(db, num); 00059 if (p -> num) 00060 { 00061 m_cache[p -> name] = p; 00062 return p; 00063 } 00064 delete p; 00065 return NULL; // bang 00066 }
db::Race * Race::GetRace | ( | Database & | , | |
const std::string & | ||||
) | [static, private] |
races_t Race::m_cache [static, private] |
db::Race* Race::m_race [private] |
Definition at line 58 of file Race.h.
Referenced by Exists(), GetHearing(), GetName(), GetNum(), GetSightRange(), Save(), SetHearing(), SetName(), and SetSightRange().