Skip to content

Commit

Permalink
Fix for bug in split string and move order of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
larochj committed Dec 12, 2024
1 parent 1102e2b commit a3dd78e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
64 changes: 42 additions & 22 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4005,20 +4005,54 @@ const char * Config::getActiveDisplays() const
return getImpl()->m_activeDisplaysStr.c_str();
}

void Config::addActiveDisplay(const char * view)
{
if( !view || !view[0] )
{
throw Exception("Active display could not be added to config, display name has to be a "
"non-empty name.");
}

auto it = std::find(getImpl()->m_activeDisplays.begin(),
getImpl()->m_activeDisplays.end(), view);

if( it != getImpl()->m_activeDisplays.end() )
{
std::ostringstream os;
os << "Active display could not be added to config. An active display named '"
<< view << "' already exists.";
throw Exception(os.str().c_str());
}

getImpl()->m_activeDisplays.push_back(view);

getImpl()->m_displayCache.clear();

AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::removeActiveDisplay(const char * display)
{
if( !display || !display[0] )
{
throw Exception("Active display could not be removed from config, display name has to be a "
"non-empty name.");
throw Exception("Active display could not be removed from config, display name has to be a "
"non-empty name.");
}

auto it = std::find(getImpl()->m_activeDisplays.begin(),
getImpl()->m_activeDisplays.end(), display);

if(it!=getImpl()->m_activeDisplays.end())
if( it != getImpl()->m_activeDisplays.end() )
{
getImpl()->m_activeDisplays.erase(it);
}
else
{
getImpl()->m_activeDisplays.erase(it);
std::ostringstream os;
os << "Active display could not be removed from config. An active display named '"
<< display << "' could be be found.";
throw Exception(os.str().c_str());
}

getImpl()->m_displayCache.clear();
Expand All @@ -4039,7 +4073,8 @@ void Config::clearActiveDisplays()

const char * Config::getActiveDisplay( int index ) const
{
if( index<0 || index >= static_cast<int>(getImpl()->m_activeDisplays.size()))
if( index<0 ||
index >= static_cast<int>(getImpl()->m_activeDisplays.size()))
{
return nullptr;
}
Expand All @@ -4052,22 +4087,6 @@ int Config::getNumActiveDisplays() const
return static_cast<int>(getImpl()->m_activeDisplays.size());
}

void Config::addActiveDisplay(const char * view)
{
if( !view || !view[0] )
{
throw Exception("Active view could not be added to config, view name has to be a "
"non-empty name.");
}

getImpl()->m_activeDisplays.push_back(view);

getImpl()->m_displayCache.clear();

AutoMutex lock(getImpl()->m_cacheidMutex);
getImpl()->resetCacheIDs();
}

void Config::setActiveViews(const char * views)
{
getImpl()->m_activeViews.clear();
Expand Down Expand Up @@ -4132,7 +4151,8 @@ void Config::clearActiveViews()

const char * Config::getActiveView( int index ) const
{
if( index<0 || index >= static_cast<int>(getImpl()->m_activeViews.size()))
if( index<0 ||
index >= static_cast<int>(getImpl()->m_activeViews.size()))
{
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/OpenColorIO/ParseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ StringUtils::StringVec SplitStringEnvStyle(const std::string & str)
const std::string s = StringUtils::Trim(str);
if( s.size() == 0 )
{
return {""};
return {};
}

StringUtils::StringVec outputvec;
Expand Down Expand Up @@ -788,7 +788,7 @@ std::string JoinStringEnvStyle(const StringUtils::StringVec & outputvec)
const int nElement = static_cast<int>(outputvec.size());
if( nElement == 0 )
{
return "";
return "";
}

// We check if the value contains a symbol that could be interpreted as a separator
Expand Down

0 comments on commit a3dd78e

Please sign in to comment.