<commit_before>#ifndef STINGRAY_TOOLKIT_FACTORY_H
#define STINGRAY_TOOLKIT_FACTORY_H


#include <stingray/toolkit/Singleton.h>


namespace stingray
{

	struct IFactoryObjectCreator
	{
		virtual ~IFactoryObjectCreator() { }

		virtual IFactoryObject* Create() const = 0;
	};


	class Factory;

	namespace Detail
	{

		template < typename ClassType >
		class SimpleFactoryObjectCreator : public virtual IFactoryObjectCreator
		{
		public:
			virtual IFactoryObject* Create() const { return new ClassType; }
		};


		class FactoryContext
		{
			typedef std::map<std::string, IFactoryObjectCreator*> ClassRegistry;

		private:
			ClassRegistry	_registry;
			Mutex			_registryGuard;

		public:
			FactoryContext() { }
			~FactoryContext();

			void Register(const std::string& name, IFactoryObjectCreator* creator);

			IFactoryObject* Create(const std::string& name);
		};


		class Factory : public Singleton<Factory>
		{
			TOOLKIT_SINGLETON_WITH_TRIVIAL_CONSTRUCTOR(Factory);

			friend class stingray::Factory;

		private:
			FactoryContext	_context;

		public:
			template < typename ClassType >
			void Register(const std::string& name)
			{
				unique_ptr<IFactoryObjectCreator> creator(new SimpleFactoryObjectCreator<ClassType>());
				_context.Register(name, creator.get());
				creator.release();
			}

		private:
			// Defined in stingray/toolkit/_FactoryClasses.cpp
			void RegisterTypes();

			template < typename T >
			T* Create(const std::string& name)
			{
				unique_ptr<IFactoryObject> factory_obj(_context.Create(name));
				T* object = TOOLKIT_CHECKED_DYNAMIC_CASTER(factory_obj.get());
				factory_obj.release();
				return object;
			}
		};

	} //Detail

	class Factory : public Singleton<Factory>
	{
		TOOLKIT_SINGLETON(Factory);

		Factory() { Detail::Factory::Instance().RegisterTypes(); }

	public:
		template < typename T >
		T* Create(const std::string& name)
		{ return Detail::Factory::Instance().Create<T>(name); }
	};

}


#define TOOLKIT_REGISTER_CLASS(Class_) \
	friend class stingray::Detail::Factory; \
	friend class stingray::Detail::SimpleFactoryObjectCreator<Class_>; \
	virtual std::string GetClassName() const { return RemovePrefix(TypeInfo(typeid(Class_)).GetName(), "stingray::"); }

#define TOOLKIT_REGISTER_CLASS_EXPLICIT(Class_) stingray::Detail::Factory::Instance().Register<Class_>(#Class_)

#endif<commit_msg>remove Factory from FactoryObject friends<commit_after>#ifndef STINGRAY_TOOLKIT_FACTORY_H
#define STINGRAY_TOOLKIT_FACTORY_H


#include <stingray/toolkit/Singleton.h>


namespace stingray
{

	struct IFactoryObjectCreator
	{
		virtual ~IFactoryObjectCreator() { }

		virtual IFactoryObject* Create() const = 0;
	};


	class Factory;

	namespace Detail
	{

		template < typename ClassType >
		class SimpleFactoryObjectCreator : public virtual IFactoryObjectCreator
		{
		public:
			virtual IFactoryObject* Create() const { return new ClassType; }
		};


		class FactoryContext
		{
			typedef std::map<std::string, IFactoryObjectCreator*> ClassRegistry;

		private:
			ClassRegistry	_registry;
			Mutex			_registryGuard;

		public:
			FactoryContext() { }
			~FactoryContext();

			void Register(const std::string& name, IFactoryObjectCreator* creator);

			IFactoryObject* Create(const std::string& name);
		};


		class Factory : public Singleton<Factory>
		{
			TOOLKIT_SINGLETON_WITH_TRIVIAL_CONSTRUCTOR(Factory);

			friend class stingray::Factory;

		private:
			FactoryContext	_context;

		public:
			template < typename ClassType >
			void Register(const std::string& name)
			{
				unique_ptr<IFactoryObjectCreator> creator(new SimpleFactoryObjectCreator<ClassType>());
				_context.Register(name, creator.get());
				creator.release();
			}

		private:
			// Defined in stingray/toolkit/_FactoryClasses.cpp
			void RegisterTypes();

			template < typename T >
			T* Create(const std::string& name)
			{
				unique_ptr<IFactoryObject> factory_obj(_context.Create(name));
				T* object = TOOLKIT_CHECKED_DYNAMIC_CASTER(factory_obj.get());
				factory_obj.release();
				return object;
			}
		};

	} //Detail

	class Factory : public Singleton<Factory>
	{
		TOOLKIT_SINGLETON(Factory);

		Factory() { Detail::Factory::Instance().RegisterTypes(); }

	public:
		template < typename T >
		T* Create(const std::string& name)
		{ return Detail::Factory::Instance().Create<T>(name); }
	};

}


#define TOOLKIT_REGISTER_CLASS(Class_) \
	friend class stingray::Detail::SimpleFactoryObjectCreator<Class_>; \
	virtual std::string GetClassName() const { return RemovePrefix(TypeInfo(typeid(Class_)).GetName(), "stingray::"); }

#define TOOLKIT_REGISTER_CLASS_EXPLICIT(Class_) stingray::Detail::Factory::Instance().Register<Class_>(#Class_)

#endif
{'fraction_non_alphanumeric': 0.1141640042598509, 'fraction_numerical': 0.0004259850905218317, 'mean_word_length': 4.90691823899371, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '29842', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1471, 'n_words': 288}