From 9d9d74faadc137ce3b96fbdfb233b47c2e4a306b Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 8 Aug 2013 14:59:59 +0200 Subject: [PATCH] Reformatting. --- common/tool/context_menu.cpp | 2 +- common/tool/tool_manager.cpp | 2 + include/tool/coroutine.h | 99 ++++++++-------- include/tool/tool_manager.h | 205 +++++++++++++++++----------------- pcbnew/tools/selection_tool.h | 2 +- 5 files changed, 151 insertions(+), 159 deletions(-) diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index 125bb2bffb..0a38f5bb0c 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -35,7 +35,7 @@ class CONTEXT_MENU::CMEventHandler : public wxEvtHandler { public: CMEventHandler( CONTEXT_MENU* aMenu ): - m_menu(aMenu) {}; + m_menu( aMenu ) {}; void onEvent( wxEvent& aEvent ) { diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 7293c6fb31..95c743cc26 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -64,10 +64,12 @@ struct TOOL_MANAGER::ToolState std::vector transitions; }; + TOOL_MANAGER::TOOL_MANAGER() { } + void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool ) { ToolState* st = new ToolState; diff --git a/include/tool/coroutine.h b/include/tool/coroutine.h index be57b97778..719c4dccd8 100644 --- a/include/tool/coroutine.h +++ b/include/tool/coroutine.h @@ -52,12 +52,11 @@ See coroutine_example.cpp for sample code. */ -template -class COROUTINE { - +template +class COROUTINE +{ public: - - COROUTINE ( ) + COROUTINE() { m_stackSize = c_defaultStackSize; m_stack = NULL; @@ -68,34 +67,26 @@ public: * Constructor * Creates a coroutine from a member method of an object */ - template - COROUTINE ( T* object, ReturnType (T::*ptr)( ArgType ) ) : - m_func (object, ptr), - m_saved(NULL), - m_stack(NULL), - m_stackSize(c_defaultStackSize) + COROUTINE( T* object, ReturnType (T::*ptr)( ArgType ) ) : + m_func( object, ptr ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize ) { - } /** * Constructor * Creates a coroutine from a delegate object */ - COROUTINE( DELEGATE < ReturnType, ArgType > aEntry ) : - m_func(aEntry), - m_saved(NULL), - m_stack(NULL), - m_stackSize(c_defaultStackSize) + COROUTINE( DELEGATE aEntry ) : + m_func( aEntry ), m_saved( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize ) {}; ~COROUTINE() { - if(m_saved) - delete m_saved; - if(m_stack) - free(m_stack); + if( m_saved ) + delete m_saved; + if( m_stack ) + free( m_stack ); } /** @@ -105,9 +96,9 @@ public: * After a yield, Call() or Resume() methods invoked by the caller will * immediately return true, indicating that we are not done yet, just asleep. */ - void Yield( ) + void Yield() { - jump_fcontext(m_self, m_saved, 0); + jump_fcontext( m_self, m_saved, 0 ); } /** @@ -119,7 +110,7 @@ public: void Yield( ReturnType& retVal ) { m_retVal = retVal; - jump_fcontext(m_self, m_saved, 0); + jump_fcontext( m_self, m_saved, 0 ); } /** @@ -127,7 +118,7 @@ public: * * Defines the entry point for the coroutine, if not set in the constructor. */ - void SetEntry ( DELEGATE < ReturnType, ArgType > aEntry ) + void SetEntry( DELEGATE aEntry ) { m_func = aEntry; } @@ -141,19 +132,19 @@ public: bool Call( ArgType args ) { // fixme: Clean up stack stuff. Add a guard - m_stack = malloc(c_defaultStackSize); + m_stack = malloc( c_defaultStackSize ); - // align to 16 bytes - void *sp = (void *) ((((ptrdiff_t) m_stack) + m_stackSize - 0xf) & 0xfffffff0); + // align to 16 bytes + void *sp = (void *) ( ( ( (ptrdiff_t) m_stack ) + m_stackSize - 0xf ) & 0xfffffff0 ); - m_args = &args; - m_self = boost::context::make_fcontext(sp, m_stackSize, callerStub ); - m_saved = new boost::context::fcontext_t(); - - m_running = true; - // off we go! - boost::context::jump_fcontext(m_saved, m_self, reinterpret_cast (this)); - return m_running; + m_args = &args; + m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); + m_saved = new boost::context::fcontext_t(); + + m_running = true; + // off we go! + boost::context::jump_fcontext( m_saved, m_self, reinterpret_cast( this ) ); + return m_running; } /** @@ -163,10 +154,10 @@ public: * @return true, if the coroutine has yielded again and false if it has finished its * execution (returned). */ - bool Resume( ) + bool Resume() { - jump_fcontext(m_saved, m_self, 0); - return m_running; + jump_fcontext( m_saved, m_self, 0 ); + return m_running; } /** @@ -190,47 +181,47 @@ public: } private: - static const int c_defaultStackSize = 2000000; /* real entry point of the coroutine */ - static void callerStub(intptr_t data) + static void callerStub( intptr_t data ) { // get pointer to self - COROUTINE *cor = reinterpret_cast *> (data); + COROUTINE* cor = reinterpret_cast*>( data ); // call the coroutine method - cor->m_retVal = cor->m_func(*cor->m_args); + cor->m_retVal = cor->m_func( *cor->m_args ); cor->m_running = false; // go back to wherever we came from. - boost::context::jump_fcontext(cor->m_self, cor->m_saved, 0); //reinterpret_cast (this)); + boost::context::jump_fcontext( cor->m_self, cor->m_saved, 0 ); //reinterpret_cast( this )); } - template struct strip_ref { - typedef T result; + template struct strip_ref + { + typedef T result; }; - template struct strip_ref { - typedef T result; + template struct strip_ref + { + typedef T result; }; - - DELEGATE < ReturnType, ArgType > m_func; + DELEGATE m_func; ///< pointer to coroutine entry arguments. Stripped of references ///< to avoid compiler errors. - typename strip_ref::result *m_args; + typename strip_ref::result* m_args; ReturnType m_retVal; ///< saved caller context - boost::context::fcontext_t *m_saved; + boost::context::fcontext_t* m_saved; ///< saved coroutine context - boost::context::fcontext_t *m_self; + boost::context::fcontext_t* m_self; ///< coroutine stack - void *m_stack; + void* m_stack; size_t m_stackSize; diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 8014eded74..dc7e62ee8f 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -50,127 +50,126 @@ class wxWindow; */ class TOOL_MANAGER { - public: - - TOOL_MANAGER(); - ~TOOL_MANAGER(); +public: + TOOL_MANAGER(); + ~TOOL_MANAGER(); - /** - * Generates an unique ID from for a tool with given name. - */ - static TOOL_ID MakeToolId( const std::string& aToolName ); + /** + * Generates an unique ID from for a tool with given name. + */ + static TOOL_ID MakeToolId( const std::string& aToolName ); - /** - * Function RegisterTool() - * Adds a tool to the manager set and sets it up. Called once for - * each tool during application initialization. - * @param aTool: tool to be added. Ownership is transferred. - */ - void RegisterTool( TOOL_BASE* aTool ); + /** + * Function RegisterTool() + * Adds a tool to the manager set and sets it up. Called once for + * each tool during application initialization. + * @param aTool: tool to be added. Ownership is transferred. + */ + void RegisterTool( TOOL_BASE* aTool ); - /** - * Function InvokeTool() - * Calls a tool by sending a tool activation event to tool of given ID or name. - * An user-defined parameter object can be also passed - */ - void InvokeTool( TOOL_ID aToolId ); - void InvokeTool( const std::string& name ); + /** + * Function InvokeTool() + * Calls a tool by sending a tool activation event to tool of given ID or name. + * An user-defined parameter object can be also passed + */ + void InvokeTool( TOOL_ID aToolId ); + void InvokeTool( const std::string& name ); - template - void InvokeTool( const std::string& name, const Parameters& aToolParams ); + template + void InvokeTool( const std::string& name, const Parameters& aToolParams ); - /** - * Function FindTool() - * Searches for a tool with given name or ID - */ - TOOL_BASE *FindTool( int aId ); - TOOL_BASE *FindTool( const std::string& aName ); + /** + * Function FindTool() + * Searches for a tool with given name or ID + */ + TOOL_BASE *FindTool( int aId ); + TOOL_BASE *FindTool( const std::string& aName ); - /** - * Resets the state of a given tool by clearing its wait and - * transition lists and calling tool's internal Reset() method. - */ - void ResetTool( TOOL_BASE *aTool ); + /** + * Resets the state of a given tool by clearing its wait and + * transition lists and calling tool's internal Reset() method. + */ + void ResetTool( TOOL_BASE *aTool ); - /** - * Takes an event from the TOOL_DISPATCHER and propagates it to - * tools that requested events of matching type(s) - */ - bool ProcessEvent( TOOL_EVENT& aEvent ); - - /** - * Sets the work environment (model, view, view controls and the parent window). - * These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME) - * when the board is set up - */ - void SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, - KiGfx::VIEW_CONTROLS* aViewControls, wxWindow* aFrame ); + /** + * Takes an event from the TOOL_DISPATCHER and propagates it to + * tools that requested events of matching type(s) + */ + bool ProcessEvent( TOOL_EVENT& aEvent ); - /* Accessors for the environment objects (view, model, etc.) */ - KiGfx::VIEW* GetView() - { - return m_view; - } + /** + * Sets the work environment (model, view, view controls and the parent window). + * These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME) + * when the board is set up + */ + void SetEnvironment( EDA_ITEM* aModel, KiGfx::VIEW* aView, + KiGfx::VIEW_CONTROLS* aViewControls, wxWindow* aFrame ); - KiGfx::VIEW_CONTROLS* GetViewControls() - { - return m_viewControls; - } + /* Accessors for the environment objects (view, model, etc.) */ + KiGfx::VIEW* GetView() + { + return m_view; + } - EDA_ITEM* GetModel() - { - return m_model; - } + KiGfx::VIEW_CONTROLS* GetViewControls() + { + return m_viewControls; + } - wxWindow* GetEditFrame() - { - return m_editFrame; - } + EDA_ITEM* GetModel() + { + return m_model; + } - /** - * Defines a state transition - the events that cause a given handler method in the tool - * to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context. - */ - void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler, - const TOOL_EVENT_LIST& aConditions ); - - /** - * Pauses execution of a given tool until one or more events matching aConditions arrives. - * The pause/resume operation is done through COROUTINE object. - * Called only from coroutines. - */ - boost::optional ScheduleWait( TOOL_BASE* aTool, - const TOOL_EVENT_LIST& aConditions ); - - /** - * Sets behaviour of the tool's context popup menu. - * @param aMenu - the menu structure, defined by the tool - * @param aTrigger - when the menu is activated: - * CMENU_NOW: opens the menu right now - * CMENU_BUTTON: opens the menu when RMB is pressed - * CMENU_OFF: menu is disabled. - * May be called from a coroutine context. - */ - void ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu, - TOOL_ContextMenuTrigger aTrigger ); + wxWindow* GetEditFrame() + { + return m_editFrame; + } - private: - void dispatchInternal( TOOL_EVENT& aEvent ); + /** + * Defines a state transition - the events that cause a given handler method in the tool + * to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context. + */ + void ScheduleNextState( TOOL_BASE* aTool, TOOL_STATE_FUNC& aHandler, + const TOOL_EVENT_LIST& aConditions ); - struct ToolState; - typedef std::pair Transition; + /** + * Pauses execution of a given tool until one or more events matching aConditions arrives. + * The pause/resume operation is done through COROUTINE object. + * Called only from coroutines. + */ + boost::optional ScheduleWait( TOOL_BASE* aTool, + const TOOL_EVENT_LIST& aConditions ); - std::map m_toolState; - std::map m_toolNameIndex; - std::map m_toolIdIndex; + /** + * Sets behaviour of the tool's context popup menu. + * @param aMenu - the menu structure, defined by the tool + * @param aTrigger - when the menu is activated: + * CMENU_NOW: opens the menu right now + * CMENU_BUTTON: opens the menu when RMB is pressed + * CMENU_OFF: menu is disabled. + * May be called from a coroutine context. + */ + void ScheduleContextMenu( TOOL_BASE* aTool, CONTEXT_MENU* aMenu, + TOOL_ContextMenuTrigger aTrigger ); - EDA_ITEM* m_model; - KiGfx::VIEW* m_view; - KiGfx::VIEW_CONTROLS* m_viewControls; - wxWindow* m_editFrame; +private: + void dispatchInternal( TOOL_EVENT& aEvent ); - ToolState* m_currentTool; + struct ToolState; + typedef std::pair Transition; + + std::map m_toolState; + std::map m_toolNameIndex; + std::map m_toolIdIndex; + + EDA_ITEM* m_model; + KiGfx::VIEW* m_view; + KiGfx::VIEW_CONTROLS* m_viewControls; + wxWindow* m_editFrame; + + ToolState* m_currentTool; }; #endif diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 179dc1e88d..3c5fb159c4 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -54,7 +54,7 @@ public: ~SELECTION_TOOL (); void Reset(); - int Main(TOOL_EVENT& aEvent); + int Main( TOOL_EVENT& aEvent ); private: void selectSingle( const VECTOR2I& aWhere, bool aAdditive );