#include "stdafx.h"
#include "../Utils/ReferenceCounted.h"
#include "Utils/Logger.h"
#include "Utils/PersistentUnitGroup.h"
#include "PerceptualState/World/CurrentWorld.h"
#include "SparAIContainer.h"
#include "BWAPI_Addon.h"
#include "Config/Config.h"
#include <boost/numeric/conversion/bounds.hpp>

class ReferenceCountedLeakageAnalysis
{
  static ReferenceCountedLeakageAnalysis s_instance;

  ~ReferenceCountedLeakageAnalysis()
  {
#if defined(_DEBUG_COMPONENT)
    ReferenceCounted::_signalMemoryLeaks();
#endif
  }
};

class ZombieComponentsDeletion
{
  static ZombieComponentsDeletion s_instance;

  ~ZombieComponentsDeletion()
  {
    Component::deleteZombieComponents();
  }
};



// Keep this one first, as it will be destroyed last (and thus memory leaks are identified correctly)
ReferenceCountedLeakageAnalysis ReferenceCountedLeakageAnalysis::s_instance;

const unsigned int Config::MS_NO_LIMIT = boost::numeric::bounds<unsigned int>::highest();
const unsigned int Config::MS_SCHEDULER = boost::numeric::bounds<unsigned int>::highest() - 1;
Config Config::s_instance;

LoggingTypes LogTypes;
#ifdef USE_SPAR_LOG
SparLogger SparLogger::s_logger;
#endif

BWAPI::detail::Singleton BWAPI::detail::singleton;

std::list<const Component*> Component::s_zombieComponents;
ZombieComponentsDeletion ZombieComponentsDeletion::s_instance;

const PersistentUnitGroup PersistentUnitGroup::EmptyGroup("Empty-group");

namespace BWAPI { Game* Broodwar; }
SparAIContainer* Spar;

CurrentWorld CurrentWorld::s_currentWorld;
