#include <hxcpp.h>

#ifndef INCLUDED_Std
#include <Std.h>
#endif
#ifndef INCLUDED_luxe_utils_json_JSONDecoder
#include <luxe/utils/json/JSONDecoder.h>
#endif
#ifndef INCLUDED_luxe_utils_json_JSONToken
#include <luxe/utils/json/JSONToken.h>
#endif
#ifndef INCLUDED_luxe_utils_json_JSONTokenType
#include <luxe/utils/json/JSONTokenType.h>
#endif
#ifndef INCLUDED_luxe_utils_json_JSONTokenizer
#include <luxe/utils/json/JSONTokenizer.h>
#endif
namespace luxe{
namespace utils{
namespace json{

Void JSONDecoder_obj::__construct(::String s,bool strict)
{
HX_STACK_FRAME("luxe.utils.json.JSONDecoder","new",0x5462c9fd,"luxe.utils.json.JSONDecoder.new","luxe/utils/json/JSONDecoder.hx",74,0x99e9ee52)

HX_STACK_ARG(s,"s")

HX_STACK_ARG(strict,"strict")
{
	HX_STACK_LINE(75)
	this->strict = strict;
	HX_STACK_LINE(76)
	this->tokenizer = ::luxe::utils::json::JSONTokenizer_obj::__new(s,strict);
	HX_STACK_LINE(77)
	this->nextToken();
	HX_STACK_LINE(78)
	this->value = this->parseValue();
	HX_STACK_LINE(79)
	if (((  ((strict)) ? bool((this->nextToken() != null())) : bool(false) ))){
		HX_STACK_LINE(80)
		this->tokenizer->parseError(HX_CSTRING("Unexpected characters left in input stream!"));
	}
}
;
	return null();
}

//JSONDecoder_obj::~JSONDecoder_obj() { }

Dynamic JSONDecoder_obj::__CreateEmpty() { return  new JSONDecoder_obj; }
hx::ObjectPtr< JSONDecoder_obj > JSONDecoder_obj::__new(::String s,bool strict)
{  hx::ObjectPtr< JSONDecoder_obj > result = new JSONDecoder_obj();
	result->__construct(s,strict);
	return result;}

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

Dynamic JSONDecoder_obj::getValue( ){
	HX_STACK_FRAME("luxe.utils.json.JSONDecoder","getValue",0x6da19c3e,"luxe.utils.json.JSONDecoder.getValue","luxe/utils/json/JSONDecoder.hx",91,0x99e9ee52)
	HX_STACK_THIS(this)
	HX_STACK_LINE(91)
	return this->value;
}


HX_DEFINE_DYNAMIC_FUNC0(JSONDecoder_obj,getValue,return )

::luxe::utils::json::JSONToken JSONDecoder_obj::nextToken( ){
	HX_STACK_FRAME("luxe.utils.json.JSONDecoder","nextToken",0x6f2a2a63,"luxe.utils.json.JSONDecoder.nextToken","luxe/utils/json/JSONDecoder.hx",99,0x99e9ee52)
	HX_STACK_THIS(this)
	HX_STACK_LINE(99)
	return this->token = this->tokenizer->getNextToken();
}


HX_DEFINE_DYNAMIC_FUNC0(JSONDecoder_obj,nextToken,return )

Dynamic JSONDecoder_obj::parseArray( ){
	HX_STACK_FRAME("luxe.utils.json.JSONDecoder","parseArray",0xde12d869,"luxe.utils.json.JSONDecoder.parseArray","luxe/utils/json/JSONDecoder.hx",105,0x99e9ee52)
	HX_STACK_THIS(this)
	HX_STACK_LINE(108)
	Dynamic a = Dynamic( Array_obj<Dynamic>::__new() );		HX_STACK_VAR(a,"a");
	HX_STACK_LINE(111)
	this->nextToken();
	HX_STACK_LINE(113)
	if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACKET))){
		HX_STACK_LINE(115)
		return a;
	}
	else{
		HX_STACK_LINE(118)
		if (((bool(!(this->strict)) && bool((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tCOMMA))))){
			HX_STACK_LINE(119)
			this->nextToken();
			HX_STACK_LINE(121)
			if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACKET))){
				HX_STACK_LINE(122)
				return a;
			}
			else{
				HX_STACK_LINE(125)
				this->tokenizer->parseError((HX_CSTRING("Leading commas are not supported.  Expecting ']' but found ") + ::Std_obj::string(this->token->value)));
			}
		}
	}
	HX_STACK_LINE(131)
	while((true)){
		HX_STACK_LINE(133)
		a->__Field(HX_CSTRING("push"),true)(this->parseValue());
		HX_STACK_LINE(135)
		this->nextToken();
		HX_STACK_LINE(136)
		if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACKET))){
			HX_STACK_LINE(138)
			return a;
		}
		else{
			HX_STACK_LINE(139)
			if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tCOMMA))){
				HX_STACK_LINE(141)
				this->nextToken();
				HX_STACK_LINE(144)
				if ((!(this->strict))){
					HX_STACK_LINE(146)
					if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACKET))){
						HX_STACK_LINE(147)
						return a;
					}
				}
			}
			else{
				HX_STACK_LINE(151)
				this->tokenizer->parseError((HX_CSTRING("Expecting ] or , but found ") + ::Std_obj::string(this->token->value)));
			}
		}
	}
	HX_STACK_LINE(154)
	return null();
}


