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

Revision 102, 2.6 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

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