/** @file iproxy.cpp
*	@headerfile iproxy.h "EABaseTypesPlus/iproxy.h"
*	proxy interface
*	@author Chris Burns (cburns@ea.com)
*
*	(c) 2013 Electronic Arts Inc.
*/

#include "EABaseTypesPlus/iproxy.h"

#include "EABaseTypes/factory.h"
#include "EABaseTypes/datatypes.h"
#include "EABaseTypes/autorefuserdata.h"

namespace EA
{
	namespace Types
	{
		bool ProxyPathNext(const char*& path, EA::String& name)
		{
			while(*path == '/') ++path;

			if(*path == '\0')
			{
				 return false;
			}
			else
			{
				 const char* start = path;
				 while(*path != '/' && *path != NULL) ++path;
				 name.assign(start, static_cast<EA::String::size_type>(path - start));
				 return true;
			}
		}

		bool ProxyPathHasNext(const char* path)
		{
			while(*path == '/') ++path;

			if(*path == '\0')
			{
				 return false;
			}
			else
			{
				 return true;
			}
		}

		/* static */ IProxyReturn IProxy::AsIProxyRef(BaseTypeIn baseType)
		{
			return baseType->As<IProxyRef>();
		}

		UserDataReturn IProxy::ToUserData(Factory* factory)
		{
			return factory->UserData(IProxyIn(this));
		}

		/* protected */ ObjectReturn IProxy::GetInterface(Factory* factory, const char* path, const char** schema)
		{
			EA::Types::ArrayRef arr = factory->Array();
			while(*schema != NULL)
			{
				arr->push_back(*schema++);
			}

			return GetInterface(path, arr);
		}
	}
}
