#include <iostream>
#include <string.h>
#include <stdlib.h>
#include "THaArrayString.h"
#include "TMath.h"
using namespace std;
THaArrayString::THaArrayString( const THaArrayString& rhs )
: fName(rhs.fName), fNdim(rhs.fNdim), fDim(NULL), fLen(rhs.fLen),
fStatus(rhs.fStatus)
{
if( fNdim > 0 ) {
fDim = new Int_t[fNdim];
for( Byte_t i = 0; i<fNdim; i++ )
fDim[i] = rhs.fDim[i];
}
}
THaArrayString& THaArrayString::operator=( const THaArrayString& rhs )
{
if( this != &rhs ) {
fName = rhs.fName;
fNdim = rhs.fNdim;
fLen = rhs.fLen;
fStatus = rhs.fStatus;
delete [] fDim;
if( fNdim > 0 ) {
fDim = new Int_t[fNdim];
for( Byte_t i = 0; i<fNdim; i++ )
fDim[i] = rhs.fDim[i];
} else
fDim = NULL;
}
return *this;
}
Int_t THaArrayString::Parse( const char* string )
{
static const size_t MAXLEN = 255;
static const Double_t LOGMAXINT = 2.14875625968926443e+01;
bool changed = false;
char *str = 0, *s, *t;
const char *cs;
size_t len;
Byte_t ncomma = 0, nl = 0, nr = 0;
Int_t j;
Double_t lsum = 0.0;
if( !string || !*string ) {
if( fLen != -1 ) goto ok;
string = fName.Data();
len = fName.Length();
} else {
len = strlen(string);
changed = true;
}
if( len > MAXLEN ) goto toolong;
str = new char[ len+1 ];
t = str;
cs = string;
while( *cs ) {
if( *cs != ' ' && *cs != '\t' )
*(t++) = *cs;
else
changed = true;
cs++;
}
*t = 0;
if( t == str ) goto notinit;
t = str;
while( *t && *t != '[' ) {
if( *t != ',' && *t != ']' && *t != '(' && *t != ')' )
t++;
else
goto illegalchars;
}
if( t == str ) goto badsyntax;
fNdim = 0; fLen = 1;
delete [] fDim; fDim = NULL;
if( !*t ) {
if( changed )
fName = str;
goto ok;
}
s = t;
while( *t ) {
switch( *t ) {
case ',':
ncomma++; break;
case '[':
nl++; break;
case ']':
nr++; break;
default:
if ( *t < '0' || *t > '9' )
goto illegalchars;
break;
}
t++;
}
if( nl != nr || (ncomma && nl>1) || *(t-1) != ']' )
goto badsyntax;
*s = 0;
t = s+1;
if( ncomma )
fNdim = ncomma+1;
else
fNdim = nl;
fDim = new Int_t[ fNdim ];
for( int i=0; i<fNdim; i++ ) {
s = t;
while ( *t && *t != ',' && *t != ']' ) {
if( *t == '[' ) goto badsyntax;
t++;
}
if( !*t || t == s ) goto badsyntax;
*t = 0;
j = atoi( s );
lsum += TMath::Log(j);
if( lsum > LOGMAXINT ) goto toolarge;
fDim[i] = j;
fLen *= j;
t++;
if( !ncomma && *t ) {
if( *t == '[' )
t++;
else
goto badsyntax;
}
}
fName = str;
goto ok;
badsyntax:
fStatus = kBadsyntax;
goto cleanup;
illegalchars:
fStatus = kIllegalchars;
goto cleanup;
toolarge:
fStatus = kToolarge;
goto cleanup;
toolong:
fStatus = kToolong;
goto cleanup;
notinit:
fStatus = kNotinit;
goto cleanup;
ok:
fStatus = kOK;
cleanup:
delete [] str;
return fStatus;
}
void THaArrayString::Print( Option_t* )
{
cout << fName ;
if( fNdim > 0 ) {
cout << "[";
for( Byte_t i = 0; i<fNdim; i++ ) {
cout << fDim[i];
if( i+1<fNdim )
cout << ",";
else
cout << "]";
}
}
cout << endl;
}
ClassImp(THaArrayString);
Last change: Sat Nov 7 21:26:42 2009
Last generated: 2009-11-07 21:26
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.