1 #include "BlockParameterGeneric.h"
\r
2 #include "GroupBlock.h"
\r
3 #include "FunctionalBlock.h"
\r
5 BlockParameterGeneric::BlockParameterGeneric() : BlockParameter() {
\r
6 userValue = defaultValue;
\r
9 BlockParameterGeneric::BlockParameterGeneric(AbstractBlock* _owner, const QString &_name, const QString &_type, const QString &_value) : BlockParameter(_owner, _name, _type, _value) {
\r
10 /* CAUTION: no check done on the type parameter !
\r
11 * It must never be "expression" but something that is numeric/boolean
\r
13 userValue = defaultValue;
\r
16 QVariant BlockParameterGeneric::getValue() {
\r
20 return defaultValue;
\r
23 bool BlockParameterGeneric::isGenericParameter() {
\r
27 void BlockParameterGeneric::setValue(const QString& _value) {
\r
28 userValue = QVariant(_value);
\r
32 bool BlockParameterGeneric::isValueSet() {
\r
33 if (userValue.isNull()) return false;
\r
37 bool BlockParameterGeneric::isDefaultValue() {
\r
38 if (userValue == defaultValue) return true;
\r
42 BlockParameter* BlockParameterGeneric::clone() {
\r
44 BlockParameter* block = new BlockParameterGeneric(owner,name,getTypeString(),defaultValue.toString());
\r
48 QString BlockParameterGeneric::toVHDL(int context, int flags) {
\r
53 if ((context == BlockParameter::Entity) || (context == BlockParameter::Component)) {
\r
55 QString formatValue = "%1 : %2 := %3";
\r
56 QString formatNoValue = "%1 : %2";
\r
57 if ((flags & BlockParameter::NoComma) == 0) {
\r
58 formatValue.append(";");
\r
59 formatNoValue.append(";");
\r
62 QString typeStr = "";
\r
63 QString valueStr = "";
\r
64 if ((type == Boolean)||(type == Bit)) {
\r
65 typeStr = "std_logic";
\r
66 if (!userValue.isNull()) {
\r
67 valueStr = "'"+userValue.toString()+"'";
\r
68 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
70 else if (!defaultValue.isNull()) {
\r
71 valueStr = "'"+defaultValue.toString()+"'";
\r
72 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
75 ret = formatNoValue.arg(name).arg(typeStr);
\r
78 else if (type == String) {
\r
80 if (!userValue.isNull()) {
\r
81 valueStr = "\""+userValue.toString()+"\"";
\r
82 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
84 else if (!defaultValue.isNull()) {
\r
85 valueStr = "\""+defaultValue.toString()+"\"";
\r
86 ret = formatValue.arg(name).arg(typeStr).arg(valueStr);
\r
89 ret = formatNoValue.arg(name).arg(typeStr);
\r
93 typeStr = getTypeString();
\r
94 if (!userValue.isNull()) {
\r
95 ret = formatValue.arg(name).arg(typeStr).arg(userValue.toString());
\r
97 else if (!defaultValue.isNull()) {
\r
98 ret = formatValue.arg(name).arg(typeStr).arg(defaultValue.toString());
\r
101 ret = formatNoValue.arg(name).arg(typeStr);
\r
105 else if (context == BlockParameter::Instance) {
\r
106 QString format = "%1 => %2";
\r
107 if ((flags & BlockParameter::NoComma) == 0) {
\r
108 format.append(";");
\r
110 AbstractBlock* parent = owner->getParent();
\r
111 BlockParameter* p = NULL;
\r
112 if (parent != NULL) {
\r
113 p = parent->getParameterFromName(name);
\r
116 /* the parent group has a generic parameter with the same
\r
119 ret = format.arg(name).arg(name);
\r
122 if (!userValue.isNull()) {
\r
123 if ((type == Boolean)||(type == Bit)) {
\r
124 ret = format.arg(name).arg("'"+userValue.toString()+"'");
\r
126 else if (type == String) {
\r
127 ret = format.arg(name).arg("\""+userValue.toString()+"\"");
\r
130 ret = format.arg(name).arg(userValue.toString());
\r
133 else if (!defaultValue.isNull()) {
\r
134 if ((type == Boolean)||(type == Bit)) {
\r
135 ret = format.arg(name).arg("'"+defaultValue.toString()+"'");
\r
137 else if (type == String) {
\r
138 ret = format.arg(name).arg("\""+defaultValue.toString()+"\"");
\r
141 ret = format.arg(name).arg(defaultValue.toString());
\r
146 ret = format.arg(name).arg("INVALID_VALUE");
\r