HX_DEFINE_DYNAMIC_FUNC0(JSONDecoder_obj,parseArray,return )

Dynamic JSONDecoder_obj::parseObject( ){
	HX_STACK_FRAME("luxe.utils.json.JSONDecoder","parseObject",0xcfb989ef,"luxe.utils.json.JSONDecoder.parseObject","luxe/utils/json/JSONDecoder.hx",160,0x99e9ee52)
	HX_STACK_THIS(this)
	struct _Function_1_1{
		inline static Dynamic Block( ){
			HX_STACK_FRAME("*","closure",0x5bdab937,"*.closure","luxe/utils/json/JSONDecoder.hx",163,0x99e9ee52)
			{
				hx::Anon __result = hx::Anon_obj::Create();
				return __result;
			}
			return null();
		}
	};
	HX_STACK_LINE(163)
	Dynamic o = _Function_1_1::Block();		HX_STACK_VAR(o,"o");
	HX_STACK_LINE(166)
	::String key;		HX_STACK_VAR(key,"key");
	HX_STACK_LINE(168)
	this->nextToken();
	HX_STACK_LINE(170)
	if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACE))){
		HX_STACK_LINE(172)
		return o;
	}
	else{
		HX_STACK_LINE(176)
		if (((bool(!(this->strict)) && bool((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tCOMMA))))){
			HX_STACK_LINE(178)
			this->nextToken();
			HX_STACK_LINE(180)
			if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACE))){
				HX_STACK_LINE(181)
				return o;
			}
			else{
				HX_STACK_LINE(184)
				this->tokenizer->parseError((HX_CSTRING("Leading commas are not supported.  Expecting '}' but found ") + ::Std_obj::string(this->token->value)));
			}
		}
	}
	HX_STACK_LINE(190)
	while((true)){
		HX_STACK_LINE(191)
		if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tSTRING))){
			HX_STACK_LINE(193)
			key = ::Std_obj::string(this->token->value);
			HX_STACK_LINE(195)
			this->nextToken();
			HX_STACK_LINE(197)
			if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tCOLON))){
				HX_STACK_LINE(199)
				this->nextToken();
				HX_STACK_LINE(200)
				{
					HX_STACK_LINE(200)
					Dynamic value = this->parseValue();		HX_STACK_VAR(value,"value");
					HX_STACK_LINE(200)
					if (((o != null()))){
						HX_STACK_LINE(200)
						o->__SetField(key,value,false);
					}
				}
				HX_STACK_LINE(202)
				this->nextToken();
				HX_STACK_LINE(204)
				if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACE))){
					HX_STACK_LINE(206)
					return o;
				}
				else{
					HX_STACK_LINE(207)
					if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tCOMMA))){
						HX_STACK_LINE(209)
						this->nextToken();
						HX_STACK_LINE(213)
						if ((!(this->strict))){
							HX_STACK_LINE(215)
							if (((this->token->type == ::luxe::utils::json::JSONTokenType_obj::tRIGHT_BRACE))){
								HX_STACK_LINE(216)
								return o;
							}
						}
					}
					else{
						HX_STACK_LINE(220)
						this->tokenizer->parseError((HX_CSTRING("Expecting } or , but found ") + ::Std_obj::string(this->token->value)));
					}
				}
			}
			else{
				HX_STACK_LINE(223)
				this->tokenizer->parseError((HX_CSTRING("Expecting : but found ") + ::Std_obj::string(this->token->value)));
			}
		}
		else{
			HX_STACK_LINE(226)
			this->tokenizer->parseError((HX_CSTRING("Expecting string but found ") + ::Std_obj::string(this->token->value)));
		}
	}
	HX_STACK_LINE(229)
	return null();
}


