stats: update stats for mmap() change.
[gem5.git] / ext / drampower / src / Parameter.cc
1 /*
2 * Copyright (c) 2012-2014, TU Delft
3 * Copyright (c) 2012-2014, TU Eindhoven
4 * Copyright (c) 2012-2014, TU Kaiserslautern
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of the copyright holder nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
23 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Authors: Andreas Hansson
35 *
36 */
37
38 #include "Parameter.h"
39
40 #include <iomanip>
41 #include "Utils.h"
42
43 using namespace Data;
44 using namespace std;
45
46 Parameter::Parameter(const string& id, const string& type,
47 const string& value) : id(id), type(type), value(value)
48 {
49 }
50
51 string Parameter::getId() const
52 {
53 return id;
54 }
55
56 string Parameter::getType() const
57 {
58 return type;
59 }
60
61 int Parameter::getIntValue() const
62 {
63 return fromString<int>(value);
64 }
65
66 unsigned int Parameter::getUIntValue() const
67 {
68 bool isHex = value.size() > 1 && value[0] == '0' && value[1] == 'x';
69
70 return fromString<unsigned int>(value, isHex ? std::hex : std::dec);
71 }
72
73 #ifdef _LP64
74
75 size_t Parameter::getSizeTValue() const
76 {
77 bool isHex = value.size() > 1 && value[0] == '0' && value[1] == 'x';
78
79 return fromString<size_t>(value, isHex ? std::hex : std::dec);
80 }
81
82 #endif
83
84 double Parameter::getDoubleValue() const
85 {
86 return fromString<double>(value);
87 }
88
89 bool Parameter::getBoolValue() const
90 {
91 return fromString<bool>(value);
92 }
93
94 string Parameter::getValue() const
95 {
96 return value;
97 }
98
99 Parameter Data::HexParameter(const string& id, int value)
100 {
101 std::ostringstream ss;
102
103 ss << "0x" << hex << setw(8) << setfill('0') << value;
104
105 return Parameter(id, "int", ss.str());
106 }
107
108 Parameter Data::StringParameter(const string& id, const string& value)
109 {
110 return Parameter(id, "string", value);
111 }
112
113 ostream& Data::operator<<(ostream& os, const Parameter& parameter)
114 {
115 os << "<parameter " <<
116 "id=\"" << parameter.getId() << "\" " <<
117 "type=\"" << parameter.getType() << "\" "
118 "value=\"" << parameter.getValue() << "\" />";
119
120 return os;
121 }