From: Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
Date: Tue, 8 Nov 2011 09:08:11 +0000 (+0000)
Subject: Almost-correct toPlainText
X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=cf035fa1849a5e65c0d636ce2718bc2c85994680;p=odcread.git

Almost-correct toPlainText
---

diff --git a/alien.cc b/alien.cc
index 49d19fe..fddd202 100644
--- a/alien.cc
+++ b/alien.cc
@@ -8,15 +8,26 @@ std::string AlienPiece::toString() {
 	return std::string("AlienPiece");
 }
 
-AlienPart::AlienPart(Store * const _store): store(_store) {}
+std::string AlienPiece::toPlainText() {
+	return std::string();
+}
+
+AlienPart::AlienPart(Store * const store): d_store(store) {}
 
 std::string AlienPart::toString() {
-	if (store != 0)
-		return store->toString();
+	if (d_store != 0)
+		return d_store->toString();
 	else
 		return "NULL";
 }
 
+std::string AlienPart::toPlainText() {
+	if (d_store != 0)
+		return d_store->toPlainText();
+	else
+		return std::string();
+}
+
 Alien::Alien(INTEGER id, const TypePath &path): Store(id), d_path(path), d_comps() {}
 
 std::vector<AlienComponent*> & Alien::getComponents() {
@@ -31,4 +42,12 @@ std::string Alien::toString() {
 	return sofar + "}";
 }
 
+std::string Alien::toPlainText() {
+	std::string sofar = std::string();
+	for (int i = 0; i < d_comps.size(); ++i) {
+		sofar += d_comps[i]->toPlainText();
+	}
+	return sofar;
+}
+
 }
diff --git a/alien.h b/alien.h
index 0c4b51d..7447f95 100644
--- a/alien.h
+++ b/alien.h
@@ -14,6 +14,7 @@ namespace odc {
  */
 struct AlienComponent {
 	virtual std::string toString() = 0;
+	virtual std::string toPlainText() = 0;
 };
 
 /**
@@ -26,17 +27,19 @@ struct AlienPiece : public AlienComponent {
 	AlienPiece(const char * const data, const size_t len);
 
 	virtual std::string toString();
+	virtual std::string toPlainText();
 };
 
 /**
  * Store component of an alien store
  */
 struct AlienPart : public AlienComponent {
-	Store * const store;
+	Store * const d_store;
 
-	AlienPart(Store * const _store);
+	AlienPart(Store * const store);
 
 	virtual std::string toString();
+	virtual std::string toPlainText();
 };
 
 class Alien : public Store {
@@ -54,6 +57,7 @@ class Alien : public Store {
 	// comps-: AlienComp	(** the constituent components of this alien store **)
 
 	virtual std::string toString();
+	virtual std::string toPlainText();
 };
 
 }
diff --git a/fold.cc b/fold.cc
index b416401..ae4d016 100644
--- a/fold.cc
+++ b/fold.cc
@@ -67,7 +67,14 @@ std::string Fold::toString() {
 	if (d_hidden == 0) {
 		return std::string("Fold(right)");
 	}
-	return std::string("Fold(left)") + std::string(" { ") + d_hidden->toString() + std::string("  }");
+	return std::string("Fold(left) \"") + std::string(d_label) + std::string("\" { ") + d_hidden->toString() + std::string("  }");
+}
+
+std::string Fold::toPlainText() {
+	if (d_hidden == 0) {
+		return std::string();
+	}
+	return std::string(d_label) + std::string("\n") + d_hidden->toPlainText();
 }
 
 } // namespace odc
diff --git a/fold.h b/fold.h
index 78eaa4e..e53e06d 100644
--- a/fold.h
+++ b/fold.h
@@ -36,6 +36,7 @@ namespace odc {
 		virtual void internalize(Reader &reader);
 
 		virtual std::string toString();
+		virtual std::string toPlainText();
 	};
 
 }
diff --git a/odcread.cc b/odcread.cc
index 6d50668..151c861 100644
--- a/odcread.cc
+++ b/odcread.cc
@@ -30,13 +30,14 @@ int main(int argc, char *argv[]) {
 	}
 	std::ifstream in(argv[1], std::ios::in | std::ios::binary);
 	odc::Store* s = odc::importDocument(in);
-	std::cout << std::endl << std::endl;
+//	std::cout << s->toPlainText() << std::endl;
+//	std::cout << std::endl << std::endl;
 
 	std::cout << s->toString() << std::endl;
