我试图从我的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
我不知道该如何递归地使用(与typedef相同,但带有模板)部分。谁能告诉我正确的方法?预先谢谢你。