C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
attr-value.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2023 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_ATTR_VALUE_H
17#define SIMICS_ATTR_VALUE_H
18
19#include <simics/base/attr-value.h>
20
21#include <utility>
22
23namespace simics {
24
25/*
26 * RAII class holding a Simics attr_value_t
27 *
28 * Construct the class from Simics API call which returns
29 * a attr_value_t, e.g, SIM_get_attribute, SIM_attr_copy.
30 * When desctructed, it frees the memory allocation used by
31 * the attr_value_t.
32 */
33class AttrValue {
34 public:
35 explicit AttrValue(attr_value_t &&attr) : attr_(std::move(attr)) {}
36
37 AttrValue(const AttrValue&) = delete;
38 AttrValue& operator=(const AttrValue &) = delete;
39 AttrValue(AttrValue &&rhs) noexcept : attr_(std::move(rhs.attr_)) {
40 rhs.attr_.private_kind = Sim_Val_Invalid;
41 }
42 AttrValue &operator=(AttrValue &&rhs) noexcept {
43 if (this != &rhs) {
44 SIM_attr_free(&attr_);
45 attr_ = std::move(rhs.attr_);
46 rhs.attr_.private_kind = Sim_Val_Invalid;
47 }
48 return *this;
49 }
51 SIM_attr_free(&attr_);
52 }
53
54 operator attr_value_t &() { return attr_; }
55
56 // Assignment operator from rvalue attr_value_t
57 AttrValue &operator=(attr_value_t &&rhs) noexcept {
58 SIM_attr_free(&attr_);
59 attr_ = std::move(rhs);
60 rhs.private_kind = Sim_Val_Invalid;
61 return *this;
62 }
63
64 private:
65 attr_value_t attr_;
66};
67
68} // namespace simics
69
70
71#endif
Definition: attr-value.h:33
~AttrValue()
Definition: attr-value.h:50
AttrValue(const AttrValue &)=delete
AttrValue(attr_value_t &&attr)
Definition: attr-value.h:35
AttrValue & operator=(attr_value_t &&rhs) noexcept
Definition: attr-value.h:57
AttrValue & operator=(const AttrValue &)=delete
AttrValue(AttrValue &&rhs) noexcept
Definition: attr-value.h:39
AttrValue & operator=(AttrValue &&rhs) noexcept
Definition: attr-value.h:42
Definition: after-bank.h:33
Definition: common-types.h:66