Skip to content

Commit

Permalink
Inspector : Prefer std::variant to boost::variant
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Dec 10, 2024
1 parent 41d12cf commit 8034c18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions include/GafferSceneUI/Private/Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
#include "boost/multi_index/member.hpp"
#include "boost/multi_index/random_access_index.hpp"
#include "boost/multi_index_container.hpp"
#include "boost/variant.hpp"

#include <unordered_set>
#include <unordered_map>
#include <variant>

namespace GafferSceneUIModule
{
Expand Down Expand Up @@ -171,7 +171,7 @@ class GAFFERSCENEUI_API Inspector : public IECore::RefCounted, public Gaffer::Si
virtual Gaffer::ValuePlugPtr source( const GafferScene::SceneAlgo::History *history, std::string &editWarning ) const;

using EditFunction = std::function<Gaffer::ValuePlugPtr ( bool createIfNecessary )>;
using EditFunctionOrFailure = boost::variant<EditFunction, std::string>;
using EditFunctionOrFailure = std::variant<EditFunction, std::string>;
/// Should be implemented to return a function that will acquire
/// an edit from the EditScope at the specified point in the history.
/// If this is not possible, should return an error explaining why
Expand All @@ -184,7 +184,7 @@ class GAFFERSCENEUI_API Inspector : public IECore::RefCounted, public Gaffer::Si
virtual EditFunctionOrFailure editFunction( Gaffer::EditScope *editScope, const GafferScene::SceneAlgo::History *history ) const;

using DisableEditFunction = std::function<void ()>;
using DisableEditFunctionOrFailure = boost::variant<DisableEditFunction, std::string>;
using DisableEditFunctionOrFailure = std::variant<DisableEditFunction, std::string>;
/// Can be implemented to return a function that will disable an edit
/// at the specified plug. If this is not possible, should return an
/// error explaining why (this is typically due to `readOnly` metadata).
Expand Down
26 changes: 14 additions & 12 deletions src/GafferSceneUI/Inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,52 +732,54 @@ const std::string &Inspector::Result::fallbackDescription() const

bool Inspector::Result::editable() const
{
return m_editFunction.which() == 0 && boost::get<EditFunction>( m_editFunction ) != nullptr;
auto f = std::get_if<EditFunction>( &m_editFunction );
return f && *f;
}

std::string Inspector::Result::nonEditableReason() const
{
if( m_editFunction.which() == 1 )
if( auto s = std::get_if<std::string>( &m_editFunction ) )
{
return boost::get<std::string>( m_editFunction );
return *s;
}

return "";
}

Gaffer::ValuePlugPtr Inspector::Result::acquireEdit( bool createIfNecessary ) const
{
if( m_editFunction.which() == 0 )
if( auto f = std::get_if<EditFunction>( &m_editFunction ) )
{
return boost::get<EditFunction>( m_editFunction )( createIfNecessary );
return (*f)( createIfNecessary );
}

throw IECore::Exception( "Not editable : " + boost::get<std::string>( m_editFunction ) );
throw IECore::Exception( "Not editable : " + std::get<std::string>( m_editFunction ) );
}

bool Inspector::Result::canDisableEdit() const
{
return m_disableEditFunction.which() == 0 && boost::get<DisableEditFunction>( m_disableEditFunction ) != nullptr;
auto f = std::get_if<DisableEditFunction>( &m_disableEditFunction );
return f && *f;
}

std::string Inspector::Result::nonDisableableReason() const
{
if( m_disableEditFunction.which() == 1 )
if( auto s = std::get_if<std::string>( &m_disableEditFunction ) )
{
return boost::get<std::string>( m_disableEditFunction );
return *s;
}

return "";
}

void Inspector::Result::disableEdit() const
{
if( m_disableEditFunction.which() == 0 )
if( auto f = std::get_if<DisableEditFunction>( &m_disableEditFunction ) )
{
return boost::get<DisableEditFunction>( m_disableEditFunction )();
return (*f)();
}

throw IECore::Exception( "Cannot disable edit : " + boost::get<std::string>( m_disableEditFunction ) );
throw IECore::Exception( "Cannot disable edit : " + std::get<std::string>( m_disableEditFunction ) );
}

std::string Inspector::Result::editWarning() const
Expand Down

0 comments on commit 8034c18

Please sign in to comment.