1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_BASE_HEX_DUMP_H_
18#define ART_RUNTIME_BASE_HEX_DUMP_H_
19
20#include "macros.h"
21
22#include <ostream>
23
24namespace art {
25
26// Prints a hex dump in this format:
27//
28// 01234560: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  0123456789abcdef
29// 01234568: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff  0123456789abcdef
30class HexDump {
31 public:
32  HexDump(const void* address, size_t byte_count, bool show_actual_addresses, const char* prefix)
33      : address_(address), byte_count_(byte_count), show_actual_addresses_(show_actual_addresses),
34        prefix_(prefix) {
35  }
36
37  void Dump(std::ostream& os) const;
38
39 private:
40  const void* const address_;
41  const size_t byte_count_;
42  const bool show_actual_addresses_;
43  const char* const prefix_;
44
45  DISALLOW_COPY_AND_ASSIGN(HexDump);
46};
47
48inline std::ostream& operator<<(std::ostream& os, const HexDump& rhs) {
49  rhs.Dump(os);
50  return os;
51}
52
53}  // namespace art
54
55#endif  // ART_RUNTIME_BASE_HEX_DUMP_H_
56