Skip to content

Commit

Permalink
json: unify handling of normal and char* arrays
Browse files Browse the repository at this point in the history
For char* another method used to store array content,
which is now specified as second argument of central macro

Signed-off-by: Sergey Linev <[email protected]>
  • Loading branch information
linev authored and pcanal committed Nov 7, 2016
1 parent 04a06f9 commit 426e239
Showing 1 changed file with 22 additions and 57 deletions.
79 changes: 22 additions & 57 deletions io/io/src/TBufferJSON.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,7 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,
// write array without size attribute
// macro also treat situation, when instead of one single array
// chain of several elements should be produced
#define TBufferJSON_WriteFastArray(vname) \
#define TBufferJSON_WriteFastArray(vname,method) \
{ \
TJSONPushValue(); \
if (n <= 0) { /*fJsonrCnt++;*/ fValue.Append("[]"); return; } \
Expand All @@ -2254,7 +2254,7 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,
JsonWriteBasic(vname[index]); \
index++; \
} else { \
TJSONWriteArrayContent((vname+index), elem->GetArrayLength());\
method((vname+index), elem->GetArrayLength()); \
index+=elem->GetArrayLength(); \
} \
PerformPostProcessing(Stack(0), elem); \
Expand All @@ -2263,7 +2263,7 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,
if ((elem!=0) && (elem->GetArrayDim()>1) && (elem->GetArrayLength()==n)) { \
TArrayI indexes(elem->GetArrayDim() - 1); \
indexes.Reset(0); \
Int_t cnt = 0; \
Int_t cnt = 0, shift = 0, len = elem->GetMaxIndex(indexes.GetSize()); \
while (cnt >= 0) { \
if (indexes[cnt] >= elem->GetMaxIndex(cnt)) { \
fValue.Append("]"); \
Expand All @@ -2273,17 +2273,13 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,
} \
fValue.Append(indexes[cnt] == 0 ? "[" : fArraySepar.Data()); \
if (++cnt == indexes.GetSize()) { \
Int_t shift = 0; \
for (Int_t k = 0; k < indexes.GetSize(); k++) \
shift = shift * elem->GetMaxIndex(k) + indexes[k]; \
Int_t len = elem->GetMaxIndex(indexes.GetSize()); \
shift *= len; \
TJSONWriteArrayContent((vname+shift), len); \
method((vname+shift), len); \
indexes[--cnt]++; \
shift+=len; \
} \
} \
} else { \
TJSONWriteArrayContent(vname, n); \
method(vname, n); \
} \
}

Expand All @@ -2292,54 +2288,23 @@ void TBufferJSON::WriteArrayDouble32(const Double_t *d, Int_t n,

void TBufferJSON::WriteFastArray(const Bool_t *b, Int_t n)
{
TBufferJSON_WriteFastArray(b);
TBufferJSON_WriteFastArray(b,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Char_t to buffer
/// If array does not include any special characters,
/// it will be reproduced as CharStar node with string as attribute

void TBufferJSON::WriteFastArray(const Char_t *c, Int_t n)
{
TStreamerElement* el = Stack(0)->fElem;

if (fExpectedChain || (el && (el->GetType() == TStreamerInfo::kOffsetP + TStreamerInfo::kChar))) {
TBufferJSON_WriteFastArray(c);
} else
if (!el || (el->GetArrayDim() < 2) || (el->GetArrayLength() != n)) {
// write as simple const char
TJSONPushValue();
JsonWriteConstChar(c, n);
} else {
// write as multi-dim array of strings
TJSONPushValue();
TArrayI indexes(el->GetArrayDim() - 1);
indexes.Reset(0);
Int_t cnt = 0, shift = 0, len = el->GetMaxIndex(indexes.GetSize());
while (cnt >= 0) {
if (indexes[cnt] >= el->GetMaxIndex(cnt)) {
fValue.Append("]");
indexes[cnt--] = 0;
if (cnt >= 0) indexes[cnt]++;
continue;
}
fValue.Append(indexes[cnt] == 0 ? "[" : fArraySepar.Data());
if (++cnt == indexes.GetSize()) {
JsonWriteConstChar(c+shift*len, len);
indexes[--cnt]++;
shift++;
}
}
}
TBufferJSON_WriteFastArray(c,JsonWriteConstChar);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Char_t to buffer

void TBufferJSON::WriteFastArrayString(const Char_t *c, Int_t n)
{
WriteFastArray(c, n);
TBufferJSON_WriteFastArray(c,JsonWriteConstChar);
}


Expand All @@ -2348,87 +2313,87 @@ void TBufferJSON::WriteFastArrayString(const Char_t *c, Int_t n)

void TBufferJSON::WriteFastArray(const UChar_t *c, Int_t n)
{
TBufferJSON_WriteFastArray(c);
TBufferJSON_WriteFastArray(c,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Short_t to buffer

void TBufferJSON::WriteFastArray(const Short_t *h, Int_t n)
{
TBufferJSON_WriteFastArray(h);
TBufferJSON_WriteFastArray(h,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of UShort_t to buffer

void TBufferJSON::WriteFastArray(const UShort_t *h, Int_t n)
{
TBufferJSON_WriteFastArray(h);
TBufferJSON_WriteFastArray(h,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Int_t to buffer

void TBufferJSON::WriteFastArray(const Int_t *i, Int_t n)
{
TBufferJSON_WriteFastArray(i);
TBufferJSON_WriteFastArray(i,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of UInt_t to buffer

void TBufferJSON::WriteFastArray(const UInt_t *i, Int_t n)
{
TBufferJSON_WriteFastArray(i);
TBufferJSON_WriteFastArray(i,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Long_t to buffer

void TBufferJSON::WriteFastArray(const Long_t *l, Int_t n)
{
TBufferJSON_WriteFastArray(l);
TBufferJSON_WriteFastArray(l,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of ULong_t to buffer

void TBufferJSON::WriteFastArray(const ULong_t *l, Int_t n)
{
TBufferJSON_WriteFastArray(l);
TBufferJSON_WriteFastArray(l,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Long64_t to buffer

void TBufferJSON::WriteFastArray(const Long64_t *l, Int_t n)
{
TBufferJSON_WriteFastArray(l);
TBufferJSON_WriteFastArray(l,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of ULong64_t to buffer

void TBufferJSON::WriteFastArray(const ULong64_t *l, Int_t n)
{
TBufferJSON_WriteFastArray(l);
TBufferJSON_WriteFastArray(l,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Float_t to buffer

void TBufferJSON::WriteFastArray(const Float_t *f, Int_t n)
{
TBufferJSON_WriteFastArray(f);
TBufferJSON_WriteFastArray(f,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
/// Write array of Double_t to buffer

void TBufferJSON::WriteFastArray(const Double_t *d, Int_t n)
{
TBufferJSON_WriteFastArray(d);
TBufferJSON_WriteFastArray(d,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -2437,7 +2402,7 @@ void TBufferJSON::WriteFastArray(const Double_t *d, Int_t n)
void TBufferJSON::WriteFastArrayFloat16(const Float_t *f, Int_t n,
TStreamerElement * /*ele*/)
{
TBufferJSON_WriteFastArray(f);
TBufferJSON_WriteFastArray(f,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -2446,7 +2411,7 @@ void TBufferJSON::WriteFastArrayFloat16(const Float_t *f, Int_t n,
void TBufferJSON::WriteFastArrayDouble32(const Double_t *d, Int_t n,
TStreamerElement * /*ele*/)
{
TBufferJSON_WriteFastArray(d);
TBufferJSON_WriteFastArray(d,TJSONWriteArrayContent);
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 426e239

Please sign in to comment.