Skip to content

Commit

Permalink
use SGStringList<char> instead of SGVector<char*>
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Dec 22, 2011
1 parent 5a8c07d commit 38cbdc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions src/shogun/base/SGObject.cpp
Expand Up @@ -468,15 +468,27 @@ void CSGObject::init()
m_load_post_called = false;
}

SGVector<char*> CSGObject::get_modelsel_names()
SGStringList<char> CSGObject::get_modelsel_names()
{
SGVector<char*> result=SGVector<char*>(
m_model_selection_parameters->get_num_parameters());
index_t num_param=m_model_selection_parameters->get_num_parameters();

for (index_t i=0; i<result.vlen; ++i)
result.vector[i]=m_model_selection_parameters->get_parameter(i)->m_name;
SGStringList<char> result(num_param, -1);

return result;
index_t max_string_length=-1;

for (index_t i=0; i<num_param; i++)
{
char* name=m_model_selection_parameters->get_parameter(i)->m_name;
index_t len=strlen(name);
result.strings[i]=SGString<char>(name, len);

if (len>max_string_length)
max_string_length=len;
}

result.max_string_length=max_string_length;

return result;
}

char* CSGObject::get_modsel_param_descr(const char* param_name)
Expand All @@ -496,11 +508,11 @@ index_t CSGObject::get_modsel_param_index(const char* param_name)
{
/* use fact that names extracted from below method are in same order than
* in m_model_selection_parameters variable */
SGVector<char*> names=get_modelsel_names();
SGStringList<char> names=get_modelsel_names();

/* search for parameter with provided name */
index_t index=-1;
for (index_t i=0; i<names.vlen; ++i)
for (index_t i=0; i<names.num_strings; i++)
{
TParameter* current=m_model_selection_parameters->get_parameter(i);
if (!strcmp(param_name, current->m_name))
Expand All @@ -511,7 +523,7 @@ index_t CSGObject::get_modsel_param_index(const char* param_name)
}

/* clean up */
names.destroy_vector();
names.destroy_list();

return index;
}
2 changes: 1 addition & 1 deletion src/shogun/base/SGObject.h
Expand Up @@ -200,7 +200,7 @@ class CSGObject

/** @return vector of names of all parameters which are registered for model
* selection */
SGVector<char*> get_modelsel_names();
SGStringList<char> get_modelsel_names();

/** Returns description of a given parameter string, if it exists. SG_ERROR
* otherwise
Expand Down

0 comments on commit 38cbdc3

Please sign in to comment.