hpp2plantuml package¶
Submodules¶
hpp2plantuml.hpp2plantuml module¶
- class hpp2plantuml.hpp2plantuml.Class(header_class)[source]¶
Bases:
ContainerRepresentation of C++ class
This class derived from
Containerspecializes 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)
- class hpp2plantuml.hpp2plantuml.ClassAggregationRelationship(c_object, c_container, c_count=1, rel_type='aggregation', **kwargs)[source]¶
Bases:
ClassRelationshipRepresentation of aggregation relationships
This module extends the base
ClassRelationshipclass by setting the link type toaggregation. 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_containerthat are of type (possibly through containers)c_object- rel_typestr
Relationship type:
aggregationorcomposition- kwargsdict
Additional parameters passed to parent class
- class hpp2plantuml.hpp2plantuml.ClassDependencyRelationship(c_parent, c_child, **kwargs)[source]¶
Bases:
ClassRelationshipDependency 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:
ClassRelationshipRepresentation of inheritance relationships
This module extends the base
ClassRelationshipclass by setting the link type toinherit.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:
ContainerMemberClass 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,privateorprotected) and a static flag.Constructor
- Parameters:
- class_memberCppVariable or CppMethod
Parsed member object (variable or method)
- member_scopestr
Member scope property:
public,privateorprotected
- 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.
constmethods are flagged with thequeryproperty). 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:
ClassMemberClass member method representation
This class extends
ClassMemberfor 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.constmethods are flagged with thequeryproperty.
- 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:
ClassRelationshipNesting 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:
objectBase 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:
inheritoraggregation- c_parentContainer
Parent container
- c_childContainer
Child container
- comparison_keys()[source]¶
Order comparison key between
ClassRelationshipobjectsCompare alphabetically based on the parent name, the child name then the link type.
- Returns:
- list
operator.attrgetterobjects for successive fields used as keys
- class hpp2plantuml.hpp2plantuml.ClassVariable(class_variable, member_scope='private')[source]¶
Bases:
ClassMemberObject representation of class member variables
This class specializes the
ClassMemberobject 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
- class hpp2plantuml.hpp2plantuml.Container(container_type, name)[source]¶
Bases:
objectBase 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,structorenum)- namestr
Object name (with
<,>characters removed)
- comparison_keys()[source]¶
Order comparison key between
ClassRelationshipobjectsUse the parent name, the child name then the link type as successive keys.
- Returns:
- list
operator.attrgetterobjects 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
parentfield to determine is thenamespacedescription fromCppHeaderParseris a parent object (e.g. class) or a propernamespace.- Parameters:
- header_containerCppClass or CppEnum
Parsed header for container
- class hpp2plantuml.hpp2plantuml.ContainerMember(header_member, **kwargs)[source]¶
Bases:
objectBase class for members of
ContainerobjectThis 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
ClassRelationshipobjectsUse the parent name, the child name then the link type as successive keys.
- Returns:
- list
operator.attrgetterobjects for successive fields used as keys
- 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
Diagramconstructor
- class hpp2plantuml.hpp2plantuml.Diagram(template_file=None, flag_dep=False)[source]¶
Bases:
objectUML diagram object
This class lists the objects in the set of files considered, and the relationships between object.
The main interface to the
Diagramobject is via thecreate_*andadd_*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
Diagramclass constructor simply initializes object lists. It does not create objects or relationships.- add_from_file(header_file)[source]¶
Augment
Diagramobject from header fileWrapper around the
_build_helper()function, withfileinput, 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
Diagramobject from list of header filesWrapper around the
_build_helper()function, withfile_listinput, skipping building of the relationship lists and without object reset (new objects are added to the object).
- add_from_string(header_string)[source]¶
Augment
Diagramobject from header stringWrapper around the
_build_helper()function, withstringinput, 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
Diagramobject from list of header stringsWrapper around the
_build_helper()function, withstring_listinput, 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
Diagramobject (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,ClassAggregationRelationshipobjects 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
Diagramobject (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
Diagramobject (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
ClassInheritanceRelationshipobject is added to the list.
- build_relationship_lists()[source]¶
Build inheritance and aggregation lists from parsed objects
This method successively calls the
build_inheritance_list()andbuild_aggregation_list()methods.
- create_from_file(header_file)[source]¶
Initialize
Diagramobject from header fileWrapper around the
_build_helper()function, withfileinput, building the relationship lists and with object reset.
- create_from_file_list(file_list)[source]¶
Initialize
Diagramobject from list of header filesWrapper around the
_build_helper()function, withfile_listinput, building the relationship lists and with object reset.
- create_from_string(header_string)[source]¶
Initialize
Diagramobject from header stringWrapper around the
_build_helper()function, withstringinput, building the relationship lists and with object reset.
- create_from_string_list(string_list)[source]¶
Initialize
Diagramobject from list of header stringsWrapper around the
_build_helper()function, withstring_listinput, 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
Classobject 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_fileis 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
Diagramobject, 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_listhelper function.
- class hpp2plantuml.hpp2plantuml.Enum(header_enum, parent=None)[source]¶
Bases:
ContainerClass representing enum objects
This class defines a simple object inherited from the base
Containerclass. It simply lists enumerated values.Constructor
- Parameters:
- header_enumCppEnum
Parsed CppEnum object
- class hpp2plantuml.hpp2plantuml.EnumValue(header_value, **kwargs)[source]¶
Bases:
ContainerMemberClass 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
- class hpp2plantuml.hpp2plantuml.Namespace(name, *args)[source]¶
Bases:
listRepresentation of C++ namespace
This class lists other containers or namespaces and wraps the rendered output in a
namespaceblock.Constructor
- Parameters:
- namestr
Namespace name
- hpp2plantuml.hpp2plantuml.expand_file_list(input_files)[source]¶
Find all files in list (expanding wildcards)
This function uses
globto 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
- hpp2plantuml.hpp2plantuml.get_namespace_link_name(namespace)[source]¶
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
objis determined to represent a point to an object of typeobj_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
--helpfor help.
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
Diagramconstructor
- class hpp2plantuml.Diagram(template_file=None, flag_dep=False)[source]¶
Bases:
objectUML diagram object
This class lists the objects in the set of files considered, and the relationships between object.
The main interface to the
Diagramobject is via thecreate_*andadd_*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
Diagramclass constructor simply initializes object lists. It does not create objects or relationships.- add_from_file(header_file)[source]¶
Augment
Diagramobject from header fileWrapper around the
_build_helper()function, withfileinput, 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
Diagramobject from list of header filesWrapper around the
_build_helper()function, withfile_listinput, skipping building of the relationship lists and without object reset (new objects are added to the object).
- add_from_string(header_string)[source]¶
Augment
Diagramobject from header stringWrapper around the
_build_helper()function, withstringinput, 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
Diagramobject from list of header stringsWrapper around the
_build_helper()function, withstring_listinput, 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
Diagramobject (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
Diagramobject (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
Diagramobject (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_relationship_lists()[source]¶
Build inheritance and aggregation lists from parsed objects
This method successively calls the
build_inheritance_list()andbuild_aggregation_list()methods.
- create_from_file(header_file)[source]¶
Initialize
Diagramobject from header fileWrapper around the
_build_helper()function, withfileinput, building the relationship lists and with object reset.
- create_from_file_list(file_list)[source]¶
Initialize
Diagramobject from list of header filesWrapper around the
_build_helper()function, withfile_listinput, building the relationship lists and with object reset.
- create_from_string(header_string)[source]¶
Initialize
Diagramobject from header stringWrapper around the
_build_helper()function, withstringinput, building the relationship lists and with object reset.
- create_from_string_list(string_list)[source]¶
Initialize
Diagramobject from list of header stringsWrapper around the
_build_helper()function, withstring_listinput, 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
Classobject 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_fileis 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
Diagramobject, including objects and object relationships