Yttrium Insights, part 2: In and Out - The System Builder

Published 04 Mai 06 01:57 | Christoph Rüegg
A recent addition to the Yttrium framework is the system builder. The idea is to define a "command based" description of a math system (MathSystem class) to seperate the construction of such a system from the system itself. In incorporates ideas from the builder design pattern. The central point is the ISystemBuilder interface, defining the description mentioned above.

There are always to parts, communication by the said interface: a director or reader, and a builder or writer. The interesting point is that both parts are interchangeable: any reader works with any writer and vice versa.

Predefined Writers
  • SystemWriter: constructs a complete math system.
  • XmlSystemWriter: describes a complete system in Xml.
  • ExpressionWriter: experimental, describes a system in the Yttrium expression language supported by the parsing infrastructre (kinf of a mixture between the Maple language and VHDL).
Predefined Readers
  • SystemReader: describes a complete math system.
  • XmlSystemReader: describes a complete system based on Xml.
Because the parts may be combined at will, it opens several useful operations:

Cloning a MathSystem


Cloning a system is as simple as combining a SystemReader with a SystemWriter:

SystemWriter writer = new SystemWriter(myContext);
SystemReader reader = new SystemReader(writer);
reader.ReadSystem(mySystem);
MathSystem clone = writer.WrittenSystems.Dequeue();


Shortcut:

MathSystem clone = mySystem.Clone();


Serialize a MathSystem to Xml

Just combine the SystemReader with an XmlWriter:

XmlSystemWriter writer = new XmlSystemWriter(myContext, myWriter);
SystemReader reader = new SystemReader(writer);
reader.ReadSystem(mySystem);
myWriter.Flush();

Shortcut:

mySystem.WriteXml(myWriter);


Deserialize a MathSystem from Xml

SystemWriter writer = new SystemWriter(myContext);
XmlSystemReader reader = new XmlSystemReader(writer);
xreader.ReadSystems(myReader, false);
MathSystem system = writer.WrittenSystems.Dequeue();


Shortcut:

MathSystem
system = MathSystem.ReadXml(myReader, myContext);

Comments

No Comments