Update Doxygen docs for class_diagram namespace

This commit is contained in:
Bartek Kryza
2023-06-24 17:23:43 +02:00
parent 627a9fe1a8
commit 935d25c8f4
20 changed files with 1358 additions and 86 deletions

View File

@@ -26,6 +26,9 @@
namespace clanguml::class_diagram::model {
/**
* @brief Base class for class elements (e.g. member or method).
*/
class class_element : public common::model::decorated_element,
public common::model::source_location {
public:
@@ -34,13 +37,46 @@ public:
~class_element() override = default;
/**
* @brief Get elements access scope.
*
* @return Elements access scope.
*/
common::model::access_t access() const;
/**
* @brief Get elements name.
*
* @return Elements name.
*/
std::string name() const;
/**
* @brief Set elements name.
*
* @param name Elements name.
*/
void set_name(const std::string &name);
/**
* @brief Get elements type as string.
*
* @return Elements type as string.
*/
std::string type() const;
/**
* @brief Set elements type as string.
*
* @param type Elements type as string.
*/
void set_type(const std::string &type);
/**
* @brief Get elements inja context in JSON.
*
* @return Context in JSON
*/
virtual inja::json context() const;
private:

View File

@@ -23,18 +23,38 @@
namespace clanguml::class_diagram::model {
/**
* @brief Class member model.
*/
class class_member : public class_element {
public:
/**
* @brief Constructor.
*
* @param access Members access scope (e.g. public)
* @param name Members name.
* @param type Members type as string.
*/
class_member(common::model::access_t access, const std::string &name,
const std::string &type);
~class_member() override = default;
/**
* @brief Whether the member is static.
*
* @return True, if the member is static.
*/
bool is_static() const;
/**
* @brief Set members static status.
*
* @param is_static True, if the member is static.
*/
void is_static(bool is_static);
private:
bool is_relationship_{false};
bool is_static_{false};
};

View File

@@ -29,56 +29,225 @@ namespace clanguml::class_diagram::model {
using clanguml::common::model::template_trait;
/**
* @brief Class method model.
*/
class class_method : public class_element, public template_trait {
public:
/**
* @brief Constructor.
*
* @param access Methods access scope (e.g. public)
* @param name Methods name.
* @param type Methods return type as string.
*/
class_method(common::model::access_t access, const std::string &name,
const std::string &type);
~class_method() override = default;
/**
* @brief Whether the method is pure virtual.
*
* @return True, if the method is pure virtual
*/
bool is_pure_virtual() const;
void is_pure_virtual(bool is_pure_virtual);
/**
* @brief Whether the method is virtual.
*
* @return True, if the method is virtual
*/
bool is_virtual() const;
/**
* @brief Set whether the method is virtual.
*
* @param is_virtual True, if the method is virtual
*/
void is_virtual(bool is_virtual);
/**
* @brief Whether the method is const.
*
* @return True, if the method is const
*/
bool is_const() const;
/**
* @brief Set whether the method is const.
*
* @param is_const True, if the method is const
*/
void is_const(bool is_const);
/**
* @brief Whether the method is defaulted.
*
* @return True, if the method is defaulted
*/
bool is_defaulted() const;
/**
* @brief Set whether the method is defaulted.
*
* @param is_defaulted True, if the method is defaulted
*/
void is_defaulted(bool is_defaulted);
/**
* @brief Whether the method is deleted.
*
* @return True, if the method is deleted
*/
bool is_deleted() const;
/**
* @brief Set whether the method is deleted.
*
* @param is_deleted True, if the method is deleted
*/
void is_deleted(bool is_deleted);
/**
* @brief Whether the method is static.
*
* @return True, if the method is static
*/
bool is_static() const;
/**
* @brief Set whether the method is static.
*
* @param is_static True, if the method is static
*/
void is_static(bool is_static);
/**
* @brief Whether the method is constexpr.
*
* @return True, if the method is constexpr
*/
bool is_constexpr() const;
/**
* @brief Set whether the method is constexpr.
*
* @param is_constexpr True, if the method is constexpr
*/
void is_constexpr(bool is_constexpr);
/**
* @brief Whether the method is consteval.
*
* @return True, if the method is consteval
*/
bool is_consteval() const;
/**
* @brief Set whether the method is consteval.
*
* @param is_consteval True, if the method is consteval
*/
void is_consteval(bool is_consteval);
/**
* @brief Whether the method is noexcept.
*
* @return True, if the method is noexcept
*/
bool is_noexcept() const;
/**
* @brief Set whether the method is noexcept.
*
* @param is_noexcept True, if the method is noexcept
*/
void is_noexcept(bool is_noexcept);
/**
* @brief Whether the method is a constructor.
*
* @return True, if the method is a constructor
*/
bool is_constructor() const;
/**
* @brief Set whether the method is a constructor.
*
* @param is_constructor True, if the method is a constructor
*/
void is_constructor(bool is_constructor);
/**
* @brief Whether the method is a destructor.
*
* @return True, if the method is a destructor
*/
bool is_destructor() const;
/**
* @brief Set whether the method is a destructor.
*
* @param is_destructor True, if the method is a destructor
*/
void is_destructor(bool is_destructor);
/**
* @brief Whether the method is move assignment.
*
* @return True, if the method is move assignment
*/
bool is_move_assignment() const;
/**
* @brief Set whether the method is a move assignment.
*
* @param is_move_assignment True, if the method is a move assignment
*/
void is_move_assignment(bool is_move_assignment);
/**
* @brief Whether the method is copy assignment.
*
* @return True, if the method is copy assignment
*/
bool is_copy_assignment() const;
/**
* @brief Set whether the method is a copy assignment.
*
* @param is_copy_assignment True, if the method is a copy assignment
*/
void is_copy_assignment(bool is_copy_assignment);
/**
* @brief Whether the method is an operator.
*
* @return True, if the method is an operator
*/
bool is_operator() const;
/**
* @brief Set whether the method is an operator.
*
* @param is_copy_assignment True, if the method is an operator
*/
void is_operator(bool is_operator);
/**
* @brief Get the method parameters.
*
* @return List of methods parameters
*/
const std::vector<method_parameter> &parameters() const;
/**
* @brief Add methods parameter.
*
* @param parameter Method parameter.
*/
void add_parameter(method_parameter &&parameter);
private:

View File

@@ -24,6 +24,10 @@ void class_parent::set_name(const std::string &name) { name_ = name; }
std::string class_parent::name() const { return name_; }
void class_parent::set_id(clanguml::common::id_t id) { id_ = id; }
clanguml::common::id_t class_parent::id() const noexcept { return id_; }
void class_parent::is_virtual(bool is_virtual) { is_virtual_ = is_virtual; }
bool class_parent::is_virtual() const { return is_virtual_; }

View File

@@ -25,25 +25,75 @@
namespace clanguml::class_diagram::model {
/**
* @brief Class parent relationship model.
*
* @todo Consider refactoring this class to a regular relationship.
*/
class class_parent {
public:
class_parent() = default;
class_parent(const std::string &name)
{
set_name(name);
set_id(common::to_id(name));
}
/**
* @brief Set the fully qualified name of class parent.
*
* @param name Fully qualified name of the parent class.
*/
void set_name(const std::string &name);
/**
* @brief Get the fully qualified name of class parent.
*
* @return Fully qualified name of the parent class.
*/
std::string name() const;
clanguml::common::id_t id() const noexcept { return id_; }
void set_id(clanguml::common::id_t id) { id_ = id; }
/**
* @brief Set the id of class parent.
*
* @param id Id of the parent class.
*/
void set_id(clanguml::common::id_t id);
/**
* @brief Get the id of class parent.
*
* @return Id of the parent class.
*/
clanguml::common::id_t id() const noexcept;
/**
* @brief Set whether the parent is virtual.
*
* @param is_virtual True if the parent is virtual
*/
void is_virtual(bool is_virtual);
/**
* @brief Get whether the parent is virtual.
*
* @return True, if the parent is virtual
*/
bool is_virtual() const;
/**
* @brief Set the parents access scope
*
* @param access Parents access scope
*/
void set_access(common::model::access_t access);
/**
* @brief Get parents access scope.
*
* @return Parents access scope.
*/
common::model::access_t access() const;
private:

View File

@@ -29,11 +29,9 @@
namespace clanguml::class_diagram::model {
struct requires_expression {
common::model::template_parameter parameter;
std::vector<std::string> requirements;
};
/**
* @brief Model of C++ concept.
*/
class concept_ : public common::model::element,
public common::model::stylable_element,
public common::model::template_trait {
@@ -45,6 +43,11 @@ public:
concept_ &operator=(const concept_ &) = delete;
concept_ &operator=(concept_ &&) = delete;
/**
* @brief Get the elements type name.
*
* @return 'concept'
*/
std::string type_name() const override { return "concept"; }
friend bool operator==(const concept_ &l, const concept_ &r);
@@ -53,12 +56,35 @@ public:
std::string full_name_no_ns() const override;
/**
* @brief Add concept parameter
*
* Concept class for convenience uses the same method parameter model
* as regular methods and functions.
*
* @param mp Concept parameter
*/
void add_parameter(const method_parameter &mp);
/**
* @brief Get concepts requires expression parameters
*
* @return List of concept requires expression parameters
*/
const std::vector<method_parameter> &requires_parameters() const;
/**
* @brief Add a concept statement
*
* @param stmt Concept statement
*/
void add_statement(std::string stmt);
/**
* @brief Get the concepts requires statements
*
* @return List of concepts requires statements
*/
const std::vector<std::string> &requires_statements() const;
private:

View File

@@ -45,6 +45,9 @@ using nested_trait_ns =
clanguml::common::model::nested_trait<clanguml::common::model::element,
clanguml::common::model::namespace_>;
/**
* @brief Class representing a class diagram.
*/
class diagram : public common::model::diagram,
public element_view<class_>,
public element_view<enum_>,
@@ -58,36 +61,132 @@ public:
diagram &operator=(const diagram &) = delete;
diagram &operator=(diagram &&) = default;
/**
* @brief Get the diagram model type - in this case class.
*
* @return Type of class diagram.
*/
diagram_t type() const override;
/**
* Inherit the should_include methods from the common diagram model.
*/
using common::model::diagram::should_include;
/**
* @brief Whether a class_member should be included in the diagram.
*
* @param m Class member
* @return True, if class member should be included in the diagram.
*/
bool should_include(const class_member &m) const;
/**
* @brief Whether a class_method should be included in the diagram.
*
* @param m Class method
* @return True, if class method should be included in the diagram.
*/
bool should_include(const class_method &m) const;
/**
* @brief Search for element in the diagram by fully qualified name.
*
* @param full_name Fully qualified element name.
* @return Optional reference to a diagram element.
*/
opt_ref<diagram_element> get(const std::string &full_name) const override;
/**
* @brief Search for element in the diagram by id.
*
* @param id Element id.
* @return Optional reference to a diagram element.
*/
opt_ref<diagram_element> get(diagram_element::id_t id) const override;
/**
* @brief Get list of references to classes in the diagram model.
*
* @return List of references to classes in the diagram model.
*/
const common::reference_vector<class_> &classes() const;
/**
* @brief Get list of references to enums in the diagram model.
*
* @return List of references to enums in the diagram model.
*/
const common::reference_vector<enum_> &enums() const;
/**
* @brief Get list of references to concepts in the diagram model.
*
* @return List of references to concepts in the diagram model.
*/
const common::reference_vector<concept_> &concepts() const;
/**
* @brief Check, if diagram contains a specific element.
*
* @tparam ElementT Type of diagram element (e.g. class_)
* @param e Element to check
* @return True, if element already exists in the diagram
*/
template <typename ElementT> bool contains(const ElementT &e);
/**
* @brief Find an element in the diagram by name.
*
* This method allows for typed search, where the type of searched for
* element is determined from template specialization.
*
* @tparam ElementT Type of element (e.g. class_)
* @param name Fully qualified name of the element
* @return Optional reference to a diagram element
*/
template <typename ElementT>
opt_ref<ElementT> find(const std::string &name) const;
/**
* @brief Find elements in the diagram by regex pattern.
*
* This method allows for typed search, where the type of searched for
* element is determined from template specialization.
*
* @tparam ElementT Type of element (e.g. class_)
* @param name String or regex pattern
* @return List of optional references to matched elements.
*/
template <typename ElementT>
std::vector<opt_ref<ElementT>> find(
const clanguml::common::string_or_regex &pattern) const;
/**
* @brief Find an element in the diagram by id.
*
* This method allows for typed search, where the type of searched for
* element is determined from template specialization.
*
* @tparam ElementT Type of element (e.g. class_)
* @param id Id of the element
* @return Optional reference to a diagram element
*/
template <typename ElementT>
opt_ref<ElementT> find(diagram_element::id_t id) const;
/**
* @brief Add element to the diagram at a specified nested path.
*
* Adds an element to a diagram, at a specific package (if any exist).
* The package is specified by the `parent_path`, which can be either
* a namespace or a directory path.
*
* @tparam ElementT Type of diagram element.
* @param parent_path Path to the parent package of the new diagram element.
* @param e Diagram element to be added.
* @return True, if the element was added to the diagram.
*/
template <typename ElementT>
bool add(const path &parent_path, std::unique_ptr<ElementT> &&e)
{
@@ -98,14 +197,41 @@ public:
return add_with_filesystem_path(parent_path, std::move(e));
}
/**
* @brief Convert element id to PlantUML alias.
*
* @todo This method does not belong here - refactor to PlantUML specific
* code.
*
* @param id Id of the diagram element.
* @return PlantUML alias.
*/
std::string to_alias(diagram_element::id_t id) const;
/**
* @brief Given an initial set of classes, add all their parents to the
* argument.
* @param parents In and out parameter with the parent classes.
*/
void get_parents(clanguml::common::reference_set<class_> &parents) const;
friend void print_diagram_tree(const diagram &d, int level);
/**
* @brief Check if diagram contains element by id.
*
* @todo Remove in favour of 'contains'
*
* @param id Id of the element.
* @return True, if diagram contains an element with a specific id.
*/
bool has_element(diagram_element::id_t id) const override;
/**
* @brief Return the elements JSON context for inja templates.
*
* @return JSON node with elements context.
*/
inja::json context() const override;
private:

View File

@@ -24,6 +24,9 @@
namespace clanguml::class_diagram::model {
/*
* @brief Diagram element representing an enum.
*/
class enum_ : public common::model::element,
public common::model::stylable_element {
public:
@@ -36,15 +39,29 @@ public:
std::string type_name() const override { return "enum"; }
// TODO: Do we need this?
friend bool operator==(const enum_ &l, const enum_ &r);
std::string full_name(bool relative = true) const override;
/**
* @brief Get the enums constants.
*
* @return Enums constants names list.
*/
std::vector<std::string> &constants();
/**
* @brief Get the enums constants.
*
* @return Enums constants names list.
*/
const std::vector<std::string> &constants() const;
/**
* @brief Get Doxygen link to documentation page for this element.
*
* @return Doxygen link for this element.
*/
std::optional<std::string> doxygen_link() const override;
private:

View File

@@ -25,23 +25,73 @@
namespace clanguml::class_diagram::model {
/**
* @brief Model of a method parameter.
*/
class method_parameter : public common::model::decorated_element {
public:
method_parameter() = default;
/**
* @brief Constructor.
*
* @param type Type of the method parameter as string.
* @param name Name of the method parameter.
* @param default_value Default value of the parameter or empty.
*/
method_parameter(
std::string type, std::string name, std::string default_value = {});
~method_parameter() override = default;
/**
* @brief Set parameters type.
*
* @param type Parameters type as string.
*/
void set_type(const std::string &type);
/**
* @brief Get parameters type.
*
* @return Parameters type as string.
*/
std::string type() const;
/**
* @brief Set parameters name.
*
* @param type Parameters name.
*/
void set_name(const std::string &name);
/**
* @brief Get parameters name.
*
* @return Parameters name.
*/
std::string name() const;
/**
* @brief Set parameters default value.
*
* @param type Parameters default value as string.
*/
void set_default_value(const std::string &value);
/**
* @brief Get parameters name.
*
* @return Parameters name.
*/
std::string default_value() const;
/**
* @brief Render the method parameter to a string.
*
* @param using_namespaces If provided, make all namespaces relative to it.
* @return String representation of the parameter.
*/
std::string to_string(
const common::model::namespace_ &using_namespaces) const;