4 if len(knob[0]) > max_len: max_len = len(knob[0])
5 max_len += len('KNOB_ ')
6 if max_len % 4: max_len += 4 - (max_len % 4)
9 knob_len = len('KNOB_' + knob)
10 return ' '*(max_len - knob_len)
12 def calc_max_name_len(choices_array):
14 for choice in choices_array:
15 if len(choice['name']) > _max_len: _max_len = len(choice['name'])
17 if _max_len % 4: _max_len += 4 - (_max_len % 4)
20 def space_name(name, max_len):
22 return ' '*(max_len - name_len)
25 %>/******************************************************************************
30 * Licensed under the Apache License, Version 2.0 (the "License");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at
34 * http ://www.apache.org/licenses/LICENSE-2.0
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
45 * @file ${filename}.cpp
48 * @brief Dynamic Knobs for Core.
50 * ======================= AUTO GENERATED: DO NOT EDIT !!! ====================
52 ******************************************************************************/
60 const T& Value() const { return m_Value; }
61 const T& Value(const T& newValue) { m_Value = newValue; return Value(); }
64 Knob(const T& defaultValue) : m_Value(defaultValue) {}
70 #define DEFINE_KNOB(_name, _type, _default) \\
72 struct Knob_##_name : Knob<_type> \\
76 Knob_##_name() : Knob<_type>(_default) { } \\
78 static const char* Name() { return "KNOB_" #_name; } \\
82 #define GET_KNOB(_name) g_GlobalKnobs._name.Value()
83 #define SET_KNOB(_name, _newValue) g_GlobalKnobs._name.Value(_newValue)
88 //-----------------------------------------------------------
91 % for line in knob[1]['desc']:
94 % if knob[1].get('choices'):
96 choices = knob[1].get('choices')
97 _max_len = calc_max_name_len(choices) %>//
98 % for i in range(len(choices)):
99 // ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')}
103 % if knob[1]['type'] == 'std::string':
104 DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, "${repr(knob[1]['default'])[1:-1]}");
106 DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, ${knob[1]['default']});
111 std::string ToString(const char* optPerLinePrefix="");
113 extern GlobalKnobs g_GlobalKnobs;
118 #define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]})
122 % for inc in includes:
126 //========================================================
127 // Static Data Members
128 //========================================================
129 GlobalKnobs g_GlobalKnobs;
131 //========================================================
132 // Knob Initialization
133 //========================================================
134 GlobalKnobs::GlobalKnobs()
137 InitKnob(${knob[0]});
141 //========================================================
142 // Knob Display (Convert to String)
143 //========================================================
144 std::string GlobalKnobs::ToString(const char* optPerLinePrefix)
146 std::basic_stringstream<char> str;
147 str << std::showbase << std::setprecision(1) << std::fixed;
149 if (optPerLinePrefix == nullptr) { optPerLinePrefix = ""; }
152 str << optPerLinePrefix << "KNOB_${knob[0]}:${space_knob(knob[0])}";
153 % if knob[1]['type'] == 'bool':
154 str << (KNOB_${knob[0]} ? "+\n" : "-\n");
155 % elif knob[1]['type'] != 'float' and knob[1]['type'] != 'std::string':
156 str << std::hex << std::setw(11) << std::left << KNOB_${knob[0]};
157 str << std::dec << KNOB_${knob[0]} << "\n";
159 str << KNOB_${knob[0]} << "\n";