Source: OmDocumentNode.h


Annotated List
Files
Globals
Hierarchy
Index
#ifndef OM_DOCUMENT_NODE_H
#define OM_DOCUMENT_NODE_H

/**
 * The document node structure.
 *
 * This class provides a specialization of OmNode to implement the Document node construction.
 * This corresponds to a sequence of OpenMath objects X[0..N].
 * This is encoded as X0 ... Xn
 * The list of children must represent the enclosed sequence of <X0, ..., Xn>.
 */
class OmDocumentNode : public OmNode
{
public:
  /** 
   * Default constructor.
   */
  OmDocumentNode() {}

  /**
   * Save the document to an output device.
   * The current (this) node is returned.
   */
  virtual OmDocumentNode * save(OmOutputDevice & output_in) {
    writeImp(output_in);
    return this; }

  /**
   * Load the document from an input device.
   * The current (this) node is returned.
   */
  virtual OmDocumentNode * load(OmInputDevice & input_in) {
    readImp(input_in);
    return this; }

  /**
   * Destructor.
   */
  virtual ~OmDocumentNode() {}

protected:
  /**
   * Copy constructor.
   */
  OmDocumentNode(const OmDocumentNode & other_in)
    : OmNode(other_in) {}

  /**
   * Implement access to the concrete type.
   */
  virtual OmType typeImp() const {
    return OmUnknownType; }

  /**
   * Implement the deep cloning.
   */
  virtual OmNode * cloneImp() const {
    return new OmDocumentNode(*this); }

  /**
   * Implement the writing to an output device.
   */
  virtual void writeImp(OmOutputDevice & output_in) const {
    for (ConstIterator it=iterate(); !it.done(); it.next()) {
      hibernate(output_in, it.get()); } }

  /**
   * Implement the reading from an input device.
   */
  virtual void readImp(OmInputDevice & input_in) {
    OmCommentCollector cc;
    try {
      while (true) {
	cc.collect(input_in);
	append(cc.uncollect(OmNode::resurrect(input_in))); } }
    catch (OmException & e) {
      if (e.getType()==OmException::Underlying && e.getStatus()==OmNoMoreTokenStatus) return;
      else throw; } }
};

#endif // OM_DOCUMENT_NODE_H

Generated by: root@localhost.localdomain on Tue Oct 12 21:02:30 199.