blob: 3c316cc01598935d2d46efd1cb4f3df01a4151fc [file] [log] [blame]
Ian Rogersc7dd2952014-10-21 23:31:19 -07001/*
2 * Copyright (C) 2011 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_DUMPABLE_H_
18#define ART_RUNTIME_BASE_DUMPABLE_H_
19
20#include "base/macros.h"
21
22namespace art {
23
24// A convenience to allow any class with a "Dump(std::ostream& os)" member function
25// but without an operator<< to be used as if it had an operator<<. Use like this:
26//
27// os << Dumpable<MyType>(my_type_instance);
28//
29template<typename T>
30class Dumpable FINAL {
31 public:
32 explicit Dumpable(const T& value) : value_(value) {
33 }
34
35 void Dump(std::ostream& os) const {
36 value_.Dump(os);
37 }
38
39 private:
40 const T& value_;
41
42 DISALLOW_COPY_AND_ASSIGN(Dumpable);
43};
44
45template<typename T>
46std::ostream& operator<<(std::ostream& os, const Dumpable<T>& rhs) {
47 rhs.Dump(os);
48 return os;
49}
50
51} // namespace art
52
53#endif // ART_RUNTIME_BASE_DUMPABLE_H_