#include <hxcpp.h>

#ifndef INCLUDED_IMap
#include <IMap.h>
#endif
#ifndef INCLUDED_Lambda
#include <Lambda.h>
#endif
#ifndef INCLUDED_List
#include <List.h>
#endif
#ifndef INCLUDED_Reflect
#include <Reflect.h>
#endif
#ifndef INCLUDED_Std
#include <Std.h>
#endif
#ifndef INCLUDED_StringTools
#include <StringTools.h>
#endif
#ifndef INCLUDED_Type
#include <Type.h>
#endif
#ifndef INCLUDED__Map_Map_Impl_
#include <_Map/Map_Impl_.h>
#endif
#ifndef INCLUDED_haxe_Log
#include <haxe/Log.h>
#endif
#ifndef INCLUDED_haxe_ds_StringMap
#include <haxe/ds/StringMap.h>
#endif
#ifndef INCLUDED_hxMath
#include <hxMath.h>
#endif
#ifndef INCLUDED_luxe_utils_json_JSONEncoder
#include <luxe/utils/json/JSONEncoder.h>
#endif
namespace luxe{
namespace utils{
namespace json{

Void JSONEncoder_obj::__construct(Dynamic value)
{
HX_STACK_FRAME("luxe.utils.json.JSONEncoder","new",0x97df6c15,"luxe.utils.json.JSONEncoder.new","luxe/utils/json/JSONEncoder.hx",45,0xc4b1173a)

HX_STACK_ARG(value,"value")
{
	HX_STACK_LINE(69)
	this->debug = false;
	HX_STACK_LINE(56)
	this->jsonString = this->convertToString(value);
}
;
	return null();
}

//JSONEncoder_obj::~JSONEncoder_obj() { }

Dynamic JSONEncoder_obj::__CreateEmpty() { return  new JSONEncoder_obj; }
hx::ObjectPtr< JSONEncoder_obj > JSONEncoder_obj::__new(Dynamic value)
{  hx::ObjectPtr< JSONEncoder_obj > result = new JSONEncoder_obj();
	result->__construct(value);
	return result;}

Dynamic JSONEncoder_obj::__Create(hx::DynamicArray inArgs)
{  hx::ObjectPtr< JSONEncoder_obj > result = new JSONEncoder_obj();
	result->__construct(inArgs[0]);
	return result;}

::String JSONEncoder_obj::getString( ){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","getString",0xc4e5837c,"luxe.utils.json.JSONEncoder.getString","luxe/utils/json/JSONEncoder.hx",66,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_LINE(66)
	return this->jsonString;
}


HX_DEFINE_DYNAMIC_FUNC0(JSONEncoder_obj,getString,return )

Void JSONEncoder_obj::_trace( ::String e){
{
		HX_STACK_FRAME("luxe.utils.json.JSONEncoder","_trace",0x6f11b931,"luxe.utils.json.JSONEncoder._trace","luxe/utils/json/JSONEncoder.hx",70,0xc4b1173a)
		HX_STACK_THIS(this)
		HX_STACK_ARG(e,"e")
		HX_STACK_LINE(70)
		if ((this->debug)){
			HX_STACK_LINE(70)
			::haxe::Log_obj::trace(e,hx::SourceInfo(HX_CSTRING("JSONEncoder.hx"),70,HX_CSTRING("luxe.utils.json.JSONEncoder"),HX_CSTRING("_trace")));
		}
	}
return null();
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,_trace,(void))

::String JSONEncoder_obj::convertToString( Dynamic value){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","convertToString",0x86f70cf4,"luxe.utils.json.JSONEncoder.convertToString","luxe/utils/json/JSONEncoder.hx",78,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(value,"value")
	HX_STACK_LINE(80)
	if (((  ((!(::Std_obj::is(value,hx::ClassOf< ::List >())))) ? bool(::Std_obj::is(value,hx::ClassOf< ::_Map::Map_Impl_ >())) : bool(true) ))){
		HX_STACK_LINE(81)
		value = ::Lambda_obj::array(value);
		HX_STACK_LINE(82)
		this->_trace(HX_CSTRING("convertToString: was List or Map"));
	}
	HX_STACK_LINE(85)
	if ((::Std_obj::is(value,hx::ClassOf< ::_Map::Map_Impl_ >()))){
		HX_STACK_LINE(86)
		value = this->mapHash(value);
		HX_STACK_LINE(87)
		this->_trace(HX_CSTRING("convertToString: was Hash"));
	}
	HX_STACK_LINE(91)
	if ((::Std_obj::is(value,hx::ClassOf< ::String >()))){
		HX_STACK_LINE(92)
		this->_trace(HX_CSTRING("convertToString: value was String"));
		HX_STACK_LINE(94)
		return this->escapeString(hx::TCast< String >::cast(value));
	}
	else{
		HX_STACK_LINE(96)
		if ((::Std_obj::is(value,hx::ClassOf< ::Float >()))){
			HX_STACK_LINE(97)
			this->_trace(HX_CSTRING("convertToString: value was Float"));
			HX_STACK_LINE(99)
			if ((::Math_obj::isFinite(hx::TCast< Float >::cast(value)))){
				HX_STACK_LINE(99)
				return (::Std_obj::string(value) + HX_CSTRING(""));
			}
			else{
				HX_STACK_LINE(99)
				return HX_CSTRING("null");
			}
		}
		else{
			HX_STACK_LINE(100)
			if ((::Std_obj::is(value,hx::ClassOf< ::Bool >()))){
				HX_STACK_LINE(101)
				this->_trace(HX_CSTRING("convertToString: value was Bool"));
				HX_STACK_LINE(103)
				if ((value)){
					HX_STACK_LINE(103)
					return HX_CSTRING("true");
				}
				else{
					HX_STACK_LINE(103)
					return HX_CSTRING("false");
				}
			}
			else{
				HX_STACK_LINE(104)
				if ((::Std_obj::is(value,hx::ClassOf< Array<int> >()))){
					HX_STACK_LINE(106)
					this->_trace(HX_CSTRING("convertToString: value was Array"));
					HX_STACK_LINE(107)
					return this->arrayToString(hx::TCastToArray(value));
				}
				else{
					HX_STACK_LINE(108)
					if (((  ((::Std_obj::is(value,hx::ClassOf< ::Dynamic >()))) ? bool((value != null())) : bool(false) ))){
						HX_STACK_LINE(110)
						this->_trace(HX_CSTRING("convertToString: value was Dynamic"));
						HX_STACK_LINE(111)
						::Class cls = ::Type_obj::getClass(value);		HX_STACK_VAR(cls,"cls");
						HX_STACK_LINE(112)
						if (((null() == cls))){
							HX_STACK_LINE(113)
							return this->objectToString(value);
						}
						else{
							HX_STACK_LINE(115)
							return this->instanceToString(value,cls);
						}
					}
					else{
						HX_STACK_LINE(117)
						if (((::Type_obj::getEnum(value) != null()))){
							HX_STACK_LINE(118)
							this->_trace(HX_CSTRING("convertToString: value was (Type.getEnum(value) != null)"));
							struct _Function_7_1{
								inline static int Block( Dynamic &value){
									HX_STACK_FRAME("*","closure",0x5bdab937,"*.closure","luxe/utils/json/JSONEncoder.hx",119,0xc4b1173a)
									{
										HX_STACK_LINE(119)
										Dynamic e = value;		HX_STACK_VAR(e,"e");
										HX_STACK_LINE(119)
										return e->__Index();
									}
									return null();
								}
							};
							HX_STACK_LINE(119)
							return ::Std_obj::string(_Function_7_1::Block(value));
						}
					}
				}
			}
		}
	}
	HX_STACK_LINE(122)
	this->_trace(HX_CSTRING("convertToString: returning null"));
	HX_STACK_LINE(123)
	return HX_CSTRING("null");
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,convertToString,return )

Dynamic JSONEncoder_obj::mapHash( ::haxe::ds::StringMap value){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","mapHash",0x367ffebf,"luxe.utils.json.JSONEncoder.mapHash","luxe/utils/json/JSONEncoder.hx",126,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(value,"value")
	struct _Function_1_1{
		inline static Dynamic Block( ){
			HX_STACK_FRAME("*","closure",0x5bdab937,"*.closure","luxe/utils/json/JSONEncoder.hx",127,0xc4b1173a)
			{
				hx::Anon __result = hx::Anon_obj::Create();
				return __result;
			}
			return null();
		}
	};
	HX_STACK_LINE(127)
	Dynamic ret = _Function_1_1::Block();		HX_STACK_VAR(ret,"ret");
	HX_STACK_LINE(128)
	for(::cpp::FastIterator_obj< ::String > *__it = ::cpp::CreateFastIterator< ::String >(value->keys());  __it->hasNext(); ){
		::String i = __it->next();
		{
			HX_STACK_LINE(129)
			Dynamic value1 = value->get(i);		HX_STACK_VAR(value1,"value1");
			HX_STACK_LINE(129)
			if (((ret != null()))){
				HX_STACK_LINE(129)
				ret->__SetField(i,value1,false);
			}
		}
;
	}
	HX_STACK_LINE(130)
	return ret;
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,mapHash,return )

::String JSONEncoder_obj::escapeString( ::String str){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","escapeString",0x7cd3bcdd,"luxe.utils.json.JSONEncoder.escapeString","luxe/utils/json/JSONEncoder.hx",140,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(str,"str")
	HX_STACK_LINE(142)
	::String s = HX_CSTRING("");		HX_STACK_VAR(s,"s");
	HX_STACK_LINE(144)
	::String ch;		HX_STACK_VAR(ch,"ch");
	HX_STACK_LINE(146)
	int len = str.length;		HX_STACK_VAR(len,"len");
	HX_STACK_LINE(157)
	{
		HX_STACK_LINE(157)
		int _g = (int)0;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(157)
		while(((_g < len))){
			HX_STACK_LINE(157)
			int i = (_g)++;		HX_STACK_VAR(i,"i");
			HX_STACK_LINE(159)
			ch = str.charAt(i);
			HX_STACK_LINE(169)
			::String _switch_1 = (ch);
			if (  ( _switch_1==HX_CSTRING("\""))){
				HX_STACK_LINE(173)
				hx::AddEq(s,HX_CSTRING("\\\""));
			}
			else if (  ( _switch_1==HX_CSTRING("\\"))){
				HX_STACK_LINE(175)
				hx::AddEq(s,HX_CSTRING("\\\\"));
			}
			else if (  ( _switch_1==HX_CSTRING("\n"))){
				HX_STACK_LINE(177)
				hx::AddEq(s,HX_CSTRING("\\n"));
			}
			else if (  ( _switch_1==HX_CSTRING("\r"))){
				HX_STACK_LINE(179)
				hx::AddEq(s,HX_CSTRING("\\r"));
			}
			else if (  ( _switch_1==HX_CSTRING("\t"))){
				HX_STACK_LINE(181)
				hx::AddEq(s,HX_CSTRING("\\t"));
			}
			else  {
				HX_STACK_LINE(184)
				Dynamic code = ch.charCodeAt((int)0);		HX_STACK_VAR(code,"code");
				HX_STACK_LINE(192)
				if (((bool((ch < HX_CSTRING(" "))) || bool((code > (int)127))))){
					HX_STACK_LINE(199)
					::String hexCode = ::StringTools_obj::hex(ch.charCodeAt((int)0),null());		HX_STACK_VAR(hexCode,"hexCode");
					HX_STACK_LINE(203)
					::String zeroPad = HX_CSTRING("");		HX_STACK_VAR(zeroPad,"zeroPad");
					HX_STACK_LINE(204)
					{
						HX_STACK_LINE(204)
						int _g2 = (int)0;		HX_STACK_VAR(_g2,"_g2");
						HX_STACK_LINE(204)
						int _g1 = ((int)4 - hexCode.length);		HX_STACK_VAR(_g1,"_g1");
						HX_STACK_LINE(204)
						while(((_g2 < _g1))){
							HX_STACK_LINE(204)
							int j = (_g2)++;		HX_STACK_VAR(j,"j");
							HX_STACK_LINE(205)
							hx::AddEq(zeroPad,HX_CSTRING("0"));
						}
					}
					HX_STACK_LINE(209)
					hx::AddEq(s,((HX_CSTRING("\\u") + zeroPad) + hexCode));
				}
				else{
					HX_STACK_LINE(212)
					hx::AddEq(s,ch);
				}
			}
;
;
		}
	}
	HX_STACK_LINE(216)
	return ((HX_CSTRING("\"") + s) + HX_CSTRING("\""));
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,escapeString,return )

::String JSONEncoder_obj::arrayToString( Dynamic a){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","arrayToString",0x1629eb5a,"luxe.utils.json.JSONEncoder.arrayToString","luxe/utils/json/JSONEncoder.hx",225,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(a,"a")
	HX_STACK_LINE(228)
	::String s = HX_CSTRING("");		HX_STACK_VAR(s,"s");
	HX_STACK_LINE(231)
	{
		HX_STACK_LINE(231)
		int _g1 = (int)0;		HX_STACK_VAR(_g1,"_g1");
		HX_STACK_LINE(231)
		int _g = a->__Field(HX_CSTRING("length"),true);		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(231)
		while(((_g1 < _g))){
			HX_STACK_LINE(231)
			int i = (_g1)++;		HX_STACK_VAR(i,"i");
			HX_STACK_LINE(234)
			if (((s.length > (int)0))){
				HX_STACK_LINE(236)
				hx::AddEq(s,HX_CSTRING(","));
			}
			HX_STACK_LINE(239)
			hx::AddEq(s,this->convertToString(a->__GetItem(i)));
		}
	}
	HX_STACK_LINE(259)
	return ((HX_CSTRING("[") + s) + HX_CSTRING("]"));
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,arrayToString,return )

::String JSONEncoder_obj::objectToString( Dynamic o){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","objectToString",0xe43828f6,"luxe.utils.json.JSONEncoder.objectToString","luxe/utils/json/JSONEncoder.hx",268,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(o,"o")
	HX_STACK_LINE(272)
	::String s = HX_CSTRING("");		HX_STACK_VAR(s,"s");
	HX_STACK_LINE(273)
	Dynamic value;		HX_STACK_VAR(value,"value");
	HX_STACK_LINE(276)
	{
		HX_STACK_LINE(276)
		int _g = (int)0;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(276)
		Array< ::String > _g1 = ::Reflect_obj::fields(o);		HX_STACK_VAR(_g1,"_g1");
		HX_STACK_LINE(276)
		while(((_g < _g1->length))){
			HX_STACK_LINE(276)
			::String key = _g1->__get(_g);		HX_STACK_VAR(key,"key");
			HX_STACK_LINE(276)
			++(_g);
			HX_STACK_LINE(278)
			value = ::Reflect_obj::field(o,key);
			HX_STACK_LINE(280)
			if ((!(::Reflect_obj::isFunction(value)))){
				HX_STACK_LINE(283)
				if (((s.length > (int)0))){
					HX_STACK_LINE(285)
					hx::AddEq(s,HX_CSTRING(","));
				}
				HX_STACK_LINE(287)
				::String _g2 = (this->escapeString(key) + HX_CSTRING(":"));		HX_STACK_VAR(_g2,"_g2");
				HX_STACK_LINE(287)
				hx::AddEq(s,(_g2 + this->convertToString(value)));
			}
		}
	}
	HX_STACK_LINE(290)
	return ((HX_CSTRING("{") + s) + HX_CSTRING("}"));
}


HX_DEFINE_DYNAMIC_FUNC1(JSONEncoder_obj,objectToString,return )

::String JSONEncoder_obj::instanceToString( Dynamic o,::Class cls){
	HX_STACK_FRAME("luxe.utils.json.JSONEncoder","instanceToString",0x9ad6408c,"luxe.utils.json.JSONEncoder.instanceToString","luxe/utils/json/JSONEncoder.hx",300,0xc4b1173a)
	HX_STACK_THIS(this)
	HX_STACK_ARG(o,"o")
	HX_STACK_ARG(cls,"cls")
	HX_STACK_LINE(301)
	::String s = HX_CSTRING("");		HX_STACK_VAR(s,"s");
	HX_STACK_LINE(302)
	Dynamic value;		HX_STACK_VAR(value,"value");
	HX_STACK_LINE(304)
	{
		HX_STACK_LINE(304)
		int _g = (int)0;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(304)
		Array< ::String > _g1 = ::Type_obj::getInstanceFields(cls);		HX_STACK_VAR(_g1,"_g1");
		HX_STACK_LINE(304)
		while(((_g < _g1->length))){
			HX_STACK_LINE(304)
			::String key = _g1->__get(_g);		HX_STACK_VAR(key,"key");
			HX_STACK_LINE(304)
			++(_g);
			HX_STACK_LINE(305)
			value = ::Reflect_obj::field(o,key);
			HX_STACK_LINE(306)
			if ((!(::Reflect_obj::isFunction(value)))){
				HX_STACK_LINE(307)
				if (((s.length > (int)0))){
					HX_STACK_LINE(308)
					hx::AddEq(s,HX_CSTRING(","));
				}
				HX_STACK_LINE(310)
				::String _g2 = (this->escapeString(key) + HX_CSTRING(":"));		HX_STACK_VAR(_g2,"_g2");
				HX_STACK_LINE(310)
				hx::AddEq(s,(_g2 + this->convertToString(value)));
			}
		}
	}
	HX_STACK_LINE(313)
	return ((HX_CSTRING("{") + s) + HX_CSTRING("}"));
}


HX_DEFINE_DYNAMIC_FUNC2(JSONEncoder_obj,instanceToString,return )


JSONEncoder_obj::JSONEncoder_obj()
{
}

void JSONEncoder_obj::__Mark(HX_MARK_PARAMS)
{
	HX_MARK_BEGIN_CLASS(JSONEncoder);
	HX_MARK_MEMBER_NAME(jsonString,"jsonString");
	HX_MARK_MEMBER_NAME(debug,"debug");
	HX_MARK_END_CLASS();
}

void JSONEncoder_obj::__Visit(HX_VISIT_PARAMS)
{
	HX_VISIT_MEMBER_NAME(jsonString,"jsonString");
	HX_VISIT_MEMBER_NAME(debug,"debug");
}

Dynamic JSONEncoder_obj::__Field(const ::String &inName,bool inCallProp)
{
	switch(inName.length) {
	case 5:
		if (HX_FIELD_EQ(inName,"debug") ) { return debug; }
		break;
	case 6:
		if (HX_FIELD_EQ(inName,"_trace") ) { return _trace_dyn(); }
		break;
	case 7:
		if (HX_FIELD_EQ(inName,"mapHash") ) { return mapHash_dyn(); }
		break;
	case 9:
		if (HX_FIELD_EQ(inName,"getString") ) { return getString_dyn(); }
		break;
	case 10:
		if (HX_FIELD_EQ(inName,"jsonString") ) { return jsonString; }
		break;
	case 12:
		if (HX_FIELD_EQ(inName,"escapeString") ) { return escapeString_dyn(); }
		break;
	case 13:
		if (HX_FIELD_EQ(inName,"arrayToString") ) { return arrayToString_dyn(); }
		break;
	case 14:
		if (HX_FIELD_EQ(inName,"objectToString") ) { return objectToString_dyn(); }
		break;
	case 15:
		if (HX_FIELD_EQ(inName,"convertToString") ) { return convertToString_dyn(); }
		break;
	case 16:
		if (HX_FIELD_EQ(inName,"instanceToString") ) { return instanceToString_dyn(); }
	}
	return super::__Field(inName,inCallProp);
}

Dynamic JSONEncoder_obj::__SetField(const ::String &inName,const Dynamic &inValue,bool inCallProp)
{
	switch(inName.length) {
	case 5:
		if (HX_FIELD_EQ(inName,"debug") ) { debug=inValue.Cast< bool >(); return inValue; }
		break;
	case 10:
		if (HX_FIELD_EQ(inName,"jsonString") ) { jsonString=inValue.Cast< ::String >(); return inValue; }
	}
	return super::__SetField(inName,inValue,inCallProp);
}

void JSONEncoder_obj::__GetFields(Array< ::String> &outFields)
{
	outFields->push(HX_CSTRING("jsonString"));
	outFields->push(HX_CSTRING("debug"));
	super::__GetFields(outFields);
};

static ::String sStaticFields[] = {
	String(null()) };

#if HXCPP_SCRIPTABLE
static hx::StorageInfo sMemberStorageInfo[] = {
	{hx::fsString,(int)offsetof(JSONEncoder_obj,jsonString),HX_CSTRING("jsonString")},
	{hx::fsBool,(int)offsetof(JSONEncoder_obj,debug),HX_CSTRING("debug")},
	{ hx::fsUnknown, 0, null()}
};
#endif

static ::String sMemberFields[] = {
	HX_CSTRING("jsonString"),
	HX_CSTRING("getString"),
	HX_CSTRING("debug"),
	HX_CSTRING("_trace"),
	HX_CSTRING("convertToString"),
	HX_CSTRING("mapHash"),
	HX_CSTRING("escapeString"),
	HX_CSTRING("arrayToString"),
	HX_CSTRING("objectToString"),
	HX_CSTRING("instanceToString"),
	String(null()) };

static void sMarkStatics(HX_MARK_PARAMS) {
	HX_MARK_MEMBER_NAME(JSONEncoder_obj::__mClass,"__mClass");
};

#ifdef HXCPP_VISIT_ALLOCS
static void sVisitStatics(HX_VISIT_PARAMS) {
	HX_VISIT_MEMBER_NAME(JSONEncoder_obj::__mClass,"__mClass");
};

#endif

Class JSONEncoder_obj::__mClass;

void JSONEncoder_obj::__register()
{
	hx::Static(__mClass) = hx::RegisterClass(HX_CSTRING("luxe.utils.json.JSONEncoder"), hx::TCanCast< JSONEncoder_obj> ,sStaticFields,sMemberFields,
	&__CreateEmpty, &__Create,
	&super::__SGetClass(), 0, sMarkStatics
#ifdef HXCPP_VISIT_ALLOCS
    , sVisitStatics
#endif
#ifdef HXCPP_SCRIPTABLE
    , sMemberStorageInfo
#endif
);
}

void JSONEncoder_obj::__boot()
{
}

} // end namespace luxe
} // end namespace utils
} // end namespace json
