OpenASIP  2.0
DesignSpaceExplorerPlugin.icc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 /**
26  * @file DesignExplorerPlugin.icc
27  *
28  * Inline definitions of DesignExplorerPlugin class.
29  *
30  * @author Esa Määttä 2008 (esa.maatta-no.spam-tut.fi)
31  */
32 
33 #include "CompilerWarnings.hh"
34 IGNORE_CLANG_WARNING("-Wunused-local-typedef")
35 #include <boost/lexical_cast.hpp>
36 POP_CLANG_DIAGS
37 
38 inline std::string
39 DesignSpaceExplorerPlugin::description() const {
40  return "base class description";
41 }
42 
43 
44 /**
45  * Adds a parameter to the plugin parameter list
46  *
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.
51  */
52 inline void
53 DesignSpaceExplorerPlugin::addParameter(
54  TCEString name,
55  ExplorerPluginParameterType type,
56  bool compulsory,
57  TCEString defaultValue,
58  TCEString description) {
59 
60  parameters_.insert(Parameter(name,
61  ExplorerPluginParameter(
62  name, type, compulsory, defaultValue,
63  description)));
64 }
65 
66 
67 /**
68  * Reads compulsory parameter from the plugin parameters.
69  *
70  * @param paramName Parameter name.
71  * @param param Variable where to read the parameter.
72  */
73 template <typename T>
74 void
75 DesignSpaceExplorerPlugin::readCompulsoryParameter(
76  const std::string paramName, T& param) const {
77  param = parameterValue<T>(paramName);
78 }
79 
80 /**
81  * Reads optional parameter from the plugin parameters.
82  *
83  * @param paramName Parameter name.
84  * @param param Variable where to read the parameter.
85  */
86 template <typename T>
87 void
88 DesignSpaceExplorerPlugin::readOptionalParameter(
89  const std::string paramName, T& param) const {
90  // optional parameters
91  if (hasParameter(paramName)) {
92  param = parameterValue<T>(paramName);
93  }
94 }
95 
96 /**
97  * Return parameter value.
98  *
99  * @param paramName Parameter name which value is to be returned.
100  */
101 template <typename RT>
102 RT
103 DesignSpaceExplorerPlugin::parameterValue(const std::string& paramName) const {
104  using boost::lexical_cast;
105  using boost::bad_lexical_cast;
106 
107  PMCIt it = parameters_.find(paramName);
108  if (it != parameters_.end()) {
109  try {
110  std::string value = it->second.value();
111  if (it->second.type() == BOOL &&
112  (value == "true" || value == "false")) {
113  value = value == "true" ? "1" : "0";
114  }
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);
120  }
121  }
122  std::string msg = paramName + " parameter has not been defined.";
123  throw NotAvailable(__FILE__, __LINE__, __func__, msg);
124 }