// MetaElements.h: interface for the MetaElements class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_METAELEMENTS_H__C9CB606A_B536_4233_8930_2585F6034B48__INCLUDED_)
#define AFX_METAELEMENTS_H__C9CB606A_B536_4233_8930_2585F6034B48__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <afxcoll.h>

class UMLModelElement;
class UMLActivity;
class UMLActivityGraph;
class UMLClass;
class UMLParameter;
class UMLAttribute;
class UMLOperation;
class UMLAssociation;
class UMLAssociationEnd;
class UMLTransEdge;
class UMLControlFlow;
class UMLSwimlane;
class UMLNamespace;
class UMLSynchActivity;
//各类集合
typedef CObjTempl<UMLParameter> UMLParameterList;
typedef CObjTempl<UMLAttribute> UMLAttributeList;
typedef CObjTempl<UMLOperation> UMLOperationList;
typedef CPtrTempl<UMLAssociationEnd*> UMLAssociationEndPointerList;
typedef CPtrTempl<UMLTransEdge*> UMLTransEdgePointerList;
typedef CPtrTempl<UMLControlFlow*> UMLControlFlowPointerList;
typedef CPtrTempl<UMLActivity*> UMLActivityPointerList;
typedef CPtrTempl<UMLSwimlane*> UMLSwimlanePointerList;
typedef CPtrTempl<UMLModelElement*> UMLModelElementPointerList;
typedef CPtrTempl<UMLClass*> UMLClassPointerList;
typedef CPtrTempl<UMLActivityGraph*> UMLActivityGraphPointerList;
typedef CPtrTempl<UMLControlFlow*> UMLControlPointerList;
typedef CPtrTempl<UMLSynchActivity*> UMLSynchActivityPointerList;
//可见性
typedef enum
{
	VISIBILITY_PUBLIC = 0,
	VISIBILITY_PRIVATE = 1,
	VISIBILITY_PROTECTED = 2,
	VISIBILITY_PACKAGE = 3
}UMLVisibility;
//关联类型
typedef enum
{
	AGGREGATION_NONE = 0,
	AGGREGATION_AGGREGATE = 1,
	AGGREGATION_COMPOSITION = 2
}UMLAggregationKind;
//顺序类型(added by myself)
typedef enum
{
	ORDERING_NONE = 0,
	ORDERING_ORDER = 1
}UMLOrderingKind;
//活动类型
typedef enum
{
	ACTIVITY_INIT = 0,//初始活动
	ACTIVITY_ACTION = 1,//一般活动
	ACTIVITY_SUB = 2,//子活动
	ACTIVITY_SYNCH = 3,//并发活动
	ACTIVITY_FINISH = 4//终止活动
}UMLActivityKind;
//参数方向
typedef enum
{
	PARAMETER_DIR_IN = 0 ,
	PARAMETER_DIR_OUT = 1 ,
	PARAMETER_DIR_INOUT = 2
}UMLParameterDirKind;
//多重性
typedef CString UMLMultiplicity;
// 名字
/*名字用于在某一范围内唯一指定一个模型元素，或着作为一个标识符来查找指定对象；
通常就是一个字符串，可以包含路径*/
typedef CString UMLName;
//表达式
typedef CString UMLExpression;
//元素类型
typedef enum{
	TYPE_ELEMENT = 0,
	TYPE_ATTRIBUTE = 1 ,
	TYPE_OPERATION = 2 ,
	TYPE_CLASS = 3 ,
	TYPE_PARAMETER = 4 ,
	TYPE_RELATIONSHIP = 5 ,
	TYPE_ACTIVITY = 6 ,
	TYPE_ACTIONACTIVITY = 7,
	TYPE_ACTIVITYGRAPH = 8 ,
	TYPE_ASSOCIATION = 9 ,
	TYPE_ASSOCIATIONEND = 10 ,
	TYPE_CONTROLFLOW = 11 ,
	TYPE_NAMESPACE = 12 ,
	TYPE_SUBACTIVITY = 13 ,
	TYPE_SWIMLANE = 14 ,
	TYPE_SYNCHACTIVITY = 15 ,
	TYPE_TRANSEDGE = 16 ,
	TYPE_GELEMENT = 17
}UMLElementType;
//元素
class UMLElement
{
public:
	UMLElement();
	~UMLElement();
};
//模型元素//
class UMLModelElement:public UMLElement
{
public:
	UMLModelElement();
	~UMLModelElement();
public:
	UMLModelElement(UMLModelElement& m );
	virtual UMLElementType Type();
	UMLName name;
	UMLNamespace *m_pNamespace;//所属得名字空间，可以没有，模型元素是名字空间得一部分
};
//名字空间//
class UMLNamespace:public UMLModelElement
{
public:
	UMLNamespace();
	~UMLNamespace();
public:
	virtual UMLElementType Type();
	UMLModelElementPointerList m_OwnedElement;
};
//可通用化元素//
class UMLGeneralizableElement:public UMLModelElement
{
public:
	virtual UMLElementType Type();
	UMLGeneralizableElement();
	~UMLGeneralizableElement();
};
//属性//
class UMLAttribute:public UMLModelElement
{
public:
	UMLAttribute();
	~UMLAttribute();
public:
	virtual UMLElementType Type();
	UMLVisibility m_Visibility;
	UMLMultiplicity m_Multiplicity;
	UMLOrderingKind m_OrderingKind;
	UMLExpression m_InitialValue;
	UMLClass *m_pType;
};
//参数//
class UMLParameter:public UMLModelElement
{
public:
	UMLParameter();
	~UMLParameter();
public:
	virtual UMLElementType Type();
	UMLExpression m_DefaultValue;
	UMLParameterDirKind m_DirKind;//参数方向
	UMLClass *m_pType;//参数类型
};
//方法//
class UMLOperation:public UMLModelElement
{
public:
	UMLOperation();
	~UMLOperation();
	UMLOperation(UMLOperation &e);
	UMLOperation &operator=(UMLOperation &e );
public:
	virtual UMLElementType Type();
	
