Added documentation for the PropertyDelegate class

This commit is contained in:
Alexander Bock
2014-09-07 17:45:53 +02:00
parent e5b61492e9
commit cdfde82522
2 changed files with 87 additions and 7 deletions
@@ -32,26 +32,109 @@ struct lua_State;
namespace openspace {
namespace properties {
/**
* The PropertyDelegate class is used by (among others) the TemplateProperty and the
* NumericalProperty classes to outsource the definitions of class names, default values,
* etc. Using the PropertyDelegate, it is possible to create new TemplateProperty types
* without subclassing the TemplateProperty, but rather creating a specialized instance
* of PropertyDelegate. See (http://openspace.itn.liu.se/trac/wiki/guides/properties) for
* more detailed information.
* \see TemplateProperty
* \see NumericalProperty
* \tparam T The full class for which this specialized instance of PropertyDelegate is
* responsible. For example <code>T = TemplateProperty<std::string></code>.
*/
template <typename T>
class PropertyDelegate {
public:
/**
* This method returns the class name for the class <code>T</code>. The default
* implementation will lead to a compile-time error if the class method is not
* specialized.
* \return The class name for the class <code>T</code>
*/
static std::string className();
/**
* This method will return the preferred default value for the class <code>T</code>.
* The default implementation will lead to a compile-time error if the class method is
* not specialized.
* \return The default value that the class <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
static U defaultValue();
/**
* This method will return the preferred default minimum value for the class
* <code>T</code>. The default implementation will lead to a compile-time error if the
* class method is not specialized. This method is not used in TemplateProperty, but
* only NumericalProperty, so the TemplateProperty does not require this method to be
* specialized.
* \return The default minimum value that the class <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
*/
template <typename U>
static U defaultMinimumValue();
/**
* This method will return the preferred default maximum value for the class
* <code>T</code>. The default implementation will lead to a compile-time error if the
* class method is not specialized. This method is not used in TemplateProperty, but
* only NumericalProperty, so the TemplateProperty does not require this method to be
* specialized.
* \return The default maximum value that the class <code>T</code> should use
* \tparam U The type by which the class T is specialized. If
* <code>T = NumericalProperty<int></code>, then <code>U = int</code>
*/
template <typename U>
static U defaultMaximumValue();
/**
* This method converts the top value from the Lua stack into a value of type
* <code>U</code> and reports the <code>success</code> back to the caller. The default
* implementation will lead to a compile-time error if the class method is not
* specialized.
* \param state The Lua state from which the value is retrieved
* \param success Will be <code>true</code> if the conversion succeeded;
* <code>false</code> otherwise
* \return The value that was created by converting the top value from the stack
* \tparam U The type by which the class T is specialized. If
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
static U fromLuaValue(lua_State* state, bool& success);
/**
* This method converts the passed <code>value</code>, encodes it and places it on the
* top value of the Lua stack and returns the success back to the caller. The default
* implementation will lead to a compile-time error if the class method is not
* specialized.
* \param state The Lua state from which the value is retrieved
* \param value The value that will be converted into a Lua object
* \return <code>true</code> if the conversion succeeded; <code>false</code> otherwise
* \tparam U The type by which the class T is specialized. If
* <code>T = TemplateProperty<std::string></code>, then <code>U = std::string</code>
*/
template <typename U>
static bool toLuaValue(lua_State* state, U value);
/**
* Returns the Lua type that will be put onto the stack in the
* PropertyDelegate::toLuaValue method and which will be consumed by the
* PropertyDelegate::fromLuaValue method. The returned value can belong to the set of
* Lua types: <code>LUA_TNONE</code>, <code>LUA_TNIL</code>,
* <code>LUA_TBOOLEAN</code>, <code>LUA_TLIGHTUSERDATA</code>,
* <code>LUA_TNUMBER</code>, <code>LUA_TSTRING</code>, <code>LUA_TTABLE</code>,
* <code>LUA_TFUNCTION</code>, <code>LUA_TUSERDATA</code>, or
* <code>LUA_TTHREAD</code>. The default implementation will return
* <code>LUA_TNONE</code>. The default implementation will lead to a compile-time
* error if the class method is not specialized.
* \return The Lua type that will be consumed or produced by the
* PropertyDelegate::toLuaValue and PropertyDelegate::fromLuaValue methods.
*/
static int typeLua();
};
@@ -24,22 +24,20 @@
#include <typeinfo>
#include <ghoul/logging/logmanager.h>
#include <cassert>
namespace openspace {
namespace properties {
template <typename T>
std::string PropertyDelegate<T>::className() {
static_assert(sizeof(T) == 0, "Unimplemented PropertyDelegate::className specialization");
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::className specialization");
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::defaultValue() {
static_assert(sizeof(T) == 0, "Unimplemented PropertyDelegate::defaultValue specialization");
static_assert(sizeof(T) == 0,
"Unimplemented PropertyDelegate::defaultValue specialization");
}
template <typename T>
@@ -49,7 +47,6 @@ U PropertyDelegate<T>::defaultMinimumValue() {
"Unimplemented PropertyDelegate::defaultMinimumValue specialization");
}
template <typename T>
template <typename U>
U PropertyDelegate<T>::defaultMaximumValue() {