2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
26 * @file DesignExplorerPlugin.icc
28 * Inline definitions of DesignExplorerPlugin class.
30 * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
33 #include "CompilerWarnings.hh"
34 IGNORE_CLANG_WARNING("-Wunused-local-typedef")
35 #include <boost/lexical_cast.hpp>
39 DesignSpaceExplorerPlugin::description() const {
40 return "base class description";
45 * Adds a parameter to the plugin parameter list
47 * @param name Parameter name.
48 * @param type Parameter type.
49 * @param compulsory Is parameter compulsory.
50 * @param defaultValue default value of the parameter is not compulsory.
53 DesignSpaceExplorerPlugin::addParameter(
55 ExplorerPluginParameterType type,
57 TCEString defaultValue,
58 TCEString description) {
60 parameters_.insert(Parameter(name,
61 ExplorerPluginParameter(
62 name, type, compulsory, defaultValue,
68 * Reads compulsory parameter from the plugin parameters.
70 * @param paramName Parameter name.
71 * @param param Variable where to read the parameter.
75 DesignSpaceExplorerPlugin::readCompulsoryParameter(
76 const std::string paramName, T& param) const {
77 param = parameterValue<T>(paramName);
81 * Reads optional parameter from the plugin parameters.
83 * @param paramName Parameter name.
84 * @param param Variable where to read the parameter.
88 DesignSpaceExplorerPlugin::readOptionalParameter(
89 const std::string paramName, T& param) const {
90 // optional parameters
91 if (hasParameter(paramName)) {
92 param = parameterValue<T>(paramName);
97 * Return parameter value.
99 * @param paramName Parameter name which value is to be returned.
101 template <typename RT>
103 DesignSpaceExplorerPlugin::parameterValue(const std::string& paramName) const {
104 using boost::lexical_cast;
105 using boost::bad_lexical_cast;
107 PMCIt it = parameters_.find(paramName);
108 if (it != parameters_.end()) {
110 std::string value = it->second.value();
111 if (it->second.type() == BOOL &&
112 (value == "true" || value == "false")) {
113 value = value == "true" ? "1" : "0";
115 return lexical_cast<RT>(value);
116 } catch (bad_lexical_cast &) {
117 std::string msg = paramName + " had an illegal type of a value: "
118 + it->second.value();
119 throw IllegalParameters(__FILE__, __LINE__, __func__, msg);
122 std::string msg = paramName + " parameter has not been defined.";
123 throw NotAvailable(__FILE__, __LINE__, __func__, msg);