hpp2plantuml package

Submodules

hpp2plantuml.hpp2plantuml module

class hpp2plantuml.hpp2plantuml.Class(header_class)[source]

Bases: Container

Representation of C++ class

This class derived from Container specializes the base class to handle class definition in C++ headers.

It supports:

  • abstract and template classes

  • member variables and methods (abstract and static)

  • public, private, protected members (static)

Constructor

Extract the class name and properties (template, abstract) and inheritance. Then, extract the class members from the header using the parse_members() method.

Parameters:
header_classtuple(str, CppClass)

Parsed header for class object (two-element list where the first element is the class name and the second element is a CppClass object)

build_inheritance_list()[source]

Get inheritance list

Returns:
list(str)

List of class names the current class inherits from

build_variable_type_list()[source]

Get type of member variables

This function extracts the type of each member variable. This is used to list aggregation relationships between classes.

Returns:
list(str)

List of types (as string) for each member variable

class hpp2plantuml.hpp2plantuml.ClassAggregationRelationship(c_object, c_container, c_count=1, rel_type='aggregation', **kwargs)[source]

Bases: ClassRelationship

Representation of aggregation relationships

This module extends the base ClassRelationship class by setting the link type to aggregation. It also keeps a count of aggregation, which is displayed near the arrow when using PlantUML.

Aggregation relationships are simplified to represent the presence of a variable type (possibly within a container such as a list) in a class definition.

Constructor

Parameters:
c_objectstr

Class corresponding to the type of the member variable in the aggregation relationship

c_containerstr

Child (or client) class of the aggregation relationship

c_countint

The number of members of c_container that are of type (possibly through containers) c_object

rel_typestr

Relationship type: aggregation or composition

kwargsdict

Additional parameters passed to parent class

class hpp2plantuml.hpp2plantuml.ClassDependencyRelationship(c_parent, c_child, **kwargs)[source]

Bases: ClassRelationship

Dependency relationship

Dependencies occur when member methods depend on an object of another class in the diagram.

Constructor

Parameters:
c_parentstr

Class corresponding to the type of the member variable in the dependency relationship

c_childstr

Child (or client) class of the dependency relationship

kwargsdict

Additional parameters passed to parent class

class hpp2plantuml.hpp2plantuml.ClassInheritanceRelationship(c_parent, c_child, **kwargs)[source]

Bases: ClassRelationship

Representation of inheritance relationships

This module extends the base ClassRelationship class by setting the link type to inherit.

Constructor

Parameters:
c_parentstr

Parent class

c_childstr

Derived class

kwargsdict

Additional parameters passed to parent class

class hpp2plantuml.hpp2plantuml.ClassMember(class_member, member_scope='private')[source]

Bases: ContainerMember

Class member (variable and method) representation

This class is the base class for class members. The representation includes the member type (variable or method), name, scope (public, private or protected) and a static flag.

Constructor

Parameters:
class_memberCppVariable or CppMethod

Parsed member object (variable or method)

member_scopestr

Member scope property: public, private or protected

render()[source]

Get string representation of member

The string representation is with the scope indicator and a static keyword when the member is static. It is postfixed by the type (return type for class methods) and additional properties (e.g. const methods are flagged with the query property). The inner part of the returned string contains the variable name and signature for methods. This is obtained using the _render_name() method.

Returns:
str

String representation of member

class hpp2plantuml.hpp2plantuml.ClassMethod(class_method, member_scope)[source]

Bases: ClassMember

Class member method representation

This class extends ClassMember for member methods. It stores additional method properties (abstract, destructor flag, input parameter types).

Constructor

The method name and additional properties are extracted from the parsed header.

  • A list of parameter types is stored to retain the function signature.

  • The ~ character is appended to destructor methods.

  • const methods are flagged with the query property.

Parameters:
class_methodCppMethod

Parsed class member method

member_scopestr

Scope of the member method

class hpp2plantuml.hpp2plantuml.ClassNestingRelationship(c_parent, c_child, **kwargs)[source]

Bases: ClassRelationship

Nesting relationship

Dependencies occur when member methods depend on an object of another class in the diagram.

Constructor

Parameters:
c_parentstr

Class corresponding to the type of the member variable in the nesting relationship

c_childstr

Child (or client) class of the dependency relationship

kwargsdict

Additional parameters passed to parent class

class hpp2plantuml.hpp2plantuml.ClassRelationship(link_type, c_parent, c_child)[source]

Bases: object

Base object for class relationships

This class defines the common structure of class relationship objects. This includes a parent/child pair and a relationship type (e.g. inheritance or aggregation).

Constructor

Parameters:
link_typestr

Relationship type: inherit or aggregation

c_parentContainer

Parent container

c_childContainer

