// $Id: util.hpp 14 2004-05-06 08:42:57Z conrado $

#ifndef _UTIL_HPP
#define _UTIL_HPP

#include <string>
#include <vector>
#include <eda/error>
#include <sys/time.h>

namespace util {
  typedef unsigned int nat;       
  typedef unsigned char byte;

  void start_time() throw();
  double stop_time() throw();

  string tostring(long int n) throw();
  string tostring(int n) throw();
  string tostring(double x) throw();

  int toint(const string& s) throw (error);
  double todouble(const string& s) throw (error);

  bool is_nat(const string& s) throw();
  bool is_int(const string& s) throw();
  bool is_double(const string& s) throw();

  byte pack(const string& s) throw(error);
  string unpack(byte c) throw();

  void split(const string& s, vector<string>& x) throw();
  void split(char* line, vector<string>& x) throw();

    class Random {
      public :
        Random(long seed = time(0));
        long operator()(long a, long b) throw (error);  
        long operator()(long n) throw (error);         
      double operator()() throw();      
    private :
        long A[56];
        long* fptr;

        void init_rand(long);
        long cycle(); 
        inline long rand() { 
             return *fptr >= 0 ? *fptr-- : cycle(); 
        }
  };
  const string nom_mod = "util";
}
#endif
