X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fengine%2FAny.cxx;h=a3c5cfa6b12f69c33b3e05e4ba660bd61fb68e01;hb=b0f05b249ace88109a4a3dae9aa4249c5577eb4c;hp=7656e9e3795e9ea6f2675c4d1a16d75d605c66da;hpb=c81be9b5e74b26e207bd6efd0ccf68418ac536a3;p=modules%2Fyacs.git diff --git a/src/engine/Any.cxx b/src/engine/Any.cxx index 7656e9e37..a3c5cfa6b 100644 --- a/src/engine/Any.cxx +++ b/src/engine/Any.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2006-2012 CEA/DEN, EDF R&D +// Copyright (C) 2006-2019 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 // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -22,18 +22,147 @@ #include "TypeCode.hxx" #include "InvalidExtractionException.hxx" +#include +#include +#include +#include +#include + +#include #include #include using namespace YACS::ENGINE; using namespace std; -StringOnHeap::StringOnHeap(const char *val):_dealloc(0),_str(strdup(val)) +// forbidden value int=-269488145 double=-1.54947e+231 bool=239 +const char SeqAlloc::DFT_CHAR_VAR=-17;//0xEF + +constexpr unsigned NB_BITS = 6; + +constexpr unsigned char TAB[64]={46, 61, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}; + +unsigned char BitAtPosSimple(char val, std::size_t bitPos) +{ + return (val >> bitPos) & 0x1; +} + +unsigned char BitAtPos(char pt0, char pt1, std::size_t bitPos) +{ + if(bitPos<8) + return BitAtPosSimple(pt0,bitPos); + else + return BitAtPosSimple(pt1,bitPos-8); +} + +unsigned char ChunkInternal(char pt0, char pt1, std::size_t startBitIdInByte) +{ + unsigned char ret(0); + for(unsigned i = 0; i>= 1; + return ret; +} + +unsigned char ChunkAtPos(const char *pt, std::size_t len, std::size_t posChunk) +{ + std::size_t startByte((posChunk*NB_BITS)/8); + std::size_t startBitIdInByte((posChunk*NB_BITS)%8); + char pt1(startByte!=len-1?pt[startByte+1]:pt[startByte]); + return ChunkInternal(pt[startByte],pt1,startBitIdInByte); +} + +std::size_t OnOff(std::size_t i) +{ + if(i!=0) + return 1; + return 0; +} + +std::string YACS::ENGINE::ToBase64(const std::string& bytes) +{//64 == 2**6 + const char *bytesPt(bytes.c_str()); + std::size_t input_len(bytes.size()); + std::size_t input_len_bit(input_len*8); + std::size_t nb_chunks( input_len_bit/NB_BITS + OnOff((NB_BITS - input_len_bit%NB_BITS)%NB_BITS) ); + std::string ret(nb_chunks,'\0'); + for(std::size_t i=0;i> 5-bitPos) & 0x1; +} + +char BitAtPosOnChunk(char pt0, char pt1, std::size_t bitPos) +{ + if(bitPos<6) + return BitAtPosSimple2(pt0,bitPos); + else + return BitAtPosSimple2(pt1,bitPos-6); +} + +char ByteInternal(char c0, char c1, std::size_t startBitIdInByte) { + unsigned char ret(0); + char ct0(TAB2[(unsigned char)c0]),ct1(TAB2[(unsigned char)c1]); + for(int i = 7; i>=0; --i) + { + ret |= BitAtPosOnChunk(ct0,ct1,startBitIdInByte+i); + if(i!=0) + ret <<= 1; + } + return ret; } -StringOnHeap::StringOnHeap(const std::string& val):_dealloc(0),_str(strdup(val.c_str())) +char ByteAtPos(const char *chunckPt, std::size_t bytePos) { + std::size_t startChunk((bytePos*8)/NB_BITS); + std::size_t startBitId((bytePos*8)%NB_BITS); + return ByteInternal(chunckPt[startChunk],chunckPt[startChunk+1],startBitId); +} + +std::string YACS::ENGINE::FromBase64(const std::string& bytes) +{ + std::size_t nb_chunks(bytes.size()); + const char *chunckPt(bytes.c_str()); + std::size_t nb_bytes_output((nb_chunks*NB_BITS)/8); + std::string ret(nb_bytes_output,'\0'); + for(std::size_t i = 0; idecrRef(); } +bool Any::IsNull(char *data) +{ + if(!data) + return true; + bool isNull(true); + for(std::size_t i=0;iisA(Runtime::_tc_string)) - return string(_value._s->cStr()); + { + std::size_t sz(_value._s->size()); + if(sz==0) + return string(_value._s->cStr()); + else + return string(_value._s->cStr(),sz); + } + else + throw Exception("Value is not a string"); +} + +const char *AtomAny::getBytesValue(std::size_t& len) const +{ + if(_type->isA(Runtime::_tc_string)) + { + len=_value._s->size(); + return _value._s->cStr(); + } else throw Exception("Value is not a string"); } @@ -272,8 +431,11 @@ void AtomAny::destroyReprAtPlace(char *data, const TypeCode *type) 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)); + } } } @@ -382,7 +544,7 @@ void SeqAlloc::initCoarseMemory(char *mem, unsigned int size, Deallocator deallo memcpy(_start,mem,sizeInByte); else { - for(unsigned int i=0;i SeqAlloc::getSetItems() const +{ + std::vector ret; + unsigned int sz(size()); + for(unsigned int i=0;idecrRef(); //((SequenceAny *)data)->~SequenceAny(); } @@ -539,6 +715,19 @@ Any *SequenceAny::clone() const return new SequenceAny(*this); } +SequenceAny *SequenceAny::removeUnsetItemsFromThis() const +{ + std::vector its(getSetItems()); + std::size_t sz(its.size()); + SequenceAny *ret(SequenceAny::New(getType()->contentType(),sz)); + for(std::size_t i=0;isetEltAtRank(i,obj); + } + return ret; +} + SequenceAny *SequenceAny::New(const TypeCode *typeOfContent) { if(typeOfContent->kind() == Objref) @@ -686,7 +875,7 @@ ArrayAny::ArrayAny(const TypeCode *typeOfContent, unsigned int lgth):ComposedAny { _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) @@ -954,7 +1143,7 @@ StructAny::StructAny(TypeCodeStruct *type):ComposedAny(type,false) { _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)