Code Monkey home page Code Monkey logo

genericparameters's Introduction

GenericParameters

GenericParameters is a C++ header-only library to define generic parameters. A generic parameter can be defined by a pointer to a variable or by set/get-functions. Moreover, a generic parameter stores additional information like the parameter type, max/min limits, a description, etc. Such parameters are very useful, e.g., for an automatic generation of GUI elements.

The library is used in [SPlisHSPlasH] (https://github.com/InteractiveComputerGraphics/SPlisHSPlasH) to handle all parameters of the implemented fluid simulation methods.

Author: Jan Bender, License: MIT

Libraries using GenericParameters

Build Instructions

Since this is a header-only library, the build is only required for the tests.

This project is based on CMake. Simply generate project, Makefiles, etc. using CMake and compile the project with the compiler of your choice. The code was tested with the following configurations:

  • Windows 10 64-bit, CMake 3.7, Visual Studio 2015 & 2017
  • Debian 8 64-bit, CMake 3.7, GCC 4.9.2.

Usage

Creating a generic parameter for an integer value by providing the pointer of an integer variable:

m_intValue = 3;
MY_INT_PARAMETER = createNumericParameter("intParam", "Int param", &m_intValue);
setGroup(MY_INT_PARAMETER, "ParameterGroup");
setDescription(MY_INT_PARAMETER, "Help text");

// Set min and max values
IntParameter* intParam = static_cast<IntParameter*>(getParameter(MY_INT_PARAMETER));
intParam->setMinValue(2);
intParam->setMaxValue(4);

The function createNumericParameter returns an integer id of the parameter which can be used to set/get values or to get information about the parameter. The value of a generic parameter can be set/get by the unified functions getValue/setValue:

getValue<int>(TestParameterObject::MY_INT_PARAMETER);
setValue<int>(TestParameterObject::MY_INT_PARAMETER, -5);

Moreover, you can query the type of any parameter:

if (getType(TestParameterObject::MY_INT_PARAMETER) == ParameterBase::INT32)

In the following an example for an enum parameter is given:

m_enumValue = 1;
MY_ENUM_PARAMETER = createEnumParameter("enumParam", "Enum param", &m_enumValue);
EnumParameter* enumParam = static_cast<EnumParameter*>(getParameter(MY_ENUM_PARAMETER));
enumParam->addEnumValue("enum1", MY_ENUM_VALUE1);
enumParam->addEnumValue("enum2", MY_ENUM_VALUE2);
enumParam->setGroup("EnumGroup");
enumParam->setDescription("This is an enum.");

Here, the integers MY_ENUM_VALUE1 and MY_ENUM_VALUE2 are set in the function addEnumValue() defining an id for the corresponding enum value.

Another example which uses get/set callback functions instead of a pointer to a variable is given here:

// header
double getDoubleValue() { return m_doubleValue; }
void setDoubleValue(double val) { m_doubleValue = val; }
// implementation
setDoubleValue(3.123);
ParameterBase::GetFunc<double> getFct = std::bind(&TestParameterObject::getDoubleValue, this);
ParameterBase::SetFunc<double> setFct = std::bind(&TestParameterObject::setDoubleValue, this, std::placeholders::_1);
MY_DOUBLE_PARAMETER = createNumericParameter<double>("doubleParam", "Double param", getFct, setFct);
setGroup(MY_DOUBLE_PARAMETER, "ParameterGroup");
setDescription(MY_DOUBLE_PARAMETER, "Help text");
DoubleParameter* doubleParam = static_cast<DoubleParameter*>(getParameter(MY_DOUBLE_PARAMETER));
doubleParam->setMinValue(0.1);
doubleParam->setMaxValue(0.9);

genericparameters's People

Contributors

digitalillusions avatar janbender avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.