OpenASIP  2.0
Parameter.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2015 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /*
25  * @file Parameter.cc
26  *
27  * Implementation of Parameter class.
28  *
29  * Created on: 20.4.2015
30  * @author: Henry Linjamäki (henry.linjamaki-no.spam-tut.fi)
31  * @note rating: red
32  */
33 
34 #include "Parameter.hh"
35 
36 #include "BaseNetlistBlock.hh"
37 
38 #include "Conversion.hh"
39 
40 namespace ProGe {
41 
42 /**
43  * Empty parameter with undefined members.
44  */
46  : name_(""), type_(""), value_(""), default_(""), package_("") {}
47 
48 /**
49  * Constructs a parameter with both the assigned and default value having the
50  * same value.
51  *
52  * @param name The name of the parameter
53  * @param type The type of the parameter given as string
54  * @param assignedAndDefaultValue The assigned and default value of the
55  * parameter.
56  */
58  const TCEString& name, const TCEString& type,
59  const TCEString& assignedAndDefaultValue)
60  : Parameter(
61  name, type, assignedAndDefaultValue, assignedAndDefaultValue) {}
62 
63 /**
64  * Constructs a parameter with separate assigned and default value.
65  *
66  * @param name The name of the parameter
67  * @param type The type of the parameter given as string
68  * @param assignedValue The assigned value of the parameter.
69  * @param defaultValue The default value of the parameter.
70  */
72  const TCEString& name, const TCEString& type,
73  const TCEString& assignedValue, const TCEString& defaultValue)
74  : name_(name),
75  type_(type),
76  value_(assignedValue),
77  default_(defaultValue),
78  package_("") {}
80  const TCEString& name, const TCEString& type, int assignedValue,
81  const TCEString& defaultValue)
82  : name_(name),
83  type_(type),
84  value_(""),
85  default_(defaultValue),
86  package_("") {
87  value_ = Conversion::toString(assignedValue);
88 }
89 
90 /**
91  * @param name The name of the parameter
92  * @param type The type of the parameter given as string
93  * @param nameOfConstant The value of the parameter as name to a constant.
94  * @param defaultValue The default value of the parameter.
95  * @param nameOfPackage The name of a package where the constant is defined.
96  */
98  const TCEString& name, const TCEString& type,
99  const TCEString& nameOfConstant, const TCEString& defaultValue,
100  const TCEString& nameOfPackage)
101  : name_(name),
102  type_(type),
103  value_(nameOfConstant),
104  default_(defaultValue),
105  package_(nameOfPackage) {}
106 
108 
109 void
111  const TCEString& name, const TCEString& type, const TCEString& value) {
112  name_ = name;
113  type_ = type;
114  value_ = value;
115 }
116 
117 void
119  name_ = name;
120 }
121 
122 void
124  type_ = type;
125 }
126 
127 void
129  value_ = value;
130 }
131 
132 const TCEString&
134  return name_;
135 }
136 
137 const TCEString&
139  return type_;
140 }
141 
142 const TCEString&
144  return value_;
145 }
146 
147 const TCEString&
149  return default_;
150 }
151 
152 /**
153  * Return true is the value is a symbol therefore the actual value is defined
154  * elsewhere. Otherwise, the value is literal.
155  */
156 bool
158  return !package_.empty(); // note: placeholder
159 }
160 
161 /**
162  * Return true is the value is a symbol to a constant that are stored in
163  * packages.
164  */
165 bool
167  return valueIsSymbol() && !package_.empty();
168 }
169 
170 const std::string&
172  return package_;
173 }
174 
175 } /* namespace ProGe */
ProGe::Parameter::setValue
void setValue(const TCEString &value)
Definition: Parameter.cc:128
ProGe::Parameter::type
const TCEString & type() const
Definition: Parameter.cc:138
ProGe::Parameter::package_
TCEString package_
Package reference by name. If non-empty the value_ is treated as name of a constant.
Definition: Parameter.hh:118
ProGe::Parameter::name_
TCEString name_
Name/identifier of the parameter.
Definition: Parameter.hh:108
Conversion::toString
static std::string toString(const T &source)
ProGe::Parameter::packageNameOfConstant
const std::string & packageNameOfConstant() const
Definition: Parameter.cc:171
ProGe::Parameter::default_
TCEString default_
Default value of the parameter if value_ is not set (empty).
Definition: Parameter.hh:115
ProGe::Parameter::type_
TCEString type_
Type of the parameter.
Definition: Parameter.hh:110
ProGe::Parameter::valueIsSymbol
bool valueIsSymbol() const
Definition: Parameter.cc:157
ProGe::Parameter::setName
void setName(const TCEString &name)
Definition: Parameter.cc:118
Conversion.hh
ProGe::Parameter
Definition: Parameter.hh:62
ProGe::Parameter::valueIsConstant
bool valueIsConstant() const
Definition: Parameter.cc:166
ProGe::Parameter::name
const TCEString & name() const
Definition: Parameter.cc:133
ProGe::Parameter::value
const TCEString & value() const
Definition: Parameter.cc:143
ProGe::Parameter::set
void set(const TCEString &name, const TCEString &type, const TCEString &value)
Definition: Parameter.cc:110
ProGe
Definition: FUGen.hh:54
BaseNetlistBlock.hh
ProGe::Parameter::setType
void setType(const TCEString &type)
Definition: Parameter.cc:123
TCEString
Definition: TCEString.hh:53
ProGe::Parameter::Parameter
Parameter()
Definition: Parameter.cc:45
ProGe::Parameter::~Parameter
virtual ~Parameter()
Definition: Parameter.cc:107
ProGe::Parameter::defaultValue
const TCEString & defaultValue() const
Definition: Parameter.cc:148
ProGe::Parameter::value_
TCEString value_
Assigned value to the parameter as actual value or as reference to another parameter or name of a con...
Definition: Parameter.hh:113
Parameter.hh