[7616] Implement .debug play cinematic and .debig play movie. Rename .debug playsound...
[AHbot.git] / src / shared / Database / SQLStorage.h
blobe6ba01ee03056aa96ec3f5cb9dd4ebbe9594897c
1 /*
2 * Copyright (C) 2005-2009 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 #ifndef SQLSTORAGE_H
20 #define SQLSTORAGE_H
22 #include "Common.h"
23 #include "Database/DatabaseEnv.h"
25 class SQLStorage
27 template<class T>
28 friend struct SQLStorageLoaderBase;
30 public:
32 SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname)
34 src_format = fmt;
35 dst_format = fmt;
36 init(_entry_field, sqlname);
39 SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname)
41 src_format = src_fmt;
42 dst_format = dst_fmt;
43 init(_entry_field, sqlname);
47 ~SQLStorage()
49 Free();
52 template<class T>
53 T const* LookupEntry(uint32 id) const
55 if( id == 0 )
56 return NULL;
57 if(id >= MaxEntry)
58 return NULL;
59 return reinterpret_cast<T const*>(pIndex[id]);
62 uint32 RecordCount;
63 uint32 MaxEntry;
64 uint32 iNumFields;
66 void Load();
67 void Free();
69 private:
70 void init(const char * _entry_field, const char * sqlname)
72 entry_field = _entry_field;
73 table=sqlname;
74 data=NULL;
75 pIndex=NULL;
76 iNumFields = strlen(src_format);
77 MaxEntry = 0;
80 char** pIndex;
82 char *data;
83 const char *src_format;
84 const char *dst_format;
85 const char *table;
86 const char *entry_field;
87 //bool HasString;
90 template <class T>
91 struct SQLStorageLoaderBase
93 public:
94 void Load(SQLStorage &storage);
96 template<class S, class D>
97 void convert(uint32 field_pos, S src, D &dst);
98 template<class S>
99 void convert_to_str(uint32 field_pos, S src, char * & dst);
100 template<class D>
101 void convert_from_str(uint32 field_pos, char * src, D& dst);
102 void convert_str_to_str(uint32 field_pos, char *src, char *&dst);
104 private:
105 template<class V>
106 void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset);
107 void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset);
110 struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>
114 #endif