Child container

comparison_keys()[source]

Order comparison key between ClassRelationship objects

Compare alphabetically based on the parent name, the child name then the link type.

Returns:
list

operator.attrgetter objects for successive fields used as keys

render()[source]

Render class relationship to string

This method generically appends the parent name, a rendering of the link type (obtained from the _render_link_type() method) and the child object name.

Returns:
str

The string representation of the class relationship following the PlantUML syntax

class hpp2plantuml.hpp2plantuml.ClassVariable(class_variable, member_scope='private')[source]

Bases: ClassMember

Object representation of class member variables

This class specializes the ClassMember object for member variables. Additionally to the base class, it stores variable types as strings. This is used to establish aggregation relationships between objects.

Constructor

Parameters:
class_variableCppVariable

Parsed class variable object

member_scopestr

Scope property to member variable

get_type()[source]

Variable type accessor

Returns:
str

Variable type as string

class hpp2plantuml.hpp2plantuml.Container(container_type, name)[source]

Bases: object

Base class for C++ objects

This class defines the basic interface for parsed objects (e.g. class).

Class constructor

Parameters:
container_typestr

String representation of container type (class, struct or enum)

namestr

Object name (with <, > characters removed)

comparison_keys()[source]

Order comparison key between ClassRelationship objects

Use the parent name, the child name then the link type as successive keys.

Returns:
list

operator.attrgetter objects for successive fields used as keys

property name

Name property accessor

Returns:
str

Object name

parse_members(header_container)[source]

Initialize object from header

Extract object from CppHeaderParser dictionary representing a class, a struct or an enum object. This extracts the namespace. Use the parent field to determine is the namespace description from CppHeaderParser is a parent object (e.g. class) or a proper namespace.

Parameters:
header_containerCppClass or CppEnum

Parsed header for container

render()[source]

Render object to string

Returns:
str

String representation of object following the PlantUML syntax

sort_members()[source]

Sort container members

sort the list of members by type and name

class hpp2plantuml.hpp2plantuml.ContainerMember(header_member, **kwargs)[source]

Bases: object

Base class for members of Container object

This class defines the basic interface for object members (e.g. class variables, etc.)

Constructor

Parameters:
header_memberstr

Member name

comparison_keys()[source]

Order comparison key between ClassRelationship objects

Use the parent name, the child name then the link type as successive keys.

Returns:
list

operator.attrgetter objects for successive fields used as keys

render()[source]

Render object to string (abstract method)

Returns:
str

String representation of object member following the PlantUML syntax

hpp2plantuml.hpp2plantuml.CreatePlantUMLFile(file_list, output_file=None, **diagram_kwargs)[source]

Create PlantUML file from list of header files

This function parses a list of C++ header files and generates a file for use with PlantUML.

Parameters:
file_listlist(str)

List of filenames (possibly, with wildcards resolved with the expand_file_list() function)

output_filestr

Name of the output file

diagram_kwargsdict

Additional parameters passed to Diagram constructor

class hpp2plantuml.hpp2plantuml.Diagram(template_file=None, flag_dep=False)[source]

Bases: object

UML diagram object

This class lists the objects in the set of files considered, and the relationships between object.

The main interface to the Diagram object is via the create_* and add_* methods. The former parses objects and builds relationship lists between the different parsed objects. The latter only parses objects and does not builds relationship lists.

Each method has versions for file and string inputs and folder string lists and file lists inputs.

Constructor

The Diagram class constructor simply initializes object lists. It does not create objects or relationships.

add_from_file(header_file)[source]

Augment Diagram object from header file

Wrapper around the _build_helper() function, with file input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_file_list(file_list)[source]

Augment Diagram object from list of header files

Wrapper around the _build_helper() function, with file_list input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_string(header_string)[source]

Augment Diagram object from header string

Wrapper around the _build_helper() function, with string input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_string_list(string_list)[source]

Augment Diagram object from list of header strings

Wrapper around the _build_helper() function, with string_list input, building the relationship lists and without object reset (new objects are added to the object).

build_aggregation_list()[source]

Build list of aggregation relationships

This method loops over objects and finds members with type corresponding to other classes defined in the Diagram object (keeping a count of occurrences).

The procedure first builds an internal dictionary of relationships found, augmenting the count using the _augment_comp() function. In a second phase, ClassAggregationRelationship objects are created for each relationships, using the calculated count.

build_dependency_list()[source]

Build list of dependency between objects

This method lists all the dependency relationships between objects contained in the Diagram object (external relationships are ignored).

The implementation establishes a list of available classes and loops over objects, list their methods adds a dependency relationship when a method takes an object as input.

build_inheritance_list()[source]

Build list of inheritance between objects

