A railroad company may erect an inclosure around a depot, where the public safety requires it, to prevent persons other than passengers from coming near the locomotive and cars, and may exclude from within such inclosure all persons except passengers.