Flip Reference

Class Class Reference

Declared in

flip/Class.h

template <class T> class Class;

flip::Class is a type that represents a declaration of a flip Class. A concrete instance of this class is acquired using an instance of the DataModel

Template Parameters

T

The type to declare. T must inherit from flip::Object

Member Functions Synopsys

Declaring

name

Set the name of the class

inherit

Inherit from a class

member

Declare a member of the class

Accessing

name

Returns the name of the class

members

Returns information on the members of the class

Member Functions

name

Class &  name (const char * name_0);

Set the name of the class. The name must be in the ascii-7 character set, with exception of spaces, control characters as well as del character.

Names starting with flip are reserved.

This function returns a reference to the Class to allow call chaining.

Example :

class Model : public DataModel <Model> {};
class Root : public Object
{
public:
   Int   value;
};
auto & root_class = Model::declare <Root> ();
// 'root_class' is of type 'Class <Root>'
root_class
   .name ("myapp.Root")
   .member <Int, &Root::value> ("value");

inherit

template <class U>   Class &  inherit ();

Inherits from class U passed as a template parameter. Multiple inheritance is not supported.

This function returns a reference to the Class to allow call chaining.

Example :

class Model : public DataModel <Model> {};
class A : public Object
{
public:
   Int   value;
};
class B : public A
{
public:
   Float value2;
};
// first declare base class
Model::declare <A> ()
   .name ("myapp.A")
   .member <Int, &A::value> ("value");
// then declare inherited classes
Model::declare <B> ()
   .name ("myapp.B")
   .inherit <A> ()
   .member <Float, &B::value2> ("value2");

Inheriting imports all members of superclass in the class, therefore :


member

template <class U, U T::*ptr_to_member>   Class &  member (const char * name_0);

Declare a member of the class. The name must be in the ascii-7 character set, with exception of spaces, control characters as well as del character.

WARNING: flip Member declaration must follow the same order as in the C++ class declaration.

All member names must be different.

This function returns a reference to the Class to allow call chaining.

Example :

class Model : public DataModel <Model> {};
class Root : public Object
{
public:
   Int   value;
   Float value2;
};
Model::declare <Root> ()
   .name ("myapp.Root")
   .member <Int, &Root::value> ("value")
   .member <Float, &Root::value2> ("value2");

name

const char *   name () const

Returns the name of the class.


members

const Members &   members () const

Returns information on the members of the class. This allows for automatic introspection of an instance of the class.

Example : \codeblock [language=c++] *** void introspect (Root & root) { for (const auto & member : root.get_class ().members ()) { auto & obj = member._representative.from (root); const char * name_0 = member._name_0;

// on the first loop iteration, // 'obj' represents a reference to 'root.value' // 'name_0' is "value"

// on the second loop iteration, // 'obj' represents a reference to 'root.value2' // 'name_0' is "value2" } } ***