#include <msp/core/maputils.h>
#include "binarywriter.h"
#include "binfloat.h"
+#include "output.h"
#include "statement.h"
using namespace std;
namespace Msp {
namespace DataFile {
-BinaryWriter::BinaryWriter(IO::Base &o):
+BinaryWriter::BinaryWriter(Output &o):
WriterMode(o),
next_kwd_id(1),
next_str_id(1),
else
{
write_int(s.size());
- out.write(s.data(), s.size());
+ out.write(s);
}
}
unsigned float_precision;
public:
- BinaryWriter(IO::Base &o);
+ BinaryWriter(Output &o);
virtual void set_float_precision(unsigned);
virtual void write(const Statement &st);
--- /dev/null
+#ifndef MSP_DATAFILE_OUTPUT_H_
+#define MSP_DATAFILE_OUTPUT_H_
+
+#include <msp/io/base.h>
+
+namespace Msp {
+namespace DataFile {
+
+class Output
+{
+private:
+ IO::Base *out;
+
+public:
+ Output(IO::Base &);
+
+ unsigned put(char);
+ unsigned write(const std::string &);
+};
+
+} // namespace DataFile
+} // namespace Msp
+
+#endif
#include <msp/io/print.h>
#include <msp/strings/utils.h>
+#include "output.h"
#include "statement.h"
#include "textwriter.h"
namespace Msp {
namespace DataFile {
-TextWriter::TextWriter(IO::Base &o):
+TextWriter::TextWriter(Output &o):
WriterMode(o),
float_format("%#.7g")
{ }
{
string indent(level, '\t');
- IO::print(out, "%s%s", indent, st.keyword);
+ out.write(format("%s%s", indent, st.keyword));
for(ValueArray::const_iterator i = st.args.begin(); i!=st.args.end(); ++i)
{
out.put(' ');
if(i->get_signature()==StringType::signature)
- IO::print(out, "\"%s\"", c_escape(i->get<StringType::Store>(), false));
+ out.write(format("\"%s\"", c_escape(i->get<StringType::Store>(), false)));
else if(i->get_signature()==BoolType::signature)
out.write(i->get<BoolType::Store>() ? "true" : "false");
else if(i->get_signature()==IntType::signature)
}
if(!st.sub.empty())
{
- IO::print(out, "\n%s{\n", indent);
+ out.write(format("\n%s{\n", indent));
for(list<Statement>::const_iterator i = st.sub.begin(); i!=st.sub.end(); ++i)
write_(*i, level+1);
- IO::print(out, "%s}", indent);
+ out.write(format("%s}", indent));
}
- out.write(";\n", 2);
+ out.write(";\n");
}
} // namespace DataFile
#ifndef MSP_DATAFILE_WRITERMODE_H_
#define MSP_DATAFILE_WRITERMODE_H_
-#include <msp/io/base.h>
-
namespace Msp {
namespace DataFile {
+class Output;
class Statement;
class WriterMode
{
protected:
- IO::Base &out;
+ Output &out;
- WriterMode(IO::Base &o): out(o) { }
+ WriterMode(Output &o): out(o) { }
public:
virtual ~WriterMode() { }