]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/Any.cxx
Salome HOME
e77a310fce86f0aea441a6d7409da1f7cb20dfcc
[modules/yacs.git] / src / engine / Any.cxx
1 #include "Any.hxx"
2 #include "Runtime.hxx"
3 #include "TypeCode.hxx"
4 #include "InvalidExtractionException.hxx"
5
6 #include <cstring>
7
8 using namespace YACS::ENGINE;
9 using namespace std;
10
11 StringOnHeap::StringOnHeap(const char *val):_dealloc(0),_str(strdup(val))
12 {
13 }
14
15 StringOnHeap::StringOnHeap(const std::string& val):_dealloc(0),_str(strdup(val.c_str()))
16 {
17 }
18
19 /*! 
20  * \Note : no copy is performed if a deallocator is given.
21  * \param val     : String in C format that is NOT copied if
22  *                  deAlloc != 0
23  * \param deAlloc : pointer on function to deallocate val after
24  *                  last use.
25  */
26 StringOnHeap::StringOnHeap(char *val, Deallocator deAlloc):_dealloc(deAlloc)
27 {
28   if(deAlloc)
29     _str=val;
30   else
31     _str=strdup(val);
32 }
33
34 bool StringOnHeap::operator ==(const StringOnHeap& other) const
35 {
36   return strcmp(_str, other._str)==0;
37 }
38
39 StringOnHeap *StringOnHeap::deepCopy() const
40 {
41   return new StringOnHeap(_str);
42 }
43
44 StringOnHeap::~StringOnHeap()
45 {
46   if(_dealloc)
47     _dealloc(_str);
48   else
49     free(_str);
50 }
51
52 Any::Any(TypeCode* type):_type(type)
53 {
54   _type->incrRef();
55 }
56
57 Any::Any(const Any& other):_type(other._type)
58 {
59   _type->incrRef();
60 }
61
62 Any::~Any()
63 {
64   _type->decrRef();
65 }
66
67 AtomAny::AtomAny(int val):Any(Runtime::_tc_int)
68 {
69   _value._i=val;
70 }
71
72 AtomAny::AtomAny(bool val):Any(Runtime::_tc_bool)
73 {
74   _value._b=val;
75 }
76
77 AtomAny::AtomAny(double val):Any(Runtime::_tc_double)
78 {
79   _value._d=val;
80 }
81
82 AtomAny::AtomAny(const char *val):Any(Runtime::_tc_string)
83 {
84   _value._s=new StringOnHeap(val);
85 }
86
87 AtomAny::AtomAny(const std::string& val):Any(Runtime::_tc_string)
88 {
89   _value._s=new StringOnHeap(val);
90 }
91
92 AtomAny::AtomAny(const AtomAny& other):Any(other)
93 {
94   if(_type->isA(Runtime::_tc_string))
95     {
96       StringOnHeap *cpy=(other._value._s)->deepCopy();
97       memcpy(&_value._s,&cpy,_type->getSizeInByteOfAnyReprInSeq());
98     }
99   else if(_type->isA(Runtime::_tc_double))
100     memcpy(&_value._d,&other._value._d,_type->getSizeInByteOfAnyReprInSeq());
101   else if(_type->isA(Runtime::_tc_int))
102     memcpy(&_value._i,&other._value._i,_type->getSizeInByteOfAnyReprInSeq());
103   else if(_type->isA(Runtime::_tc_bool))
104     memcpy(&_value._b,&other._value._b,_type->getSizeInByteOfAnyReprInSeq());
105 }
106
107 AtomAny::AtomAny(char *val, Deallocator deAlloc):Any(Runtime::_tc_string)
108 {
109   _value._s=new StringOnHeap(val,deAlloc);
110 }
111
112 AtomAny::AtomAny(char *data, TypeCode* type):Any(type)
113 {
114   if(type->isA(Runtime::_tc_string))
115     {
116       void **tmp=(void **)data;
117       StringOnHeap *cpy=((StringOnHeap *)(*tmp))->deepCopy();
118       memcpy(&_value._s,&cpy,type->getSizeInByteOfAnyReprInSeq());
119     }
120   else if(type->isA(Runtime::_tc_double))
121     memcpy(&_value._d,data,type->getSizeInByteOfAnyReprInSeq());
122   else if(type->isA(Runtime::_tc_int))
123     memcpy(&_value._i,data,type->getSizeInByteOfAnyReprInSeq());
124   else if(type->isA(Runtime::_tc_bool))
125     memcpy(&_value._b,data,type->getSizeInByteOfAnyReprInSeq());
126 }
127
128 Any *AtomAny::clone() const
129 {
130   return new AtomAny(*this);
131 }
132
133 AtomAny *AtomAny::New(char *val,Deallocator dealloc)
134 {
135   return new AtomAny(val,dealloc);
136 }
137
138 AnyPtr AtomAny::operator[](int i) const
139 {
140   throw InvalidExtractionException(_type->kind(),Sequence);
141 }
142
143 bool AtomAny::operator ==(const Any& other) const
144 {
145   if(!_type->isA(other.getType()))
146     return false;
147   const AtomAny& otherC=(const AtomAny&) other;//cast granted due to previous lines
148   if(_type->isA(Runtime::_tc_double))
149     return _value._d==otherC._value._d;
150   else if(_type->isA(Runtime::_tc_int))
151     return _value._i==otherC._value._i;
152   else if(_type->isA(Runtime::_tc_bool))
153     return _value._b==otherC._value._b;
154   else if(_type->isA(Runtime::_tc_string))
155     return (*_value._s)==*(otherC._value._s);
156   else
157     return false;
158 }
159
160 int AtomAny::getIntValue() const throw(Exception)
161 {
162   if(_type->isA(Runtime::_tc_int))
163     return _value._i;
164   else
165     throw Exception("Value is not an Int");
166 }
167
168 bool AtomAny::getBoolValue() const throw(Exception)
169 {
170   if(_type->isA(Runtime::_tc_bool))
171     return _value._b;
172   else
173     throw Exception("Value is not a Bool");
174 }
175
176 double AtomAny::getDoubleValue() const throw(Exception)
177 {
178   if(_type->isA(Runtime::_tc_double))
179     return _value._d;
180   else
181     throw Exception("Value is not a Double");
182 }
183
184 std::string AtomAny::getStringValue() const throw(Exception)
185 {
186   if(_type->isA(Runtime::_tc_string))
187     return string(_value._s->cStr());
188   else
189     throw Exception("Value is not a String");
190 }
191
192 /*!
193  * \note : This method put in data its zipped recursive content in data.
194  *         The ownership of the recursive content is tranfered to data.
195  *         So this owns nothing and its counter fall by 1.
196  *         For memory space minimal use, not all of '*this' is pushed at data location. 
197  * \param data : already allocated memory zone where to put compressed content of 'this'
198  */
199 void AtomAny::putMyReprAtPlace(char *data) const
200 {
201   if(_type->isA(Runtime::_tc_string))
202     {
203       StringOnHeap *tmp=_value._s->deepCopy();
204       memcpy(data,&tmp,_type->getSizeInByteOfAnyReprInSeq());
205     }
206   else if(_type->isA(Runtime::_tc_double))
207     memcpy(data,&_value._d,_type->getSizeInByteOfAnyReprInSeq());
208   else if(_type->isA(Runtime::_tc_int))
209     memcpy(data,&_value._i,_type->getSizeInByteOfAnyReprInSeq());
210   else if(_type->isA(Runtime::_tc_bool))
211     memcpy(data,&_value._b,_type->getSizeInByteOfAnyReprInSeq());
212 }
213
214 /*!
215  * \note : This method put in data its zipped recursive content in data.
216  *         The ownership of the recursive content is tranfered to data.
217  *         So this owns nothing and its counter fall by 1.
218  *         For memory space minimal use, not all of '*this' is pushed at data location.
219  *         'deepCpy' param is not used here because by definition of AtomAny deep copy is performed.
220  * \param data : already allocated memory zone where to put compressed content of 'this'
221  */
222 void AtomAny::putReprAtPlace(char *data, const char *src, const TypeCode *type, bool deepCpy)
223 {
224   if(type->isA(Runtime::_tc_string))
225     {
226       void **tmp1=(void **)src;
227       StringOnHeap *tmp=((const StringOnHeap *)(*tmp1))->deepCopy();
228       memcpy(data,&tmp,type->getSizeInByteOfAnyReprInSeq());
229     }
230   else if(type->isA(Runtime::_tc_double))
231     memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
232   else if(type->isA(Runtime::_tc_int))
233     memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
234   else if(type->isA(Runtime::_tc_bool))
235     memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
236 }
237
238 /*!
239  * \note : Opposite method of putMyReprAtPlace. But static because due to data compression
240  *         instance is lost.
241  */
242 void AtomAny::destroyReprAtPlace(char *data, const TypeCode *type)
243 {
244   DynType typ=type->kind();
245   if(typ==String)
246     {
247       void **tmp=(void **)data;
248       delete ((StringOnHeap *)(*tmp));
249     }
250 }
251
252 AnyPtr AtomAny::getOrBuildFromData(char *data, const TypeCode *type)
253 {
254   Any *ret;
255   ret=new AtomAny(data,(TypeCode *)type);
256   return AnyPtr(ret);
257 }
258
259 bool AtomAny::takeInChargeStorageOf(TypeCode *type)
260 {
261   DynType typ=type->kind();
262   return (typ==Double || typ==Int || typ==Bool || typ==String);
263 }
264
265 AtomAny::~AtomAny()
266 {
267   if(_type->isA(Runtime::_tc_string))
268     delete _value._s;
269 }
270
271 ComposedAny::ComposedAny(const ComposedAny& other):Any(other)
272 {
273 }
274
275 ComposedAny::ComposedAny(TypeCode* type):Any(type)
276 {
277   _type->decrRef();
278 }
279
280 int ComposedAny::getIntValue() const throw(Exception)
281 {
282  throw InvalidExtractionException(_type->kind(),Runtime::_tc_int->kind());
283 }
284
285 bool ComposedAny::getBoolValue() const throw(Exception)
286 {
287   throw InvalidExtractionException(_type->kind(),Runtime::_tc_bool->kind());
288 }
289
290 double ComposedAny::getDoubleValue() const throw(Exception)
291 {
292   throw InvalidExtractionException(_type->kind(),Runtime::_tc_double->kind());
293 }
294
295 std::string ComposedAny::getStringValue() const throw(Exception)
296 {
297   throw InvalidExtractionException(_type->kind(),Runtime::_tc_string->kind());
298 }
299
300 SeqAlloc::SeqAlloc(const SeqAlloc& other):_sizeOf1Elm(other._sizeOf1Elm),_notStdDeAlloc(0),
301  _start(0),_finish(0),_endOfStorage(0)
302 {
303   _start=allocate(other._finish-other._start);
304   _finish=_start+(other._finish-other._start);
305   _endOfStorage=_finish;
306 }
307
308 SeqAlloc::SeqAlloc(unsigned int sizeOf1Elm):_sizeOf1Elm(sizeOf1Elm),_notStdDeAlloc(0),
309                                             _start(0),_finish(0),_endOfStorage(0)
310 {
311 }
312
313 SeqAlloc::~SeqAlloc()
314 {
315   deallocate(_start);
316 }
317
318 void SeqAlloc::clear()
319 {
320   deallocate(_start);
321   _start=0;
322   _finish=0;
323   _endOfStorage=0;
324 }
325
326 /*!
327  * \note : This method is exclusively reserved for arrays of C++ built-in types because no
328  *         constructor is applied atomically.
329  */
330 void SeqAlloc::initCoarseMemory(char *mem, unsigned int size, Deallocator dealloc)
331 {
332   unsigned sizeInByte=size*_sizeOf1Elm;
333   if(dealloc)
334     {
335       _notStdDeAlloc=dealloc;
336       _start=mem;
337     }
338   else
339     {
340       _start=allocate(sizeInByte);
341       if(mem)
342         memcpy(_start,mem,sizeInByte);
343       else
344         {
345           for(unsigned int i=0;i<sizeInByte;i++) _start[i]=0;
346         }
347     }
348   _finish=_start+sizeInByte;
349   _endOfStorage=_finish;
350 }
351
352 void SeqAlloc::construct(char *pt, const Any *val)
353 {
354   val->putMyReprAtPlace(pt);
355 }
356
357 /*!
358  * \note: This performs the placement new or zip info into pt.
359  * \param val     : the source from which the construction will be performed.
360  * \param deepCpy : If true in pt place a deep copy pointed by val will be put.
361  */
362 void SeqAlloc::construct(char *pt, const char *val, const TypeCode *tc, bool deepCpy)
363 {
364   tc->putReprAtPlace(pt,val,deepCpy);
365 }
366
367 char *SeqAlloc::allocate(unsigned int nbOfByte)
368
369   if(nbOfByte>0)
370     return (char *)::operator new(nbOfByte);
371   else
372     return 0;
373 }
374
375 // pt is not permitted to be a null pointer.
376 void SeqAlloc::deallocate(char *pt)
377
378   if(pt)
379     {
380       if(!_notStdDeAlloc)
381         ::operator delete(pt); 
382       else
383         {
384           _notStdDeAlloc(pt);
385           _notStdDeAlloc=0;
386         }
387     }
388 }
389
390 void SeqAlloc::destroy(char *pt, const TypeCode *tc) 
391
392   tc->destroyZippedAny(pt);
393 }
394
395 unsigned int SeqAlloc::size() const
396 {
397   return (_finish-_start)/_sizeOf1Elm;
398 }
399
400 void SequenceAny::clear()
401 {
402   for (char *cur=_alloc._start;cur!=_alloc._finish;cur+=_alloc._sizeOf1Elm)
403     _alloc.destroy(cur,_type->contentType());
404   _alloc.clear();
405 }
406
407 void SequenceAny::popBack()
408 {
409   _alloc._finish-=_alloc._sizeOf1Elm;
410   _alloc.destroy(_alloc._finish,_type->contentType());
411 }
412
413 void SequenceAny::pushBack(const Any* elem)
414 {
415   if(!elem->_type->isA(_type->contentType()))
416     throw InvalidExtractionException(elem->_type->kind(),_type->contentType()->kind());
417   if(_alloc._finish != _alloc._endOfStorage)
418     {
419       _alloc.construct(_alloc._finish, elem);
420       _alloc._finish+=_alloc._sizeOf1Elm;
421     }
422   else
423     realloc(_alloc._finish, elem);
424 }
425
426 bool SequenceAny::operator ==(const Any& other) const
427 {
428   if(!_type->isA(other.getType()))
429     return false;
430   const SequenceAny& otherC=(const SequenceAny&) other;//cast granted due to previous lines
431   if(size()!=otherC.size())
432     return false;
433   for(unsigned i=0;i<size();i++)
434     if(!((*(*this)[i])==(*otherC[i])))
435       return false;
436   return true;
437 }
438
439 void SequenceAny::setEltAtRank(int i, const Any *elem)
440 {
441   _alloc.destroy(_alloc._start+i*_alloc._sizeOf1Elm,_type->contentType());
442   _alloc.construct(_alloc._start+i*_alloc._sizeOf1Elm,elem);
443 }
444
445 AnyPtr SequenceAny::operator[](int i) const
446 {
447   return _type->contentType()->getOrBuildAnyFromZippedData(_alloc._start+i*_alloc._sizeOf1Elm);
448 }
449
450 /*!
451  * \note : Contrary to AtomAny 'this' (ref) is put in data NOT a deep copy.
452  * \param data : already allocated memory zone where to put address of 'this'
453  */
454 void SequenceAny::putMyReprAtPlace(char *data) const
455 {
456   const void *tmp=(const void *)this;
457   memcpy(data,&tmp,_type->getSizeInByteOfAnyReprInSeq());
458   const void **tmp2=(const void **) data;
459   ((SequenceAny *)(*tmp2))->incrRef();
460   //::new((SequenceAny *)data) SequenceAny((SequenceAny&) (*this));
461 }
462
463 void SequenceAny::putReprAtPlace(char *data, const char *src, const TypeCode *type, bool deepCpy)
464 {
465   void **tmp2=(void **) src;
466   if(!deepCpy)
467     {
468       ((SequenceAny *)(*tmp2))->incrRef();
469       memcpy(data,src,type->getSizeInByteOfAnyReprInSeq());
470     }
471   else
472     {
473       SequenceAny *cpy=new SequenceAny(*((SequenceAny *)(*tmp2)));
474       memcpy(data,&cpy,type->getSizeInByteOfAnyReprInSeq());
475     }
476   //::new((SequenceAny *)data) SequenceAny((SequenceAny&) (*this));
477 }
478
479 void SequenceAny::destroyReprAtPlace(char *data, const TypeCode *type)
480 {
481   void **tmp=(void **) data;
482   if(*tmp)
483     ((SequenceAny *)(*tmp))->decrRef();
484   //((SequenceAny *)data)->~SequenceAny();
485 }
486
487 AnyPtr SequenceAny::getOrBuildFromData(char *data, const TypeCode *type)
488 {
489   void **tmp=(void **) data;
490   ((SequenceAny *) (*tmp))->incrRef();
491   return AnyPtr((SequenceAny *)(*tmp));
492 }
493
494 Any *SequenceAny::clone() const
495 {
496   return new SequenceAny(*this);
497 }
498
499 SequenceAny *SequenceAny::New(const TypeCode *typeOfContent)
500 {
501   if(typeOfContent->kind() == Objref)
502     {
503       //In case of Objref, use a sequence of string
504       return new SequenceAny(Runtime::_tc_string);
505     }
506   else
507     return new SequenceAny(typeOfContent);
508 }
509
510 SequenceAny *SequenceAny::New(const TypeCode *typeOfContent, unsigned lgth)
511 {
512   if(typeOfContent->kind() == Objref)
513     {
514       //In case of Objref, use a sequence of string
515       return new SequenceAny(Runtime::_tc_string,lgth);
516     }
517   else
518     return new SequenceAny(typeOfContent,lgth);
519 }
520
521 bool SequenceAny::takeInChargeStorageOf(TypeCode *type)
522 {
523   DynType typ=type->kind();
524   return (typ==Sequence);
525 }
526
527 SequenceAny::SequenceAny(const SequenceAny& other):ComposedAny(other),_alloc(other._alloc)
528 {
529   const char *srcCur=other._alloc._start;
530   for(char *cur=_alloc._start;srcCur != other._alloc._finish; srcCur+=_alloc._sizeOf1Elm, cur+=_alloc._sizeOf1Elm)
531     _alloc.construct(cur, srcCur, _type->contentType(),true);
532 }
533
534 SequenceAny::~SequenceAny()
535 {
536   for (char *cur=_alloc._start;cur!=_alloc._finish;cur+=_alloc._sizeOf1Elm)
537     _alloc.destroy(cur,_type->contentType());
538 }
539
540 /*!
541  * \param typeOfContent : typeCode of the type of elements stored in sequence.
542  */
543 SequenceAny::SequenceAny(const TypeCode *typeOfContent):ComposedAny(new TypeCodeSeq("","",typeOfContent)),
544                                                         _alloc(typeOfContent->getSizeInByteOfAnyReprInSeq())
545 {
546 }
547
548 SequenceAny::SequenceAny(const TypeCode *typeOfContent, unsigned lgth):ComposedAny(new TypeCodeSeq("","",typeOfContent)),
549                                                                        _alloc(typeOfContent->getSizeInByteOfAnyReprInSeq())
550 {
551   _alloc.initCoarseMemory(0,lgth,0);
552 }
553
554 SequenceAny::SequenceAny(int *val, unsigned int lgth, Deallocator deAlloc):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_int)),
555                                                                            _alloc(Runtime::_tc_int->getSizeInByteOfAnyReprInSeq())
556 {
557   _alloc.initCoarseMemory((char *)val,lgth,deAlloc);
558 }
559
560 SequenceAny::SequenceAny(bool *val, unsigned int lgth, Deallocator deAlloc):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_bool)),
561                                                                             _alloc(Runtime::_tc_bool->getSizeInByteOfAnyReprInSeq())
562 {
563   _alloc.initCoarseMemory((char *)val,lgth,deAlloc);
564 }
565
566 SequenceAny::SequenceAny(double *val, unsigned int lgth, Deallocator deAlloc):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_double)),
567                                                                               _alloc(Runtime::_tc_double->getSizeInByteOfAnyReprInSeq())
568 {
569   _alloc.initCoarseMemory((char *)val,lgth,deAlloc);
570 }
571
572 SequenceAny::SequenceAny(const std::vector<int>& val):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_int)),
573                                                       _alloc(Runtime::_tc_int->getSizeInByteOfAnyReprInSeq())
574 {
575   _alloc.initCoarseMemory((char *)&val[0],val.size(),0);
576 }
577
578 SequenceAny::SequenceAny(const std::vector<bool>& val):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_bool)),
579                                                        _alloc(Runtime::_tc_bool->getSizeInByteOfAnyReprInSeq())
580 {
581   for(vector<bool>::const_iterator iter=val.begin();iter!=val.end();iter++)
582     {
583       AtomAnyPtr tmp=AtomAny::New(*iter);
584       pushBack(tmp);
585     }
586 }
587
588 SequenceAny::SequenceAny(const std::vector<double>& val):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_double)),
589                                                          _alloc(Runtime::_tc_double->getSizeInByteOfAnyReprInSeq())
590 {
591   _alloc.initCoarseMemory((char *)&val[0],val.size(),0);
592 }
593
594 SequenceAny::SequenceAny(const std::vector<std::string>& val):ComposedAny(new TypeCodeSeq("","",Runtime::_tc_string)),
595                                                               _alloc(Runtime::_tc_string->getSizeInByteOfAnyReprInSeq())
596 {
597   for(vector<string>::const_iterator iter=val.begin();iter!=val.end();iter++)
598     {
599       AtomAnyPtr tmp=AtomAny::New(*iter);
600       pushBack(tmp);
601     }
602 }
603
604 void SequenceAny::realloc(char *endOfCurrentAllocated, const Any *elem)
605 {
606   unsigned int oldSize=_alloc._finish-_alloc._start;
607   unsigned int newSize = oldSize != 0 ? 2 * oldSize : _alloc._sizeOf1Elm;
608   char *newStart=_alloc.allocate(newSize);
609   //
610   char *newFinish=performCpy(_alloc._start, endOfCurrentAllocated,newStart);
611   _alloc.construct(newFinish, elem);
612   newFinish+=_alloc._sizeOf1Elm;
613   newFinish=performCpy(endOfCurrentAllocated, _alloc._finish, newFinish);
614   //
615   for (char *cur=_alloc._start;cur!=_alloc._finish;cur+=_alloc._sizeOf1Elm)
616     _alloc.destroy(cur,_type->contentType());
617   _alloc.deallocate(_alloc._start);
618   _alloc._start = newStart;
619   _alloc._finish = newFinish;
620   _alloc._endOfStorage=newStart+newSize;
621 }
622
623 char *SequenceAny::performCpy(char *srcStart, char *srcFinish, char *destStart)
624 {
625   char *cur=destStart;
626   for (;srcStart != srcFinish; srcStart+=_alloc._sizeOf1Elm, cur+=_alloc._sizeOf1Elm)
627     _alloc.construct(cur, srcStart, _type->contentType(),false);
628   return cur;
629 }
630
631 ArrayAny::~ArrayAny()
632 {
633   delete [] _data;
634 }
635
636 ArrayAny::ArrayAny(char *data, TypeCodeArray * type):ComposedAny(type),_data(0)
637 {
638   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
639   const TypeCode *subType=_type->contentType();
640   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
641   for(unsigned i=0;i<type->getStaticLgth();i++)
642     subType->putReprAtPlace(_data+i*sizePerContent,data+i*sizePerContent,true);
643 }
644
645 ArrayAny::ArrayAny(const ArrayAny& other):ComposedAny(other)
646 {
647   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
648   const TypeCode *subType=_type->contentType();
649   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
650   for(unsigned i=0;i<((TypeCodeArray *)_type)->getStaticLgth();i++)
651     subType->putReprAtPlace(_data+i*sizePerContent,other._data+i*sizePerContent,true);
652 }
653
654 ArrayAny::ArrayAny(const int *val, unsigned int lgth):ComposedAny(new TypeCodeArray("","",Runtime::_tc_int,lgth)),
655                                                       _data(0)
656 {
657   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
658   memcpy(_data,val,_type->getSizeInByteOfAnyReprInSeq());
659 }
660
661 ArrayAny::ArrayAny(const bool *val, unsigned int lgth):ComposedAny(new TypeCodeArray("","",Runtime::_tc_bool,lgth)),
662                                                        _data(0)
663 {
664   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
665   memcpy(_data,val,_type->getSizeInByteOfAnyReprInSeq());
666 }
667
668 ArrayAny::ArrayAny(const double *val, unsigned int lgth):ComposedAny(new TypeCodeArray("","",Runtime::_tc_double,lgth)),
669                                                          _data(0)
670 {
671   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
672   memcpy(_data,val,_type->getSizeInByteOfAnyReprInSeq());
673 }
674
675 ArrayAny::ArrayAny(const std::vector<int>& val):ComposedAny(new TypeCodeArray("","",Runtime::_tc_int,val.size())),
676                                                 _data(0)
677 {
678   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
679   memcpy(_data,&val[0],_type->getSizeInByteOfAnyReprInSeq());
680 }
681
682 ArrayAny::ArrayAny(const std::vector<double>& val):ComposedAny(new TypeCodeArray("","",Runtime::_tc_double,val.size())),
683                                                 _data(0)
684 {
685   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
686   memcpy(_data,&val[0],_type->getSizeInByteOfAnyReprInSeq());
687 }
688
689 ArrayAny::ArrayAny(const std::vector<std::string>& val):ComposedAny(new TypeCodeArray("","",Runtime::_tc_string,val.size())),
690                                                         _data(0)
691 {
692   _data=new char[_type->getSizeInByteOfAnyReprInSeq()];
693   unsigned i=0;
694   const TypeCode *subType=_type->contentType();
695   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
696   for(vector<std::string>::const_iterator iter=val.begin();iter!=val.end();iter++,i++)
697     {
698       StringOnHeap *st=new StringOnHeap(*iter);
699       memcpy(_data+i*sizePerContent,&st,sizePerContent);
700     }
701 }
702
703 bool ArrayAny::operator ==(const Any& other) const
704 {
705   if(!_type->isA(other.getType()))
706     return false;
707   const ArrayAny& otherC=(const ArrayAny&) other;//cast granted due to previous lines
708   for(unsigned i=0;i<((const TypeCodeArray *)_type)->getStaticLgth();i++)
709     if(!((*(*this)[i])==(*otherC[i])))
710       return false;
711   return true;
712 }
713
714 AnyPtr ArrayAny::operator[](int i) const
715 {
716   const TypeCode *subType=_type->contentType();
717   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
718   if(i<0 || i>=((TypeCodeArray *)_type)->getStaticLgth())
719     throw Exception("Trying to access to an invalid index in an Any Tuple");
720   return _type->getOrBuildAnyFromZippedData(_data+i*sizePerContent);
721 }
722
723 Any *ArrayAny::clone() const
724 {
725   return new ArrayAny(*this);
726 }
727
728 void ArrayAny::putMyReprAtPlace(char *data) const
729 {
730   const TypeCode *subType=_type->contentType();
731   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
732   for(unsigned i=0;i<((const TypeCodeArray *)_type)->getStaticLgth();i++)
733     subType->putReprAtPlace(data+i*sizePerContent,_data+i*sizePerContent,false);
734 }
735
736 void ArrayAny::putReprAtPlace(char *data, const char *src, const TypeCodeArray *type, bool deepCpy)
737 {
738   const TypeCode *subType=type->contentType();
739   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
740   for(unsigned i=0;i<type->getStaticLgth();i++)
741     subType->putReprAtPlace(data+i*sizePerContent,src+i*sizePerContent,deepCpy);
742 }
743
744 void ArrayAny::destroyReprAtPlace(char *data, const TypeCodeArray *type)
745 {
746   const TypeCode *subType=type->contentType();
747   unsigned sizePerContent=subType->getSizeInByteOfAnyReprInSeq();
748   for(unsigned i=0;i<type->getStaticLgth();i++)
749     subType->destroyZippedAny(data+i*sizePerContent);
750 }
751
752 AnyPtr ArrayAny::getOrBuildFromData(char *data, const TypeCodeArray *type)
753 {
754   Any *ret;
755   type->incrRef();
756   ret=new ArrayAny(data,(TypeCodeArray *)type);
757   return AnyPtr(ret);
758 }
759
760 bool ArrayAny::takeInChargeStorageOf(TypeCode *type)
761 {
762   DynType typ=type->kind();
763   return (typ==Array);
764 }