📄 visible.h
字号:
#ifndef VISIBLE_H#define VISIBLE_H#include <algae/algae.h>#include <functional>#include <iostream>// The ALGAE animator displays those objects that are subclasses// of class Visibleclass Visible{private: Visible() {} // Can't create a Visible object without parameters.public: static const std::string emptyLabel; Visible (AlgAE::Color color, bool vertical = true); // color: color to use when displaying object // vertical: If this object has Visible components, should the // components be stacked vertically (false => horizontally) // Ignored if object has no Visible components. Visible (const Visible&); void operator= (const Visible&) {} virtual ~Visible(); void touch (const Visible* ptr, AlgAE::Directions dir=AlgAE::AnyDir, const std::string& edgeLabel = emptyLabel ) const; void touch (const Visible& ptr, AlgAE::Directions dir=AlgAE::AnyDir, const std::string& edgeLabel = emptyLabel ) const; // The programmer of a Visible subclass S has 4 main obligations. // 1) The non-copy constructors S must invoke the Visible constructor // above with the proper values for color. // 2) If the object is to be portrayed as having pointer/arrows to other // Visible objects, then a new body must be supplied for the virtual // member function touchAllPointers. // // When s.touchAllPointers() is called, then for each pointer p // from s to another Visible object, the programmer's code should // call s.touch(p, dir). dir is the "exit" direction from which // the ALGAE system will draw the arrow denoting that pointer. // [For convenience, an alternate form of touch() is provided that // accepts references to Visible objects rather than pointers. Use // whichever works better with your ADTs.] // 3) A virtual member function writeText(ostream&) must be supplied, // which writes the text to be displayed in the picture of the object // into the given output stream. // 4) If the object is to be portrayed as a compound structure containing // other Visible objects, then a new body must be supplied for the // virtual member function touchAllComponents. // // When s.touchAllComponents() is called, then for each contained // component p, the programmer's code should // call s.touch(p). [This is the same touch() function employed in // step 2, but the direction and edgeLabel parameters are ignored in // this case. virtual void touchAllPointers() const {} virtual void writeText(std::ostream&) const = 0; virtual void touchAllComponents() const {}//////////////////////////////////////////////////// // The remaining functions provide ways to elaborate on basic // animations. // Highlight (temporary color changes) nodes void highlight() const; void highlight(AlgAE::Color color) const; void unHighlight() const; // Highlight (temporary color changes) pointers void highlight(AlgAE::Directions dir) const; // highlight by direction void unHighlight(AlgAE::Directions dir) const; void highlight(const Visible* ptr) const; // highlight by identity ot void unHighlight(const Visible* ptr) const; // object pointed to // Turn off both node and pointer highlights for all objects. static void unHighlightAll(); // Permanent color change to nodes void setColor (AlgAE::Color color) const; // What is the current color of this node? (may have been changed // via highlighting) AlgAE::Color color() const; // Show this object (and all others reachable from it) in // the animation drawings. void show() const; // Prevent this object from appearing in the animation drawings unless // it is pointed to or contained within another object being drawn. void hide() const; // Prevent this object, and all that have been show()'n since it, from // appearing in the animation drawings unless // it is pointed to or contained within another object being drawn. void hideAllSince() const; // Assign the object a "name" to be used when displaying it void setName (const std::string&) const; void setName (const char*) const; // What is the assigned name for this object? std::string getName () const; // What ID does this object have? int id () const; // Change vertical/horizontal arrangement void setVertical (bool vert) const; // Should components of this object be arranged vertically? bool vertical() const; // Utility comparison functors typedef std::binary_function<Visible, Visible, bool> Comparator; class LessThanID: public Visible::Comparator { // LessThanID()(x,y) == (x.id() < y.id()) public: bool operator() (const Visible& x, const Visible& y); }; class EqualID: public Visible::Comparator { // EqualID()(x,y) == (x.id() == y.id()) bool operator() (const Visible& x, const Visible& y); }; private: // unique integer ID for this object int ID; struct VisibleInfo; VisibleInfo* vis; static unsigned lastID; AlgAE::Color edgeColor (const Visible* dest, AlgAE::Directions dir) const; void setMark (bool) const; bool marked() const; void Visible::clearHighlighting(); friend void AlgAE::unHighlightAll(); friend void AlgAE::enqueue(const Visible*); friend void AlgAE::describeData(); };#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -