/thirdparty/breakpad/processor/address_map-inl.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 93 lines · 38 code · 15 blank · 40 comment · 5 complexity · ea88069423f83b008d8659f5298d38d5 MD5 · raw file

  1. // Copyright (c) 2006, 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. // address_map-inl.h: Address map implementation.
  30. //
  31. // See address_map.h for documentation.
  32. //
  33. // Author: Mark Mentovai
  34. #ifndef PROCESSOR_ADDRESS_MAP_INL_H__
  35. #define PROCESSOR_ADDRESS_MAP_INL_H__
  36. #include "processor/address_map.h"
  37. #include <assert.h>
  38. #include "processor/logging.h"
  39. namespace google_breakpad {
  40. template<typename AddressType, typename EntryType>
  41. bool AddressMap<AddressType, EntryType>::Store(const AddressType &address,
  42. const EntryType &entry) {
  43. // Ensure that the specified address doesn't conflict with something already
  44. // in the map.
  45. if (map_.find(address) != map_.end()) {
  46. BPLOG(INFO) << "Store failed, address " << HexString(address) <<
  47. " is already present";
  48. return false;
  49. }
  50. map_.insert(MapValue(address, entry));
  51. return true;
  52. }
  53. template<typename AddressType, typename EntryType>
  54. bool AddressMap<AddressType, EntryType>::Retrieve(
  55. const AddressType &address,
  56. EntryType *entry, AddressType *entry_address) const {
  57. BPLOG_IF(ERROR, !entry) << "AddressMap::Retrieve requires |entry|";
  58. assert(entry);
  59. // upper_bound gives the first element whose key is greater than address,
  60. // but we want the first element whose key is less than or equal to address.
  61. // Decrement the iterator to get there, but not if the upper_bound already
  62. // points to the beginning of the map - in that case, address is lower than
  63. // the lowest stored key, so return false.
  64. MapConstIterator iterator = map_.upper_bound(address);
  65. if (iterator == map_.begin())
  66. return false;
  67. --iterator;
  68. *entry = iterator->second;
  69. if (entry_address)
  70. *entry_address = iterator->first;
  71. return true;
  72. }
  73. template<typename AddressType, typename EntryType>
  74. void AddressMap<AddressType, EntryType>::Clear() {
  75. map_.clear();
  76. }
  77. } // namespace google_breakpad
  78. #endif // PROCESSOR_ADDRESS_MAP_INL_H__