Scope& Scope::operator=(const Scope& rhs) { if (this != &rhs) { Orphan(); Clear(); mTable.Resize(rhs.mTable.Size()); // this should be OK to call since the hash map is empty after Clear() for (std::uint32_t i = 0; i < rhs.mOrder.Size(); ++i) { if (rhs.mOrder[i]->second.GetType() != Datum::Table) { Datum& d = Append(rhs.mOrder[i]->first); d = rhs.mOrder[i]->second; } else { std::uint32_t datumSize = rhs.mOrder[i]->second.Size(); for (std::uint32_t datumCounter = 0; datumCounter < datumSize; ++datumCounter) { Scope& s = AppendScope(rhs.mOrder[i]->first); // s is a reference to a scope Datum* scopeDatum = Find(rhs.mOrder[i]->first); // scopeDatum contains s Scope* scopePointer = rhs.mOrder[i]->second.GetTable(datumCounter); // scope pointer is a pointer to the corresponding scope in scopeDatum if (scopePointer == nullptr) scopeDatum->Set((Scope*)nullptr, datumCounter); // if the scope in the rhs datum is null, this scope should also be null else s = *scopePointer; // recursive call } } } } return *this; }
Scope& Attributed::AppendAuxiliaryScope(const std::string& name) { if (IsPrescribedAttribute(name)) throw std::exception("Attribute already exists"); return AppendScope(name); }