7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-11 13:50:13 +00:00

refactoring: wrapped boost::optional in OPT<> class for the purpose of easier transition to C++17 in the future

This commit is contained in:
Tomasz Włostowski 2017-11-01 12:14:16 +01:00
parent 3292d622c1
commit 9932ff32ae
65 changed files with 187 additions and 190 deletions

View File

@ -23,6 +23,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <commit.h>
#include <base_struct.h>

View File

@ -22,11 +22,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <algorithm>
#include <geometry/shape_line_chain.h>
#include <geometry/shape_circle.h>
using boost::optional;
bool SHAPE_LINE_CHAIN::Collide( const VECTOR2I& aP, int aClearance ) const
{
// fixme: ugly!
@ -366,7 +366,7 @@ bool SHAPE_LINE_CHAIN::PointOnEdge( const VECTOR2I& aP ) const
}
const optional<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfIntersecting() const
const OPT<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfIntersecting() const
{
for( int s1 = 0; s1 < SegmentCount(); s1++ )
{
@ -410,7 +410,7 @@ const optional<SHAPE_LINE_CHAIN::INTERSECTION> SHAPE_LINE_CHAIN::SelfIntersectin
}
}
return optional<INTERSECTION>();
return OPT<SHAPE_LINE_CHAIN::INTERSECTION>();
}

View File

@ -25,6 +25,8 @@
#include <tool/tool_action.h>
#include <tool/action_manager.h>
#include <algorithm>
TOOL_ACTION::TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope,
int aDefaultHotKey, const wxString aMenuItem, const wxString& aMenuDesc,
const BITMAP_OPAQUE* aIcon, TOOL_ACTION_FLAGS aFlags, void* aParam ) :

View File

@ -35,7 +35,7 @@
#include <class_draw_panel_gal.h>
#include <pcbnew_id.h>
#include <boost/optional.hpp>
#include <core/optional.h>
///> Stores information about a mouse button state
struct TOOL_DISPATCHER::BUTTON_STATE
@ -154,7 +154,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti
{
BUTTON_STATE* st = m_buttons[aIndex];
wxEventType type = aEvent.GetEventType();
boost::optional<TOOL_EVENT> evt;
OPT<TOOL_EVENT> evt;
bool isClick = false;
// bool up = type == st->upEvent;
@ -307,7 +307,7 @@ int translateSpecialCode( int aKeyCode )
void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
{
bool motion = false, buttonEvents = false;
boost::optional<TOOL_EVENT> evt;
OPT<TOOL_EVENT> evt;
int key = 0; // key = 0 if the event is not a key event
bool keyIsSpecial = false; // True if the key is a special key code
@ -436,7 +436,7 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent )
{
boost::optional<TOOL_EVENT> evt = m_actions->TranslateLegacyId( aEvent.GetId() );
OPT<TOOL_EVENT> evt = m_actions->TranslateLegacyId( aEvent.GetId() );
if( evt )
m_toolMgr->ProcessEvent( *evt );

View File

@ -27,7 +27,7 @@
#include <stack>
#include <algorithm>
#include <boost/optional.hpp>
#include <core/optional.h>
#include <wx/event.h>
#include <wx/clipbrd.h>
@ -44,8 +44,6 @@
#include <wxPcbStruct.h>
#include <class_draw_panel_gal.h>
using boost::optional;
/// Struct describing the current execution state of a TOOL
struct TOOL_MANAGER::TOOL_STATE
{
@ -494,7 +492,7 @@ void TOOL_MANAGER::RunMainStack( TOOL_BASE* aTool, std::function<void()> aFunc )
}
optional<TOOL_EVENT> TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool,
OPT<TOOL_EVENT> TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool,
const TOOL_EVENT_LIST& aConditions )
{
TOOL_STATE* st = m_toolState[aTool];
@ -632,7 +630,6 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent )
return false;
}
void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
{
// Store the current tool ID to decide whether to restore the cursor position
@ -703,10 +700,10 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
if( activeTool == GetCurrentToolId() )
{
m_viewControls->ForceCursorPosition( (bool) m_origCursor,
m_origCursor.get_value_or( VECTOR2D( 0, 0 ) ) );
m_origCursor.value_or( VECTOR2D( 0, 0 ) ) );
}
m_origCursor = boost::none;
m_origCursor = NULLOPT;
break;
}
}

View File

@ -29,8 +29,6 @@
#include <base_units.h>
#include <wx/valnum.h>
#include <boost/optional.hpp>
#include "wx_unit_binder.h"
WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextEntry* aTextInput,

View File

