#ifndef SYMS_HPP
#define SYMS_HPP 1

#include <ostream>
#include <vector>
#include <string>

struct Sym
{
  explicit Sym(int id):id_(id),addr_() { }
  Sym():id_(),addr_() { }

  int id_;
  unsigned long addr_;
  std::string name_;

  static int next_id_;

  bool operator<(unsigned long b) const
    { return addr_ < b; }
  bool operator<(const Sym& b) const
    { return addr_ < b.addr_; }
};

inline bool operator<(unsigned long a, const Sym& b)
{ return a < b.addr_; }
std::ostream& operator<<(std::ostream& ost,const Sym& s);

class IELFISection;
class IELFI;

class Syms
{
public:
  typedef std::vector<Sym> SymTable;
  typedef SymTable::iterator iterator;
  typedef SymTable::const_iterator const_iterator;

  Syms(const char* filename, int offset);
  const Sym* resolve(unsigned long addr) const; // you do not own this memory!

  void print(std::ostream& ost) const;
private:
  void loadSection(const IELFISection*, unsigned long,const char*,
		  bool,IELFI*);
  SymTable table_;
};

inline std::ostream& operator<<(std::ostream& ost,const Syms& s)
{
  s.print(ost);
  return ost;
}

#endif
