<commit_before>#include <stingray/toolkit/any.h>


namespace stingray
{

	void any::Copy(Type type, const DataType& data)
	{
		switch (type)
		{
		case Type::Empty:
		case Type::Int:
		case Type::Bool:
		case Type::U8:
		case Type::S8:
		case Type::U16:
		case Type::S16:
		case Type::U32:
		case Type::S32:
		case Type::Float:
		case Type::Double:
			_data = data;
			break;
		case Type::String:
			_data.String.Ctor(data.String.Ref());
			break;
		case Type::Object:
			_data.Object = data.Object->Clone();
			break;
		default:
			TOOLKIT_THROW(ArgumentException("type", type.ToString()));
		}
		_type = type;
	}


	void any::Destroy()
	{
		switch (_type)
		{
		case Type::String:	_data.String.Dtor();	break;
		case Type::Object:	delete _data.Object;	break;
		default:			break;
		}

		_type = Type::Empty;
	}


	bool any::IsSerializable() const
	{ return _type != Type::Object || _data.Object->IsSerializable(); }


	std::string any::ToString() const
	{
		switch (_type)
		{
		case Type::Empty:	return "<empty>";
		case Type::Int:		return stingray::ToString(_data.Int);
		case Type::Bool:	return stingray::ToString(_data.Bool);
		case Type::U8:		return stingray::ToString(_data.U8);
		case Type::S8:		return stingray::ToString(_data.S8);
		case Type::U16:		return stingray::ToString(_data.U16);
		case Type::S16:		return stingray::ToString(_data.S16);
		case Type::U32:		return stingray::ToString(_data.U32);
		case Type::S32:		return stingray::ToString(_data.S32);
		case Type::Float:	return stingray::ToString(_data.Float);
		case Type::Double:	return stingray::ToString(_data.Double);
		case Type::String:	return _data.String.Ref();
		case Type::Object:	return _data.Object->ToString();
		default:			TOOLKIT_THROW("Unknown type: " + _type.ToString());
		}
		return "";
	}


	void any::Serialize(ObjectOStream & ar) const
	{
		ar.Serialize("type", _type);
		switch (_type)
		{
		case Type::Empty:	return;
		case Type::Int:		ar.Serialize("val", _data.Int);				break;
		case Type::Bool:	ar.Serialize("val", _data.Bool);			break;
		case Type::U8:		ar.Serialize("val", _data.U8);				break;
		case Type::S8:		ar.Serialize("val", _data.S8);				break;
		case Type::U16:		ar.Serialize("val", _data.U16);				break;
		case Type::S16:		ar.Serialize("val", _data.S16);				break;
		case Type::U32:		ar.Serialize("val", _data.U32);				break;
		case Type::S32:		ar.Serialize("val", _data.S32);				break;
		case Type::Float:	ar.Serialize("val", _data.Float);			break;
		case Type::Double:	ar.Serialize("val", _data.Double);			break;
		case Type::String:	ar.Serialize("val", _data.String.Ref());	break;
		case Type::Object:
			{
				TOOLKIT_CHECK(_data.Object->IsSerializable(), "'any' object is not a serializable one!");
				const IFactoryObjectCreator& creator = _data.Object->GetFactoryObjectCreator();
				std::string classname(creator.Name());<commit_msg>output type of the any object in serialization exception<commit_after>#include <stingray/toolkit/any.h>


namespace stingray
{

	void any::Copy(Type type, const DataType& data)
	{
		switch (type)
		{
		case Type::Empty:
		case Type::Int:
		case Type::Bool:
		case Type::U8:
		case Type::S8:
		case Type::U16:
		case Type::S16:
		case Type::U32:
		case Type::S32:
		case Type::Float:
		case Type::Double:
			_data = data;
			break;
		case Type::String:
			_data.String.Ctor(data.String.Ref());
			break;
		case Type::Object:
			_data.Object = data.Object->Clone();
			break;
		default:
			TOOLKIT_THROW(ArgumentException("type", type.ToString()));
		}
		_type = type;
	}


	void any::Destroy()
	{
		switch (_type)
		{
		case Type::String:	_data.String.Dtor();	break;
		case Type::Object:	delete _data.Object;	break;
		default:			break;
		}

		_type = Type::Empty;
	}


	bool any::IsSerializable() const
	{ return _type != Type::Object || _data.Object->IsSerializable(); }


	std::string any::ToString() const
	{
		switch (_type)
		{
		case Type::Empty:	return "<empty>";
		case Type::Int:		return stingray::ToString(_data.Int);
		case Type::Bool:	return stingray::ToString(_data.Bool);
		case Type::U8:		return stingray::ToString(_data.U8);
		case Type::S8:		return stingray::ToString(_data.S8);
		case Type::U16:		return stingray::ToString(_data.U16);
		case Type::S16:		return stingray::ToString(_data.S16);
		case Type::U32:		return stingray::ToString(_data.U32);
		case Type::S32:		return stingray::ToString(_data.S32);
		case Type::Float:	return stingray::ToString(_data.Float);
		case Type::Double:	return stingray::ToString(_data.Double);
		case Type::String:	return _data.String.Ref();
		case Type::Object:	return _data.Object->ToString();
		default:			TOOLKIT_THROW("Unknown type: " + _type.ToString());
		}
		return "";
	}


	void any::Serialize(ObjectOStream & ar) const
	{
		ar.Serialize("type", _type);
		switch (_type)
		{
		case Type::Empty:	return;
		case Type::Int:		ar.Serialize("val", _data.Int);				break;
		case Type::Bool:	ar.Serialize("val", _data.Bool);			break;
		case Type::U8:		ar.Serialize("val", _data.U8);				break;
		case Type::S8:		ar.Serialize("val", _data.S8);				break;
		case Type::U16:		ar.Serialize("val", _data.U16);				break;
		case Type::S16:		ar.Serialize("val", _data.S16);				break;
		case Type::U32:		ar.Serialize("val", _data.U32);				break;
		case Type::S32:		ar.Serialize("val", _data.S32);				break;
		case Type::Float:	ar.Serialize("val", _data.Float);			break;
		case Type::Double:	ar.Serialize("val", _data.Double);			break;
		case Type::String:	ar.Serialize("val", _data.String.Ref());	break;
		case Type::Object:
			{
				TOOLKIT_CHECK(_data.Object->IsSerializable(), "'any' object (" + Demangle(typeid(*_data.Object).name()) + ") is not a serializable one!");
				const IFactoryObjectCreator& creator = _data.Object->GetFactoryObjectCreator();
				std::string classname(creator.Name());
{'fraction_non_alphanumeric': 0.167069799585349, 'fraction_numerical': 0.017277125086385625, 'mean_word_length': 4.37012987012987, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '1898245', 'n_tokens_mistral': 2395, 'n_tokens_neox': 2124, 'n_words': 446}