PageRenderTime 31ms CodeModel.GetById 16ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/thirdparty/breakpad/processor/static_contained_range_map.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 96 lines | 23 code | 13 blank | 60 comment | 0 complexity | d934956723a6e613d39790393654f6b1 MD5 | raw file
 1// Copyright (c) 2010, Google Inc.
 2// All rights reserved.
 3//
 4// Redistribution and use in source and binary forms, with or without
 5// modification, are permitted provided that the following conditions are
 6// met:
 7//
 8//     * Redistributions of source code must retain the above copyright
 9// notice, this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14//     * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// static_contained_range_map.h: StaticContainedRangeMap.
31//
32// StaticContainedRangeMap is similar to ContainedRangeMap.  However,
33// StaticContainedRangeMap wraps a StaticMap instead of std::map, and does not
34// support dynamic operations like StoreRange(...).
35// StaticContainedRangeMap provides same RetrieveRange(...) interfaces as
36// ContainedRangeMap.
37//
38// Please see contained_range_map.h for more documentation.
39//
40// Author: Siyang Xie (lambxsy@google.com)
41
42#ifndef PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__
43#define PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__
44
45#include "processor/static_map-inl.h"
46
47namespace google_breakpad {
48
49template<typename AddressType, typename EntryType>
50class StaticContainedRangeMap {
51 public:
52  StaticContainedRangeMap(): base_(), entry_size_(), entry_ptr_(), map_() { }
53  explicit StaticContainedRangeMap(const char *base);
54
55  // Retrieves the most specific (smallest) descendant range encompassing
56  // the specified address.  This method will only return entries held by
57  // child ranges, and not the entry contained by |this|.  This is necessary
58  // to support a sparsely-populated root range.  If no descendant range
59  // encompasses the address, returns false.
60  bool RetrieveRange(const AddressType &address, const EntryType *&entry) const;
61
62 private:
63  friend class ModuleComparer;
64  // AddressToRangeMap stores pointers.  This makes reparenting simpler in
65  // StoreRange, because it doesn't need to copy entire objects.
66  typedef StaticContainedRangeMap* SelfPtr;
67  typedef
68  StaticMap<AddressType, StaticContainedRangeMap> AddressToRangeMap;
69  typedef typename AddressToRangeMap::const_iterator MapConstIterator;
70
71  // The base address of this range.  The high address does not need to
72  // be stored, because it is used as the key to an object in its parent's
73  // map, and all ContainedRangeMaps except for the root range are contained
74  // within maps.  The root range does not actually contain an entry, so its
75  // base_ field is meaningless, and the fact that it has no parent and thus
76  // no key is unimportant.  For this reason, the base_ field should only be
77  // is accessed on child ContainedRangeMap objects, and never on |this|.
78  AddressType base_;
79
80  // The entry corresponding to this range.  The root range does not
81  // actually contain an entry, so its entry_ field is meaningless.  For
82  // this reason, the entry_ field should only be accessed on child
83  // ContainedRangeMap objects, and never on |this|.
84  u_int32_t entry_size_;
85  const EntryType *entry_ptr_;
86
87  // The map containing child ranges, keyed by each child range's high
88  // address.  This is a pointer to avoid allocating map structures for
89  // leaf nodes, where they are not needed.
90  AddressToRangeMap map_;
91};
92
93}  // namespace google_breakpad
94
95
96#endif  // PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__