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// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2017 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_SYSTEMC_INJECTION_ATTR_DICT_PARSER_H
17#define SIMICS_SYSTEMC_INJECTION_ATTR_DICT_PARSER_H
18
20#include <simics/base/attr-value.h>
21#include <simics/base/log.h>
22
23#include <stdio.h>
24
25#include <map>
26#include <set>
27#include <string>
28#include <vector>
29
30namespace simics {
31namespace systemc {
32namespace injection {
33
34#define ATTR_DICT_PARSER_NAMESPACE(ns) \
35virtual std::string prefix() { \
36 return ns; \
37}
38
41 public:
43 public:
44 virtual ~ParserInterface() {}
45 virtual std::string prefix() = 0;
46 virtual bool parse(AttrDictParser *parser, const std::string &key,
47 attr_value_t *attr) = 0;
48 };
49
50 explicit AttrDictParser(conf_object_t *obj);
51
52 AttrDictParser(conf_object_t *obj, const attr_value_t *attr);
53 AttrDictParser init(const attr_value_t *attr);
54 template<typename T>
55 bool lookUp(std::string key, T *v) {
56 std::map<std::string, attr_value_t>::iterator entry;
57 entry = key_to_attr_.find(key);
58 if (entry == key_to_attr_.end()) {
59 SIM_LOG_ERROR(obj_, 0, "Attribute key %s not found", key.c_str());
60 return false;
61 }
62
63 return value(v, key, entry->second);
64 }
65 template<typename T>
66 bool value(T *v) {
67 return value(v, entry_->first, entry_->second);
68 }
69 template<typename T, typename A>
70 bool value(std::vector<T, A> *v, std::string key, attr_value_t value) {
71 if (!SIM_attr_is_list(value)) {
72 SIM_LOG_ERROR(obj_, 0, "%s must be list",
73 key.c_str());
74 return false;
75 }
76
77 v->clear();
78 for (unsigned int i = 0; i < SIM_attr_list_size(value); ++i) {
79 T t;
80 if (this->value(&t, key, SIM_attr_list_item(value, i)))
81 v->push_back(t);
82 else
83 return false;
84 }
85
86 return true;
87 }
88 bool value(uint64_t *v, std::string key, attr_value_t value);
89 bool value(uint32_t *v, std::string key, attr_value_t value);
90 bool value(uint16_t *v, std::string key, attr_value_t value);
91 bool value(uint8_t *v, std::string key, attr_value_t value);
92 bool value(int64_t *v, std::string key, attr_value_t value);
93 bool value(int32_t *v, std::string key, attr_value_t value);
94 bool value(int16_t *v, std::string key, attr_value_t value);
95 bool value(int8_t *v, std::string key, attr_value_t value);
96 bool value(bool *v, std::string key, attr_value_t value);
97 bool value(attr_value_t *v, std::string key, attr_value_t value);
98 bool value(const char **v, std::string key, attr_value_t value);
99 bool value(const unsigned char **v, std::string key, attr_value_t value);
100 bool parse(ParserInterface *parser);
101 void reportError(const char *str, ...);
103
104 private:
105 conf_object_t *obj_;
106 std::set<std::string> parsed_keys_;
107 std::map<std::string, attr_value_t> key_to_attr_;
108 std::map<std::string, attr_value_t>::iterator entry_;
109 static std::string error_msg_;
110};
111
112} // namespace injection
113} // namespace systemc
114} // namespace simics
115
116#endif
virtual ~ParserInterface()
Definition: attr_dict_parser.h:44
virtual bool parse(AttrDictParser *parser, const std::string &key, attr_value_t *attr)=0
Definition: attr_dict_parser.h:40
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:66
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:70
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(uint32_t *v, std::string key, attr_value_t value)
bool value(uint8_t *v, std::string key, attr_value_t value)
bool value(bool *v, std::string key, attr_value_t value)
bool lookUp(std::string key, T *v)
Definition: attr_dict_parser.h:55
Definition: pci_bus_interface.h:24