Commit 6f94f954 authored by Jesse Beder's avatar Jesse Beder
Browse files

Overloaded more integral types for emitting

parent 90fd24d1
......@@ -46,7 +46,12 @@ namespace YAML
// overloads of write
Emitter& Write(const std::string& str);
Emitter& Write(const char *str);
Emitter& Write(int i);
Emitter& Write(int value) { return WriteIntegralType(value); }
Emitter& Write(unsigned int value) { return WriteIntegralType(value); }
Emitter& Write(short value) { return WriteIntegralType(value); }
Emitter& Write(unsigned short value) { return WriteIntegralType(value); }
Emitter& Write(long value) { return WriteIntegralType(value); }
Emitter& Write(unsigned long value) { return WriteIntegralType(value); }
Emitter& Write(bool b);
Emitter& Write(float f);
Emitter& Write(double d);
......@@ -56,6 +61,13 @@ namespace YAML
Emitter& Write(const _Comment& comment);
Emitter& Write(const _Null& null);
private:
void PreWriteIntegralType(std::stringstream& str);
void PostWriteIntegralType(const std::stringstream& str);
template <typename T>
Emitter& WriteIntegralType(T value);
private:
enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
......@@ -76,6 +88,19 @@ namespace YAML
std::auto_ptr <EmitterState> m_pState;
};
template <typename T>
inline Emitter& Emitter::WriteIntegralType(T value)
{
if(!good())
return *this;
std::stringstream str;
PreWriteIntegralType(str);
str << value;
PostWriteIntegralType(str);
return *this;
}
// overloads of insertion
template <typename T>
inline Emitter& operator << (Emitter& emitter, T v) {
......
......@@ -557,16 +557,12 @@ namespace YAML
return Write(std::string(str));
}
Emitter& Emitter::Write(int i)
void Emitter::PreWriteIntegralType(std::stringstream& str)
{
if(!good())
return *this;
PreAtomicWrite();
EmitSeparationIfNecessary();
EMITTER_MANIP intFmt = m_pState->GetIntFormat();
std::stringstream str;
switch(intFmt) {
case Dec:
str << std::dec;
......@@ -580,12 +576,12 @@ namespace YAML
default:
assert(false);
}
}
str << i;
void Emitter::PostWriteIntegralType(const std::stringstream& str)
{
m_stream << str.str();
PostAtomicWrite();
return *this;
}
Emitter& Emitter::Write(bool b)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment