C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
conf-class.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2021 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_CONF_CLASS_H
17#define SIMICS_CONF_CLASS_H
18
19#include <simics/base/conf-object.h> // class_kind_t
20#include <simics/base/sim-exception.h> // SIM_clear_exception
21
22#include <string>
23#include <memory> // unique_ptr
24#include <vector>
25
26#include "object-factory.h"
28#include "attribute.h"
29#include "init-class.h"
30#include "log.h"
31#include "event.h"
32
33namespace simics {
34
35using ConfClassPtr = std::unique_ptr<ConfClass>;
36
41int array_index(const std::string &name);
42
50std::vector<std::string> expand_names(const std::string &name,
51 const char delimiter = '.');
52
62// coverity[rule_of_three_violation:FALSE]
63class ConfClass {
64 public:
65 virtual ~ConfClass();
66
68 ConfClass(const ConfClass&) = delete;
69 ConfClass& operator=(const ConfClass&) = delete;
70
82 const std::string &name,
83 const std::string &short_desc,
84 const std::string &description,
85 const class_kind_t kind,
86 const iface::ObjectFactoryInterface &factory);
87
91 operator conf_class_t*() const { return cls_; }
92
96 const std::string &name() const { return name_; }
97
101 const std::string &description() const { return description_; }
102
106 const std::vector<std::string> &log_groups() const { return log_groups_; }
107
117
125 ConfClass *add(const Attribute &attr);
126
139 ConfClass *add(const char * const *names);
140 ConfClass *add(const LogGroups &names);
141
154 ConfClass *add(ConfClass *port, const std::string &name);
155 ConfClass *add(const ConfClassPtr &port, const std::string &name);
156
165
166 protected:
168 explicit ConfClass(conf_class_t *cls, const std::string &name,
169 const std::string &description)
170 : cls_(cls), name_(name), description_(description) {}
171
172 private:
174 void register_log_groups() const noexcept;
175
176 conf_class_t *cls_;
177 std::string name_;
178 std::string description_;
179 std::vector<std::string> log_groups_;
180};
181
184template <typename T>
185void decorate_class(...) {}
186
199template <typename T> ConfClassPtr
200make_class(const std::string &name, const std::string &short_desc,
201 const std::string &description,
202 const class_kind_t kind = Sim_Class_Kind_Vanilla) {
203 auto cls = ConfClass::createInstance(name, short_desc, description, kind,
205 detail::init_class<T>(cls.get());
206 decorate_class<T>(nullptr, cls.get());
207 return cls;
208}
209
223template <typename T, typename A> ConfClassPtr
224make_class(const std::string &name, const std::string &short_desc,
225 const std::string &description, A *constructor_arg,
226 const class_kind_t kind = Sim_Class_Kind_Vanilla) {
227 auto cls = ConfClass::createInstance(name, short_desc, description, kind,
229 constructor_arg));
230 detail::init_class<T>(cls.get());
231 decorate_class<T>(nullptr, cls.get());
232 return cls;
233}
234
235} // namespace simics
236
237#endif
Represents a Simics attribute.
Definition: attribute.h:88
Represents Simics C type conf_class_t.
Definition: conf-class.h:63
ConfClass * add(ConfClass *port, const std::string &name)
A function to add a port object to the set of ports defined by the class.
ConfClass * add(const Attribute &attr)
A function to add an attribute to the set of attributes of ConfClass.
const std::string & name() const
Return the class name.
Definition: conf-class.h:96
const std::string & description() const
Return the class description.
Definition: conf-class.h:101
virtual ~ConfClass()
ConfClass(const ConfClass &)=delete
Avoid implicit copy.
ConfClass * add(EventInfo &&event)
A function to add an event to the set of events of ConfClass.
ConfClass * add(const iface::InterfaceInfo &iface)
A function to register that ConfClass implements the iface interface.
ConfClass(conf_class_t *cls, const std::string &name, const std::string &description)
Must use factory method to create instance.
Definition: conf-class.h:168
ConfClass * add(const ConfClassPtr &port, const std::string &name)
ConfClass * add(const LogGroups &names)
ConfClass * add(const char *const *names)
Functions to add log groups that an object can use to separate messages.
const std::vector< std::string > & log_groups() const
Return the class log groups.
Definition: conf-class.h:106
static ConfClassPtr createInstance(const std::string &name, const std::string &short_desc, const std::string &description, const class_kind_t kind, const iface::ObjectFactoryInterface &factory)
A function to create a ConfClass instance All parameters except the last one is used to call the Simi...
ConfClass & operator=(const ConfClass &)=delete
An object factory creates class T object with argument.
Definition: object-factory.h:49
An object factory creates class T object.
Definition: object-factory.h:29
Definition: interface-info.h:27
Definition: object-factory-interface.h:33
Definition: attr-value.h:23
std::initializer_list< std::string > LogGroups
Type used for log group names.
Definition: log.h:26
std::unique_ptr< ConfClass > ConfClassPtr
Definition: conf-class.h:35
std::vector< std::string > expand_names(const std::string &name, const char delimiter='.')
If name contains an array indicator, i.e.
void decorate_class(...)
Overload it with specific implementation by including the other header before this file.
Definition: conf-class.h:185
ConfClassPtr make_class(const std::string &name, const std::string &short_desc, const std::string &description, const class_kind_t kind=Sim_Class_Kind_Vanilla)
A factory method to create a ConfClassPtr which associate with the C++ class T.
Definition: conf-class.h:200
int array_index(const std::string &name)
Return the array index if name is using an array format like array[N].
Definition: common-types.h:63
Definition: event.h:46