LibreOffice Module configmgr (master)  1
nodemap.hxx
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  * 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 #pragma once
21 
22 #include <sal/config.h>
23 #include "config_map.hxx"
24 #include <rtl/ref.hxx>
25 #include "node.hxx"
26 
27 namespace configmgr {
28 
30 class NodeMap
31 {
32  NodeMapImpl maImpl;
33 
34  NodeMap(const NodeMap &rMap) = delete;
35 
36  public:
37  typedef NodeMapImpl::iterator iterator;
38  typedef NodeMapImpl::const_iterator const_iterator;
39  typedef NodeMapImpl::value_type value_type;
40 
42  bool empty() const { return maImpl.empty(); }
43  iterator find(const OUString &aStr) { return maImpl.find( aStr ); }
44 
45  const_iterator find(const OUString &aStr) const { return maImpl.find( aStr ); }
46  iterator begin() { return maImpl.begin(); }
47  const_iterator begin() const { return maImpl.begin(); }
48 
49  iterator end() { return maImpl.end(); }
50  const_iterator end() const { return maImpl.end(); }
51 
52  rtl::Reference<Node> &operator[](const OUString &aStr) { clearCache(); return maImpl[aStr]; }
53  std::pair<iterator,bool> insert(const value_type &vt) { clearCache(); return maImpl.insert(vt); }
54  void erase(const iterator &it) { maImpl.erase(it); clearCache(); }
55  void erase(const OUString &aStr) { maImpl.erase(aStr); clearCache(); }
56 
57  rtl::Reference< Node > findNode(int layer, OUString const & name) const;
58  void cloneInto(NodeMap * target) const;
59 
60 private:
61  // We get a large number of repeated identical lookups.
62  mutable const_iterator maCache;
63  void clearCache() { maCache = maImpl.end(); }
64 };
65 
66 }
67 
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
iterator find(const OUString &aStr)
Definition: nodemap.hxx:43
void cloneInto(NodeMap *target) const
Definition: nodemap.cxx:31
iterator begin()
Definition: nodemap.hxx:46
std::pair< iterator, bool > insert(const value_type &vt)
Definition: nodemap.hxx:53
const_iterator maCache
Definition: nodemap.hxx:62
const_iterator begin() const
Definition: nodemap.hxx:47
bool empty() const
Definition: nodemap.hxx:42
void erase(const iterator &it)
Definition: nodemap.hxx:54
config_map< rtl::Reference< Node > > NodeMapImpl
Definition: nodemap.hxx:29
NodeMapImpl::value_type value_type
Definition: nodemap.hxx:39
const_iterator find(const OUString &aStr) const
Definition: nodemap.hxx:45
NodeMapImpl::iterator iterator
Definition: nodemap.hxx:37
rtl::Reference< Node > & operator[](const OUString &aStr)
Definition: nodemap.hxx:52
void erase(const OUString &aStr)
Definition: nodemap.hxx:55
const_iterator end() const
Definition: nodemap.hxx:50
OUString name
Definition: components.cxx:83
NodeMapImpl maImpl
Definition: nodemap.hxx:32
iterator end()
Definition: nodemap.hxx:49
NodeMapImpl::const_iterator const_iterator
Definition: nodemap.hxx:38
rtl::Reference< Node > findNode(int layer, OUString const &name) const
Definition: nodemap.cxx:43