SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
attr_dict_parser.h
Go to the documentation of this file.
1/*
2 © 2017 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_INJECTION_ATTR_DICT_PARSER_H
15#define SIMICS_SYSTEMC_INJECTION_ATTR_DICT_PARSER_H
16
18#include <simics/base/attr-value.h>
19#include <simics/base/log.h>
20
21#include <stdio.h>
22
23#include <map>
24#include <set>
25#include <string>
26#include <vector>
27
28namespace simics {
29namespace systemc {
30namespace injection {
31
32#define ATTR_DICT_PARSER_NAMESPACE(ns) \
33std::string prefix() override { \
34 return ns; \
35}
36
39 public:
41 public:
42 virtual ~ParserInterface() {}
43 virtual std::string prefix() = 0;
44 virtual bool parse(AttrDictParser *parser, const std::string &key,
45 attr_value_t *attr) = 0;
46 };
47
48 explicit AttrDictParser(conf_object_t *obj);
49
50 AttrDictParser(conf_object_t *obj, const attr_value_t *attr);
51 AttrDictParser init(const attr_value_t *attr);
52 template<typename T>
53 bool lookUp(const std::string &key, T *v) {
54 std::map<std::string, attr_value_t>::iterator entry;
55 entry = key_to_attr_.find(key);
56 if (entry == key_to_attr_.end()) {
57 SIM_LOG_ERROR(obj_, 0, "Attribute key %s not found", key.c_str());
58 return false;
59 }
60
61 return value(v, key, entry->second);
62 }
63 template<typename T>
64 bool value(T *v) {
65 return value(v, entry_->first, entry_->second);
66 }
67 template<typename T, typename A>
68 bool value(std::vector<T, A> *v, std::string key, attr_value_t value) {
69 if (!SIM_attr_is_list(value)) {
70 SIM_LOG_ERROR(obj_, 0, "%s must be list",
71 key.c_str());
72 return false;
73 }
74
75 v->clear();
76 for (unsigned int i = 0; i < SIM_attr_list_size(value); ++i) {
77 T t;
78 if (this->value(&t, key, SIM_attr_list_item(value, i)))
79 v->push_back(t);
80 else
81 return false;
82 }
83
84 return true;
85 }
86 bool value(uint64_t *v, std::string key, attr_value_t value);
87 bool value(uint32_t *v, std::string key, attr_value_t value);
88 bool value(uint16_t *v, std::string key, attr_value_t value);
89 bool value(uint8_t *v, std::string key, attr_value_t value);
90 bool value(int64_t *v, std::string key, attr_value_t value);
91 bool value(int32_t *v, std::string key, attr_value_t value);
92 bool value(int16_t *v, std::string key, attr_value_t value);
93 bool value(int8_t *v, std::string key, attr_value_t value);
94 bool value(bool *v, std::string key, attr_value_t value);
95 bool value(attr_value_t *v, std::string key, attr_value_t value);
96 bool value(conf_object_t **v, std::string key, attr_value_t value);
97 bool value(const char **v, std::string key, attr_value_t value);
98 bool value(const unsigned char **v, std::string key, attr_value_t value);
99 bool parse(ParserInterface *parser);
100 void reportError(const char *str, ...);
102
103 private:
104 conf_object_t *obj_;
105 std::set<std::string> parsed_keys_;
106 std::map<std::string, attr_value_t> key_to_attr_;
107 std::map<std::string, attr_value_t>::iterator entry_;
108 static std::string error_msg_;
109};
110
111} // namespace injection
112} // namespace systemc
113} // namespace simics
114
115#endif
virtual ~ParserInterface()
Definition: attr_dict_parser.h:42
virtual bool parse(AttrDictParser *parser, const std::string &key, attr_value_t *attr)=0
Definition: attr_dict_parser.h:38
bool value(uint16_t *v, std::string key, attr_value_t value)
bool value(int8_t *v, std::string key, attr_value_t value)
bool value(int16_t *v, std::string key, attr_value_t value)
void reportError(const char *str,...)
bool value(int64_t *v, std::string key, attr_value_t value)
bool value(uint64_t *v, std::string key, attr_value_t value)
bool value(T *v)
Definition: attr_dict_parser.h:64
AttrDictParser(conf_object_t *obj, const attr_value_t *attr)
bool parse(ParserInterface *parser)
bool value(std::vector< T, A > *v, std::string key, attr_value_t value)
Definition: attr_dict_parser.h:68
bool value(const char **v, std::string key, attr_value_t value)
bool value(int32_t *v, std::string key, attr_value_t value)
AttrDictParser init(const attr_value_t *attr)
bool value(const unsigned char **v, std::string key, attr_value_t value)
bool value(attr_value_t *v, std::string key, attr_value_t value)
bool value(conf_object_t **v, std::string key, attr_value_t value)
bool value(uint32_t *v, std::string key, attr_value_t value)
bool value(uint8_t *v, std::string key, attr_value_t value)
bool lookUp(const std::string &key, T *v)
Definition: attr_dict_parser.h:53
bool value(bool *v, std::string key, attr_value_t value)
Definition: adapter.h:79