/// <summary> /// We ignore the passed Id on the resource. We populate the Id on the resource /// </summary> /// <param name="r">MODIFIED by action</param> public virtual void Alloc(Types.Resource r) { if (r.Id_ != Resource.ID_NOT_SET) { throw new ArgumentException("requested resource id must be ID_NOT_SET when requesting generic resource"); } else if (Available_.Count == 0) { throw new OutOfResourceException("No more resources of the Alloc() type: " + r.Type); } r.Id_ = Available_.First <int>(); Allocated_.Add(r.Id_); Available_.Remove(r.Id_); }
/// <summary> /// The resource we are freeing /// </summary> /// <param name="r">we will de-allocate the resource bound by Id_</param> /// <summary> /// Frees the resource and sets the Resource id to ID_NOT_SET /// </summary> /// <param name="r">MODIFIED by action</param> public virtual void Free(Types.Resource r) { if (r.Id_ == Resource.ID_NOT_SET) { throw new ArgumentException("requested resource id must be specified when Free() specific resource"); } else if (Allocated_.Contains <int>(r.Id_)) { Available_.Add(r.Id_); Allocated_.Remove(r.Id_); r.Id_ = Types.Resource.ID_NOT_SET; } else { throw new ArgumentException("Resource " + r.Id_ + " not allocated."); } }