This method lists all the inheritance relationships between objects contained in the Diagram object (external relationships are ignored).

The implementation establishes a list of available classes and loops over objects to obtain their inheritance. When parent classes are in the list of available classes, a ClassInheritanceRelationship object is added to the list.

build_nesting_list()[source]

Build list of nested objects

build_relationship_lists()[source]

Build inheritance and aggregation lists from parsed objects

This method successively calls the build_inheritance_list() and build_aggregation_list() methods.

clear()[source]

Reinitialize object

create_from_file(header_file)[source]

Initialize Diagram object from header file

Wrapper around the _build_helper() function, with file input, building the relationship lists and with object reset.

create_from_file_list(file_list)[source]

Initialize Diagram object from list of header files

Wrapper around the _build_helper() function, with file_list input, building the relationship lists and with object reset.

create_from_string(header_string)[source]

Initialize Diagram object from header string

Wrapper around the _build_helper() function, with string input, building the relationship lists and with object reset.

create_from_string_list(string_list)[source]

Initialize Diagram object from list of header strings

Wrapper around the _build_helper() function, with string_list input, skipping building of the relationship lists and with object reset.

find_parent(parent_in, obj_ns_list_base, f_cmp=None)[source]

Find object matching name and scope of input

Parameters:
parent_instr

Name of object to locate

obj_ns_list_baselist(str)

List of namespaces and nested classes for current object

f_cmpcallable

Comparison function with two arguments object name to search and regular expression (string equality by default)

Returns:
Class or None

Matching Class object if found

parse_objects(header_file, arg_type='string')[source]

Parse objects

This method parses file of string inputs using the CppHeaderParser module and extracts internal objects for rendering.

Parameters:
header_filestr

A string containing C++ header code or a filename with C++ header code

arg_typestr

If set to string, header_file is considered to be a string, otherwise, it is assumed to be a filename

render()[source]

Render full UML diagram

The string returned by this function should be ready to use with the PlantUML program. It includes all the parsed objects with their members, and the inheritance and aggregation relationships extracted from the list of objects.

Returns:
str

String containing the full string representation of the Diagram object, including objects and object relationships

sort_elements()[source]

Sort elements in diagram

Sort the objects and relationship links. Objects are sorted using the Container.comparison_keys() comparison function and list are sorted using the _sort_list helper function.

class hpp2plantuml.hpp2plantuml.Enum(header_enum, parent=None)[source]

Bases: Container

Class representing enum objects

This class defines a simple object inherited from the base Container class. It simply lists enumerated values.

Constructor

Parameters:
header_enumCppEnum

Parsed CppEnum object

class hpp2plantuml.hpp2plantuml.EnumValue(header_value, **kwargs)[source]

Bases: ContainerMember

Class representing values in enum object

This class only contains the name of the enum value (the actual integer value is ignored).

Constructor

Parameters:
header_valuestr

Name of enum member

render()[source]

Rendering to string

This method simply returns the variable name

Returns:
str

The enumeration element name

class hpp2plantuml.hpp2plantuml.Namespace(name, *args)[source]

Bases: list

Representation of C++ namespace

This class lists other containers or namespaces and wraps the rendered output in a namespace block.

Constructor

Parameters:
namestr

Namespace name

render()[source]

Render namespace content

Render the elements and wrap the result in a namespace block

Returns:
str

String representation of namespace in PlantUML syntax

hpp2plantuml.hpp2plantuml.expand_file_list(input_files)[source]

Find all files in list (expanding wildcards)

This function uses glob to find files matching each string in the input list.

Parameters:
input_fileslist(str)

List of strings representing file names and possibly including wildcards

Returns:
list(str)

List of filenames (with wildcards expanded). Each element contains the name of an existing file

Generate namespace string for link

Parameters:
namespacestr

Namespace name (in the form nested::ns)

Returns:
str

The namespace name formatted for use in links (e.g. nested.nested::ns)

hpp2plantuml.hpp2plantuml.is_ptr(obj_name, obj)[source]

Determine if object type represents a pointer

Parameters:
obj_namestr

Object base name

objstr

Full type

Returns:
bool

True if obj is determined to represent a point to an object of type obj_name

Examples

>>> is_ptr('Object', 'Object*')
True
>>> is_ptr('Object', 'unique_ptr<Object>')
True
>>> is_ptr('Object', 'unique_ptr<AnotherObject>')
False
hpp2plantuml.hpp2plantuml.main()[source]

Command line interface

This function is a command-line interface to the hpp2plantuml.CreatePlantUMLFile() function.

Arguments are read from the command-line, run with --help for help.

hpp2plantuml.hpp2plantuml.wrap_namespace(input_str, namespace)[source]

Wrap string in namespace

Parameters:
input_strstr

