mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-08 12:21:17 +00:00
Added writing integral types
This commit is contained in:
@@ -74,6 +74,9 @@ namespace YAML
|
||||
template<typename T> void SetStreamablePrecision(std::stringstream&) {}
|
||||
unsigned GetFloatPrecision() const;
|
||||
unsigned GetDoublePrecision() const;
|
||||
|
||||
void PrepareIntegralStream(std::stringstream& stream) const;
|
||||
void StartedScalar();
|
||||
|
||||
private:
|
||||
void EmitBeginDoc();
|
||||
@@ -111,6 +114,15 @@ namespace YAML
|
||||
if(!good())
|
||||
return *this;
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
|
||||
std::stringstream stream;
|
||||
PrepareIntegralStream(stream);
|
||||
stream << value;
|
||||
m_stream << stream.str();
|
||||
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -436,6 +436,31 @@ namespace YAML
|
||||
m_stream << IndentTo(indent);
|
||||
}
|
||||
|
||||
void Emitter::PrepareIntegralStream(std::stringstream& stream) const
|
||||
{
|
||||
|
||||
switch(m_pState->GetIntFormat()) {
|
||||
case Dec:
|
||||
stream << std::dec;
|
||||
break;
|
||||
case Hex:
|
||||
stream << "0x";
|
||||
stream << std::hex;
|
||||
break;
|
||||
case Oct:
|
||||
stream << "0";
|
||||
stream << std::oct;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Emitter::StartedScalar()
|
||||
{
|
||||
m_pState->StartedScalar();
|
||||
}
|
||||
|
||||
// *******************************************************************************************
|
||||
// overloads of Write
|
||||
|
||||
@@ -464,7 +489,7 @@ namespace YAML
|
||||
break;
|
||||
}
|
||||
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -521,7 +546,7 @@ namespace YAML
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
m_stream << ComputeFullBoolName(b);
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -533,7 +558,7 @@ namespace YAML
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
m_stream << ch;
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -555,7 +580,7 @@ namespace YAML
|
||||
return *this;
|
||||
}
|
||||
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -639,7 +664,7 @@ namespace YAML
|
||||
return *this;
|
||||
|
||||
// TODO
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -653,7 +678,7 @@ namespace YAML
|
||||
|
||||
PrepareNode(EmitterNodeType::Scalar);
|
||||
Utils::WriteBinary(m_stream, binary);
|
||||
m_pState->StartedScalar();
|
||||
StartedScalar();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ int main()
|
||||
out << YAML::Anchor("a") << YAML::Comment("anchor") << "item 1" << YAML::Comment("a");
|
||||
out << YAML::BeginMap << YAML::Comment("b");
|
||||
out << "pens" << YAML::Comment("foo") << "a" << YAML::Comment("bar");
|
||||
out << "pencils" << "b";
|
||||
out << "pencils" << 15;
|
||||
out << YAML::EndMap << YAML::Comment("monkey");
|
||||
out << "item 2";
|
||||
out << YAML::EndSeq;
|
||||
|
Reference in New Issue
Block a user