1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 * @file CommandObject.h
24 * This file contains the CommandObject class.
34 * This template defines a function binding.
36 * A binding is made to a name, allowing some sort of reflection later on.
42 typedef void (T::*CommandFunction
)(const std::string
& argument
); /**< The type of the function to bind on. */
44 /** Construct a CommandObject, binding the specified function to the specified name. */
45 CommandObject(const char* name
, CommandFunction command
, bool fullname
= false);
47 /** Destructor, a noop. */
51 /** Execute the stored function with the specified owner and argument. */
52 void Run(T
* owner
, const std::string
& argument
) const;
54 /** Return the name of the bound function. */
55 const char* getName() const;
57 /** Whether, when performing a lookup on this function, only the full alias should be allowed. */
58 bool fullName() const;
61 const char* m_name
; /**< The name of the bound function. */
62 CommandFunction m_command
; /**< The bound function. */
63 bool m_fullName
; /**< Whether only the full alias should be allowed. */
67 const char* CommandObject
<T
>::getName() const
73 bool CommandObject
<T
>::fullName() const
79 CommandObject
<T
>::CommandObject(const char* name
, CommandFunction command
, bool fullname
) :
88 CommandObject
<T
>::~CommandObject()
93 void CommandObject
<T
>::Run(T
* owner
, const std::string
& argument
) const
98 (owner
->*m_command
)(argument
);