LibreOffice Module unoidl (master) 1
sourcefileprovider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <sal/config.h>
11
12#include <map>
13#include <utility>
14#include <vector>
15
18
19namespace unoidl::detail {
20
21namespace {
22
23class Cursor: public MapCursor {
24public:
25 explicit Cursor(std::map< OUString, rtl::Reference<Entity> > const & map):
27 {}
28
29private:
30 virtual ~Cursor() noexcept override {}
31
32 virtual rtl::Reference< Entity > getNext(OUString * name) override;
33
34 std::map< OUString, rtl::Reference<Entity> > const & map_; //TODO: extent
35 std::map< OUString, rtl::Reference<Entity> >::const_iterator iterator_;
36};
37
38rtl::Reference< Entity > Cursor::getNext(OUString * name) {
39 assert(name != nullptr);
41 if (iterator_ != map_.end()) {
42 *name = iterator_->first;
43 ent = iterator_->second;
44 ++iterator_;
45 }
46 return ent;
47}
48
49class Module: public ModuleEntity {
50public:
51 Module() {}
52
53 std::map< OUString, rtl::Reference<Entity> > map;
54
55private:
56 virtual ~Module() noexcept override {}
57
58 virtual std::vector<OUString> getMemberNames() const override;
59
60 virtual rtl::Reference<MapCursor> createCursor() const override
61 { return new Cursor(map); }
62};
63
64std::vector<OUString> Module::getMemberNames() const {
65 std::vector<OUString> names;
66 for (auto & i: map) {
67 names.push_back(i.first);
68 }
69 return names;
70}
71
72}
73
75 rtl::Reference<Manager> const & manager, OUString const & uri)
76{
78 if (!parse(uri, &data)) {
79 throw NoSuchFileException(uri);
80 }
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));
88 if (j == -1) {
89 map->insert(std::make_pair(id, i.second.entity));
90 break;
91 }
92 std::map< OUString, rtl::Reference<Entity> >::const_iterator k(
93 map->find(id));
94 if (k == map->end()) {
95 k = map->insert(std::make_pair(id, new Module)).first;
96 }
97 Module& mod = dynamic_cast<Module&>(*k->second);
98 map = &mod.map;
99 }
100 }
101 }
102}
103
105 return new Cursor(rootMap_);
106}
107
109 const
110{
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(
115 map->find(id));
116 if (j == map->end()) {
117 return rtl::Reference<Entity>();
118 }
119 if (i == -1) {
120 return j->second;
121 }
122 if (j->second->getSort() != Entity::SORT_MODULE) {
123 return rtl::Reference<Entity>();
124 }
125 Module * mod = dynamic_cast< Module * >(j->second.get());
126 assert(mod != nullptr);
127 map = &mod->map;
128 }
129}
130
132
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~SourceFileProvider() noexcept override
virtual rtl::Reference< MapCursor > createRootCursor() const override
SourceFileProvider(rtl::Reference< Manager > const &manager, OUString const &uri)
std::map< OUString, rtl::Reference< Entity > > rootMap_
virtual rtl::Reference< Entity > findEntity(OUString const &name) const override
rtl::Reference< ParseManager > manager
const char * name
int i
enumrange< T >::Iterator begin(enumrange< T >)
bool parse(OUString const &uri, SourceProviderScannerData *data)
std::map< OUString, rtl::Reference< Entity > >::const_iterator iterator_
std::map< OUString, rtl::Reference< Entity > > map
std::map< OUString, rtl::Reference< Entity > > const & map_
std::map< OUString, SourceProviderEntity > entities