#include "GuiResourceManager.h"
#include "GuiParserManager.h"
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
stream
;
using
namespace
parsing
::
xml
;
using
namespace
reflection
::
description
;
using
namespace
controls
;
class
GuiResourceClassNameRecordTypeResolver
:
public
,
public
,
private
IGuiResourceTypeResolver_DirectLoadStream
{
public
:
()
override
{
return
L"ClassNameRecord"
;
}
bool
()
override
{
return
false
;
}
bool
()
override
{
return
true
;
}
IGuiResourceTypeResolver_DirectLoadStream
*
()
override
{
return
this
;
}
void
(
<
>
,
<
>
,
stream
::
&
)
override
{
if
(
auto
=
.
<
GuiResourceClassNameRecord
>())
{
internal
::
(
);
writer
obj
;
}
}
<
>
ResolveResourcePrecompiled
(
<
>
,
stream
::
&
,
::
&
)
override
{
internal
::
(
);
auto
=
<
GuiResourceClassNameRecord
>();
reader
obj
;
return
obj
;
}
};
*
=
nullptr
;
*
()
{
return
resourceManager
;
}
class
:
public
,
public
,
public
{
protected
:
typedef
<
,
<
>>
;
<
<
>>
;
;
;
class
:
public
{
public
:
<
>
;
;
;
<
>
;
<
>
()
{
.
(
0
);
<
>
;
auto
=
::
(
,
errors
);
CHECK_ERROR(errors.Count() == 0, L"PendingResource::LoadResource()#Failed to load the resource.");
do
{
if
(!(
errors
.
() ==
0
))
throw
(
L"PendingResource::LoadResource()#Failed to load the resource."
);}
while
(
0
);
return
resource
;
}
};
<
,
<
>>
;
<
<
>>
;
public
:
GUI_PLUGIN_NAME(GacUI_Res_Resource)
vl
::
()
override
{
return
L"GacUI_Res_Resource"
; }
void
(
vl
::
collections
::
<
>&
)
override
{
GUI_PLUGIN_DEPEND(GacUI_Res_ResourceResolver);
.
(
L"GacUI_Res_ResourceResolver"
);
}
void
()
override
{
resourceManager
=
this
;
IGuiResourceResolverManager
*
=
GetResourceResolverManager
();
manager
->
(
new
GuiResourceClassNameRecordTypeResolver
);
}
void
()
override
{
resourceManager
=
nullptr
;
}
void
(
<
>
,
::
&
,
)
override
{
auto
=
();
if
(
metadata
==
L""
)
{
if
(
.
(
.
()))
return
;
(
,
);
if
(
.
() >
0
)
{
return
;
}
.
(
);
}
else
{
CHECK_ERROR(!resources.Keys().Contains(metadata->name), L"GuiResourceManager::SetResource(Ptr<GuiResource>, GuiResourceUsage)#A resource with the same name has been loaded.");
do
{
if
(!(!
.
().
(
metadata
)))
throw
(
L"GuiResourceManager::SetResource(Ptr<GuiResource>, GuiResourceUsage)#A resource with the same name has been loaded."
);}
while
(
0
);
(
,
);
if
(
.
() >
0
)
{
return
;
}
.
(
metadata
,
);
}
if
(
auto
=
(
L"Precompiled/ClassNameRecord"
).Cast<
GuiResourceClassNameRecord
>())
{
FOREACH(WString, className, record->classNames)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
record
->classNames);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
className
);)
{
.
(
className
,
);
}
}
if
(
metadata
!=
L""
)
{
=
.
().
(
metadata
);
if
(
index
!= -
1
)
{
<
<
>>
;
(
prs
,
.
(
index
));
.
(
metadata
);
FOREACH(Ptr<PendingResource>, pr, prs)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
prs
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
pr
);)
{
pr
.
(
metadata
);
if
(
pr
.
() ==
0
)
{
.
(
pr
.
());
(
pr
(),
,
pr
);
}
}
}
}
}
<
>
(
const
&
)
override
{
=
.
().
(
);
return
index
== -
1
?
nullptr
:
.
()
index
];
}
<
>
(
const
&
)
override
{
=
.
().
(
);
if
(
index
== -
1
)
return
nullptr
;
return
.
()
index
];
}
void
(
const
&
)
override
{
=
.
().
(
);
if
(
index
!= -
1
)
{
auto
=
.
()
index
];
.
(
);
if
(
auto
=
resource
(
L"Precompiled/ClassNameRecord"
).Cast<
GuiResourceClassNameRecord
>())
{
FOREACH(WString, className, record->classNames)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
record
->classNames);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
className
);)
{
.
(
className
);
}
}
}
}
void
(
stream
::
&
,
::
&
,
)
override
{
auto
=
<
>();
pr
=
;
(
,
pr
);
pr
<
>();
{
pr
.
(
0
);
stream
::
internal
::
(
pr
);
;
reader
metadata
;
<
>
;
auto
=
()->
<
>(
L"XML"
);
auto
=
parser
->Parse({},
metadata
,
errors
);
CHECK_ERROR(xmlMetadata, L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#This resource does not contain a valid metadata.");
do
{
if
(!(
xmlMetadata
))
throw
(
L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#This resource does not contain a valid metadata."
);}
while
(
0
);
pr
(
xmlMetadata
, {},
errors
);
CHECK_ERROR(errors.Count() == 0, L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#This resource does not contain a valid metadata.");
do
{
if
(!(
errors
.
() ==
0
))
throw
(
L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#This resource does not contain a valid metadata."
);}
while
(
0
);
}
CHECK_ERROR(
pr->metadata->name != L"" || pr->dependencies.Count() == 0,
L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#The name of this resource cannot be empty because it has dependencies."
);
do
{
if
(!(
pr
!=
L""
||
pr
.
() ==
0
))
throw
(
L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#The name of this resource cannot be empty because it has dependencies."
);}
while
(
0
);
(
pr
,
(
pr
).Except(
.
()));
if
(
pr
.
() ==
0
)
{
(
pr
(),
,
pr
);
}
else
{
.
(
pr
);
FOREACH(WString, dep, pr->dependencies)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
pr
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
dep
);)
{
.
(
dep
,
pr
);
}
}
}
void
(
stream
::
&
,
)
override
{
::
;
(
,
errors
,
);
CHECK_ERROR(errors.Count() == 0, L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#Error happened.");
do
{
if
(!(
errors
.
() ==
0
))
throw
(
L"GuiResourceManager::LoadResourceOrPending(stream::IStream&, GuiResourceUsage)#Error happened."
);}
while
(
0
);
}
void
(
collections
::
<
>&
)
override
{
(
,
(
).Select([](
<
>
) {
return
pr
; }));
}
};
GUI_REGISTER_PLUGIN(GuiResourceManager)
class
GuiRegisterPluginClass_GuiResourceManager
{
public
:
GuiRegisterPluginClass_GuiResourceManager
() {
vl
::
presentation
::
controls
::
()->
(
new
); } }
instance_GuiRegisterPluginClass_GuiResourceManager
;
}
}