A general theory for the topology of transfinite heterotic strings and quantum gravity