whitebox.h

来自「ALGAE是一个快速创建算法演示的框架。目前支持的算法实现语言包括java和c」· C头文件 代码 · 共 88 行

H
88 行
字号
#ifndef WHITEBOX_H#define WHITEBOX_H#include <algae/visible.h>#include <algorithm>#include <strstream>#include <vector>////  A WhiteBox is simply a white (and therefore invisible) container//  of other Visible items.   It forms a convenient way to gather a//  a group of small visible items into a row or column so that they//  don't scatter all around the screen.  It can also represent a programming//  convenience, since by showing/hiding the whitebox, the visibility of all //  of the elements added to it can be altered at once.//  class WhiteBox : public Visible{public:  WhiteBox (bool vertical = false);  void add (const Visible* newComponent);  void add (const Visible& newComponent);  void remove (Visible* oldComponent);    //   //  The usual Visible overrides:  virtual void touchAllComponents() const;  virtual void writeText (STD ostream &) const  {}private:  vector<const Visible*> contents;  struct WBsearch   {    const Visible* lookFor;        WBsearch (const Visible* lf): lookFor(lf) {}        bool operator() (const Visible* v) {return v->id() == lookFor->id();}  };};inline WhiteBox::WhiteBox (bool vertical)  : Visible(AlgAE::White, vertical){}inline void WhiteBox::add (const Visible* newComponent){  contents.push_back (newComponent);}inline void WhiteBox::add (const Visible& newComponent){  contents.push_back (&newComponent);}inline void WhiteBox::remove (Visible* oldComponent){  vector<const Visible*>::iterator p    = find_if(contents.begin(),	      contents.end(),	      WBsearch(oldComponent));    if (p != contents.end())    contents.erase (p);}inline void WhiteBox::touchAllComponents() const{  for (int i = 0; i < contents.size(); ++i)    touch (contents[i]);}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?