Salome HOME
Copyright update: 2016
[modules/yacs.git] / src / engine / Test / PluginOptEvTest1.cxx
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 #include "PluginOptEvTest1.hxx"
21 #include "TypeCode.hxx"
22 #include "Pool.hxx"
23
24 #include <cmath>
25
26 using namespace YACS::ENGINE;
27
28 PluginOptEvTest1::PluginOptEvTest1(Pool *pool):OptimizerAlgSync(pool),_tcIn(0),_tcOut(0),_idTest(0)
29 {
30   _tcIn=new TypeCode(Double);
31   _tcOut=new TypeCode(Int);
32 }
33
34 PluginOptEvTest1::~PluginOptEvTest1()
35 {
36   _tcIn->decrRef();
37   _tcOut->decrRef();
38 }
39
40 TypeCode *PluginOptEvTest1::getTCForIn() const
41 {
42   return _tcIn;
43 }
44
45 TypeCode *PluginOptEvTest1::getTCForOut() const
46 {
47   return _tcOut;
48 }
49
50 TypeCode *PluginOptEvTest1::getTCForAlgoResult() const
51 {
52   return _tcIn;
53 }
54
55 Any * PluginOptEvTest1::getAlgoResult()
56 {
57   return AtomAny::New(45.6);
58 }
59
60 void PluginOptEvTest1::parseFileToInit(const std::string& fileName)
61 {
62 }
63
64 void PluginOptEvTest1::start()
65 {
66   _idTest=0;
67   Any *val=AtomAny::New(1.2);
68   _pool->pushInSample(4,val);
69   val=AtomAny::New(3.4);
70   _pool->pushInSample(9,val);
71 }
72
73 void PluginOptEvTest1::takeDecision()
74 {
75   if(_idTest==1)
76     {
77       Any *val=AtomAny::New(5.6);
78       _pool->pushInSample(16,val);
79       val=AtomAny::New(7.8);
80       _pool->pushInSample(25,val);
81       val=AtomAny::New(9. );
82       _pool->pushInSample(36,val);
83       val=AtomAny::New(12.3);
84       _pool->pushInSample(49,val);
85     }
86   else if(_idTest==4)
87     {
88       Any *val=AtomAny::New(45.6);
89       _pool->pushInSample(64,val);
90       val=AtomAny::New(78.9);
91       _pool->pushInSample(81,val);
92     }
93   else
94     {
95       Any *tmp= _pool->getCurrentInSample();
96       if(fabs(tmp->getDoubleValue()-45.6)<1.e-12)
97         _pool->destroyAll();
98     }
99   _idTest++;
100 }
101
102 void PluginOptEvTest1::initialize(const Any *input) throw(YACS::Exception)
103 {
104 }
105
106 void PluginOptEvTest1::finish()
107 {
108 }
109
110 OptimizerAlgBase *PluginOptEvTest1Factory(Pool *pool)
111 {
112   return new PluginOptEvTest1(pool);
113 }