@ -29,7 +29,7 @@
#include <limits>
#include <base_units.h>
#include <wx/valnum.h>
#include <boost/optional.hpp>
#include <core/optional.h>
WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aValue, double aStep ) :
wxPanel( aParent, wxID_ANY ),
@ -109,18 +109,18 @@ void WX_UNIT_TEXT::SetValue( double aValue )
}
boost::optional<double> WX_UNIT_TEXT::GetValue() const
OPT<double> WX_UNIT_TEXT::GetValue() const
{
wxString text = m_inputValue->GetValue();
double value;
if( text == DEFAULT_VALUE )
return boost::optional<double>( -1.0 );
return OPT<double>( -1.0 );
if( !text.ToDouble( &value ) )
return boost::optional<double>();
return OPT<double>();
return boost::optional<double>( value );
return OPT<double>( value );
}

View File

@ -36,7 +36,7 @@ void GERBVIEW_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager )
aToolManager->RegisterTool( new ZOOM_TOOL );
}
boost::optional<TOOL_EVENT> GERBVIEW_ACTIONS::TranslateLegacyId( int aId )
OPT<TOOL_EVENT> GERBVIEW_ACTIONS::TranslateLegacyId( int aId )
{
switch( aId )
{
@ -72,5 +72,5 @@ boost::optional<TOOL_EVENT> GERBVIEW_ACTIONS::TranslateLegacyId( int aId )
break;
}
return boost::optional<TOOL_EVENT>();
return OPT<TOOL_EVENT>();
}

View File

@ -23,7 +23,7 @@
#include <tool/tool_action.h>
#include <tool/actions.h>
#include <boost/optional.hpp>
#include <core/optional.h>
class TOOL_EVENT;
class TOOL_MANAGER;
@ -130,7 +130,7 @@ public:
static TOOL_ACTION highlightAttribute;
///> @copydoc COMMON_ACTIONS::TranslateLegacyId()
virtual boost::optional<TOOL_EVENT> TranslateLegacyId( int aId ) override;
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) override;
///> @copydoc COMMON_ACTIONS::RegisterAllTools()
virtual void RegisterAllTools( TOOL_MANAGER* aToolManager ) override;

View File

