Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / engine / Pool.hxx
1 // Copyright (C) 2006-2014  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 __POOL_HXX__
21 #define __POOL_HXX__
22
23 #include "YACSlibEngineExport.hxx"
24 #include "Exception.hxx"
25
26 #include <list>
27
28 namespace YACS
29 {
30   namespace ENGINE
31   {
32     class Any;
33     class OptimizerLoop;
34
35     class YACSLIBENGINE_EXPORT Pool
36     {
37       friend class OptimizerLoop;
38
39       class ExpData
40       {
41       private:
42         Any *_in;
43         Any *_out;
44         unsigned char _priority;
45       public:
46         ExpData(Any *inValue, unsigned char priority);
47         ExpData(const ExpData& other);
48         ~ExpData();
49         Any *inValue() const { return _in; }
50         Any *outValue() const { return _out; }
51         void setOutValue(Any *outValue);
52         void markItAsInUse();
53         bool isLaunchable() const;
54         unsigned char getPriority() const { return _priority; }
55       private:
56         static Any *NOT_USED_NOR_COMPUTED;
57         static Any *USED_BUT_NOT_COMPUTED_YET;
58       };
59     private:
60       std::list< std::pair<int, ExpData> > _container;
61       std::list< std::pair<int, ExpData> >::iterator _currentCase;
62     public:
63       //For algorithm use
64       int getCurrentId() const ;
65       Any *getCurrentInSample() const ;
66       Any *getCurrentOutSample() const ;
67       Any *getOutSample(int id);
68       void pushInSample(int id, Any *inSample, unsigned char priority = 0);
69       void destroyAll();
70     private:
71       //For OptimizerNode use
72       void destroyCurrentCase();
73       void checkConsistency() throw(Exception);
74       void setCurrentId(int id) throw(Exception);
75       void putOutSampleAt(int id, Any *outValue) throw(Exception);
76       Any *getNextSampleWithHighestPriority(int& id, unsigned char& priority) const;
77       void markIdAsInUse(int id);
78       bool empty() const;
79     private:
80       static const char MESSAGEFORUNXSTNGID[];
81     };
82   }
83 }
84
85 #endif