#ifndef __BDBENV_H__
#define __BDBENV_H__

#include <db_cxx.h>
#include <string>
#include "dbtable.h"
#include <vector>

class bdbenv
{
 public:
  bdbenv();
  ~bdbenv();

  int remove( std::string d );
  int open( std::string d );
  int recover( std::string d );
  int close();
  /// sets cache size in gigabytes
  int setcache( int sz, int szmb )
  {
    cachesz = sz;
    cacheszmb = szmb;
    return 0;
  }
  int setopenflags( unsigned int f )
  {
    std::cout << "switching flags\n";
    openflags = f;
    return 0;
  }

  int cleanlog();

  int adddb( dbtable *t );

  DbEnv *envptr();

  DbTxn *begintransaction()
  {
    DbTxn *m;
    dbenvp.txn_begin(NULL, &m, 0 );
    return m;
  }

  int removedb( std::string dbname );

 private:
  int printflags();
  std::vector<dbtable*> mydbs;

  std::string dbdir;
  DbEnv dbenvp;
  int opened;
  int cachesz, cacheszmb;
  unsigned int openflags;
};

#endif