@ -692,7 +692,7 @@ EDA_ITEM* GERBVIEW_SELECTION_TOOL::disambiguationMenu( GERBER_COLLECTOR* aCollec
}
else if( evt->Action() == TA_CONTEXT_MENU_CHOICE )
{
boost::optional<int> id = evt->GetCommandId();
OPT<int> id = evt->GetCommandId();
// User has selected an item, so this one will be returned
if( id && ( *id > 0 ) )

11
include/core/optional.h Normal file
View File

@ -0,0 +1,11 @@
# ifndef ___OPTIONAL_H___
# define ___OPTIONAL_H___
#include <boost/optional.hpp>
template<typename T>
using OPT = boost::optional<T>;
const auto NULLOPT = boost::none;
# endif //___OPTIONAL_HPP___

View File

@ -179,7 +179,7 @@ T Convert( const wxString& aValue )
/**
* Class OPTIONAL_XML_ATTRIBUTE
* models an optional XML attribute.
* This was implemented as an alternative to boost::optional. This class should be replaced with a
* This was implemented as an alternative to OPT. This class should be replaced with a
* simple typedef per type using std::optional when C++17 is published.
*/
template <class T>

View File

@ -30,6 +30,8 @@
#define STROKE_FONT_H_
#include <deque>
#include <algorithm>
#include <utf8.h>
#include <eda_text.h>

View File

@ -29,10 +29,9 @@
#include <climits>
#include <math/vector2d.h>
#include <core/optional.h>
#include <boost/optional/optional.hpp>
typedef boost::optional<VECTOR2I> OPT_VECTOR2I;
typedef OPT<VECTOR2I> OPT_VECTOR2I;
class SEG
{

View File

@ -25,8 +25,6 @@
#ifndef __SHAPE_INDEX_LIST_H
#define __SHAPE_INDEX_LIST_H
#include <boost/unordered_map.hpp>
template <class T>
const SHAPE* defaultShapeFunctor( const T aItem )
{

View File

@ -29,7 +29,7 @@
#include <vector>
#include <sstream>
#include <boost/optional.hpp>
#include <core/optional.h>
#include <math/vector2d.h>
#include <geometry/shape.h>
@ -538,7 +538,7 @@ public:
* Checks if the line chain is self-intersecting.
* @return (optional) first found self-intersection point.
*/
const boost::optional<INTERSECTION> SelfIntersecting() const;
const OPT<INTERSECTION> SelfIntersecting() const;
/**
* Function Simplify()

View File

@ -30,7 +30,7 @@
#include <math/vector2d.h>
#include <limits>
#include <boost/optional.hpp>
#include <core/optional.h>
/**
* Class BOX2
@ -468,7 +468,7 @@ public:
typedef BOX2<VECTOR2I> BOX2I;
typedef BOX2<VECTOR2D> BOX2D;
typedef boost::optional<BOX2I> OPT_BOX2I;
typedef OPT<BOX2I> OPT_BOX2I;
// FIXME should be removed to avoid multiple typedefs for the same type
typedef BOX2D DBOX;

View File

@ -27,7 +27,7 @@
#define __ACTIONS_H
#include <tool/tool_action.h>
#include <boost/optional.hpp>
#include <core/optional.h>
class TOOL_EVENT;
class TOOL_MANAGER;
@ -73,7 +73,7 @@ public:
* @return std::string is name of the corresponding TOOL_ACTION. It may be empty, if there is
* no corresponding TOOL_ACTION.
*/
virtual boost::optional<TOOL_EVENT> TranslateLegacyId( int aId ) = 0;
virtual OPT<TOOL_EVENT> TranslateLegacyId( int aId ) = 0;
///> Registers all valid tools for an application with the tool manager
virtual void RegisterAllTools( TOOL_MANAGER* aToolManager ) = 0;

View File

@ -26,7 +26,6 @@
#define CONDITIONAL_MENU_H
#include "selection_conditions.h"
#include <boost/unordered_map.hpp>
#include <list>
#include <wx/wx.h>

View File

@ -172,7 +172,7 @@ public:
bool HasReferencePoint() const
{
return m_referencePoint != boost::none;
return m_referencePoint != NULLOPT;
}
VECTOR2I GetReferencePoint() const
@ -187,12 +187,12 @@ public:
void ClearReferencePoint()
{
m_referencePoint = boost::none;
m_referencePoint = NULLOPT;
}
private:
boost::optional<VECTOR2I> m_referencePoint;
OPT<VECTOR2I> m_referencePoint;
/// Set of selected items
std::set<EDA_ITEM*> m_items;

View File

@ -32,7 +32,7 @@
#include <math/vector2d.h>
#include <cassert>
#include <boost/optional.hpp>
#include <core/optional.h>
class TOOL_ACTION;
class TOOL_MANAGER;
@ -387,12 +387,12 @@ public:
m_param = (void*) aParam;
}
boost::optional<int> GetCommandId() const
OPT<int> GetCommandId() const
{
return m_commandId;
}
boost::optional<std::string> GetCommandStr() const
OPT<std::string> GetCommandStr() const
{
return m_commandStr;
}
@ -453,11 +453,11 @@ private:
///> Generic parameter used for passing non-standard data.
void* m_param;
boost::optional<int> m_commandId;
boost::optional<std::string> m_commandStr;
OPT<int> m_commandId;
OPT<std::string> m_commandStr;
};
typedef boost::optional<TOOL_EVENT> OPT_TOOL_EVENT;
typedef OPT<TOOL_EVENT> OPT_TOOL_EVENT;
/**
* Class TOOL_EVENT_LIST
@ -490,13 +490,13 @@ public:
*/
const std::string Format() const;
boost::optional<const TOOL_EVENT&> Matches( const TOOL_EVENT& aEvent ) const
OPT<const TOOL_EVENT&> Matches( const TOOL_EVENT& aEvent ) const
{
for( const_iterator i = m_events.begin(); i != m_events.end(); ++i )
if( i->Matches( aEvent ) )
return *i;
return boost::optional<const TOOL_EVENT&>();
return OPT<const TOOL_EVENT&>();
}
/**

View File

@ -329,7 +329,7 @@ public:
* The pause/resume operation is done through COROUTINE object.
* Called only from coroutines.
*/
boost::optional<TOOL_EVENT> ScheduleWait( TOOL_BASE* aTool,
OPT<TOOL_EVENT> ScheduleWait( TOOL_BASE* aTool,
const TOOL_EVENT_LIST& aConditions );
/**
@ -514,7 +514,7 @@ private:
ACTION_MANAGER* m_actionMgr;
/// Original cursor position, if overridden by the context menu handler
boost::optional<VECTOR2D> m_origCursor;
OPT<VECTOR2D> m_origCursor;
EDA_ITEM* m_model;
KIGFX::VIEW* m_view;

View File

@ -80,7 +80,7 @@ public:
* Function GetValue
* Returns the current value in currently used units.
*/
virtual boost::optional<double> GetValue() const;
virtual OPT<double> GetValue() const;
/**
* Function GetUnits

View File

@ -262,5 +262,5 @@ void BOARD_ITEM::DeleteStructure()
void BOARD_ITEM::SwapData( BOARD_ITEM* aImage )
{
}

View File

@ -381,8 +381,7 @@ bool D_PAD::GetBestAnchorPosition( VECTOR2I& aPos )
minDistEdge = std::max( GetSize().x, GetSize().y );
}
boost::optional<VECTOR2I> bestAnchor( []()->
boost::optional<VECTOR2I>{ return boost::none; }() );
OPT<VECTOR2I> bestAnchor;
for ( int y = 0; y < stepsY ; y++ )
{

Some files were not shown because too many files have changed in this diff Show More