SHOGUN  v3.2.0
SGString.cpp
浏览该文件的文档.
1 #include <shogun/lib/SGString.h>
2 #include <shogun/lib/SGVector.h>
3 #include <shogun/io/File.h>
4 
5 namespace shogun
6 {
7 
8 template <class T>
9 SGString<T>::SGString() : string(NULL), slen(0), do_free(false) { }
10 
11 template <class T>
12 SGString<T>::SGString(T* s, index_t l, bool free_s)
13  : string(s), slen(l), do_free(free_s) { }
14 
15 template <class T>
17  : string(v.vector), slen(v.vlen), do_free(false) { }
18 
19 template <class T>
20 SGString<T>::SGString(index_t len, bool free_s) :
21  slen(len), do_free(free_s)
22 {
23  string=SG_CALLOC(T, len);
24 }
25 
26 template <class T>
28  : string(orig.string), slen(orig.slen), do_free(orig.do_free) { }
29 
30 template <class T>
31 bool SGString<T>::operator==(const SGString & other) const
32 {
33  if (other.slen != slen)
34  return false;
35 
36  for (int i = 0; i < slen; i++)
37  {
38  if (other.string[i] != string[i])
39  return false;
40  }
41 
42  return true;
43 }
44 
45 template <class T>
47 {
48  if (do_free)
49  SG_FREE(string);
50 
51  string=NULL;
52  do_free=false;
53  slen=0;
54 }
55 
56 template <class T>
58 {
59  do_free=true;
60  free_string();
61 }
62 
63 template<class T> void SGString<T>::load(CFile* loader)
64 {
65  ASSERT(loader)
66  free_string();
67 
69  loader->get_vector(string, slen);
70  do_free=true;
72 }
73 
74 template<class T> void SGString<T>::save(CFile* saver)
75 {
76  ASSERT(saver)
77 
79  saver->set_vector(string, slen);
81 }
82 
83 template class SGString<bool>;
84 template class SGString<char>;
85 template class SGString<int8_t>;
86 template class SGString<uint8_t>;
87 template class SGString<int16_t>;
88 template class SGString<uint16_t>;
89 template class SGString<int32_t>;
90 template class SGString<uint32_t>;
91 template class SGString<int64_t>;
92 template class SGString<uint64_t>;
93 template class SGString<float32_t>;
94 template class SGString<float64_t>;
95 template class SGString<floatmax_t>;
96 }
#define SG_RESET_LOCALE
Definition: SGIO.h:88
void free_string()
Definition: SGString.cpp:46
int32_t index_t
Definition: common.h:60
bool operator==(const SGString &other) const
Definition: SGString.cpp:31
#define SG_SET_LOCALE_C
Definition: SGIO.h:87
shogun string
#define ASSERT(x)
Definition: SGIO.h:203
virtual void get_vector(bool *&vector, int32_t &len)
Definition: File.cpp:73
index_t slen
Definition: SGString.h:79
void save(CFile *saver)
Definition: SGString.cpp:74
A File access base class.
Definition: File.h:34
void destroy_string()
Definition: SGString.cpp:57
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
void load(CFile *loader)
Definition: SGString.cpp:63
virtual void set_vector(const bool *vector, int32_t len)
Definition: File.cpp:87

SHOGUN Machine Learning Toolbox - Documentation