Stylistic changes for RangeMap (#24). r=bryner

http://groups.google.com/group/airbag-dev/browse_thread/thread/97c378bd175ab7c0


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@25 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
mmentovai 2006-09-14 19:19:24 +00:00
parent 683c86e6c5
commit d9fb68c3e0
2 changed files with 41 additions and 47 deletions

View File

@ -32,9 +32,6 @@
namespace google_airbag {
using std::map;
template<typename AddressType, typename EntryType>
class RangeMap {
public:
@ -69,13 +66,12 @@ class RangeMap {
// be stored, because RangeMap uses it as the key to the map.
const AddressType base_;
// The entry, owned by the Range object.
// The entry corresponding to a range.
const EntryType entry_;
};
typedef map<AddressType, Range> AddressToRangeMap;
// Can't depend on implicit typenames in a template
// Convenience types.
typedef std::map<AddressType, Range> AddressToRangeMap;
typedef typename AddressToRangeMap::const_iterator const_iterator;
typedef typename AddressToRangeMap::value_type value_type;
@ -124,8 +120,7 @@ bool RangeMap<AddressType, EntryType>::StoreRange(const AddressType& base,
template<typename AddressType, typename EntryType>
bool RangeMap<AddressType, EntryType>::RetrieveRange(
const AddressType& address,
EntryType* entry) const {
const AddressType &address, EntryType *entry) const {
if (!entry)
return false;

View File

@ -17,9 +17,8 @@
// Author: Mark Mentovai
#include <stdio.h>
#include <climits>
#include <cstdio>
#include <memory>
#include "processor/range_map.h"
@ -33,7 +32,7 @@ using google_airbag::RangeMap;
// allocated CountedObjects is maintained to help test memory management.
class CountedObject {
public:
CountedObject(int id) : id_(id) { ++count_; }
explicit CountedObject(int id) : id_(id) { ++count_; }
CountedObject(const CountedObject &that) : id_(that.id_) { ++count_; }
~CountedObject() { --count_; }
@ -122,10 +121,10 @@ bool RetrieveTest(TestMap* range_map, const RangeTest* range_test) {
AddressType low_offset = -1;
AddressType high_offset = 1;
if (range_test->size == 1) {
if (!side) // when checking the low side,
high_offset = 0; // don't check one over the target
else // when checking the high side,
low_offset = 0; // don't check one under the target
if (!side) // When checking the low side,
high_offset = 0; // don't check one over the target.
else // When checking the high side,
low_offset = 0; // don't check one under the target.
}
for (AddressType offset = low_offset; offset <= high_offset; ++offset) {
@ -134,14 +133,14 @@ bool RetrieveTest(TestMap* range_map, const RangeTest* range_test) {
(!side ? range_test->address :
range_test->address + range_test->size - 1);
bool expected_result = false; // correct for tests not stored
bool expected_result = false; // This is correct for tests not stored.
if (range_test->expect_storable) {
if (offset == 0) // when checking target,
expected_result = true; // should always succeed
else if (offset == -1) // when checking one below target,
expected_result = side; // should fail low and succeed high
else // when checking one above target,
expected_result = !side; // should succeed low and fail high
if (offset == 0) // When checking the target address,
expected_result = true; // test should always succeed.
else if (offset == -1) // When checking one below the target,
expected_result = side; // should fail low and succeed high.
else // When checking one above the target,
expected_result = !side; // should succeed low and fail high.
}
CountedObject object(-1);