// This code is auto-generated by Qul's qmltocpp tool.
// WARNING! All changes made in this file will be lost!
#include "Slider.h"
#include "Button.h"
#include "ProgressBar.h"
#include "CheckBox.h"
#include "DefaultStyle.h"
#include "SwipeView.h"
#include "Switch.h"
#include "RadioButton.h"
#include "Dial.h"


#include <qul/private/unicodestring.h>
#include <qul/private/file.h>
#include <qul/private/items/itembase.h>
#include <qul/private/bundledresources.h>

namespace QtQuick {
namespace Controls {
namespace StyleDefault {



static const Qul::Private::ModuleResource module_qml_resources_data[] = {
{"Button.qml", NULL, 10, sizeof(Button), true},
{"CheckBox.qml", NULL, 12, sizeof(CheckBox), true},
{"DefaultStyle.qml", "QtObject", 16, sizeof(DefaultStyle), true},
{"Dial.qml", NULL, 8, sizeof(Dial), true},
{"ProgressBar.qml", NULL, 15, sizeof(ProgressBar), true},
{"RadioButton.qml", NULL, 15, sizeof(RadioButton), true},
{"Slider.qml", NULL, 10, sizeof(Slider), true},
{"SwipeView.qml", NULL, 13, sizeof(SwipeView), true},
{"Switch.qml", NULL, 10, sizeof(Switch), true},

};

const Qul::Private::ModuleResource *module_qml_resources = module_qml_resources_data;
int module_qml_resources_count = 9;


struct LoaderItemAppRelativePathCallbackItemData {
    LoaderItemAppRelativePathCallbackItemData()
        : item(NULL)
    {
    }

    Qul::Private::Items::ItemBase *item;
};

static bool loaderItemAppRelativePathCallback(const Qul::Private::String &relativePath, void *data)
{
    LoaderItemAppRelativePathCallbackItemData *d = static_cast<LoaderItemAppRelativePathCallbackItemData *>(data);


    for (int i = 0; i < module_qml_resources_count; ++i) {
        const Qul::Private::ModuleResource &r = module_qml_resources[i];
        if (relativePath == Qul::Private::String(r.url, r.urlLength)) {
            if (r.nonVisualItemBaseType != NULL) {
                Qul::PlatformInterface::log("[Loader Error] Failed to load nonvisual item '%s' in '%s'."
                                        " Wrap '%s' in 'Item' item.\n", r.nonVisualItemBaseType, r.url, r.nonVisualItemBaseType);
                return false;
            }
            Qul::PlatformInterface::MemoryAllocator *allocator = Qul::Platform::getPlatformInstance()->memoryAllocator(Qul::PlatformInterface::MemoryAllocator::QmlDynamicObjects);
            Qul::Private::Items::ItemBase *element = static_cast<Qul::Private::Items::ItemBase *>(allocator->allocate(r.qmlComponentSize));
            if (!element) return false;
            switch (i) {
            case 0: new (element) Button; break;
            case 1: new (element) CheckBox; break;
            case 3: new (element) Dial; break;
            case 4: new (element) ProgressBar; break;
            case 5: new (element) RadioButton; break;
            case 6: new (element) Slider; break;
            case 7: new (element) SwipeView; break;
            case 8: new (element) Switch; break;

            default: Qul::PlatformInterface::log("failed to contruct item: %s\n", r.url);
            }
            d->item = element;
        }
    }


    if (!d->item) {
        Qul::PlatformInterface::log("failed to load item from: %s\n", relativePath.maybeUtf8());
    }
    return d->item ? true : false;
}

Qul::Private::Items::ItemBase *loaderItemAllocator(const Qul::Private::String &uri, const Qul::Private::String &currentFileDir)
{
    if (uri.isEmpty())
        return NULL;

    LoaderItemAppRelativePathCallbackItemData loaderData;

    bool ok = Qul::Private::appRelativePath(uri, currentFileDir, loaderItemAppRelativePathCallback, &loaderData);
    QUL_UNUSED(ok);

    return loaderData.item;
}

} // namespace QtQuick
} // namespace Controls
} // namespace StyleDefault
