using namespace std;
/*
 *
 * time2usec.H: Convert human readble durations to usecs
 *
 *
 */
 
#ifndef TIME2USEC_H
#define TIME2USEC_H

//c - c++

inline int time2usec(const string &time)
	{
	int val;
	char denom[100];
	int n(sscanf(time.c_str(), "%d%s", &val, denom));
	if(n<1)
		{
		cerr<<"+++Invalid duration "<<time<<endl;
		exit(1);
		}
//no denominator mean usecs
	if(n==1) return val;
	int mult(1);
//process denominator
	string sdenom(denom);
	if(sdenom=="s")
		mult=1000000;
	else if(sdenom=="ms")
		mult=1000;
	else if(sdenom=="us")
		mult=1;
	else
		{
		cerr<<"Invalid time denominator '"<<denom<<"'!"<<endl;
		exit(1);
		}
	return val*mult;
	}
#endif
