LAview.LaTeX-Struct/src/latex-struct/DocIfaces.vala

76 lines
1.4 KiB
Vala
Raw Normal View History

2014-04-09 17:43:14 +04:00
namespace LAview {
/**
* Interface of any LaTeX Document.
*/
public interface IDoc : Object {
/**
2014-07-25 18:30:55 +04:00
* Gets a copy of the ``IDoc``.
2014-04-09 17:43:14 +04:00
*/
public abstract IDoc copy ();
/**
2014-07-25 18:30:55 +04:00
* Generates LaTeX string for the ``IDoc``.
2014-04-09 17:43:14 +04:00
*/
public abstract string generate ();
}
/**
* Any non-iterable LaTeX Document.
*/
public abstract class ADoc : Object, IDoc {
protected ADoc () {}
/**
2014-07-25 18:30:55 +04:00
* Gets a copy of the ``ADoc``.
2014-04-09 17:43:14 +04:00
*/
public virtual IDoc copy () {
return Object.new (this.get_type ()) as IDoc;
}
/**
2014-07-25 18:30:55 +04:00
* Generates LaTeX string for the ``ADoc``.
2014-04-09 17:43:14 +04:00
*/
public virtual string generate () { return ""; }
}
/**
* Any iterable LaTeX Document.
*/
public abstract class ADocList<T> : Gee.ArrayList<T>, IDoc {
2014-04-09 17:43:14 +04:00
protected ADocList () {}
/**
* Object.new (this.get_type ()) doesn't work for me for ArrayList.
*/
protected abstract ADocList<T> create_default_instance ();
2014-04-09 17:43:14 +04:00
/**
2014-07-25 18:30:55 +04:00
* Gets a copy of the ``ADocList``.
2014-04-09 17:43:14 +04:00
*/
public virtual IDoc copy () {
var clone = create_default_instance ();
foreach (T dociface in this)
clone.add ((dociface as IDoc).copy ());
2014-04-09 17:43:14 +04:00
return clone;
}
/**
2014-07-25 18:30:55 +04:00
* Generates LaTeX string for the ``ADocList``.
2014-04-09 17:43:14 +04:00
*/
public virtual string generate () {
var result = new StringBuilder ();
foreach (T dociface in this)
result.append ((dociface as IDoc).generate ());
2014-04-09 17:43:14 +04:00
return result.str;
}
}
}