Add AbstractTextDumper to implement stream holding and indendation

This commit is contained in:
Jan 2022-01-15 17:44:56 +01:00
parent c9a0392fc1
commit b48d55671e
8 changed files with 60 additions and 38 deletions

View File

@ -0,0 +1,28 @@
#include "AbstractTextDumper.h"
#include <cassert>
AbstractTextDumper::AbstractTextDumper(std::ostream& stream)
: m_stream(stream),
m_indent(0u)
{
}
void AbstractTextDumper::Indent() const
{
for (auto i = 0u; i < m_indent; i++)
m_stream << " ";
}
void AbstractTextDumper::IncIndent()
{
++m_indent;
}
void AbstractTextDumper::DecIndent()
{
assert(m_indent > 0);
if (m_indent > 0)
m_indent--;
}

View File

@ -0,0 +1,16 @@
#pragma once
#include <ostream>
class AbstractTextDumper
{
protected:
std::ostream& m_stream;
size_t m_indent;
void Indent() const;
void IncIndent();
void DecIndent();
explicit AbstractTextDumper(std::ostream& stream);
};

View File

@ -2,8 +2,8 @@
#include <regex>
StringFileDumper::StringFileDumper(Zone* zone, std::ostream& stream)
: m_zone(zone),
m_stream(stream),
: AbstractTextDumper(stream),
m_zone(zone),
m_language_caps("ENGLISH"),
m_wrote_header(false)
{

View File

@ -1,13 +1,11 @@
#pragma once
#include <ostream>
#include "Dumping/AbstractTextDumper.h"
#include "Zone/Zone.h"
class StringFileDumper
class StringFileDumper : AbstractTextDumper
{
Zone* m_zone;
std::ostream& m_stream;
std::string m_config_file;
std::string m_notes;

View File

@ -32,32 +32,13 @@ MapFileDumper::PhysicsCylinder::PhysicsCylinder(const Vec3 middlePoint, const fl
}
MapFileDumper::MapFileDumper(std::ostream& stream)
: m_stream(stream),
: AbstractTextDumper(stream),
m_flags{},
m_indent(0u),
m_entity_index(0u),
m_brush_index(0u)
{
}
void MapFileDumper::Indent() const
{
for (auto i = 0u; i < m_indent; i++)
m_stream << " ";
}
void MapFileDumper::IncIndent()
{
++m_indent;
}
void MapFileDumper::DecIndent()
{
assert(m_indent > 0);
if (m_indent > 0)
m_indent--;
}
void MapFileDumper::Init() const
{
m_stream << "iwmap 4\n";

View File

@ -2,7 +2,9 @@
#include <ostream>
class MapFileDumper
#include "Dumping/AbstractTextDumper.h"
class MapFileDumper : AbstractTextDumper
{
public:
union Vec3
@ -13,6 +15,7 @@ public:
float m_y;
float m_z;
};
float v[3];
Vec3(float x, float y, float z);
@ -39,21 +42,15 @@ public:
};
private:
std::ostream& m_stream;
struct
{
bool m_in_entity : 1;
bool m_in_brush : 1;
} m_flags;
size_t m_indent;
size_t m_entity_index;
size_t m_brush_index;
void Indent() const;
void IncIndent();
void DecIndent();
public:
explicit MapFileDumper(std::ostream& stream);

View File

@ -9,7 +9,7 @@ SndCurveDumper::SndCurveDumper(std::ostream& stream)
}
SndCurveDumper::SndCurveDumper(std::ostream& stream, const size_t precision)
: m_stream(stream),
: AbstractTextDumper(stream),
m_precision(precision),
m_current_knot(0u),
m_total_knots(0u)

View File

@ -1,11 +1,13 @@
#pragma once
#include <ostream>
class SndCurveDumper
#include "Dumping/AbstractTextDumper.h"
class SndCurveDumper : AbstractTextDumper
{
static constexpr auto DEFAULT_PRECISION = 4;
std::ostream& m_stream;
size_t m_precision;
size_t m_current_knot;
size_t m_total_knots;