	UMLVisibility m_Visibility;
	UMLParameterList m_TypedParameter;//{order}
	UMLParameter m_ReturnType;//added by myself
};
//关系//
class UMLRelationship:public UMLModelElement
{
public:
	virtual UMLElementType Type();
	UMLRelationship();
	~UMLRelationship();
};
//关联端//
class UMLAssociationEnd:public UMLModelElement
{
friend class UMLAssociation;
public:
	UMLAssociationEnd();
	~UMLAssociationEnd();

	UMLClass* GetParticipent();
	void SetParticipent(UMLClass * p);

	UMLAssociation* GetAssociation();

public://属性
	UMLMultiplicity m_Multiplicity;//多重性
	UMLAggregationKind m_Aggregation;//聚集类型
	UMLOrderingKind m_Ordering;//顺序性
	UMLVisibility m_Visibility;//可见性
	BOOL m_IsNavigable;//是否可导航
public://关联
	virtual UMLElementType Type();
	UMLClass *m_pParticipent;//该关联端相联系得类
private://关联(added by myself)
	UMLAssociation *m_pAssociation;
};
//关联//
class UMLAssociation:public UMLGeneralizableElement , public UMLRelationship
{
public:
	UMLAssociation();
	~UMLAssociation();
public:
	virtual UMLElementType Type();
	UMLAssociationEnd m_Connection[2];//只考虑2元关联
};
//类/(未加入通用化的相关内容)
class UMLClass:public UMLNamespace , public UMLGeneralizableElement
{
public:
	UMLClass();
	virtual ~UMLClass();
public:
	UMLAttributeList m_Attributes;//属性
	UMLOperationList m_Operations;//操作
public://关联
	virtual UMLElementType Type();
	UMLAssociationEndPointerList m_Associations; //关联的端
	UMLActivityGraphPointerList m_ActivityGraphs;//活动图
};
//活动//
class UMLActivity:public UMLModelElement
{
public:
	UMLActivity();
	~UMLActivity();
public:
	virtual UMLElementType Type();
	UMLTransEdgePointerList m_InTransEdge;//入边
	UMLTransEdgePointerList m_OutTransEdge;//出边
	UMLClass* m_pClass;//所属类
	UMLActivityKind m_ActivityKind;//活动类型

