summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/assocrules.h
blob: df33d6d8c9ad05245eeb0a44ff862f5f95c669e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2002-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#ifndef ASSOCRULES_H
#define ASSOCRULES_H

#include "umlnamespace.h"
namespace std
    { class type_info; }

class UMLWidget;

/**
 * Used to determine rules for associations.
 *
 * @author Paul Hensgen
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.kde.org
 */
class AssocRules {
public:
    /**
     * Constructor.
     */
    AssocRules();

    /**
     * Deconstructor.
     */
    ~AssocRules();

    /**
     * Returns whether an association is going to be allowed for the given
     * values. This method is used to test if you can start an association.
     */
    static bool allowAssociation( Uml::Association_Type assocType, UMLWidget * widget );

    static bool allowAssociation( Uml::Association_Type assocType, const std::type_info & );

    /**
     * Returns whether an association is valid with the given variables.
     * This method is used to finish an association.
     */
    static bool allowAssociation( Uml::Association_Type assocType,
                                  UMLWidget * widgetA, UMLWidget * widgetB,
                                  bool extendedCheck = true );

    /**
     * Returns whether to allow a role text for the given association type.
     */
    static bool allowRole( Uml::Association_Type assocType );

    /**
     * Returns whether to allow a multiplicity text for the given
     * association and widget type.
     */
    static bool allowMultiplicity( Uml::Association_Type assocType, Uml::Widget_Type widgetType );

    /**
     * Returns whether to allow an association to self for given variables.
     */
    static bool allowSelf( Uml::Association_Type assocType, Uml::Widget_Type widgetType );

    /**
     * Returns whether an implements association should be a Realisation or
     * a Generalisation.
     * as defined in m_AssocRules.
     */
    static Uml::Association_Type isGeneralisationOrRealisation(UMLWidget* widgetA, UMLWidget* widgetB);

private:

    /**
     * Structure to help determine association rules.
     */
    struct Assoc_Rule {
        Uml::Association_Type assoc_type; ///< association type
        Uml::Widget_Type widgetA_type; ///< type of role A widget
        Uml::Widget_Type widgetB_type; ///< type of role B widget
        bool role;                   ///< role text
        bool multiplicity;           ///< multipliciy text on association
        /// can have an association of same type going between widget each way
        bool directional;

        bool self;                   ///< association to self
    };

    /**
     * Container that holds all the rules.
     */
    static Assoc_Rule m_AssocRules[];

    /**
     * The number of rules known about.
     */
    static int m_nNumRules;
};

#endif