root/trunk/src/shared/Database/Field.h @ 13

Revision 2, 2.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#if !defined(FIELD_H)
20#define FIELD_H
21
22class Field
23{
24    public:
25
26        enum DataTypes
27        {
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
33        };
34
35        Field();
36        Field(Field &f);
37        Field(const char *value, enum DataTypes type);
38
39        ~Field();
40
41        enum DataTypes GetType() const { return mType; }
42
43        const char *GetString() const { return mValue; }
44        std::string GetCppString() const
45        {
46            return mValue ? mValue : "";                    // std::string s = 0 have undefine result in C++
47        }
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
56        {
57            if(mValue)
58            {
59                uint64 value;
60                sscanf(mValue,I64FMTD,&value);
61                return value;
62            }
63            else
64                return 0;
65        }
66
67        void SetType(enum DataTypes type) { mType = type; }
68
69        void SetValue(const char *value);
70
71    private:
72        char *mValue;
73        enum DataTypes mType;
74};
75#endif
Note: See TracBrowser for help on using the browser.