【问题标题】:uml - Template class diagram with typedefuml - 带有 typedef 的模板类图
【发布时间】:2018-08-26 14:43:44
【问题描述】:

我正在尝试从我的 c++ 代码开始创建一个类图。我遇到了麻烦,因为我找不到关于如何表示我在代码中的内容的标准规则。这就是我所拥有的。 编辑:扩展 .h 文件

#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED

#include <vector>

using namespace std;

//natural numbers
typedef unsigned int N;

//lattice c_no<c_lt,c_gt<c_eq of comparison results in a PO
typedef char CMP;

//intervals [l,u] in R with l<=u, with inclusion order
template <typename R> 
struct IR
{
  R l, u;
  IR() {};
  IR(R,R);
};

//unions of intervals (increasing sequence of disjoint intervals)
template <typename R> 
struct U_IR
{
    vector<IR <R> > S;
    U_IR() {};
};

//points in R^d with d>0, with pointwise order
template <typename R> 
struct PR
{
    vector<R> x;
    PR(N d){ x=vector<R>(d);};
};

//boxes in R^d with d>0, with inclusion order
template <typename R> 
struct BR
{
    vector<IR <R> > x;
    BR(N d){ x=vector<IR <R> >(d);};
};

//U_BR unions of boxes in Number^d, see UBR.h

#include "IR.tpp"
#include "UIR.tpp"
#include "basic.tpp"
#include "BR.tpp"


#endif// TYPES_H_INCLUDED

#ifndef DAG_H_INCLUDED
#define DAG_H_INCLUDED

#include <fstream>
#include "types.h"

using namespace std;

template <typename R>
using Leaf=U_IR<R>; 
//typedef U_IR<R> Leaf;//non-empty leaf in DAG

typedef vector<N> ListN;

template <typename R> 
struct Node//non-empty node in DAG
{
    vector < R > x; //incresing sequence in R of size #x>0
    ListN ux;//sequences of #x links to level below in DAG
    ListN u; //sequences of #x-1 links to level below in DAG
    friend bool operator==(const Node<R>&X1, const Node<R>&X2)
    {
        return X1.x==X2.x &&X1.ux==X2.ux &&X1.u==X2.u;
    };
};

template <typename R>
using Leaves=vector < Leaf<R> >;
//typedef vector < Leaf<R> > Leaves;//set of nodes at level 0 in DAG

template <typename R> 
using Nodes=vector<Node <R> >;
//typedef vector < Node<R> > Nodes;//set of nodes at a given level in DAG

template <typename R> 
class DAG
{
protected:
    Leaves<R> leaf;  //set of non-empty nodes at level 0, G empty if #leaf=0
    vector < Nodes<R> > nodes;//nodes[l] set of non-empty nodes at level l+
    //memoization
    vector<vector <vector <CMP> > > C;
    //C[l][j][i] comparison of i and j at level l, with i<j ('?' if not computed yet)
    vector<vector <vector <N> > > U;
    //U[l][j][i] result of union of i and j  at level l, with i<j (0 if not computed yet)
    N add_leaf(const Leaf<R>&);//prevent duplication
    N add_node(const Node<R>&, N l);//prevent duplication
    bool cover(const BR<R>&,ListN&,N l) const;
    bool cover(R,R,const Node<R>&,ListN&) const;
    CMP cmp(N,N,N l);//comparison of nodes at level l
    void cmp(const Node<R> &, const Node<R> &, CMP &, N l);
    N make(const BR<R>&,N l);//make at level l
    N sum(N,N,N l);//union of nodes at level l
    Node<R> sum(const Node<R> & X1, const Node<R> & X2, N l);
public:
    DAG(N d);//dimension d>0
    void print() const;//print DAG (for debug purposes)
    void print_test(ostream &cout) const;//print for testing
    void print2(N) const;//print subsets of the plane with integer bounds
    N dim() const;
    N empty() const;
    bool cover(const BR<R>&,N) const;
    CMP cmp(N,N);
    N make(const BR<R>&);
    N sum(N,N);
};

#include "DAG.tpp"
#include "DAG-sum.tpp"
#include "DAG-cover.tpp"
#include "DAG-make.tpp"
#include "DAG-cmp.tpp"


#endif  // DAG_H_INCLUDED

我不知道如何在 uml 中递归地使用(与 typedef 相同但使用模板)部分。谁能告诉我正确的方法?提前谢谢你。

【问题讨论】:

  • Typedefs 通常表示为自 UML 2 标准以来的特殊构造型。模板选项要么保留通用参数,要么与这些规范一起使用。
  • 那么在我的情况下,我该如何表示 typedef 的 typedef?我的意思是图形化@πάνταῥεῖ
  • 可能会很好,是的。如果图形表示看起来代表这种情况。无法判断代码生成是否正确。可能有点取决于工具。
  • 我仍然拥有 Enterprise Architect,并且可能会尝试导入您的代码,如果您希望我这样做,该工具会如何处理它。 (可能需要一些时间,因为我的笔记本电脑有点蹩脚)
  • 可能是this 可能对您自己有所帮助。

标签: class uml diagram class-diagram


【解决方案1】:

这是我的 UML 工具自动生成的 UML 图:

我没有深入了解您的用例,因此您可能想要添加额外的依赖关系(使用正确的构造型 «use» / «bind» 作为需要)为图表的读者澄清更多的事情。

【讨论】:

  • 非常感谢!但正如您所见,未提及使用 using 而不是 typedef 定义的类型。可能是因为模板(我不能模板化类型定义)我需要使用“使用”,而 EA 无法识别这种构造。我会把它描述成一个普通的 typedef。
  • @cristina 是的,当然。我提到您可能会添加更多关系或中间类型(定义)实例来阐明您的意图。我通常知道这个问题,因为我有时也倾向于首先编写工作代码,然后在 UML 中记录它。我总是需要调整 UML 工具从代码中导入的内容,以添加一些技术不高的同事可以理解的额外信息。
  • 他在 using namespace std; 我猜应该是&lt;&lt;import&gt;&gt;
猜你喜欢
  • 1970-01-01
  • 2012-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多