[6888] Add to character.sql not added changes from 2008_11_12_01_character_character_...
[getmangos.git] / src / shared / Database / Field.h
blob631c97db52b29cfbd4e48990dc95eeef9c654757
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #if !defined(FIELD_H)
20 #define FIELD_H
22 class Field
24 public:
26 enum DataTypes
28 DB_TYPE_UNKNOWN = 0x00,
29 DB_TYPE_STRING = 0x01,
30 DB_TYPE_INTEGER = 0x02,
31 DB_TYPE_FLOAT = 0x03,
32 DB_TYPE_BOOL = 0x04
35 Field();
36 Field(Field &f);
37 Field(const char *value, enum DataTypes type);
39 ~Field();
41 enum DataTypes GetType() const { return mType; }
43 const char *GetString() const { return mValue; }
44 std::string GetCppString() const
46 return mValue ? mValue : ""; // std::string s = 0 have undefine result in C++
48 float GetFloat() const { return mValue ? static_cast<float>(atof(mValue)) : 0.0f; }
49 bool GetBool() const { return mValue ? atoi(mValue) > 0 : false; }
50 int32 GetInt32() const { return mValue ? static_cast<int32>(atol(mValue)) : int32(0); }
51 uint8 GetUInt8() const { return mValue ? static_cast<uint8>(atol(mValue)) : uint8(0); }
52 uint16 GetUInt16() const { return mValue ? static_cast<uint16>(atol(mValue)) : uint16(0); }
53 int16 GetInt16() const { return mValue ? static_cast<int16>(atol(mValue)) : int16(0); }
54 uint32 GetUInt32() const { return mValue ? static_cast<uint32>(atol(mValue)) : uint32(0); }
55 uint64 GetUInt64() const
57 if(mValue)
59 uint64 value;
60 sscanf(mValue,I64FMTD,&value);
61 return value;
63 else
64 return 0;
67 void SetType(enum DataTypes type) { mType = type; }
69 void SetValue(const char *value);
71 private:
72 char *mValue;
73 enum DataTypes mType;
75 #endif