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
{ namespace 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() throw () {}
32 virtual rtl::Reference
< Entity
> getNext(OUString
* name
) SAL_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
) {
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() throw () {}
58 virtual std::vector
<rtl::OUString
> getMemberNames() const SAL_OVERRIDE
;
60 virtual rtl::Reference
<MapCursor
> createCursor() const SAL_OVERRIDE
61 { return new Cursor(map
); }
64 std::vector
<rtl::OUString
> Module::getMemberNames() const {
65 std::vector
<rtl::OUString
> names
;
66 for (std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator
i(
70 names
.push_back(i
->first
);
77 SourceFileProvider::SourceFileProvider(
78 rtl::Reference
<Manager
> const & manager
, OUString
const & uri
)
80 SourceProviderScannerData
data(manager
);
81 if (!parse(uri
, &data
)) {
82 throw NoSuchFileException(uri
);
84 for (std::map
<OUString
, SourceProviderEntity
>::iterator
i(
85 data
.entities
.begin());
86 i
!= data
.entities
.end(); ++i
)
88 if (i
->second
.kind
== SourceProviderEntity::KIND_LOCAL
) {
89 assert(i
->second
.entity
.is());
90 assert(i
->second
.entity
->getSort() != Entity::SORT_MODULE
);
91 std::map
< OUString
, rtl::Reference
<Entity
> > * map
= &rootMap_
;
92 for (sal_Int32 j
= 0;;) {
93 OUString
id(i
->first
.getToken(0, '.', j
));
95 map
->insert(std::make_pair(id
, i
->second
.entity
));
98 std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator
k(
100 if (k
== map
->end()) {
101 k
= map
->insert(std::make_pair(id
, new Module
)).first
;
103 Module
& mod
= dynamic_cast<Module
&>(*k
->second
.get());
110 rtl::Reference
<MapCursor
> SourceFileProvider::createRootCursor() const {
111 return new Cursor(rootMap_
);
114 rtl::Reference
<Entity
> SourceFileProvider::findEntity(OUString
const & name
)
117 std::map
< OUString
, rtl::Reference
<Entity
> > const * map
= &rootMap_
;
118 for (sal_Int32 i
= 0;;) {
119 OUString
id(name
.getToken(0, '.', i
));
120 std::map
< OUString
, rtl::Reference
<Entity
> >::const_iterator
j(
122 if (j
== map
->end()) {
123 return rtl::Reference
<Entity
>();
128 if (j
->second
->getSort() != Entity::SORT_MODULE
) {
129 return rtl::Reference
<Entity
>();
131 Module
* mod
= dynamic_cast< Module
* >(j
->second
.get());
137 SourceFileProvider::~SourceFileProvider() throw () {}
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */