in src/cas/xcasdeserializer_handler.cpp [597:693]
void XCASDeserializerHandler::addArrayElement(icu::UnicodeString & buffer) {
if (arrayPos >= iv_casimpl.getHeap().getArraySize(currentAddr) ) {
ErrorInfo errInfo;
errInfo.setErrorId((TyErrorId)UIMA_ERR_RESOURCE_CORRUPTED);
ErrorMessage msg(UIMA_MSG_ID_EXC_XML_SAXPARSE_FATALERROR);
assertWithMsg(sizeof(XMLCh) == sizeof(UChar), "Port required");
msg.addParam("Invalid array FS in the CAS" );
errInfo.setMessage(msg);
errInfo.setSeverity(ErrorInfo::unrecoverable);
ExcIllFormedInputError exc(errInfo);
throw exc;
}
FeatureStructure fs = uima::internal::FSPromoter::promoteFS(currentAddr, *iv_cas);
switch (arrayType) {
case internal::gs_tyIntArrayType: {
int val = atoi(UnicodeStringRef(buffer).asUTF8().c_str());
IntArrayFS intFS(fs);
intFS.set( (size_t) arrayPos, val);
break;
}
case internal::gs_tyFloatArrayType: {
float val = atof(UnicodeStringRef(buffer).asUTF8().c_str());
FloatArrayFS floatFS(fs);
floatFS.set( (size_t) arrayPos, val);
break;
}
case internal::gs_tyStringArrayType: {
//add the string
int stringoffset = iv_cas->getHeap()->addString(buffer);
//set the array value in fs heap
lowlevel::TyFS stringref = iv_cas->getHeap()->getStringAsFS(stringoffset);
lowlevel::TyHeapCell * fsarray = iv_cas->getHeap()->getCArrayFromFS(currentAddr);
fsarray[arrayPos] = stringref;
break;
}
case internal::gs_tyByteArrayType: {
short intval = atoi(UnicodeStringRef(buffer).asUTF8().c_str());
char charval[2];
sprintf(charval,"%c",intval);
ByteArrayFS byteFS(fs);
byteFS.set( (size_t) arrayPos, charval[0]);
break;
}
case internal::gs_tyBooleanArrayType: {
string val = UnicodeStringRef(buffer).asUTF8();
BooleanArrayFS booleanFS(fs);
if (val.compare("1")==0) {
booleanFS.set( (size_t) arrayPos, true);
//cout << "bool buffer " << buffer << " val= " << val << "set " << true << endl;
} else {
booleanFS.set ( (size_t) arrayPos, false);
//cout << arrayPos << " bool buffer " << buffer << " val= " << val << "set " << false << endl;
}
break;
}
case internal::gs_tyShortArrayType: {
short val;
string strval;
UnicodeStringRef(buffer).extractUTF8(strval);
stringstream s;
s << strval.c_str();
s >> val;
ShortArrayFS shortFS(fs);
shortFS.set( (size_t) arrayPos, val);
break;
}
case internal::gs_tyLongArrayType: {
INT64 val;
stringstream s;
s << UnicodeStringRef(buffer).asUTF8();
s >> val;
LongArrayFS longFS(fs);
longFS.set( (size_t) arrayPos, val);
break;
}
case internal::gs_tyDoubleArrayType: {
DoubleArrayFS doubleFS(fs);
stringstream s;
s << UnicodeStringRef(buffer).asUTF8();
long double doubleval;
s >> doubleval;
doubleFS.set((size_t) arrayPos, doubleval);
break;
}
default: { //array of FSs
lowlevel::TyFS fsid = atoi(UnicodeStringRef(buffer).asUTF8().c_str());
FeatureStructure fsitem(fsid, *iv_cas);
ArrayFS fsArrayfs(fs);
fsArrayfs.set((size_t) arrayPos, fsitem);
}
}
++arrayPos;
}