Salome HOME
Copyright update: 2016
[modules/yacs.git] / src / engine / LinkInfo.hxx
1 // Copyright (C) 2006-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __LINKINFO_HXX__
21 #define __LINKINFO_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "Exception.hxx"
25
26 #include <vector>
27 #include <list>
28 #include <map>
29 #include <set>
30
31 namespace YACS
32 {
33   namespace ENGINE
34   {
35     class Node;
36     class InGate;
37     class InPort;
38     class OutGate;
39     class OutPort;
40     class ComposedNode;
41     class CollectorSwOutPort;
42
43     typedef enum
44       {
45         I_CF_USELESS   = 41,
46         I_USELESS      = 42,
47         I_BACK         = 43,//In loop context
48         I_BACK_USELESS = 44,//In loop context - Not implemented yet
49         I_BACK_CRAZY   = 45,//Out of loop context
50         I_DFDS         = 46,
51         I_ALL          = 49,
52       } InfoReason;
53
54     typedef enum
55       {
56         W_COLLAPSE                     = 141,
57         W_COLLAPSE_AND_USELESS         = 142,
58         W_COLLAPSE_EL                  = 143,
59         W_COLLAPSE_EL_AND_USELESS      = 144,
60         W_BACK_COLLAPSE                = 145,
61         W_BACK_COLLAPSE_AND_USELESS    = 146,
62         W_BACK_COLLAPSE_EL             = 147,
63         W_BACK_COLLAPSE_EL_AND_USELESS = 148,
64         W_ALL                          = 149
65       } WarnReason;
66
67     typedef enum
68       {
69         E_NEVER_SET_INPUTPORT     = 241,
70         E_ONLY_BACKWARD_DEFINED   = 242,
71         E_DS_LINK_UNESTABLISHABLE = 243,
72         E_COLLAPSE_DFDS           = 244,
73         E_COLLAPSE_DS             = 245,
74         E_UNPREDICTABLE_FED       = 246,
75         E_UNCOMPLETE_SW            =247,
76         E_ALL                     = 249
77       } ErrReason;
78
79     /*!
80      * \brief Class that deal with list of \b semantics links for high level analysis.
81      */
82     class YACSLIBENGINE_EXPORT LinkInfo
83     {
84     private:
85       ComposedNode *_pov;
86       unsigned int _level;
87       unsigned char _levelOfInfo;
88       std::vector<InPort *> _unsetInPort;
89       std::vector<InPort *> _onlyBackDefined;
90       std::set< std::pair<Node *, Node *> > _uselessLinks;
91       std::map<InfoReason, std::vector< std::pair<OutPort *,InPort *> > > _infos;
92       std::map<WarnReason, std::vector< std::vector< std::pair<OutPort *,InPort *> > > > _collapse;
93       std::map<ErrReason, std::vector< std::pair<OutPort *,InPort *> > > _errors;
94       std::vector<CollectorSwOutPort *> _errorsOnSwitchCases;
95     public:
96       LinkInfo(unsigned char level);
97       void clearAll();
98       void startCollapseTransac();
99       void endCollapseTransac() throw(Exception);
100       void setPointOfView(ComposedNode *pov);
101       void pushInfoLink(OutPort *semStart, InPort *end, InfoReason reason);
102       void pushWarnLink(OutPort *semStart, InPort *end, WarnReason reason);
103       void pushErrLink(OutPort *semStart, InPort *end, ErrReason reason) throw(Exception);
104       void pushErrSwitch(CollectorSwOutPort *collector) throw(Exception);
105       void pushUselessCFLink(Node *start, Node *end);
106       void takeDecision() const throw(Exception);
107       //Typically methods for high level use.
108       std::string getGlobalRepr() const;
109       std::string getInfoRepr() const;
110       std::string getWarnRepr() const;
111       std::string getErrRepr() const;
112       bool areWarningsOrErrors() const;
113       unsigned getNumberOfInfoLinks(InfoReason reason) const;
114       unsigned getNumberOfWarnLinksGrp(WarnReason reason) const;
115       unsigned getNumberOfErrLinks(ErrReason reason) const;
116       std::set< std::pair<Node *, Node *> > getInfoUselessLinks() const;
117       std::pair<OutPort *, InPort *> getInfoLink(unsigned id, InfoReason reason) const;
118       std::vector< std::pair<OutPort *, InPort *> > getWarnLink(unsigned id, WarnReason reason) const;
119       std::pair<OutPort *, InPort *> getErrLink(unsigned id, ErrReason reason) const;
120     protected:
121       static std::string getStringReprOfI(InfoReason reason);
122       static std::string getStringReprOfW(WarnReason reason);
123       static std::string getStringReprOfE(ErrReason reason);
124       static std::string printThereIsAre(unsigned val, const std::string& other);
125     public:
126       static const unsigned char ALL_STOP_ASAP       = 1;
127       static const unsigned char ALL_DONT_STOP       = 2;
128       static const unsigned char WARN_ONLY_DONT_STOP = 3;
129     };
130   }
131 }
132
133 #endif