source: XMLIO_V2/dev/dev_rv/src/xmlio/functor.cpp @ 199

Last change on this file since 199 was 187, checked in by hozdoba, 13 years ago
File size: 3.2 KB
Line 
1#include "functor.hpp"
2
3namespace xmlioserver
4{
5   namespace func
6   {
7      /// ////////////////////// Définitions ////////////////////// ///
8
9      CFunctor::CFunctor(const StdString & id, ARRAY(double, 1) doutput,
10                         const CFunData & data, CFuncType type)
11         : SuperClass(id)
12         , doutput(doutput), size()
13         , data(data), type(type)
14      { this->resize(size); }
15
16      CFunctor::CFunctor(const StdString & id, DoubleArray doutput,
17                         const std::vector<StdSize> size,
18                         const CFunData & data, CFuncType type)
19         : SuperClass(id)
20         , doutput(doutput), size(size)
21         , data(data), type(type)
22      { this->resize(size); }
23
24      CFunctor::~CFunctor(void)
25      { /* Ne rien faire de plus */ }
26
27      //---------------------------------------------------------------
28
29      const CFunctor::CFunData  & CFunctor::getData(void) const
30      { return (this->data); }
31
32      CFunctor::CFuncType CFunctor::getType(void) const
33      { return (this->type); }
34
35      ARRAY(double, 1) CFunctor::getDataOutput(void) const
36      { return (this->doutput); }
37
38      const std::vector<StdSize> & CFunctor::getShape(void) const
39      { return (this->size); }
40
41      StdSize CFunctor::getSize(void) const
42      { return (this->doutput->size()); }
43
44      //---------------------------------------------------------------
45
46      void CFunctor::resize(StdSize x, StdSize y, StdSize z)
47      {
48         this->size.clear();
49         this->size.push_back(x);
50         if (y != 1) this->size.push_back(y);
51         if (z != 1) this->size.push_back(z);
52         this->doutput->resize(boost::extents[x * y * z]);
53      }
54
55      void CFunctor::resize(const std::vector<StdSize> & sizes)
56      {
57         StdSize newsize = 1;
58         this->size.clear();
59         std::vector<StdSize>::const_iterator it = sizes.begin(), end = sizes.end();
60         
61         for (; it!=end; it++)
62         { 
63            StdSize size = *it;
64            newsize *= size;
65            this->size.push_back(size);
66         }
67         this->doutput->resize(boost::extents[newsize]);
68      }
69
70      //---------------------------------------------------------------
71
72      StdString CFunctor::toString(void) const
73      {
74         ERROR("CFunctor::toString()", << "Not implemented yet !");
75         return (SuperClass::getId());
76      }
77
78      void CFunctor::fromString(const StdString & str)
79      {
80         ERROR("CFunctor::fromString(str)",
81                << "[ str = " << str << "] Not implemented yet !");
82      }
83
84      //---------------------------------------------------------------
85
86      ARRAY(double, 1) CFunctor::operator ()(const ARRAY(double, 1) dinput)
87      {
88         if (dinput->size() != this->doutput->size())
89            ERROR("CFunctor::operator ()(dinput)",
90                   << "[ input size = "  << dinput->size()
91                   << ", output size = " << this->doutput->size() << " ]"
92                   << " size of input array !=  size of output array !");
93         this->apply(dinput, this->doutput, this->size, this->data);
94         return (this->doutput);
95      }
96
97      //---------------------------------------------------------------
98
99   } // namespace func
100} // namespace xmlioserver
Note: See TracBrowser for help on using the repository browser.