1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "List.hpp"
#include "Binding.hpp"
#include "algo.hpp"
namespace macrovsa {
  void List::add(const Symbol& current, const Symbol& value)
  {
    const Symbol& next = getNext(current);
    AssociativeMap::erase(current);
    AssociativeMap::add(current, value);
    AssociativeMap::add(value, next);
  }
  void List::erase(const Symbol& current)
  {
    const Symbol& previous = getPrevious(current), & next = getNext(current);
    AssociativeMap::erase(previous);
    AssociativeMap::erase(current);
    AssociativeMap::add(previous, next);
  }
  const Symbol& List::getNext(const Symbol& current) const
  {
    return get(current);
  }
  const Symbol& List::getPrevious(const Symbol& current) const
  {
    for(auto it = get().cbegin(); it != get().cend(); it++) {
      const Symbol *c = it->second.second.cbegin()->second;
      if(c->equals(current)) {
        return *it->second.first;
      }
    }
    return nill;
  }
}