returnValue Matrix::printToString( char** string, const char* const name, const char* const startString, const char* const endString, uint width, uint precision, const char* const colSeparator, const char* const rowSeparator, BooleanType allocateMemory ) const { uint i,j; /* determine length of single component */ uint componentLength = width; // 0.e-0000 if ( componentLength < (9 + (uint)precision) ) componentLength = 9 + precision; char* componentString = new char[componentLength]; /* determine length of whole string */ if ( allocateMemory == BT_TRUE ) { uint stringLength = determineStringLength( name,startString,endString, width,precision,colSeparator,rowSeparator ); *string = new char[stringLength]; for( i=0; i<stringLength; ++i ) (*string)[i] = '\0'; } if ( getStringLength(name) > 0 ) { strcat( *string,name ); strcat( *string," = " ); } if ( getStringLength(startString) > 0 ) strcat( *string,startString ); int writtenChars; for( i=0; i<getNumRows( ); ++i ) { for( j=0; j<getNumCols( ); ++j ) { if ( precision > 0 ) writtenChars = ::sprintf( componentString,"%*.*e",width,precision,operator()( i,j ) ); else { writtenChars = ::sprintf( componentString,"%*.0d",width,(int)operator()( i,j ) ); // spritf does not print zeros, that's a hack to circumvent this! if ( ( (int)operator()( i,j ) == 0 ) && ( writtenChars > 0 ) ) componentString[writtenChars-1] = '0'; } if ( ( writtenChars < 0 ) || ( (uint)writtenChars+1 > componentLength ) ) { delete[] componentString; return ACADOERROR( RET_UNKNOWN_BUG ); } strcat( *string,componentString ); if ( j < getNumCols( )-1 ) if ( getStringLength(colSeparator) > 0 ) strcat( *string,colSeparator ); } if ( i < getNumRows( )-1 ) if ( getStringLength(rowSeparator) > 0 ) strcat( *string,rowSeparator ); } if ( getStringLength(endString) > 0 ) strcat( *string,endString ); delete[] componentString; return SUCCESSFUL_RETURN; }
returnValue VectorspaceElement::printToString( char** string, const char* const name, const char* const startString, const char* const endString, uint width, uint precision, const char* const colSeparator, const char* const rowSeparator, BooleanType allocateMemory ) const { uint i; /* determine length of single component */ uint componentLength = width; // 0.e-0000 if ( componentLength < (9 + (uint)precision) ) componentLength = 9 + precision; char* componentString = new char[componentLength]; /* determine length of whole string */ if ( allocateMemory == BT_TRUE ) { uint stringLength = determineStringLength( name,startString,endString, width,precision,colSeparator,rowSeparator ); *string = new char[stringLength]; for( i=0; i<stringLength; ++i ) (*string)[i] = '\0'; } if ( getStringLength(name) > 0 ) { strcat( *string,name ); strcat( *string," = " ); } if ( getStringLength(startString) > 0 ) strcat( *string,startString ); int writtenChars; for( i=0; i<getDim( ); ++i ) { if ( precision > 0 ) writtenChars = sprintf( componentString,"%*.*e",width,precision,operator()( i ) ); else writtenChars = sprintf( componentString,"%*.d",width,(int)operator()( i ) ); if ( ( writtenChars < 0 ) || ( (uint)writtenChars+1 > componentLength ) ) { delete[] componentString; return ACADOERROR( RET_UNKNOWN_BUG ); } strcat( *string,componentString ); if ( i < getDim( )-1 ) if ( getStringLength(rowSeparator) > 0 ) strcat( *string,rowSeparator ); } if ( getStringLength(endString) > 0 ) strcat( *string,endString ); delete[] componentString; return SUCCESSFUL_RETURN; }