Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

IotrMatrixDisplayFormat.hh

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     // This element is to be displayed
00029     int k = 0;
00030     char c;
00031     while( (c = formatString[k]) != 0 ) {
00032       // There are more characters in the format string
00033       if( c != '%' ) { // just echo the character
00034         out << c;
00035       } else { // this is the start of a format commant
00036         // Brain-dead variable substitution, but good enough for this
00037         // simple case
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       } // end else this is the start of a format command
00057       k++;
00058     } // end while there are more characters in the format string
00059     out << std::endl;
00060   } // end if this element is to be displayed.
00061 }
00062 
00063 
00064 #endif

Generated on Wed Aug 27 10:03:41 2003 for iotr by doxygen1.2.18