This server is intended for use for Academic Classwork related Git repositories only. Projects/repositories will generally be removed after 6 months following close of the semester. Inactive repositories from previous semester are now being archived when no activity for 365 days. They are renamed and marked as 'archived'. After 90 days in that state they will be removed from the system completely.

SymbolTable.h 1.27 KB
Newer Older
Jonathan Evans's avatar
Jonathan Evans committed
1 2 3 4 5 6 7 8 9
#ifndef SYMBOL_TABLE_H
#define SYMBOL_TABLE_H

#include <map>
#include <string>
#include <iostream>
#include "SymbolTableEntry.h"
using namespace std;

Hogan's avatar
Hogan committed
10

11

Jonathan Evans's avatar
Jonathan Evans committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
class SYMBOL_TABLE 
{
private:
  std::map<string, SYMBOL_TABLE_ENTRY> hashTable;

public:
  //Constructor
  SYMBOL_TABLE( ) { }

  // Add SYMBOL_TABLE_ENTRY x to this symbol table.
  // If successful, return true; otherwise, return false.
  bool addEntry(SYMBOL_TABLE_ENTRY x) 
  {
    // Make sure there isn't already an entry with the same name
    map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
    if ((itr = hashTable.find(x.getName())) == hashTable.end()) 
    {
      hashTable.insert(make_pair(x.getName(), x));
      return(true);
    }
    else return(false);
  }

  // If a SYMBOL_TABLE_ENTRY with name theName is
  // found in this symbol table, then return true;
  // otherwise, return false.
  bool findEntry(string theName) 
  {
    map<string, SYMBOL_TABLE_ENTRY>::iterator itr;
    if ((itr = hashTable.find(theName)) == hashTable.end())
      return(false);
    else return(true);
  }

jdev52's avatar
jdev52 committed
46 47
  SYMBOL_TABLE_ENTRY getEntry(string theName)
  {
48
    return hashTable.find(theName)->second;
jdev52's avatar
jdev52 committed
49 50 51 52 53 54 55
  }

  int count()
  {
    return(hashTable.size());
  }

Jonathan Evans's avatar
Jonathan Evans committed
56 57 58
};

#endif  // SYMBOL_TABLE_H