HX_DEFINE_DYNAMIC_FUNC0(JSONDecoder_obj,parseObject,return )

Dynamic JSONDecoder_obj::parseValue( ){
	HX_STACK_FRAME("luxe.utils.json.JSONDecoder","parseValue",0xea3bea41,"luxe.utils.json.JSONDecoder.parseValue","luxe/utils/json/JSONDecoder.hx",235,0x99e9ee52)
	HX_STACK_THIS(this)
	HX_STACK_LINE(237)
	if (((this->token == null()))){
		HX_STACK_LINE(238)
		this->tokenizer->parseError(HX_CSTRING("Unexpected end of input"));
	}
	HX_STACK_LINE(239)
	{
		HX_STACK_LINE(239)
		::luxe::utils::json::JSONTokenType _g = this->token->type;		HX_STACK_VAR(_g,"_g");
		HX_STACK_LINE(239)
		switch( (int)(_g->__Index())){
			case (int)2: {
				HX_STACK_LINE(241)
				return this->parseObject();
			}
			;break;
			case (int)4: {
				HX_STACK_LINE(243)
				return this->parseArray();
			}
			;break;
			case (int)10: {
				HX_STACK_LINE(245)
				return this->token->value;
			}
			;break;
			case (int)11: {
				HX_STACK_LINE(247)
				return this->token->value;
			}
			;break;
			case (int)7: {
				HX_STACK_LINE(249)
				return true;
			}
			;break;
			case (int)8: {
				HX_STACK_LINE(251)
				return false;
			}
			;break;
			case (int)9: {
				HX_STACK_LINE(253)
				return null();
			}
			;break;
			case (int)12: {
				HX_STACK_LINE(255)
				if ((!(this->strict))){
					HX_STACK_LINE(256)
					return this->token->value;
				}
				else{
					HX_STACK_LINE(258)
					this->tokenizer->parseError((HX_CSTRING("Unexpected ") + ::Std_obj::string(this->token->value)));
				}
			}
			;break;
			default: {
				HX_STACK_LINE(260)
				this->tokenizer->parseError((HX_CSTRING("Unexpected ") + ::Std_obj::string(this->token->value)));
			}
		}
	}
	HX_STACK_LINE(262)
	return null();
}


HX_DEFINE_DYNAMIC_FUNC0(JSONDecoder_obj,parseValue,return )


JSONDecoder_obj::JSONDecoder_obj()
{
}

void JSONDecoder_obj::__Mark(HX_MARK_PARAMS)
{
	HX_MARK_BEGIN_CLASS(JSONDecoder);
	HX_MARK_MEMBER_NAME(strict,"strict");
	HX_MARK_MEMBER_NAME(value,"value");
	HX_MARK_MEMBER_NAME(tokenizer,"tokenizer");
	HX_MARK_MEMBER_NAME(token,"token");
	HX_MARK_END_CLASS();
}

