A
Angus
Hello
I have the following string variables in my class:
m_PrimaryID, m_SecondaryID and m_TertiaryID.
I have a search function, FindTool(), which goes through each of these
ID's to search for something.
I have a getID() function like this:
const char* CTool::getID(int index) const
{
switch(index)
{
case 0: return m_PrimaryID && *m_PrimaryID ? m_PrimaryID : 0;
case 1: return m_SecondaryID && *m_SecondaryID ?
m_SecondaryID : 0;
case 2: return m_TertiaryID && *m_TertiaryID ? m_TertiaryID :
0;
default: return 0;
}
}
which returns the requisite variable if not null.
I do the search like this:
CTool* CTool::FindTool()
{
CTool* tool = 0;
//try all available gcid's
for(int it = 0; it != 3; ++it)
{
if(getID(it))
tool = findTool(getID(it)); //this is using library I need
to use
if(tool && tool->Exists())
return tool;
}
return 0;
}
But I am concerned the code looks obscure. How can I make it more
elegant?
Angus
I have the following string variables in my class:
m_PrimaryID, m_SecondaryID and m_TertiaryID.
I have a search function, FindTool(), which goes through each of these
ID's to search for something.
I have a getID() function like this:
const char* CTool::getID(int index) const
{
switch(index)
{
case 0: return m_PrimaryID && *m_PrimaryID ? m_PrimaryID : 0;
case 1: return m_SecondaryID && *m_SecondaryID ?
m_SecondaryID : 0;
case 2: return m_TertiaryID && *m_TertiaryID ? m_TertiaryID :
0;
default: return 0;
}
}
which returns the requisite variable if not null.
I do the search like this:
CTool* CTool::FindTool()
{
CTool* tool = 0;
//try all available gcid's
for(int it = 0; it != 3; ++it)
{
if(getID(it))
tool = findTool(getID(it)); //this is using library I need
to use
if(tool && tool->Exists())
return tool;
}
return 0;
}
But I am concerned the code looks obscure. How can I make it more
elegant?
Angus