Files
TCPlayerbotCore/src/shared/Database/Field.h
T

90 lines
2.8 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* 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
2008-10-02 16:23:55 -05:00
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#if !defined(FIELD_H)
#define FIELD_H
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
class Field
{
public:
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum DataTypes
{
DB_TYPE_UNKNOWN = 0x00,
DB_TYPE_STRING = 0x01,
DB_TYPE_INTEGER = 0x02,
DB_TYPE_FLOAT = 0x03,
DB_TYPE_BOOL = 0x04
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
Field();
Field(Field &f);
Field(const char *value, enum DataTypes type);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
~Field();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum DataTypes GetType() const { return mType; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
const char *GetString() const { return mValue; }
std::string GetCppString() const
{
return mValue ? mValue : ""; // std::string s = 0 have undefine result in C++
}
float GetFloat() const { return mValue ? static_cast<float>(atof(mValue)) : 0.0f; }
bool GetBool() const { return mValue ? atoi(mValue) > 0 : false; }
int32 GetInt32() const { return mValue ? static_cast<int32>(atol(mValue)) : int32(0); }
uint8 GetUInt8() const { return mValue ? static_cast<uint8>(atol(mValue)) : uint8(0); }
uint16 GetUInt16() const { return mValue ? static_cast<uint16>(atol(mValue)) : uint16(0); }
int16 GetInt16() const { return mValue ? static_cast<int16>(atol(mValue)) : int16(0); }
uint32 GetUInt32() const { return mValue ? static_cast<uint32>(atol(mValue)) : uint32(0); }
uint64 GetUInt64() const
{
if(mValue)
{
uint64 value;
sscanf(mValue,UI64FMTD,&value);
2008-10-02 16:23:55 -05:00
return value;
}
else
return 0;
}
uint64 GetInt64() const
{
if(mValue)
{
int64 value;
sscanf(mValue,SI64FMTD,&value);
return value;
}
else
return 0;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetType(enum DataTypes type) { mType = type; }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void SetValue(const char *value);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
private:
char *mValue;
enum DataTypes mType;
};
#endif
2009-02-17 20:07:49 -06:00