1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
16 #include "sourcefileprovider.hxx"
17 #include "sourceprovider-scanner.hxx"
19 namespace unoidl::detail
{
23 class Cursor
: public MapCursor
{
25 explicit Cursor(std::map
< OUString
, rtl::Reference
<Entity
> > const & map
):
26 map_(map
), iterator_(map_
.begin())
30 virtual ~Cursor() noexcept override
{}
32 virtual rtl::Reference
< Entity
> getNext(OUString
* name
) override
;
34 std::map
< OUString
, rtl::Reference
<Entity
> > const & map_
; //TODO: extent
35 std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator iterator_
;
38 rtl::Reference
< Entity
> Cursor::getNext(OUString
* name
) {
39 assert(name
!= nullptr);
40 rtl::Reference
< Entity
> ent
;
41 if (iterator_
!= map_
.end()) {
42 *name
= iterator_
->first
;
43 ent
= iterator_
->second
;
49 class Module
: public ModuleEntity
{
53 std::map
< OUString
, rtl::Reference
<Entity
> > map
;
56 virtual ~Module() noexcept override
{}
58 virtual std::vector
<OUString
> getMemberNames() const override
;
60 virtual rtl::Reference
<MapCursor
> createCursor() const override
61 { return new Cursor(map
); }
64 std::vector
<OUString
> Module::getMemberNames() const {
65 std::vector
<OUString
> names
;
67 names
.push_back(i
.first
);
74 SourceFileProvider::SourceFileProvider(
75 rtl::Reference
<Manager
> const & manager
, OUString
const & uri
)
77 SourceProviderScannerData
data(manager
);
78 if (!parse(uri
, &data
)) {
79 throw NoSuchFileException(uri
);
81 for (auto & i
: data
.entities
) {
82 if (i
.second
.kind
== SourceProviderEntity::KIND_LOCAL
) {
83 assert(i
.second
.entity
.is());
84 assert(i
.second
.entity
->getSort() != Entity::SORT_MODULE
);
85 std::map
< OUString
, rtl::Reference
<Entity
> > * map
= &rootMap_
;
86 for (sal_Int32 j
= 0;;) {
87 OUString
id(i
.first
.getToken(0, '.', j
));
89 map
->insert(std::make_pair(id
, i
.second
.entity
));
92 std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator
k(
94 if (k
== map
->end()) {
95 k
= map
->insert(std::make_pair(id
, new Module
)).first
;
97 Module
& mod
= dynamic_cast<Module
&>(*k
->second
);
104 rtl::Reference
<MapCursor
> SourceFileProvider::createRootCursor() const {
105 return new Cursor(rootMap_
);
108 rtl::Reference
<Entity
> SourceFileProvider::findEntity(OUString
const & name
)
111 std::map
< OUString
, rtl::Reference
<Entity
> > const * map
= &rootMap_
;
112 for (sal_Int32 i
= 0;;) {
113 OUString
id(name
.getToken(0, '.', i
));
114 std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator
j(
116 if (j
== map
->end()) {
117 return rtl::Reference
<Entity
>();
122 if (j
->second
->getSort() != Entity::SORT_MODULE
) {
123 return rtl::Reference
<Entity
>();
125 Module
* mod
= dynamic_cast< Module
* >(j
->second
.get());
126 assert(mod
!= nullptr);
131 SourceFileProvider::~SourceFileProvider() noexcept
{}
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */