/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. // static_contained_range_map.h: StaticContainedRangeMap.
  30. //
  31. // StaticContainedRangeMap is similar to ContainedRangeMap. However,
  32. // StaticContainedRangeMap wraps a StaticMap instead of std::map, and does not
  33. // support dynamic operations like StoreRange(...).
  34. // StaticContainedRangeMap provides same RetrieveRange(...) interfaces as
  35. // ContainedRangeMap.
  36. //
  37. // Please see contained_range_map.h for more documentation.
  38. //
  39. // Author: Siyang Xie (lambxsy@google.com)
  40. #ifndef PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__
  41. #define PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__
  42. #include "processor/static_map-inl.h"
  43. namespace google_breakpad {
  44. template<typename AddressType, typename EntryType>
  45. class StaticContainedRangeMap {
  46. public:
  47. StaticContainedRangeMap(): base_(), entry_size_(), entry_ptr_(), map_() { }
  48. explicit StaticContainedRangeMap(const char *base);
  49. // Retrieves the most specific (smallest) descendant range encompassing
  50. // the specified address. This method will only return entries held by
  51. // child ranges, and not the entry contained by |this|. This is necessary
  52. // to support a sparsely-populated root range. If no descendant range
  53. // encompasses the address, returns false.
  54. bool RetrieveRange(const AddressType &address, const EntryType *&entry) const;
  55. private:
  56. friend class ModuleComparer;
  57. // AddressToRangeMap stores pointers. This makes reparenting simpler in
  58. // StoreRange, because it doesn't need to copy entire objects.
  59. typedef StaticContainedRangeMap* SelfPtr;
  60. typedef
  61. StaticMap<AddressType, StaticContainedRangeMap> AddressToRangeMap;
  62. typedef typename AddressToRangeMap::const_iterator MapConstIterator;
  63. // The base address of this range. The high address does not need to
  64. // be stored, because it is used as the key to an object in its parent's
  65. // map, and all ContainedRangeMaps except for the root range are contained
  66. // within maps. The root range does not actually contain an entry, so its
  67. // base_ field is meaningless, and the fact that it has no parent and thus
  68. // no key is unimportant. For this reason, the base_ field should only be
  69. // is accessed on child ContainedRangeMap objects, and never on |this|.
  70. AddressType base_;
  71. // The entry corresponding to this range. The root range does not
  72. // actually contain an entry, so its entry_ field is meaningless. For
  73. // this reason, the entry_ field should only be accessed on child
  74. // ContainedRangeMap objects, and never on |this|.
  75. u_int32_t entry_size_;
  76. const EntryType *entry_ptr_;
  77. // The map containing child ranges, keyed by each child range's high
  78. // address. This is a pointer to avoid allocating map structures for
  79. // leaf nodes, where they are not needed.
  80. AddressToRangeMap map_;
  81. };
  82. } // namespace google_breakpad
  83. #endif // PROCESSOR_STATIC_CONTAINED_RANGE_MAP_H__