/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the Collabora Office project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <sal/config.h>

#include <cstddef>

#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <compbase2.hxx>
#include <rtl/ref.hxx>
#include <sal/types.h>

namespace com::sun::star {
    namespace reflection { class XTypeDescription; }
}
namespace unoidl {
    class ConstantGroupEntity;
    class Entity;
    class EnumTypeEntity;
    class Manager;
}

namespace cppuhelper {

typedef WeakComponentImplHelper2<
    css::lang::XServiceInfo, css::container::XHierarchicalNameAccess,
    css::container::XSet, css::reflection::XTypeDescriptionEnumerationAccess >
TypeManager_Base;

class TypeManager: public TypeManager_Base {
public:
    TypeManager();

    using TypeManager_Base::acquire;
    using TypeManager_Base::release;

    void init(std::u16string_view rdbUris);

    cpo::uno::Any find(OUString const & name);

    css::uno::Reference< css::reflection::XTypeDescription > resolve(
        OUString const & name);

private:
    virtual ~TypeManager() noexcept override;

    virtual OUString getImplementationName() override;

    virtual bool supportsService(OUString const & ServiceName) override;

    virtual cpo::uno::Sequence< OUString >
    getSupportedServiceNames() override;

    virtual cpo::uno::Any getByHierarchicalName(
        OUString const & aName) override;

    virtual bool hasByHierarchicalName(OUString const & aName) override;

    virtual cpo::uno::Type getElementType() override;

    virtual bool hasElements() override;

    virtual css::uno::Reference< css::container::XEnumeration >
    createEnumeration() override;

    virtual bool has(cpo::uno::Any const & aElement) override;

    virtual void insert(cpo::uno::Any const & aElement) override;

    virtual void remove(cpo::uno::Any const & aElement) override;

    virtual css::uno::Reference< css::reflection::XTypeDescriptionEnumeration >
    createTypeDescriptionEnumeration(
        OUString const & moduleName,
        cpo::uno::Sequence< cpo::uno::TypeClass > const & types,
        css::reflection::TypeDescriptionSearchDepth depth) override;

    void readRdbDirectory(std::u16string_view uri, bool optional);

    void readRdbFile(std::u16string_view uri, bool optional);

    cpo::uno::Any getSequenceType(OUString const & name);

    cpo::uno::Any getInstantiatedStruct(
        OUString const & name, sal_Int32 separator);

    cpo::uno::Any getInterfaceMember(
        std::u16string_view name, std::size_t separator);

    cpo::uno::Any getNamed(
        OUString const & name,
        rtl::Reference< unoidl::Entity > const & entity);

    static cpo::uno::Any getEnumMember(
        rtl::Reference< unoidl::EnumTypeEntity > const & entity,
        std::u16string_view member);

    static cpo::uno::Any getConstant(
        std::u16string_view constantGroupName,
        rtl::Reference< unoidl::ConstantGroupEntity > const & entity,
        std::u16string_view member);

    rtl::Reference< unoidl::Entity > findEntity(OUString const & name);

    rtl::Reference< unoidl::Manager > manager_;
};

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
