forked from xcore/tool_axe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Property.h
69 lines (63 loc) · 2.09 KB
/
Property.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2011-2012, Richard Osborne, All rights reserved
// This software is freely distributable under a derivative of the
// University of Illinois/NCSA Open Source License posted in
// LICENSE.txt and at <http://github.xcore.com/>
#ifndef _Property_h_
#define _Property_h_
#include <cassert>
#include "PeripheralDescriptor.h"
#include "PortArg.h"
#include <stdint.h>
class Property {
const PropertyDescriptor *descriptor;
int32_t integer;
std::string string;
PortArg port;
Property(const PropertyDescriptor *d) : descriptor(d), integer(0) {}
void setInteger(int32_t value) {
assert(descriptor->getType() == PropertyDescriptor::INTEGER);
integer = value;
}
void setString(const std::string &value) {
assert(descriptor->getType() == PropertyDescriptor::STRING);
string = value;
}
void setPort(const PortArg &value) {
assert(descriptor->getType() == PropertyDescriptor::PORT);
port = value;
}
public:
static Property integerProperty(const PropertyDescriptor *d, int32_t value);
static Property stringProperty(const PropertyDescriptor *d,
const std::string &value);
static Property portProperty(const PropertyDescriptor *d,
const PortArg &value);
const PropertyDescriptor *getDescriptor() const { return descriptor; }
int32_t getAsInteger() const {
assert(descriptor->getType() == PropertyDescriptor::INTEGER);
return integer;
}
std::string getAsString() const {
assert(descriptor->getType() == PropertyDescriptor::STRING);
return string;
}
const PortArg &getAsPort() const {
assert(descriptor->getType() == PropertyDescriptor::PORT);
return port;
}
};
class Properties {
std::map<std::string,Property> properties;
public:
void set(const Property &p) {
properties.insert(std::make_pair(p.getDescriptor()->getName(), p));
}
const Property *get(const std::string &name) const {
std::map<std::string,Property>::const_iterator it = properties.find(name);
if (it != properties.end()) {
return &it->second;
}
return 0;
}
};
#endif //_Property_h_