Flip Reference

BackEndIR::Type Class Reference

Declared in

flip/BackEndIR.h

class BackEndIR
{
public:
   class Type;
}

flip::BackEndIR::Type represents an intermediate representation of a document's object. Instead of directly to matching to flip class members, this objects holds class and attribute names as strings, allowing to modify this representation before it is fed to the document.

Every BackEndIR holds one instance of BackEndIR::Type which represents the root of the document.

Typically, converting a document to one model revision to another consists of manipulating the data stored in that tree. The members of Type are exposed below.

class Type
{
public:
   Ref                                          ref;
   std::string                                  type_name;
   std::list <Member>                           members;
   Value                                        value;
   std::map <KeyRandom, Type>                   collection;
   std::map <KeyFloat, Type>                    array;
   std::map <KeyBlob, Type>                     map;
};

flip::BackEndIR::Type can be manipulated through the monolithic and convenient API described below.

Member Types

Member

std::pair <std::string, Type>, a type representing a member in an Object

CollectionElement

std::pair <const KeyRandom, Type>, a type representing an element in a Collection

ArrayElement

std::pair <const KeyFloat, Type>, a type representing an element in an Array

MapElement

std::pair <const KeyBlob, Type>, a type representing an element in a Map

Member Functions Synopsys

get_class

Returns the class name or base type

Object Methods

object_set_class

Sets the class of an object

member

Returns a member of an Object

object_add_member_array

Add a Array member to the object

object_add_member_blob

Add a Blob member to the object

object_add_member_bool

Add a Bool member to the object

object_add_member_collection

Add a Collection member to the object

object_add_member_enum

Add a Enum member to the object

object_add_member_float

Add a Float member to the object

object_add_member_int

Add a Int member to the object

object_add_member_map

Add a Map member to the object

object_add_member_message

Add a Message member to the object

object_add_member_object

Add a Object member to the object

object_add_member_object_ref

Add a ObjectRef member to the object

object_add_member_optional

Add a Collection member to the object

object_add_member_string

Add a String member to the object

object_add_member_variant

Add a Collection member to the object

object_add_member_vector

Add a Blob member to the object

object_remove_member

Remove a member from the object

object_rename_member

Rename a member of an object

Value Methods

value_set_blob

Sets the value of the Blob

value_set_bool

Sets the value of the Bool

value_set_enum

Sets the value of the Enum

value_set_float

Sets the value of the Float

value_set_int

Sets the value of the Int

value_set_object_ref

Sets the value of the ObjectRef

value_set_string

Sets the value of the String

Collection Methods

collection_add_object

Add an Object to the Collection

collection_add

Add an element to the Collection

Array Methods

array_add_object

Add an Object to the Array

array_add

Add an element to the Array

Map Methods

map_add_object

Add an Object to the Map

map_add

Add an element to the Map

Member Variables Synopsys

ref

Unique reference number of object

type_name

Type name as declared in the data model

members

List of members of the object

value

Value of the object

collection

Elements of the collection

array

Elements of the array

map

Elements of the map

Non-member Functions Synopsys

walk

Walk the data model tree

Member Functions

get_class

std::string get_class () const;

If the underyling Type represents a flip Object, then this method returns the class name of this Object.

If the underlying Type represents a base type such as Float or Collection, then this method returns the flip name for this base type.


object_set_class

void  object_set_class (std::string class_name);

Sets the class of an object or throws if the Type is not an object.

This function is usually only used when changing an Object class name in a document converter.


member

Member & member (std::string name);

Returns a member of an Object or throws if the Type is not an object or the member does not exist.


object_add_member_array

Member & object_add_member_array (std::string name);

Add a Array member to the object or throws if the member already exists.


object_add_member_blob

Member & object_add_member_blob (std::string name, std::vector <uint8_t> value = std::vector <uint8_t> {});

Add a Blob member to the object or throws if the type is not an object or if the member already exists.


object_add_member_bool

Member & object_add_member_bool (std::string name, bool value = false);

Add a Bool member to the object or throws if the type is not an object or if the member already exists.


object_add_member_collection

Member & object_add_member_collection (std::string name);

Add a Collection member to the object or throws if the type is not an object or if the member already exists.


object_add_member_enum

Member & object_add_member_enum (std::string name, std::string enum_type, std::string enum_value);

Add a Enum member to the object or throws if the type is not an object or if the member already exists.


object_add_member_float

Member & object_add_member_float (std::string name, double value = 0.0);

Add a Float member to the object or throws if the type is not an object or if the member already exists.


object_add_member_int

Member & object_add_member_int (std::string name, int64_t value = 0);

Add a Int member to the object or throws if the type is not an object or if the member already exists.


object_add_member_map

Member & object_add_member_map (std::string name);