	UMLModelElement* m_pOwnedElement;//属于泳道或者活动图
};
//动作活动//
class UMLActionActivity:public UMLActivity
{
public:
	UMLActionActivity();
	~UMLActionActivity();
public:
	virtual UMLElementType Type();
	UMLExpression m_Expression;//(应该是表达式列表)
};
//子活动//
class UMLSubActivity:public UMLActivity
{
public:
	UMLSubActivity();
	~UMLSubActivity();
public:
	virtual UMLElementType Type();
	UMLActivityGraph* m_pActivityGraph;
};
//并发状态//
class UMLSynchActivity:public UMLActivity
{
public:
	UMLSynchActivity();
	~UMLSynchActivity();
public:
	virtual UMLElementType Type();
	UMLControlFlowPointerList m_EndControlFlow;//终止于该并发状态的控制流（是引申关联）
	UMLControlFlowPointerList m_BeginControlFlow;//开始于该并发状态的控制流（是引申关联）

	UMLSynchActivity *m_pSynchActivityNext;//主控制流的下一跳
	UMLSynchActivity *m_pSynchActivityLast;//主控制流的上一跳
};
//边//
class UMLTransEdge:public UMLModelElement
{
public:
	UMLTransEdge();
	~UMLTransEdge();
public:
	virtual UMLElementType Type();
	UMLExpression m_BoolExpression;//布尔表达式
	UMLActivity* m_pActivities[2];//连接的活动
};
//活动图//
class UMLActivityGraph:public UMLModelElement
{
public:
	UMLActivityGraph();
	~UMLActivityGraph();
public:
	//从first边出发，终止于to节点的边数
	int GetRouteNumberOnEnd(UMLActivity*from ,UMLTransEdge *first ,UMLActivity* to );
	//从from节点出发，终止于to节点的边数
	int GetRouteNumberOnEnd(UMLActivity * from ,UMLActivity * to);
	void DetachMainControlFlow();//分解出主控制流
	virtual UMLElementType Type();
	UMLControlFlow* GetControlBySynchAndEdge(UMLSynchActivity* a , UMLTransEdge* edge );//获得当个控制流
	void GetControlFlows();//分解控制流
	UMLSwimlanePointerList m_Swimlanes;//泳道
	UMLActivityPointerList m_Activities;//活动
	UMLTransEdgePointerList m_Edges;//边
	UMLClass *m_pClass;//该活动图隶属的类

	UMLControlPointerList m_ControlFlows;//控制流
};
//控制流//
class UMLControlFlow
{
public:
	UMLControlFlow();
	~UMLControlFlow();
public:
	void GetReachableSynch(UMLActivity* me , UMLActivityPointerList &list);
	void GetReachableSynch();
	virtual UMLElementType Type();
	UMLSynchActivity* m_pBegin;//起始并发状态
	UMLSynchActivityPointerList m_pEndList;//可选的并发终点
	UMLSynchActivity* m_pMainCFEnd;//所属的主控制流的终点
	UMLTransEdge* m_pFirstEdge;//起始并发状态的一条出边
	UMLActivityPointerList m_pActivities;//包含的活动
	UMLTransEdgePointerList m_pEdges;//包含的边

	UMLSynchActivityPointerList m_ReachableSynch;//可达的并发节点
};
//泳道//
class UMLSwimlane: public UMLModelElement
{
public:
	UMLSwimlane();
	~UMLSwimlane();
public:
	virtual UMLElementType Type();
	UMLClass *pType;
	UMLActivityPointerList m_Activities;//包含的活动（活动中包含类的信息）
};
#endif // !defined(AFX_METAELEMENTS_H__C9CB606A_B536_4233_8930_2585F6034B48__INCLUDED_)
