#ifndef KUTILITY_INTERACTION_H
#define KUTILITY_INTERACTION_H
#include "kutility/kutility.def"
namespace kutility
{
void error( string str1, int code=1 );
void error( string str1, string str2, int code=1 );
void error( string str1, string str2, string str3, int code=1 );
void warning( string str1, string str2="", string str3="" );
void major_message( string str1, string str2="", string str3="", string sep="-" );
void message( string str1, string str2="", string str="" );
template<class T>
void message( string str, T num )
{
std::cout<<str<<" : "<<num<<std::endl;
}
template<class T1, class T2> inline
void progress(T1 state, T2 range, int freq, time_t elapsed=-1)
{
if( ((int)(state)) % freq == 0 )
{
std::cout.width(5);
std::cout.precision(4);
double percent = ((double)(state))/((double)(range));
std::cout<<"completed: "<<100*percent<<"%";
double eta;
if( elapsed != -1 )
{
eta = ((double)elapsed)/percent;
std::cout<<"\tremaining: "<<(double)(eta-elapsed)<<"s\t total: "<<eta<<"s";
}
std::cout<<"\n";
}
}
template<class T> inline
void display( T* data, int r, int c=1, bool no_zero=false, bool legend=false, int precision=3, int width=4, string sep="\t")
{
cout.width(width);
cout.fill(' ');
cout.precision(precision);
int i,j;
if( legend )
{
cout<<"\t"<<" ";
cout.setf( ios_base::right);
for(j=0; j<c; j++)
{
cout.width(width);
cout.precision(precision);
cout<<j<<sep;
}
cout<<endl;
for(j=0; j<140; j++)
{
cout<<'.';
}
}
cout<<endl;
for(i=0; i<r; i++)
{
if( legend )
{
cout.setf( ios_base::right );
cout.width(width);
cout.precision(precision);
cout<<i<<"\t"<<": ";
}
cout.setf( ios_base::right );
for(j=0; j<c; j++)
{
cout.width(width);
cout.setf( ios_base::right );
cout.precision(precision);
if( no_zero && data[i*c+j] == 0 )
cout<<" "<<sep;
else
cout<<data[i*c+j]<<sep;
}
cout<<endl;
}
cout<<endl;
}
template<class T> inline
void display( T** data, int r, int c=1, bool no_zero=false, bool legend=false, int precision=3, int width=4, char* sep="\t")
{
cout.width(width);
cout.fill(' ');
cout.precision(precision);
int i,j;
if( legend )
{
cout<<"\t"<<" ";
cout.setf( ios_base::right);
for(j=0; j<c; j++)
{
cout.width(width);
cout.precision(precision);
cout<<j<<sep;
}
cout<<endl;
for(j=0; j<140; j++)
{
cout<<'.';
}
}
cout<<endl;
for(i=0; i<r; i++)
{
if( legend )
{
cout.setf( ios_base::right );
cout.width(width);
cout.precision(precision);
cout<<i<<"\t"<<": ";
}
cout.setf( ios_base::right );
for(j=0; j<c; j++)
{
cout.width(width);
cout.setf( ios_base::right );
cout.precision(precision);
if( no_zero && data[i][j] == 0 )
cout<<" "<<sep;
else
cout<<data[i][j]<<sep;
}
cout<<endl;
}
cout<<endl;
}
}
#endif