SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2014 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_SYSTEMC_AWARENESS_LOG_H
17#define SIMICS_SYSTEMC_AWARENESS_LOG_H
18
19#include <simics/cc-api.h>
20
21#include <ostream> // NOLINT(readability/streams)
22#include <sstream>
23#include <string>
24
25namespace simics {
27// <add id="awareness/log.h">
28// <insert-until text="// EOF awareness/log.h"/></add>
29template<log_type_t Type = Sim_Log_Info,
30 unsigned Level = 1,
31 int Groups = 0>
32class LogStream : public std::ostream {
33 public:
34 explicit LogStream(ConfObjectRef log_obj)
35// EOF awareness/log.h
36 : std::ostream(&str_buf_), str_buf_(log_obj) {}
38 if (tellp() != std::streampos(0)) {
39 flush();
40 }
41 }
42
43 private:
44 class StrBuf : public std::stringbuf {
45 public:
46 explicit StrBuf(ConfObjectRef log_obj)
47 : std::stringbuf(ios_base::out),
48 log_obj_(log_obj.object()) {}
49
50 private:
51 int sync() {
52 std::string msg = str();
53 // trim trailing newline (and whitespace)
54 std::string::size_type pos = msg.find_last_not_of(" \t\n");
55 if (pos != msg.length() - 1) {
56 if (pos == std::string::npos) {
57 pos = -1;
58 }
59 msg.erase(pos + 1);
60 }
61
62 VT_log_message(log_obj_, Level, Groups, Type, msg.c_str());
63 msg.clear();
64 str(msg);
65 return std::stringbuf::sync();
66 }
67
68 conf_object_t *log_obj_;
69 };
70
71 StrBuf str_buf_;
72};
73
74} // namespace simics
75
76#endif
Output stream class using the Simics log API.
Definition: log.h:32
~LogStream()
Definition: log.h:37
LogStream(ConfObjectRef log_obj)
Definition: log.h:34
Definition: pci_bus_interface.h:24