Skip to content

Commit

Permalink
made to_string method const
Browse files Browse the repository at this point in the history
implemented a proper order on SGParamInfo (which fixes a bug)
  • Loading branch information
karlnapf committed Dec 28, 2011
1 parent b5ed057 commit c7a7d8f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
62 changes: 55 additions & 7 deletions src/shogun/base/ParameterMap.cpp
Expand Up @@ -65,7 +65,7 @@ SGParamInfo::~SGParamInfo()
SG_FREE(m_name);
}

char* SGParamInfo::to_string()
char* SGParamInfo::to_string() const
{
char* buffer=SG_MALLOC(char, 200);
strcpy(buffer, "SGParamInfo with: ");
Expand Down Expand Up @@ -118,26 +118,74 @@ bool SGParamInfo::operator==(const SGParamInfo& other) const
result&=m_stype==other.m_stype;
result&=m_ptype==other.m_ptype;
result&=m_param_version==other.m_param_version;
SG_SPRINT("result: %d\n", result);
return result;
}

bool SGParamInfo::operator<(const SGParamInfo& other) const
{
int32_t result=strcmp(m_name, other.m_name);

if (!result)
return m_param_version<other.m_param_version;
if (result==0)
{
if (m_param_version==other.m_param_version)
{
if (m_ctype==other.m_ctype)
{
if (m_stype==other.m_stype)
{
if (m_ptype==other.m_ptype)
{
return false;
}
else
return m_ptype<other.m_ptype;
}
else
return m_stype<other.m_stype;
}
else
return m_ctype<other.m_ctype;
}
else
return m_param_version<other.m_param_version;

}
else
return result<0;
}

bool SGParamInfo::operator>(const SGParamInfo& other) const
{
int32_t result=strcmp(m_name, other.m_name);
if (!result)
return m_param_version<other.m_param_version;
else
return result>0;

if (result==0)
{
if (m_param_version==other.m_param_version)
{
if (m_ctype==other.m_ctype)
{
if (m_stype==other.m_stype)
{
if (m_ptype==other.m_ptype)
{
return false;
}
else
return m_ptype>other.m_ptype;
}
else
return m_stype>other.m_stype;
}
else
return m_ctype>other.m_ctype;
}
else
return m_param_version>other.m_param_version;

}
else
return result>0;
}

ParameterMapElement::ParameterMapElement()
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/base/ParameterMap.h
Expand Up @@ -61,7 +61,7 @@ class SGParamInfo
void print_param_info();

/** @return string representation, caller has to clean up */
char* to_string();
char* to_string() const;

/** @return an identical copy */
SGParamInfo* duplicate() const;
Expand Down

0 comments on commit c7a7d8f

Please sign in to comment.