-	std::cout << in.tellg() << " " << in.eof() << std::endl;
+//	std::cout << in.tellg() << " " << in.eof() << std::endl;
 
-	odc::TypePath path;
-	odc::ContainerModel(0).getTypePath(&path);
-	std::cout << path.toString() << std::endl;
+//	odc::TypePath path;
+//	odc::ContainerModel(0).getTypePath(&path);
+//	std::cout << path.toString() << std::endl;
 	return 0;
 }
diff --git a/store.cc b/store.cc
index c2fd5b4..d03467c 100644
--- a/store.cc
+++ b/store.cc
@@ -65,6 +65,10 @@ std::string Store::toString() {
 	return getTypeName(); 
 }
 
+std::string Store::toPlainText() {
+	return std::string();
+}
+
 const std::string Elem::TYPENAME("Stores.Elem^");
 const TypeProxy<Elem> Elem::PROXY;
 
diff --git a/store.h b/store.h
index da84340..66e58b0 100644
--- a/store.h
+++ b/store.h
@@ -130,6 +130,7 @@ namespace odc {
 		// FIXME
 
 		virtual std::string toString();
+		virtual std::string toPlainText();
 
 		private:
 		void calcTypePath(TypePath * out, const std::string &name) const;
diff --git a/textmodel.cc b/textmodel.cc
index 81ac03d..977bd44 100644
--- a/textmodel.cc
+++ b/textmodel.cc
@@ -157,6 +157,14 @@ std::string StdTextModel::toString() {
 	return sofar + "}";
 }
 
+std::string StdTextModel::toPlainText() {
+	std::string sofar = "";
+	for (int i = 0; i < d_pieces.size(); ++i) {
+		sofar += d_pieces[i]->toPlainText();
+	}
+	return sofar;
+}
+
 TextPiece::TextPiece(size_t len): d_len(len) {}
 
 LongPiece::LongPiece(size_t len): TextPiece(len) {}
@@ -174,6 +182,10 @@ std::string LongPiece::toString() {
 	return std::string("LongPiece(FIXME)");// + std::wstring((wchar_t*)d_buf) + std::string(")");
 }
 
+std::string LongPiece::toPlainText() {
+	return std::string("FIXME");// + std::wstring((wchar_t*)d_buf) + std::string(")");
+}
+
 ShortPiece::ShortPiece(size_t len): TextPiece(len) {}
 
 ShortPiece::~ShortPiece() {
@@ -197,6 +209,10 @@ std::string ShortPiece::toString() {
 	return std::string("ShortPiece(") + std::string(d_buf) + std::string(")");
 }
 
+std::string ShortPiece::toPlainText() {
+	return std::string(d_buf);
+}
+
 ViewPiece::ViewPiece(Store *view): TextPiece(0), d_view(view) {}
 
 void ViewPiece::read(Reader &reader) {
@@ -207,4 +223,8 @@ std::string ViewPiece::toString() {
 	return std::string("ViewPiece { ") + d_view->toString() + " }";
 }
 
+std::string ViewPiece::toPlainText() {
+	return d_view->toPlainText();
+}
+
 } // namespace odc
diff --git a/textmodel.h b/textmodel.h
index 9cab44d..38eb7c5 100644
--- a/textmodel.h
+++ b/textmodel.h
@@ -26,6 +26,7 @@ namespace odc {
 		TextPiece(size_t len);
 		virtual void read(Reader &reader) = 0;
 		virtual std::string toString() = 0;
+		virtual std::string toPlainText() = 0;
 	};
 
 	class LongPiece : public TextPiece {
@@ -36,6 +37,7 @@ namespace odc {
 		~LongPiece();
 		virtual void read(Reader &reader);
 		virtual std::string toString();
+		virtual std::string toPlainText();
 	};
 
 	class ShortPiece : public TextPiece {
@@ -46,6 +48,7 @@ namespace odc {
 		~ShortPiece();
 		virtual void read(Reader &reader);
 		virtual std::string toString();
+		virtual std::string toPlainText();
 	};
 
 	class ViewPiece : public TextPiece {
@@ -54,6 +57,7 @@ namespace odc {
 		ViewPiece(Store *view);
 		virtual void read(Reader &reader);
 		virtual std::string toString();
+		virtual std::string toPlainText();
 	};
 
 	class StdTextModel : public TextModel {
@@ -70,6 +74,7 @@ namespace odc {
 		virtual void internalize(Reader &reader);
 
 		virtual std::string toString();
+		virtual std::string toPlainText();
 	};
 
 } // namespace odc