LCOV - code coverage report
Current view: top level - libreoffice/autodoc/source/ary/inc - nametreenode.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 38 38 100.0 %
Date: 2012-12-27 Functions: 26 28 92.9 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef ARY_NAMETREENODE_HXX
      21             : #define ARY_NAMETREENODE_HXX
      22             : //  KORR_DEPRECATED_3.0
      23             : //      Replace by ::ary::symtree::Node.
      24             : 
      25             : // USED SERVICES
      26             : #include <cosv/tpl/tpltools.hxx>
      27             : #include <sci_impl.hxx>
      28             : // HACK because of SunPro 5.2 compiler bug with templates:
      29             : #include <ary/idl/i_module.hxx>
      30             : 
      31             : 
      32             : 
      33             : 
      34             : namespace ary
      35             : {
      36             : 
      37             : 
      38             : /** Implementation of a node in a namespace-tree.
      39             : */
      40             : template<class ITEM_ID>
      41             : class NameTreeNode
      42             : {
      43             :   public:
      44             :     typedef NameTreeNode                    self;
      45             :     typedef ITEM_ID                         item_id;
      46             :     typedef StringVector::const_iterator    name_iterator;
      47             :     typedef std::map<String, item_id>       Map_LocalNames;
      48             : 
      49             :     // LIFECYCLE
      50             :                         NameTreeNode();
      51             :                         NameTreeNode(
      52             :                             const String &      i_sName,
      53             :                             const self &        i_rParent,
      54             :                             ITEM_ID             i_nParentId );
      55             :     virtual             ~NameTreeNode();
      56             : 
      57             :     // OPERATIONS
      58             :     void                Add_Name(
      59             :                             const String &      i_sName,
      60             :                             item_id             i_nId );
      61             :     // INQUIRY
      62      379901 :     const String &      Name() const            { return Depth() > 0 ? aCompleteNameChain.back() : String::Null_(); }
      63      846868 :     item_id             Parent() const          { return nParent; }
      64      384708 :     intt                Depth() const           { return aCompleteNameChain.size(); }
      65             : 
      66             :     bool                IsEquivalent(
      67             :                             const NameTreeNode &
      68             :                                                 i_rNode ) const;
      69        7448 :     name_iterator       NameChain_Begin() const { return aCompleteNameChain.begin(); }
      70        7678 :     name_iterator       NameChain_End() const   { return aCompleteNameChain.end(); }
      71             : 
      72             :     item_id             Search_Name(
      73             :                             const String &      i_sName ) const;
      74             :     void                Get_Names(
      75             :                             Dyn_StdConstIterator<ITEM_ID> &
      76             :                                                 o_rResult ) const;
      77             :     const Map_LocalNames &
      78      161704 :                         LocalNames() const      { return aLocalNames; }
      79             :   private:
      80             :     // Locals
      81        8970 :     Map_LocalNames &    LocalNames()            { return aLocalNames; }
      82             : 
      83             :     // DATA
      84             :     Map_LocalNames      aLocalNames;
      85             :     StringVector        aCompleteNameChain;
      86             :     item_id             nParent;
      87             : };
      88             : 
      89             : 
      90             : 
      91             : 
      92             : // IMPLEMENTATION
      93             : template<class ITEM_ID>
      94         113 : NameTreeNode<ITEM_ID>::NameTreeNode()
      95             :     :   aLocalNames(),
      96             :         aCompleteNameChain(),
      97         113 :         nParent(0)
      98             : {
      99         113 : }
     100             : 
     101             : template<class ITEM_ID>
     102        1107 : NameTreeNode<ITEM_ID>::NameTreeNode( const String &      i_sName,
     103             :                                      const self &        i_rParent,
     104             :                                      ITEM_ID             i_nParentId )
     105             :     :   aLocalNames(),
     106             :         aCompleteNameChain(),
     107        1107 :         nParent(i_nParentId)
     108             : {
     109        1107 :     aCompleteNameChain.reserve(i_rParent.Depth()+1);
     110        3936 :     for ( name_iterator it = i_rParent.NameChain_Begin();
     111             :           it != i_rParent.NameChain_End();
     112             :           ++it )
     113             :     {
     114        2829 :         aCompleteNameChain.push_back(*it);
     115             :     }
     116        1107 :     aCompleteNameChain.push_back(i_sName);
     117        1107 : }
     118             : 
     119             : template<class ITEM_ID>
     120         238 : NameTreeNode<ITEM_ID>::~NameTreeNode()
     121             : {
     122         238 : }
     123             : 
     124             : 
     125             : template<class ITEM_ID>
     126             : inline void
     127        8970 : NameTreeNode<ITEM_ID>::Add_Name( const String &      i_sName,
     128             :                                  item_id             i_nId )
     129             : {
     130        8970 :     LocalNames().insert( typename Map_LocalNames::value_type(i_sName, i_nId) );
     131        8970 : }
     132             : 
     133             : 
     134             : template<class ITEM_ID>
     135             : inline bool
     136             : NameTreeNode<ITEM_ID>::IsEquivalent( const NameTreeNode & i_rNode ) const
     137             : {
     138             :     return aCompleteNameChain == i_rNode.aCompleteNameChain;
     139             : }
     140             : 
     141             : template<class ITEM_ID>
     142             : inline ITEM_ID
     143      161347 : NameTreeNode<ITEM_ID>::Search_Name( const String & i_sName ) const
     144             : {
     145      161347 :     return csv::value_from_map(LocalNames(),i_sName, ITEM_ID(0));
     146             : }
     147             : 
     148             : template<class ITEM_ID>
     149             : inline void
     150         119 : NameTreeNode<ITEM_ID>::Get_Names( Dyn_StdConstIterator<ITEM_ID> & o_rResult ) const
     151             : {
     152         119 :     o_rResult = new SCI_DataInMap<String,item_id>(LocalNames());
     153         119 : }
     154             : 
     155             : 
     156             : // HACK because of SunPro 5.2 compiler bug with templates:
     157             : //   ary::idl::Module has to be "FIND_NODE::node_type"
     158             : //   must be solved later somehow.
     159             : template <class FIND_NODE>
     160             : typename FIND_NODE::id_type
     161       13355 : Search_SubTree( const ary::idl::Module &    i_rStart,
     162             :                 const FIND_NODE &           i_rNodeFinder )
     163             : {
     164             :     const ary::idl::Module *
     165       13355 :         ret = &i_rStart;
     166             : 
     167       33670 :     for ( StringVector::const_iterator  it = i_rNodeFinder.Begin();
     168             :           it != i_rNodeFinder.End() AND ret != 0;
     169             :           ++it )
     170             :     {
     171       20315 :         ret = i_rNodeFinder(ret->Search_Name(*it));
     172             :     }
     173             : 
     174       13355 :     typename FIND_NODE::id_type nret(0);
     175             :     return ret != 0
     176             :             ?   ret->Search_Name(i_rNodeFinder.Name2Search())
     177       13355 :             :   nret;
     178             : }
     179             : 
     180             : template <class  FIND_NODE>
     181             : typename FIND_NODE::id_type
     182        3386 : Search_SubTree_UpTillRoot( const ary::idl::Module &    i_rStart,
     183             :                            const FIND_NODE &           i_rNodeFinder )
     184             : {
     185             :     typename FIND_NODE::id_type
     186        3386 :         ret(0);
     187       16427 :     for ( const ary::idl::Module * start = &i_rStart;
     188             :           start != 0 AND NOT ret.IsValid();
     189             :           start = i_rNodeFinder(start->Owner()) )
     190             :     {
     191       13041 :         ret = Search_SubTree( *start,
     192             :                               i_rNodeFinder );
     193             :     }
     194        3386 :     return ret;
     195             : }
     196             : // END Hack for SunPro 5.2 compiler bug.
     197             : 
     198             : 
     199             : 
     200             : 
     201             : }   // namespace ary
     202             : #endif
     203             : 
     204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10