Skip to content

Commit 2d45daf

Browse files
sawenzeldavidrohr
authored andcommitted
Make sure to store number representation of char parameters
1 parent 5e753c6 commit 2d45daf

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Common/Utils/src/ConfigurableParamHelper.cxx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,21 @@ size_t getSizeOfUnderlyingType(const TDataMember& dm)
138138

139139
// ----------------------------------------------------------------------
140140

141-
const char* asString(TDataMember const& dm, char* pointer)
141+
std::string asString(TDataMember const& dm, char* pointer)
142142
{
143143
// first check if this is a basic data type, in which case
144144
// we let ROOT do the work
145145
if (auto dt = dm.GetDataType()) {
146+
// we put the numeric interpration for char / unsigned char
147+
// instead of the string one
148+
if (dt->GetType() == EDataType::kChar_t) {
149+
auto c = (char)(*pointer);
150+
return std::to_string((int)c).c_str();
151+
} else if (dt->GetType() == EDataType::kUChar_t) {
152+
auto u = (unsigned char)(*pointer);
153+
return std::to_string((unsigned int)u).c_str();
154+
}
155+
146156
auto val = dt->AsString(pointer);
147157

148158
// For enums we grab the string value of the member
@@ -156,13 +166,13 @@ const char* asString(TDataMember const& dm, char* pointer)
156166
for (int i = 0; i < constantlist->GetEntries(); ++i) {
157167
const auto e = (TEnumConstant*)(constantlist->At(i));
158168
if (val == std::to_string((int)e->GetValue())) {
159-
return e->GetName();
169+
return std::string(e->GetName());
160170
}
161171
}
162172
}
163173
}
164174

165-
return val;
175+
return std::string(val);
166176
}
167177

168178
// if data member is a std::string just return
@@ -186,7 +196,7 @@ std::vector<ParamDataMember>* _ParamHelper::getDataMembersImpl(std::string const
186196
auto TS = getSizeOfUnderlyingType(*dm);
187197
char* pointer = ((char*)obj) + dm->GetOffset() + index * TS;
188198
const std::string name = getName(dm, index, size);
189-
const char* value = asString(*dm, pointer);
199+
auto value = asString(*dm, pointer);
190200

191201
std::string prov = "";
192202
auto iter = provmap->find(mainkey + "." + name);

0 commit comments

Comments
 (0)