bump product version to 5.0.4.1
[LibreOffice.git] / unoidl / source / sourcefileprovider.cxx
blobc73142dc83e35cfdb733d4b98c6ba376a40b62c2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "sal/config.h"
12 #include <map>
13 #include <utility>
14 #include <vector>
16 #include "sourcefileprovider.hxx"
17 #include "sourceprovider-scanner.hxx"
19 namespace unoidl { namespace detail {
21 namespace {
23 class Cursor: public MapCursor {
24 public:
25 explicit Cursor(std::map< OUString, rtl::Reference<Entity> > const & map):
26 map_(map), iterator_(map_.begin())
29 private:
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) {
39 assert(name != 0);
40 rtl::Reference< Entity > ent;
41 if (iterator_ != map_.end()) {
42 *name = iterator_->first;
43 ent = iterator_->second;
44 ++iterator_;
46 return ent;
49 class Module: public ModuleEntity {
50 public:
51 Module() {}
53 std::map< OUString, rtl::Reference<Entity> > map;
55 private:
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(
67 map.begin());
68 i != map.end(); ++i)
70 names.push_back(i->first);
72 return names;
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));
94 if (j == -1) {
95 map->insert(std::make_pair(id, i->second.entity));
96 break;
98 std::map< OUString, rtl::Reference<Entity> >::const_iterator k(
99 map->find(id));
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());
104 map = &mod.map;
110 rtl::Reference<MapCursor> SourceFileProvider::createRootCursor() const {
111 return new Cursor(rootMap_);
114 rtl::Reference<Entity> SourceFileProvider::findEntity(OUString const & name)
115 const
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(
121 map->find(id));
122 if (j == map->end()) {
123 return rtl::Reference<Entity>();
125 if (i == -1) {
126 return j->second;
128 if (j->second->getSort() != Entity::SORT_MODULE) {
129 return rtl::Reference<Entity>();
131 Module * mod = dynamic_cast< Module * >(j->second.get());
132 assert(mod != 0);
133 map = &mod->map;
137 SourceFileProvider::~SourceFileProvider() throw () {}
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */