00001 // $Header: /nfs/slac/g/glast/ground/cvs/gui/gui/DisplayMenu.h,v 1.1.1.1 2001/01/04 01:01:11 burnett Exp $ 00002 #ifndef D0VE_DISPLAYMENU_HPP 00003 #define D0VE_DISPLAYMENU_HPP 00004 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00005 #include "gui/DisplayControl.h" 00006 #include "gui/DisplayRep.h" 00007 00008 namespace gui { 00009 00010 // class that should be below, but KAI compiler chokes 00011 class AnonymousRep : public DisplayRep { public: void update(){}; void clear(){};}; 00012 00013 template <class Element, class Key, class Rep>class DisplayMenu 00014 // Purpose: combine static display elements according to some criterion, 00015 // with individual show/hide capability on a named button. 00016 // template arguments: 00017 // Element: a class with 3D info to display 00018 // Key: a class that classifies instances of Element: must have constructor 00019 // Key(const Element&), and be usable as a key: e.g., an operator int(), 00020 // and a member function std::string name(). (Which could be the key.) 00021 // Rep: a DisplayRep that has constructor Rep(const Element&); 00022 // all Elements with the same Key will be appended to a rep on the button with label name. 00023 { 00024 public: 00025 DisplayMenu(DisplayControl::SubMenu& menu):_menu(menu),_count(0){} 00026 // ctor: specify menu to add buttons to. 00027 00028 void add(const Element& element) 00029 // add a new instance of the class Element to the display. Will create a new button 00030 // if Key returns a new value, otherwist append its display to previous with that 00031 // value. 00032 { 00033 //KAI chokes: cannot be here 00034 //class AnonymousRep : public DisplayRep { public: void update(){}; void clear(){};}; 00035 ++_count; 00036 Key key(element); 00037 if( _map.find(key)==_map.end()) { 00038 _map[key]=new AnonymousRep; 00039 _menu.add(_map[key], key.name()); 00040 } 00041 Rep r(element); 00042 _map[key]->append(r); 00043 } 00044 int count()const {return _count;} 00045 // number of times added to 00046 00047 int size()const { return _map.size();} 00048 // number of different keys found 00049 private: 00050 std::map<Key, DisplayRep*> _map; 00051 DisplayControl::SubMenu& _menu; 00052 int _count; 00053 }; 00054 00055 } // namespace gui 00056 #endif // D0VE_DISPLAYMENU_HPP 00057 00058
1.2.3 written by Dimitri van Heesch,
© 1997-2000