SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SGString.cpp
Go to the documentation of this file.
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 }

SHOGUN Machine Learning Toolbox - Documentation