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

SHOGUN Machine Learning Toolbox - Documentation