-// Copyright (C) 2006-2014 CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
using namespace YACS::ENGINE;
using namespace std;
+// forbidden value int=-269488145 double=-1.54947e+231 bool=239
+const char SeqAlloc::DFT_CHAR_VAR=-17;//0xEF
+
StringOnHeap::StringOnHeap(const char *val):_dealloc(0),_str(strdup(val))
{
}
_type->decrRef();
}
+bool Any::IsNull(char *data)
+{
+ if(!data)
+ return true;
+ bool isNull(true);
+ for(std::size_t i=0;i<sizeof(void *) && isNull;i++)
+ isNull=(data[i]==SeqAlloc::DFT_CHAR_VAR);
+ return isNull;
+}
+
AtomAny::AtomAny(int val):Any(Runtime::_tc_int)
{
_value._i=val;
DynType typ=type->kind();
if(typ==String)
{
- void **tmp=(void **)data;
- delete ((StringOnHeap *)(*tmp));
+ if(!Any::IsNull(data))
+ {
+ void **tmp=(void **)data;
+ delete ((StringOnHeap *)(*tmp));
+ }
}
}
memcpy(_start,mem,sizeInByte);
else
{
- for(unsigned int i=0;i<sizeInByte;i++) _start[i]=0;
+ for(unsigned int i=0;i<sizeInByte;i++) _start[i]=DFT_CHAR_VAR;// see getSetItems
}
}
_finish=_start+sizeInByte;
return (_finish-_start)/_sizeOf1Elm;
}
+std::vector<unsigned int> SeqAlloc::getSetItems() const
+{
+ std::vector<unsigned int> ret;
+ unsigned int sz(size());
+ for(unsigned int i=0;i<sz;i++)
+ {
+ const char *pt(_start+i*_sizeOf1Elm);
+ for(unsigned j=0;j<_sizeOf1Elm && *pt==DFT_CHAR_VAR;j++,pt++); //see initCoarseMemory
+ if(pt!=_start+(i+1)*_sizeOf1Elm)
+ ret.push_back(i);
+ }
+ return ret;
+}
+
void SequenceAny::clear()
{
for (char *cur=_alloc._start;cur!=_alloc._finish;cur+=_alloc._sizeOf1Elm)
void SequenceAny::destroyReprAtPlace(char *data, const TypeCode *type)
{
void **tmp=(void **) data;
- if(*tmp)
+ if(!Any::IsNull(data))
((SequenceAny *)(*tmp))->decrRef();
//((SequenceAny *)data)->~SequenceAny();
}
return new SequenceAny(*this);
}
+SequenceAny *SequenceAny::removeUnsetItemsFromThis() const
+{
+ std::vector<unsigned int> its(getSetItems());
+ std::size_t sz(its.size());
+ SequenceAny *ret(SequenceAny::New(getType()->contentType(),sz));
+ for(std::size_t i=0;i<sz;i++)
+ {
+ AnyPtr obj((*this)[its[i]]);
+ ret->setEltAtRank(i,obj);
+ }
+ return ret;
+}
+
SequenceAny *SequenceAny::New(const TypeCode *typeOfContent)
{
if(typeOfContent->kind() == Objref)
{
_data=new char[_type->getSizeInByteOfAnyReprInSeq()];
for(unsigned int i=0;i<_type->getSizeInByteOfAnyReprInSeq();i++)
- _data[i]='\0';
+ _data[i]=SeqAlloc::DFT_CHAR_VAR;
}
ArrayAny::ArrayAny(char *data, TypeCodeArray * type):ComposedAny(type,false),_data(0)
{
_data=new char[_type->getSizeInByteOfAnyReprInSeq()];
for(unsigned int i=0;i<_type->getSizeInByteOfAnyReprInSeq();i++)
- _data[i]='\0';
+ _data[i]=SeqAlloc::DFT_CHAR_VAR;
}
StructAny::StructAny(const StructAny& other):ComposedAny(other)