Commits

Anonymous committed 2f8f34e

Added some code.

Comments (0)

Files changed (8)

+SRC = \
+	src/main.cpp \
+	src/object.cpp \
+	src/line.cpp
+
+HEADERS = \
+	src/object.h \
+	src/line.h \
+	src/point.h
+
+OBJ = ${SRC:.cpp=.o}
+CC = g++
+CFLAGS = -Wall -g
+EXECUTABLE = bin/app
+
+all: app
+
+${OBJ}: ${HEADERS}
+
+${EXECUTABLE}: ${OBJ}
+	${CC} ${CFLAGS} ${OBJ} -o ${EXECUTABLE}
+
+$.o: $.cpp
+	${CC} ${CFLAGS} -c -o $@ $<
+
+app: ${EXECUTABLE} ${HEADERS}
+
+.PHONY: all app
+Binaries go here.
+#include <iostream>
+#include "line.h"
+
+using namespace svg;
+
+
+void Line::write_svg(std::ostream &stream) const
+{
+	stream << "<line "
+		<< "x1=\"" << _start.get_x() << "\" "
+		<< "y1=\"" << _start.get_y() << "\" "
+		<< "x2=\"" << _end.get_x() << "\" "
+		<< "y2=\"" << _end.get_y() << "\" "
+		<< "style=\"stroke: black; stroke-width: 2\" />";
+}
+#ifndef _SVG_LINE_H
+#define _SVG_LINE_H
+
+#include <string>
+#include "object.h"
+#include "point.h"
+
+namespace svg {
+
+	class Line : public Object {
+		const Point _start;
+		const Point _end;
+		Line(const Line &);
+
+	public:
+		Line() {}
+		Line(Point start, Point end)
+			: _start(start), _end(end) {}
+
+		inline const Point &get_start() const
+		{
+			return _start;
+		}
+
+		inline const Point &get_end() const
+		{
+			return _end;
+		}
+
+		void write_svg(std::ostream &stream) const;
+	};
+
+}
+
+#endif
+#include <iostream>
+#include "object.h"
+#include "line.h"
+#include "point.h"
+
+using namespace svg;
+
+
+int main()
+{
+	Object *l = new Line(Point(1, 2), Point(4, 5));
+	l->write_svg(std::cout);
+	std::cout << "\n";
+	delete l;
+}
+#include <iostream>
+#include "object.h"
+
+using namespace svg;
+
+
+void Object::write_svg(std::ostream &stream) const
+{
+	stream << "<!-- unimplemented object " << this << " -->";
+}
+#ifndef _SVG_OBJECT_H
+#define _SVG_OBJECT_H
+#include <string>
+
+namespace svg {
+
+	class Object {
+		const std::string _id;
+		Object(const Object &);
+
+	public:
+		Object() : _id("") {}
+		Object(std::string id) : _id(id) {}
+		virtual ~Object() {}
+
+		inline std::string get_id() const
+		{
+			return _id;
+		}
+
+		virtual void write_svg(std::ostream &stream) const;
+	};
+
+}
+
+#endif
+#ifndef _SVG_POINT_H
+#define _SVG_POINT_H
+
+namespace svg {
+
+	class Point {
+		int _x;
+		int _y;
+
+	public:
+		inline Point() : _x(0), _y(0) {}
+		inline Point(int x, int y) : _x(x), _y(y) {}
+		inline Point(const Point &point) : _x(point._x), _y(point._y) {}
+
+		inline int get_x() const
+		{
+			return _x;
+		}
+
+		inline int get_y() const
+		{
+			return _y;
+		}
+	};
+
+}
+
+#endif