String containing PlantUML code

namespacestr

Namespace name

Returns:
str

input_str wrapped in namespace block

Module contents

Convert C++ header files to PlantUML <https://github.com/thibaultmarin/hpp2plantuml>

hpp2plantuml.CreatePlantUMLFile(file_list, output_file=None, **diagram_kwargs)[source]

Create PlantUML file from list of header files

This function parses a list of C++ header files and generates a file for use with PlantUML.

Parameters:
file_listlist(str)

List of filenames (possibly, with wildcards resolved with the expand_file_list() function)

output_filestr

Name of the output file

diagram_kwargsdict

Additional parameters passed to Diagram constructor

class hpp2plantuml.Diagram(template_file=None, flag_dep=False)[source]

Bases: object

UML diagram object

This class lists the objects in the set of files considered, and the relationships between object.

The main interface to the Diagram object is via the create_* and add_* methods. The former parses objects and builds relationship lists between the different parsed objects. The latter only parses objects and does not builds relationship lists.

Each method has versions for file and string inputs and folder string lists and file lists inputs.

Constructor

The Diagram class constructor simply initializes object lists. It does not create objects or relationships.

add_from_file(header_file)[source]

Augment Diagram object from header file

Wrapper around the _build_helper() function, with file input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_file_list(file_list)[source]

Augment Diagram object from list of header files

Wrapper around the _build_helper() function, with file_list input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_string(header_string)[source]

Augment Diagram object from header string

Wrapper around the _build_helper() function, with string input, skipping building of the relationship lists and without object reset (new objects are added to the object).

add_from_string_list(string_list)[source]

Augment Diagram object from list of header strings

Wrapper around the _build_helper() function, with string_list input, building the relationship lists and without object reset (new objects are added to the object).

build_aggregation_list()[source]

Build list of aggregation relationships

This method loops over objects and finds members with type corresponding to other classes defined in the Diagram object (keeping a count of occurrences).

The procedure first builds an internal dictionary of relationships found, augmenting the count using the _augment_comp() function. In a second phase, ClassAggregationRelationship objects are created for each relationships, using the calculated count.

build_dependency_list()[source]

Build list of dependency between objects

This method lists all the dependency relationships between objects contained in the Diagram object (external relationships are ignored).

The implementation establishes a list of available classes and loops over objects, list their methods adds a dependency relationship when a method takes an object as input.

build_inheritance_list()[source]

Build list of inheritance between objects

This method lists all the inheritance relationships between objects contained in the Diagram object (external relationships are ignored).

The implementation establishes a list of available classes and loops over objects to obtain their inheritance. When parent classes are in the list of available classes, a ClassInheritanceRelationship object is added to the list.

build_nesting_list()[source]

Build list of nested objects

build_relationship_lists()[source]

Build inheritance and aggregation lists from parsed objects

This method successively calls the build_inheritance_list() and build_aggregation_list() methods.

clear()[source]

Reinitialize object

create_from_file(header_file)[source]

Initialize Diagram object from header file

Wrapper around the _build_helper() function, with file input, building the relationship lists and with object reset.

create_from_file_list(file_list)[source]

Initialize Diagram object from list of header files

Wrapper around the _build_helper() function, with file_list input, building the relationship lists and with object reset.

create_from_string(header_string)[source]

Initialize Diagram object from header string

Wrapper around the _build_helper() function, with string input, building the relationship lists and with object reset.

create_from_string_list(string_list)[source]

Initialize Diagram object from list of header strings

Wrapper around the _build_helper() function, with string_list input, skipping building of the relationship lists and with object reset.

find_parent(parent_in, obj_ns_list_base, f_cmp=None)[source]

Find object matching name and scope of input

Parameters:
parent_instr

Name of object to locate

obj_ns_list_baselist(str)

List of namespaces and nested classes for current object

f_cmpcallable

Comparison function with two arguments object name to search and regular expression (string equality by default)

Returns:
Class or None

Matching Class object if found

parse_objects(header_file, arg_type='string')[source]

Parse objects

This method parses file of string inputs using the CppHeaderParser module and extracts internal objects for rendering.

Parameters:
header_filestr

A string containing C++ header code or a filename with C++ header code

arg_typestr

If set to string, header_file is considered to be a string, otherwise, it is assumed to be a filename

render()[source]

Render full UML diagram

The string returned by this function should be ready to use with the PlantUML program. It includes all the parsed objects with their members, and the inheritance and aggregation relationships extracted from the list of objects.

Returns:
str

String containing the full string representation of the Diagram object, including objects and object relationships

sort_elements()[source]

Sort elements in diagram

Sort the objects and relationship links. Objects are sorted using the Container.comparison_keys() comparison function and list are sorted using the _sort_list helper function.