Add a Map member to the object or throws if the type is not an object or if the member already exists.


object_add_member_message

Member & object_add_member_message (std::string name);

Add a Message member to the object or throws if the type is not an object or if the member already exists.


object_add_member_object

Member & object_add_member_object (std::string name, std::string class_name);

Add a Object member to the object or throws if the type is not an object or if the member already exists.


object_add_member_object_ref

Member & object_add_member_object_ref (std::string name, flip::Ref ref = flip::Ref::null);

Add a Object member to the object or throws if the type is not an object or if the member already exists.


object_add_member_optional

Member & object_add_member_optional (std::string name);

Optional in Flip is modeled using Collection. Add a Collection member to the object or throws if the type is not an object or if the member already exists.


object_add_member_string

Member & object_add_member_string (std::string name, std::string value = "");

Add a String member to the object or throws if the type is not an object or if the member already exists.


object_add_member_variant

Member & object_add_member_variant (std::string name);

Variant in Flip is modeled using Collection. Add a Collection member to the object or throws if the type is not an object or if the member already exists.


object_add_member_vector

Member & object_add_member_vector (std::string name);

Vector in Flip is modeled using Blob. Add a Blob member to the object or throws if the type is not an object or if the member already exists.


object_remove_member

void object_remove_member (std::string name);

Remove the member with name from the object or throws if the type is not an object or if the member does not exist.


object_rename_member

void object_rename_member (std::string old_name, std::string new_name);

Rename the member from old_name to new_name or throws if the type is not an object or if the member old_name does not exist.


value_set_blob

void  value_set_blob (const std::vector <uint8_t> & value);

Sets the value of the Blob. Throws if the type is not a Blob.


value_set_bool

void  value_set_bool (bool value);

Sets the value of the Bool. Throws if the type is not a Bool.


value_set_enum

void  value_set_enum (std::string enum_type, std::string value);

Sets the value of the Enum. Throws if the type is not a Enum.


value_set_float

void  value_set_float (double value);

Sets the value of the Float. Throws if the type is not a Float.


value_set_int

void  value_set_int (int64_t value);

Sets the value of the Int. Throws if the type is not a Int.


value_set_object_ref

void  value_set_object_ref (flip::Ref value);

Sets the value of the ObjectRef. Throws if the type is not a ObjectRef.


value_set_string

void  value_set_string (std::string value);

Sets the value of the String. Throws if the type is not a String.


collection_add_object

CollectionElement & collection_add_object (std::string class_name);

Add an Object to the Collection.


collection_add

CollectionElement & collection_add (const CollectionElement & element);

Add an element to the Collection.


array_add_object

ArrayElement & array_add_object (std::string class_name, ArrayType::iterator pos);

Add an Object to the Array before pos.


array_add

ArrayElement & array_add (const ArrayElement & element);

Add an element to the Array or throws if the key of the element already exists.


map_add_object

MapElement & map_add_object (std::string class_name, KeyBlob pos);

Add an Object to the Map to pos or throws if the pos already exists.


map_add

MapElement & map_add (const MapElement & element);

Add an element to the Map or throws if the key of the element already exists.

Member Variables

ref

Ref ref;

This variable represents the unique reference number of the object.


type_name

std::string type_name;

This variable represents the type name as declared in the data model.


members

std::list <std::pair <std::string, Type>> members;

iff the type represents a flip object, this variable represents the list of members of the object. The list itself is a std::pair which first element is the name of the member, and the second element a Type.


value

Value value;

iff the type represents a flip basic type and not a container, this variable represents the value of the object. The Value type holds value for all basic types.


collection

std::map <KeyRandom, Type> collection;

iff the type represents a collection, this variable represents the elements of the object.

Important: For proper tracking of objects for document differentiation, the value of KeyRandom must not be changed.


array

std::map <KeyFloat, Type>  array;

iff the type represents a array, this variable represents the elements of the object.

Important: For proper tracking of objects for document differentiation, the value of KeyFloat must not be changed.


map

std::map <KeyBlob, Type>  map;

iff the type represents a map, this variable represents the elements of the object.

Important: For proper tracking of objects for document differentiation, the value of KeyBlob must not be changed.

Non-member Functions

walk

void  walk (BackEndIR::Type & type, std::function <void (BackEndIR::Type &)> && f);

Walk the data model tree, starting from type and recursively, applying function f on each Type nodes.

Example :

void  Converter_v100_v110::process (BackEndIR & backend)
{
   // walk the all document, starting from the document root
   walk (backend.root, [](BackEndIR::Type & type){
      // skip every type that is not a "Note"
      if (!type.is ("Note")) return;
      auto & member = type.member ("body");
      member.first = "content";
   });
   backend.version = "v110";
}