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 <typeinfo>
20#include <typeindex>
21#include <unordered_map>
22#include <unordered_set>
23#include <string>
24#include <set>
25#include <deque>
26#include <utility>
27#include <vector>
28#include <list>
29#include <map>
30#include <array>
31
32#include "conf-object.h"
33
34namespace simics {
35namespace detail {
36
37const std::unordered_map<std::type_index, const std::string> type_strs {
38 {std::type_index(typeid(bool)), "b"},
39 {std::type_index(typeid(char)), "i"},
40 {std::type_index(typeid(signed char)), "i"},
41 {std::type_index(typeid(unsigned char)), "i"},
42 {std::type_index(typeid(short)), "i"}, // NOLINT(runtime/int)
43 {std::type_index(typeid(unsigned short)), "i"}, // NOLINT(runtime/int)
44 {std::type_index(typeid(int)), "i"},
45 {std::type_index(typeid(unsigned int)), "i"},
46 {std::type_index(typeid(long int)), "i"}, // NOLINT(runtime/int)
47 {std::type_index(typeid(unsigned long int)), "i"}, // NOLINT(runtime/int)
48 {std::type_index(typeid(long long int)), "i"}, // NOLINT(runtime/int)
49 {std::type_index(typeid(unsigned long long int)), // NOLINT(runtime/int)
50 "i"},
51 {std::type_index(typeid(float)), "f"},
52 {std::type_index(typeid(double)), "f"},
53 {std::type_index(typeid(simics::ConfObjectRef)), "[os]|o|n"},
54 {std::type_index(typeid(std::string)), "s"},
55 {std::type_index(typeid(const char *)), "s|n"},
56 {std::type_index(typeid(attr_value_t)), "a"},
57};
58
59template <typename T>
61 static std::string f() { return type_strs.at(std::type_index(typeid(T))); }
62};
63
64} // namespace detail
65
66template <typename T>
67inline std::string attr_type_str() {
68 static_assert(!std::is_member_pointer<T>::value,
69 "Use Foo::bar instead of &Foo::bar");
70 static_assert(!std::is_function<T>::value,
71 "Function type is not supported");
73}
74
75namespace detail {
76
77template <typename X, typename Y>
78struct attr_type_str_helper<std::pair<X, Y>> {
79 static std::string f() {
80 return std::string("[") + attr_type_str<X>() + attr_type_str<Y>() + "]";
81 }
82};
83
84template <typename X, typename Y>
85struct attr_type_str_helper<std::map<X, Y>> {
86 static std::string f() {
87 return std::string("[") + attr_type_str<std::pair<X, Y>>() + "*]";
88 }
89};
90
91template <typename T, std::size_t N>
92struct attr_type_str_helper<std::array<T, N>> {
93 static std::string f() {
94 return std::string("[") + attr_type_str<T>() + "{" \
95 + std::to_string(N) + "}]";
96 }
97};
98
99template <typename T>
101 static std::string f() {
102 return std::string("[") + attr_type_str<typename T::value_type>() + \
103 "*]";
104 }
105};
106
107#define _ATTR_LIST_TYPE_STR_HELPER(type) \
108 template <typename T> \
109 struct attr_type_str_helper<type<T>> : \
110 attr_list_type_str_helper<type<T>> {};
111
115_ATTR_LIST_TYPE_STR_HELPER(std::unordered_set)
117#undef _ATTR_LIST_TYPE_STR_HELPER
118
119// Special handling for Simics data type
120template <>
121struct attr_type_str_helper< std::vector<uint8> > {
122 static std::string f() {
123 return "d";
124 }
125};
126
127} // namespace detail
128} // namespace simics
129
130#endif
#define _ATTR_LIST_TYPE_STR_HELPER(type)
Definition: attribute-type-string.h:107
Represents Simics C type conf_object_t.
Definition: conf-object.h:37
const std::unordered_map< std::type_index, const std::string > type_strs
Definition: attribute-type-string.h:37
Definition: attr-value.h:23
std::string attr_type_str()
Definition: attribute-type-string.h:67
Definition: common-types.h:63
Definition: attribute-type-string.h:100
static std::string f()
Definition: attribute-type-string.h:101
static std::string f()
Definition: attribute-type-string.h:93
static std::string f()
Definition: attribute-type-string.h:86
static std::string f()
Definition: attribute-type-string.h:79
static std::string f()
Definition: attribute-type-string.h:122
Definition: attribute-type-string.h:60
static std::string f()
Definition: attribute-type-string.h:61