void JSONDecoder_obj::__Visit(HX_VISIT_PARAMS)
{
	HX_VISIT_MEMBER_NAME(strict,"strict");
	HX_VISIT_MEMBER_NAME(value,"value");
	HX_VISIT_MEMBER_NAME(tokenizer,"tokenizer");
	HX_VISIT_MEMBER_NAME(token,"token");
}

Dynamic JSONDecoder_obj::__Field(const ::String &inName,bool inCallProp)
{
	switch(inName.length) {
	case 5:
		if (HX_FIELD_EQ(inName,"value") ) { return value; }
		if (HX_FIELD_EQ(inName,"token") ) { return token; }
		break;
	case 6:
		if (HX_FIELD_EQ(inName,"strict") ) { return strict; }
		break;
	case 8:
		if (HX_FIELD_EQ(inName,"getValue") ) { return getValue_dyn(); }
		break;
	case 9:
		if (HX_FIELD_EQ(inName,"tokenizer") ) { return tokenizer; }
		if (HX_FIELD_EQ(inName,"nextToken") ) { return nextToken_dyn(); }
		break;
	case 10:
		if (HX_FIELD_EQ(inName,"parseArray") ) { return parseArray_dyn(); }
		if (HX_FIELD_EQ(inName,"parseValue") ) { return parseValue_dyn(); }
		break;
	case 11:
		if (HX_FIELD_EQ(inName,"parseObject") ) { return parseObject_dyn(); }
	}
	return super::__Field(inName,inCallProp);
}

Dynamic JSONDecoder_obj::__SetField(const ::String &inName,const Dynamic &inValue,bool inCallProp)
{
	switch(inName.length) {
	case 5:
		if (HX_FIELD_EQ(inName,"value") ) { value=inValue.Cast< Dynamic >(); return inValue; }
		if (HX_FIELD_EQ(inName,"token") ) { token=inValue.Cast< ::luxe::utils::json::JSONToken >(); return inValue; }
		break;
	case 6:
		if (HX_FIELD_EQ(inName,"strict") ) { strict=inValue.Cast< bool >(); return inValue; }
		break;
	case 9:
		if (HX_FIELD_EQ(inName,"tokenizer") ) { tokenizer=inValue.Cast< ::luxe::utils::json::JSONTokenizer >(); return inValue; }
	}
	return super::__SetField(inName,inValue,inCallProp);
}

void JSONDecoder_obj::__GetFields(Array< ::String> &outFields)
{
	outFields->push(HX_CSTRING("strict"));
	outFields->push(HX_CSTRING("value"));
	outFields->push(HX_CSTRING("tokenizer"));
	outFields->push(HX_CSTRING("token"));
	super::__GetFields(outFields);
};

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

#if HXCPP_SCRIPTABLE
static hx::StorageInfo sMemberStorageInfo[] = {
	{hx::fsBool,(int)offsetof(JSONDecoder_obj,strict),HX_CSTRING("strict")},
	{hx::fsObject /*Dynamic*/ ,(int)offsetof(JSONDecoder_obj,value),HX_CSTRING("value")},
	{hx::fsObject /*::luxe::utils::json::JSONTokenizer*/ ,(int)offsetof(JSONDecoder_obj,tokenizer),HX_CSTRING("tokenizer")},
	{hx::fsObject /*::luxe::utils::json::JSONToken*/ ,(int)offsetof(JSONDecoder_obj,token),HX_CSTRING("token")},
	{ hx::fsUnknown, 0, null()}
};
#endif

static ::String sMemberFields[] = {
	HX_CSTRING("strict"),
	HX_CSTRING("value"),
	HX_CSTRING("tokenizer"),
	HX_CSTRING("token"),
	HX_CSTRING("getValue"),
	HX_CSTRING("nextToken"),
	HX_CSTRING("parseArray"),
	HX_CSTRING("parseObject"),
	HX_CSTRING("parseValue"),
	String(null()) };

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

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

#endif

Class JSONDecoder_obj::__mClass;

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

void JSONDecoder_obj::__boot()
{
}

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