SGStringList.h

Go to the documentation of this file.
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 #include <shogun/lib/SGReferencedData.h>
00019 
00020 namespace shogun
00021 {
00023 template <class T> struct SGStringList : public SGReferencedData
00024 {
00025 public:
00027     SGStringList() : SGReferencedData()
00028     {
00029         init_data();
00030     }
00031 
00033     SGStringList(SGString<T>* s, index_t num_s, index_t max_length,
00034             bool ref_counting=true) : 
00035         SGReferencedData(ref_counting), num_strings(num_s),
00036         max_string_length(max_length), strings(s)
00037     {
00038     }
00039 
00041     SGStringList(index_t num_s, index_t max_length, bool ref_counting=true) : 
00042         SGReferencedData(ref_counting),
00043         num_strings(num_s), max_string_length(max_length)
00044     {
00045         strings=SG_MALLOC(SGString<T>, num_strings);
00046     }
00047 
00049     SGStringList(const SGStringList &orig) :
00050         SGReferencedData(orig)
00051     {
00052         copy_data(orig);
00053     }
00054 
00056     virtual ~SGStringList()
00057     {
00058         unref();
00059     }
00060 
00061 protected:
00062 
00064     virtual void copy_data(const SGReferencedData &orig)
00065     {
00066         strings = ((SGStringList*)(&orig))->strings;
00067         num_strings = ((SGStringList*)(&orig))->num_strings;
00068         max_string_length = ((SGStringList*)(&orig))->max_string_length;
00069     }
00070 
00072     virtual void init_data()
00073     {
00074         strings = NULL;
00075         num_strings = 0;
00076         max_string_length = 0;
00077     }
00078 
00080     void free_data()
00081     {
00082         SG_FREE(strings);
00083 
00084         strings = NULL;
00085         num_strings = 0;
00086         max_string_length = 0;
00087     }
00088 
00089 public:
00091     index_t num_strings;
00092 
00094     index_t max_string_length;
00095 
00097     SGString<T>* strings;
00098 };
00099 }
00100 #endif // __SGSTRINGLIST_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation