Simulation Modeling Tool Kit
Classes | Namespaces | Macros
Generator.h File Reference

Generator templates. More...

#include "smtk/common/CompilerInformation.h"
#include <algorithm>
#include <cassert>
#include <memory>
#include <set>
Include dependency graph for Generator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


struct  smtk::common::detail::NullGeneratorBase
class  smtk::common::GeneratorBase< Input, Output, Base >
 Base for all generators. More...
class  smtk::common::Generator< Input, Output, Base >
 Interface generator class. More...
class  smtk::common::GeneratorType< Input, Output, Self, Base >
 Base class for specific generator types. More...


 The main namespace for the Simulation Modeling Tool Kit (SMTK).
 Classes used throughout the toolkit.



Detailed Description

Generator templates.

Given an input type <Input> and a desired output type <Output>, the following class templates describe a class Generator<Input, Output> for generating an instance of the Output type given the Input type. The output type must have a default constructor; this value will be returned when no conditions for generation have been satisfied. Here is an example of an implementation that accepts std::string and outputs type Foo:

(RegisterGenerateFoo.h) This class can exist external to smtk, like in a plugin (RGG, for example).

class RegisterGenerateFoo : public GeneratorType<std::string, Foo, RegisterGenerateFoo>
bool valid(const std::string&) const override;
Foo operator()(const std::string&) override;

(RegisterGenerateFoo.cxx) Note that valid() and operator() may be defined in the header, and registerClass() may be called in another .cxx file, like smtk's Registrar.cxx files.

static bool registered_Foo_1 = RegisterGenerateFoo::registerClass();
bool RegisterGenerateFoo::valid(const std::string& input) const
return <Logic to decide if input1 is useable by RegisterGenerateFoo>
Foo RegisterGenerateFoo::operator()(const std::string& input)
return <a generated Foo>

(GenerateFoo.h) Note: the macros used here are different and depend on the smtk module, here IOVTK

#ifndef smtkIOVTK_EXPORTS
template class SMTKIOVTK_EXPORT Generator<std::string, Foo>;
using GenerateFoo = Generator<std::string, Foo>;

(GenerateFoo.cxx) The .cxx must exist to generate the right symbols to link against.

template class Generator<std::string, Foo>;


std::string foo_string = "<input for GenerateFoo>";
GenerateFoo generateFoo;
Foo foo = generateFoo(foo_string);