LCOV - code coverage report
Current view: top level - unoidl/source - sourcefileprovider.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 62 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 { namespace detail {
      20             : 
      21             : namespace {
      22             : 
      23             : class Cursor: public MapCursor {
      24             : public:
      25           0 :     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() throw () {}
      31             : 
      32             :     virtual rtl::Reference< Entity > getNext(OUString * name) SAL_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             :     assert(name != 0);
      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             :     }
      46           0 :     return ent;
      47             : }
      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() throw () {}
      57             : 
      58             :     virtual std::vector<rtl::OUString> getMemberNames() const SAL_OVERRIDE;
      59             : 
      60           0 :     virtual rtl::Reference<MapCursor> createCursor() const SAL_OVERRIDE
      61           0 :     { return new Cursor(map); }
      62             : };
      63             : 
      64           0 : std::vector<rtl::OUString> Module::getMemberNames() const {
      65           0 :     std::vector<rtl::OUString> names;
      66           0 :     for (std::map< OUString, rtl::Reference<Entity> >::const_iterator i(
      67           0 :              map.begin());
      68           0 :          i != map.end(); ++i)
      69             :     {
      70           0 :         names.push_back(i->first);
      71             :     }
      72           0 :     return names;
      73             : }
      74             : 
      75             : }
      76             : 
      77           0 : SourceFileProvider::SourceFileProvider(
      78           0 :     rtl::Reference<Manager> const & manager, OUString const & uri)
      79             : {
      80           0 :     SourceProviderScannerData data(manager);
      81           0 :     if (!parse(uri, &data)) {
      82           0 :         throw NoSuchFileException(uri);
      83             :     }
      84           0 :     for (std::map<OUString, SourceProviderEntity>::iterator i(
      85           0 :              data.entities.begin());
      86           0 :          i != data.entities.end(); ++i)
      87             :     {
      88           0 :         if (i->second.kind == SourceProviderEntity::KIND_LOCAL) {
      89             :             assert(i->second.entity.is());
      90             :             assert(i->second.entity->getSort() != Entity::SORT_MODULE);
      91           0 :             std::map< OUString, rtl::Reference<Entity> > * map = &rootMap_;
      92           0 :             for (sal_Int32 j = 0;;) {
      93           0 :                 OUString id(i->first.getToken(0, '.', j));
      94           0 :                 if (j == -1) {
      95           0 :                     map->insert(std::make_pair(id, i->second.entity));
      96           0 :                     break;
      97             :                 }
      98             :                 std::map< OUString, rtl::Reference<Entity> >::const_iterator k(
      99           0 :                     map->find(id));
     100           0 :                 if (k == map->end()) {
     101           0 :                     k = map->insert(std::make_pair(id, new Module)).first;
     102             :                 }
     103           0 :                 Module * mod = dynamic_cast< Module * >(k->second.get());
     104             :                 assert(mod != 0);
     105           0 :                 map = &mod->map;
     106           0 :             }
     107             :         }
     108           0 :     }
     109           0 : }
     110             : 
     111           0 : rtl::Reference<MapCursor> SourceFileProvider::createRootCursor() const {
     112           0 :     return new Cursor(rootMap_);
     113             : }
     114             : 
     115           0 : rtl::Reference<Entity> SourceFileProvider::findEntity(OUString const & name)
     116             :     const
     117             : {
     118           0 :     std::map< OUString, rtl::Reference<Entity> > const * map = &rootMap_;
     119           0 :     for (sal_Int32 i = 0;;) {
     120           0 :         OUString id(name.getToken(0, '.', i));
     121             :         std::map< OUString, rtl::Reference<Entity> >::const_iterator j(
     122           0 :             map->find(id));
     123           0 :         if (j == map->end()) {
     124           0 :             return rtl::Reference<Entity>();
     125             :         }
     126           0 :         if (i == -1) {
     127           0 :             return j->second;
     128             :         }
     129           0 :         if (j->second->getSort() != Entity::SORT_MODULE) {
     130           0 :             return rtl::Reference<Entity>();
     131             :         }
     132           0 :         Module * mod = dynamic_cast< Module * >(j->second.get());
     133             :         assert(mod != 0);
     134           0 :         map = &mod->map;
     135           0 :     }
     136             : }
     137             : 
     138           0 : SourceFileProvider::~SourceFileProvider() throw () {}
     139             : 
     140             : } }
     141             : 
     142             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10