00001 #ifndef IOTRMATRIXDISPLAYFORMAT
00002 #define IOTRMATRIXDISPLAYFORMAT
00003
00004 #include <iostream>
00005 #include <cstring>
00006
00011 struct IotrMatrixDisplayFormat {
00012 IotrMatrixDisplayFormat( const char * str )
00013 : formatString( str ), displayAsFullMatrix(0) {}
00014 IotrMatrixDisplayFormat()
00015 : formatString( 0 ), displayAsFullMatrix(0) {}
00016 const char * formatString;
00017 char displayAsFullMatrix;
00018 };
00019
00020
00021 inline void
00022 iotr_display_matrix_elt( int i, int j, double d,
00023 const IotrMatrixDisplayFormat & format,
00024 const char * formatString,
00025 std::ostream & out )
00026 {
00027 if( d != 0 || format.displayAsFullMatrix ) {
00028
00029 int k = 0;
00030 char c;
00031 while( (c = formatString[k]) != 0 ) {
00032
00033 if( c != '%' ) {
00034 out << c;
00035 } else {
00036
00037
00038 if( 0 == strncmp( "{value}", &formatString[k + 1], 7 ) ) {
00039 out << d;
00040 k += 7;
00041 } else if ( 0 == strncmp( "{irow}", &formatString[k + 1], 6 ) ) {
00042 out << i;
00043 k += 6;
00044 } else if ( 0 == strncmp( "{jcol}", &formatString[k+1], 6) ) {
00045 out << j;
00046 k += 6;
00047 } else if ( 0 == strncmp( "{ifrow}", &formatString[k + 1], 7 ) ) {
00048 out << i + 1;
00049 k += 7;
00050 } else if ( 0 == strncmp( "{jfcol}", &formatString[k+1], 7) ) {
00051 out << j + 1;
00052 k += 7;
00053 } else {
00054 out << c;
00055 }
00056 }
00057 k++;
00058 }
00059 out << std::endl;
00060 }
00061 }
00062
00063
00064 #endif