SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2012 Fernando José Iglesias García 00008 * Written (W) 2010,2012 Soeren Sonnenburg 00009 * Copyright (C) 2010 Berlin Institute of Technology 00010 * Copyright (C) 2012 Soeren Sonnenburg 00011 */ 00012 #ifndef __SGSTRINGLIST_H__ 00013 #define __SGSTRINGLIST_H__ 00014 00015 #include <shogun/lib/config.h> 00016 #include <shogun/lib/DataType.h> 00017 #include <shogun/lib/SGString.h> 00018 00019 namespace shogun 00020 { 00022 template <class T> struct SGStringList 00023 { 00024 public: 00026 SGStringList() : num_strings(0), max_string_length(0), strings(NULL), 00027 do_free(false) { } 00028 00030 SGStringList(SGString<T>* s, index_t num_s, index_t max_length, 00031 bool free_strings=false) : num_strings(num_s), 00032 max_string_length(max_length), strings(s), do_free(free_strings) { } 00033 00035 SGStringList(index_t num_s, index_t max_length, bool free_strings=false) 00036 : num_strings(num_s), max_string_length(max_length), 00037 do_free(free_strings) 00038 { 00039 strings=SG_MALLOC(SGString<T>, num_strings); 00040 } 00041 00043 SGStringList(const SGStringList &orig) : 00044 num_strings(orig.num_strings), 00045 max_string_length(orig.max_string_length), 00046 strings(orig.strings), do_free(orig.do_free) { } 00047 00049 void free_list() 00050 { 00051 if (do_free) 00052 SG_FREE(strings); 00053 00054 strings=NULL; 00055 do_free=false; 00056 num_strings=0; 00057 max_string_length=0; 00058 } 00059 00061 void destroy_list() 00062 { 00063 do_free=true; 00064 free_list(); 00065 } 00066 00067 public: 00069 index_t num_strings; 00070 00072 index_t max_string_length; 00073 00075 SGString<T>* strings; 00076 00078 bool do_free; 00079 }; 00080 } 00081 #endif // __SGSTRINGLIST_H__