Changeset 260 for trunk/src/shared/Database/SQLStorage.h
- Timestamp:
- 11/21/08 08:47:55 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shared/Database/SQLStorage.h
r102 r260 11 11 * This program is distributed in the hope that it will be useful, 12 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 * GNU General Public License for more details. 15 15 * 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USA18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 */ 20 20 … … 27 27 class SQLStorage 28 28 { 29 template<class T> 30 friend struct SQLStorageLoaderBase; 31 29 32 public: 30 33 31 SQLStorage(const char* fmt,const char * _entry_field,const char * sqlname)34 SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname) 32 35 { 33 format=fmt; 34 entry_field = _entry_field; 35 table=sqlname; 36 data=NULL; 37 pIndex=NULL; 38 iNumFields =strlen(fmt); 39 MaxEntry = 0; 36 src_format = fmt; 37 dst_format = fmt; 38 init(_entry_field, sqlname); 40 39 } 40 41 SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname) 42 { 43 src_format = src_fmt; 44 dst_format = dst_fmt; 45 init(_entry_field, sqlname); 46 } 47 48 41 49 ~SQLStorage() 42 50 { … … 57 65 uint32 MaxEntry; 58 66 uint32 iNumFields; 67 59 68 void Load(); 60 69 void Free(); 70 61 71 private: 72 void init(const char * _entry_field, const char * sqlname) 73 { 74 entry_field = _entry_field; 75 table=sqlname; 76 data=NULL; 77 pIndex=NULL; 78 iNumFields = strlen(src_format); 79 MaxEntry = 0; 80 } 81 62 82 char** pIndex; 63 83 64 84 char *data; 65 const char *format; 85 const char *src_format; 86 const char *dst_format; 66 87 const char *table; 67 88 const char *entry_field; 68 89 //bool HasString; 69 90 }; 91 92 template <class T> 93 struct SQLStorageLoaderBase 94 { 95 public: 96 void Load(SQLStorage &storage); 97 98 template<class S, class D> 99 void convert(uint32 field_pos, S src, D &dst); 100 template<class S> 101 void convert_to_str(uint32 field_pos, S src, char * & dst); 102 template<class D> 103 void convert_from_str(uint32 field_pos, char * src, D& dst); 104 void convert_str_to_str(uint32 field_pos, char *src, char *&dst); 105 106 private: 107 template<class V> 108 void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset); 109 void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset); 110 }; 111 112 struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader> 113 { 114 }; 115 70 116 #endif