SHOGUN
v3.2.0
|
00001 #include <shogun/lib/SGString.h> 00002 #include <shogun/lib/SGVector.h> 00003 #include <shogun/io/File.h> 00004 00005 namespace shogun 00006 { 00007 00008 template <class T> 00009 SGString<T>::SGString() : string(NULL), slen(0), do_free(false) { } 00010 00011 template <class T> 00012 SGString<T>::SGString(T* s, index_t l, bool free_s) 00013 : string(s), slen(l), do_free(free_s) { } 00014 00015 template <class T> 00016 SGString<T>::SGString(SGVector<T> v) 00017 : string(v.vector), slen(v.vlen), do_free(false) { } 00018 00019 template <class T> 00020 SGString<T>::SGString(index_t len, bool free_s) : 00021 slen(len), do_free(free_s) 00022 { 00023 string=SG_CALLOC(T, len); 00024 } 00025 00026 template <class T> 00027 SGString<T>::SGString(const SGString &orig) 00028 : string(orig.string), slen(orig.slen), do_free(orig.do_free) { } 00029 00030 template <class T> 00031 bool SGString<T>::operator==(const SGString & other) const 00032 { 00033 if (other.slen != slen) 00034 return false; 00035 00036 for (int i = 0; i < slen; i++) 00037 { 00038 if (other.string[i] != string[i]) 00039 return false; 00040 } 00041 00042 return true; 00043 } 00044 00045 template <class T> 00046 void SGString<T>::free_string() 00047 { 00048 if (do_free) 00049 SG_FREE(string); 00050 00051 string=NULL; 00052 do_free=false; 00053 slen=0; 00054 } 00055 00056 template <class T> 00057 void SGString<T>::destroy_string() 00058 { 00059 do_free=true; 00060 free_string(); 00061 } 00062 00063 template<class T> void SGString<T>::load(CFile* loader) 00064 { 00065 ASSERT(loader) 00066 free_string(); 00067 00068 SG_SET_LOCALE_C; 00069 loader->get_vector(string, slen); 00070 do_free=true; 00071 SG_RESET_LOCALE; 00072 } 00073 00074 template<class T> void SGString<T>::save(CFile* saver) 00075 { 00076 ASSERT(saver) 00077 00078 SG_SET_LOCALE_C; 00079 saver->set_vector(string, slen); 00080 SG_RESET_LOCALE; 00081 } 00082 00083 template class SGString<bool>; 00084 template class SGString<char>; 00085 template class SGString<int8_t>; 00086 template class SGString<uint8_t>; 00087 template class SGString<int16_t>; 00088 template class SGString<uint16_t>; 00089 template class SGString<int32_t>; 00090 template class SGString<uint32_t>; 00091 template class SGString<int64_t>; 00092 template class SGString<uint64_t>; 00093 template class SGString<float32_t>; 00094 template class SGString<float64_t>; 00095 template class SGString<floatmax_t>; 00096 }