C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
attribute-type-string.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_ATTRIBUTE_TYPE_STRING_H
17#define SIMICS_ATTRIBUTE_TYPE_STRING_H
18
19#include <array>
20#include <deque>
21#include <list>
22#include <map>
23#include <set>
24#include <string>
25#include <typeindex>
26#include <typeinfo>
27#include <tuple>
28#include <unordered_map>
29#include <unordered_set>
30#include <utility>
31#include <vector>
32
33#include "simics/conf-object.h"
34
35namespace simics {
36namespace detail {
37
38const std::unordered_map<std::type_index, const std::string> type_strs {
39 {std::type_index(typeid(bool)), "b"},
40 {std::type_index(typeid(char)), "i"},
41 {std::type_index(typeid(signed char)), "i"},
42 {std::type_index(typeid(unsigned char)), "i"},
43 {std::type_index(typeid(short)), "i"}, // NOLINT(runtime/int)
44 {std::type_index(typeid(unsigned short)), "i"}, // NOLINT(runtime/int)
45 {std::type_index(typeid(int)), "i"},
46 {std::type_index(typeid(unsigned int)), "i"},
47 {std::type_index(typeid(long int)), "i"}, // NOLINT(runtime/int)
48 {std::type_index(typeid(unsigned long int)), "i"}, // NOLINT(runtime/int)
49 {std::type_index(typeid(long long int)), "i"}, // NOLINT(runtime/int)
50 {std::type_index(typeid(unsigned long long int)), // NOLINT(runtime/int)
51 "i"},
52 {std::type_index(typeid(float)), "f"},
53 {std::type_index(typeid(double)), "f"},
54 {std::type_index(typeid(simics::ConfObjectRef)), "[os]|o|n"},
55 {std::type_index(typeid(std::string)), "s"},
56 {std::type_index(typeid(const char *)), "s|n"},
57 {std::type_index(typeid(attr_value_t)), "a"},
58};
59
60template <typename T>
62 static std::string f() { return type_strs.at(std::type_index(typeid(T))); }
63};
64
65} // namespace detail
66
67template <typename T>
68inline std::string attr_type_str() {
69 static_assert(!std::is_member_pointer<T>::value,
70 "Use Foo::bar instead of &Foo::bar");
71 static_assert(!std::is_function<T>::value,
72 "Function type is not supported");
74}
75
76namespace detail {
77
78template <typename X, typename Y>
79struct attr_type_str_helper<std::pair<X, Y>> {
80 static std::string f() {
81 return std::string("[") + attr_type_str<X>() + attr_type_str<Y>() + "]";
82 }
83};
84
85template <typename X, typename Y>
86struct attr_type_str_helper<std::map<X, Y>> {
87 static std::string f() {
88 return std::string("[") + attr_type_str<std::pair<X, Y>>() + "*]";
89 }
90};
91
92template <typename T, std::size_t N>
93struct attr_type_str_helper<std::array<T, N>> {
94 static std::string f() {
95 return std::string("[") + attr_type_str<T>() + "{" \
96 + std::to_string(N) + "}]";
97 }
98};
99
100template <typename... Args>
101struct attr_type_str_helper<std::tuple<Args...>> {
102 static std::string f() {
103 return "[" + type_str() + "]";
104 }
105
106 private:
107 // Function to get the concatenated type string
108 static std::string type_str() {
109 return concat_types<Args...>();
110 }
111
112 // Helper function to concatenate type strings
113 template <typename First, typename Second, typename ...Rest>
114 static std::string concat_types() {
115 return attr_type_str<First>() + concat_types<Second, Rest...>();
116 }
117
118 template <typename Last>
119 static std::string concat_types() {
120 return attr_type_str<Last>();
121 }
122};
123
124template <typename T>
126 static std::string f() {
127 return std::string("[") + attr_type_str<typename T::value_type>() + \
128 "*]";
129 }
130};
131
132#define _ATTR_LIST_TYPE_STR_HELPER(type) \
133 template <typename T> \
134 struct attr_type_str_helper<type<T>> : \
135 attr_list_type_str_helper<type<T>> {};
136
140_ATTR_LIST_TYPE_STR_HELPER(std::unordered_set)
142#undef _ATTR_LIST_TYPE_STR_HELPER
143
144// Special handling for Simics data type
145template <>
146struct attr_type_str_helper< std::vector<uint8> > {
147 static std::string f() {
148 return "d";
149 }
150};
151
152} // namespace detail
153} // namespace simics
154
155#endif
#define _ATTR_LIST_TYPE_STR_HELPER(type)
Definition: attribute-type-string.h:132
Represents Simics C type conf_object_t.
Definition: conf-object.h:38
const std::unordered_map< std::type_index, const std::string > type_strs
Definition: attribute-type-string.h:38
Definition: after-bank.h:33
std::string attr_type_str()
Definition: attribute-type-string.h:68
Definition: common-types.h:66
Definition: attribute-type-string.h:125
static std::string f()
Definition: attribute-type-string.h:126
static std::string f()
Definition: attribute-type-string.h:94
static std::string f()
Definition: attribute-type-string.h:87
static std::string f()
Definition: attribute-type-string.h:80
static std::string f()
Definition: attribute-type-string.h:102
static std::string f()
Definition: attribute-type-string.h:147
Definition: attribute-type-string.h:61
static std::string f()
Definition: attribute-type-string.h:62