Android-cuttlefish cvd tool
stack_trace_entry.h
Go to the documentation of this file.
1//
2// Copyright (C) 2022 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#pragma once
17
18#include <unistd.h>
19
20#include <source_location>
21#include <sstream>
22#include <string>
23#include <utility>
24
25namespace cuttlefish {
26
28 public:
30 std::source_location location = std::source_location::current());
31
32 StackTraceEntry(std::string expression, std::source_location location =
33 std::source_location::current());
34
35 StackTraceEntry(const StackTraceEntry& other);
36
40
41 template <typename T>
42 StackTraceEntry& operator<<(T&& message_ext) & {
43 message_ << std::forward<T>(message_ext);
44 return *this;
45 }
46 template <typename T>
47 StackTraceEntry operator<<(T&& message_ext) && {
48 message_ << std::forward<T>(message_ext);
49 return std::move(*this);
50 }
51
52 bool HasMessage() const;
53 const std::string& Expression() const;
54 const std::source_location& Location() const;
55 std::string Message() const;
56
57 private:
58 std::string expression_;
59 std::source_location location_;
60 std::stringstream message_;
61};
62
63} // namespace cuttlefish
Definition: stack_trace_entry.h:27
StackTraceEntry(std::source_location location=std::source_location::current())
Definition: stack_trace_entry.cc:27
std::source_location location_
Definition: stack_trace_entry.h:59
StackTraceEntry & operator=(const StackTraceEntry &other)
Definition: stack_trace_entry.cc:39
StackTraceEntry operator<<(T &&message_ext) &&
Definition: stack_trace_entry.h:47
const std::string & Expression() const
Definition: stack_trace_entry.cc:47
std::stringstream message_
Definition: stack_trace_entry.h:60
bool HasMessage() const
Definition: stack_trace_entry.cc:46
StackTraceEntry & operator=(StackTraceEntry &&)=default
const std::source_location & Location() const
Definition: stack_trace_entry.cc:48
std::string Message() const
Definition: stack_trace_entry.cc:51
std::string expression_
Definition: stack_trace_entry.h:58
StackTraceEntry(StackTraceEntry &&)=default
StackTraceEntry & operator<<(T &&message_ext) &
Definition: stack_trace_entry.h:42
Definition: alloc_driver.h:21