TiXmlElement::QueryValueAttribute
использует std::istringstream
для анализа значения. Таким образом, вы можете создать класс оболочки около bool
, который перегружает operator >>
, чтобы всегда устанавливать boolalpha
перед извлечением:
class TinyXmlBoolWrapper
{
public:
TinyXmlBoolWrapper(bool& value) : m_value(value) {}
bool& m_value;
};
std::istream& operator >> (std::istream& stream, TinyXmlBoolWrapper& boolValue)
{
// Save the state of the boolalpha flag & set it
std::ios_base::fmtflags fmtflags = stream.setf(std::ios_base::boolalpha);
std::istream& result = stream >> boolValue.m_value;
stream.flags(fmtflags); // restore previous flags
return result;
}
...
bool boolValue;
TinyXmlBoolWrapper boolWrapper(boolValue);
myTinyXmlElement->QueryAttribute("attributeName", &boolWrapper);
// boolValue now contains the parsed boolean value with boolalpha used for
// parsing