+#include <msp/io/zlibcompressed.h>
#include "input.h"
namespace Msp {
namespace DataFile {
Input::Input(IO::Base &i):
- in(i),
+ in(&i),
+ compressed(0),
line(1),
next(-1)
{ }
+Input::~Input()
+{
+ delete compressed;
+}
+
+void Input::set_decompress()
+{
+ compressed = new IO::ZlibCompressed(*in);
+ in = compressed;
+}
+
int Input::get()
{
int c = next;
next = -1;
- if(c<0) c = in.get();
+ if(c<0)
+ c = in->get();
if(c=='\n')
++line;
int Input::peek()
{
if(next<0)
- next = in.get();
+ next = in->get();
return next;
}
Input::operator bool() const
{
- return next>=0 || !in.eof();
+ return next>=0 || !in->eof();
}
} // namespace DataFile
class Input
{
private:
- IO::Base ∈
+ IO::Base *in;
+ IO::Base *compressed;
unsigned line;
int next;
public:
Input(IO::Base &);
+ ~Input();
+ void set_decompress();
int get();
int peek();
unsigned get_line_number() const { return line; }
+#include <msp/io/zlibcompressed.h>
#include "output.h"
using namespace std;
namespace DataFile {
Output::Output(IO::Base &o):
- out(&o)
+ out(&o),
+ compressed(0)
{ }
+Output::~Output()
+{
+ delete compressed;
+}
+
+void Output::set_compressed()
+{
+ compressed = new IO::ZlibCompressed(*out);
+ out = compressed;
+}
+
unsigned Output::put(char c)
{
return out->put(c);
{
private:
IO::Base *out;
+ IO::Base *compressed;
public:
Output(IO::Base &);
+ ~Output();
+
+ void set_compressed();
unsigned put(char);
unsigned write(const std::string &);
delete mode;
mode = new TextParser(in, src);
}
+ else if(st.keyword=="__z")
+ in.set_decompress();
else if(st.keyword=="__src")
{
string s = st.args[0].get<string>();
+#include <msp/io/zlibcompressed.h>
#include "binarywriter.h"
#include "statement.h"
#include "textwriter.h"
mode = new TextWriter(out);
}
+void Writer::set_compressed()
+{
+ Statement st;
+ st.keyword = "__z";
+ mode->write(st);
+
+ out.set_compressed();
+}
+
void Writer::set_float_precision(unsigned fp)
{
mode->set_float_precision(fp);
*/
void set_binary(bool b);
+ /** Enables output compression. Once enabled, it won't be possible to
+ disable compression. */
+ void set_compressed();
+
/** Sets the precision of floating point numbers in bits. Depending on the
mode not all values may be valid, but any value between 16 and 64 that is
divisible by 8 is guaranteed to work. */
out_fn("-"),
binary(false),
compile(false),
- float_size(0)
+ float_size(0),
+ compress(false)
{
GetOpt getopt;
getopt.add_option('b', "binary", binary, GetOpt::NO_ARG);
getopt.add_option('c', "compile", compile, GetOpt::NO_ARG);
getopt.add_option('f', "float-size", float_size, GetOpt::REQUIRED_ARG);
getopt.add_option('o', "output", out_fn, GetOpt::REQUIRED_ARG);
+ getopt.add_option('z', "compress", compress, GetOpt::NO_ARG);
getopt(argc, argv);
const vector<string> &args = getopt.get_args();
DataFile::Parser parser(in_buf, in_fn);
IO::Buffered out_buf(*out);
DataFile::Writer writer(out_buf);
+ if(compress)
+ writer.set_compressed();
if(binary)
writer.set_binary(true);
if(float_size)
bool binary;
bool compile;
unsigned float_size;
+ bool compress;
public:
DataTool(int argc, char **argv);