/src/libreoffice/unoidl/source/sourcefileprovider.cxx
Line | Count | Source |
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 | | |
16 | | #include "sourcefileprovider.hxx" |
17 | | #include "sourceprovider-scanner.hxx" |
18 | | |
19 | | namespace unoidl::detail { |
20 | | |
21 | | namespace { |
22 | | |
23 | | class Cursor: public MapCursor { |
24 | | public: |
25 | | explicit Cursor(std::map< OUString, rtl::Reference<Entity> > const & map): |
26 | 0 | map_(map), iterator_(map_.begin()) |
27 | 0 | {} |
28 | | |
29 | | private: |
30 | 0 | 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 | | |
38 | 0 | rtl::Reference< Entity > Cursor::getNext(OUString * name) { |
39 | 0 | assert(name != nullptr); |
40 | 0 | rtl::Reference< Entity > ent; |
41 | 0 | if (iterator_ != map_.end()) { |
42 | 0 | *name = iterator_->first; |
43 | 0 | ent = iterator_->second; |
44 | 0 | ++iterator_; |
45 | 0 | } |
46 | 0 | return ent; |
47 | 0 | } |
48 | | |
49 | | class Module: public ModuleEntity { |
50 | | public: |
51 | 0 | Module() {} |
52 | | |
53 | | std::map< OUString, rtl::Reference<Entity> > map; |
54 | | |
55 | | private: |
56 | 0 | virtual ~Module() noexcept override {} |
57 | | |
58 | | virtual std::vector<OUString> getMemberNames() const override; |
59 | | |
60 | | virtual rtl::Reference<MapCursor> createCursor() const override |
61 | 0 | { return new Cursor(map); } |
62 | | }; |
63 | | |
64 | 0 | std::vector<OUString> Module::getMemberNames() const { |
65 | 0 | std::vector<OUString> names; |
66 | 0 | for (auto & i: map) { |
67 | 0 | names.push_back(i.first); |
68 | 0 | } |
69 | 0 | return names; |
70 | 0 | } |
71 | | |
72 | | } |
73 | | |
74 | | SourceFileProvider::SourceFileProvider( |
75 | | rtl::Reference<Manager> const & manager, OUString const & uri) |
76 | 0 | { |
77 | 0 | SourceProviderScannerData data(manager); |
78 | 0 | if (!parse(uri, &data)) { |
79 | 0 | throw NoSuchFileException(uri); |
80 | 0 | } |
81 | 0 | for (auto & i: data.entities) { |
82 | 0 | if (i.second.kind == SourceProviderEntity::KIND_LOCAL) { |
83 | 0 | assert(i.second.entity.is()); |
84 | 0 | assert(i.second.entity->getSort() != Entity::SORT_MODULE); |
85 | 0 | std::map< OUString, rtl::Reference<Entity> > * map = &rootMap_; |
86 | 0 | for (sal_Int32 j = 0;;) { |
87 | 0 | OUString id(i.first.getToken(0, '.', j)); |
88 | 0 | if (j == -1) { |
89 | 0 | map->insert(std::make_pair(id, i.second.entity)); |
90 | 0 | break; |
91 | 0 | } |
92 | 0 | std::map< OUString, rtl::Reference<Entity> >::const_iterator k( |
93 | 0 | map->find(id)); |
94 | 0 | if (k == map->end()) { |
95 | 0 | k = map->insert(std::make_pair(id, new Module)).first; |
96 | 0 | } |
97 | 0 | Module& mod = dynamic_cast<Module&>(*k->second); |
98 | 0 | map = &mod.map; |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } |
102 | 0 | } |
103 | | |
104 | 0 | rtl::Reference<MapCursor> SourceFileProvider::createRootCursor() const { |
105 | 0 | return new Cursor(rootMap_); |
106 | 0 | } |
107 | | |
108 | | rtl::Reference<Entity> SourceFileProvider::findEntity(OUString const & name) |
109 | | const |
110 | 0 | { |
111 | 0 | std::map< OUString, rtl::Reference<Entity> > const * map = &rootMap_; |
112 | 0 | for (sal_Int32 i = 0;;) { |
113 | 0 | OUString id(name.getToken(0, '.', i)); |
114 | 0 | std::map< OUString, rtl::Reference<Entity> >::const_iterator j( |
115 | 0 | map->find(id)); |
116 | 0 | if (j == map->end()) { |
117 | 0 | return rtl::Reference<Entity>(); |
118 | 0 | } |
119 | 0 | if (i == -1) { |
120 | 0 | return j->second; |
121 | 0 | } |
122 | 0 | if (j->second->getSort() != Entity::SORT_MODULE) { |
123 | 0 | return rtl::Reference<Entity>(); |
124 | 0 | } |
125 | 0 | Module * mod = dynamic_cast< Module * >(j->second.get()); |
126 | 0 | assert(mod != nullptr); |
127 | 0 | map = &mod->map; |
128 | 0 | } |
129 | 0 | } |
130 | | |
131 | 0 | SourceFileProvider::~SourceFileProvider() noexcept {} |
132 | | |
133 | | } |
134 | | |
135 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |