1 /* -*- c++ -*- 2 FILE: MacroManager.h 3 RCS REVISION: $Revision: 1.12 $ 4 5 COPYRIGHT: (c) 1999 -- 2003 Melinda Green, Don Hatch, and Jay Berkenbilt - Superliminal Software 6 7 LICENSE: Free to use and modify for non-commercial purposes as long as the 8 following conditions are adhered to: 9 1) Obvious credit for the source of this code and the designs it embodies 10 are clearly made, and 11 2) Ports and derived versions of 4D Magic Cube programs are not distributed 12 without the express written permission of the authors. 13 14 DESCRIPTION: 15 This class provides the primary interface for working with 16 macros. It keeps track of which macros are currently in use and 17 serves as a proxy for communicating with the Macro class. This 18 is done so that additional state required when interacting with 19 Macros can be stored in one place and not made the concern of the 20 clients. 21 */ 22 23 #ifndef MACROMANAGER_H 24 #define MACROMANAGER_H 25 26 #include "MagicCube.h" 27 #include "Macro.h" 28 #include <stdio.h> 29 30 class Preferences; 31 class PolygonManager4D; 32 33 class MacroManager 34 { 35 public: 36 enum mode_e { m_reading, m_writing }; 37 38 MacroManager(Preferences&, PolygonManager4D*); 39 ~MacroManager(); 40 41 void* destroy(int which); 42 void create(char *name, int nrefs, int refs[MAXREFS][4]); 43 void setUIData(int which, void* ui_data); 44 void* getUIData(int which); 45 int findWithUIData(void* ui_data); 46 47 // Convenience functions 48 void setMacroName(int which, char *name); 49 char *getMacroName(int i); 50 void setMacroRefs(int which, int nrefs, int refs[MAXREFS][4]); 51 52 // Returns true on success, false if reading and it doesn't exist 53 // or the reference stickers don't match the macro. 54 bool open(int which, int nrefs, int refs[MAXREFS][4], 55 mode_e mode, int direction); 56 void close(); 57 58 void setRefs(int which, int nrefs, int refs[MAXREFS][4]); 59 60 // Return true on success, false if not opened properly. Return 61 // true and do nothing if no macro is open. 62 bool addMove(struct stickerspec *sticker, int dir, int slicesmask); 63 // Return true on success, false if at end of the macro 64 bool getMove(struct stickerspec* grip, int* direction, int* slicesmask); 65 66 void dump(FILE *fp); 67 // Returns true on success 68 bool read(FILE *fp); 69 int getNMacros(); 70 71 private: 72 Preferences& prefs; 73 PolygonManager4D* polymgr; 74 75 int nmacros; 76 int nmacros_allocated; 77 Macro** the_macros; 78 79 Macro* the_writing_macro; 80 Macro* the_reading_macro; 81 int the_reading_macro_direction; 82 int the_reading_mat[4][4]; 83 int the_reading_mat_det; 84 }; 85 86 #endif 87 88 // Local Variables: 89 // c-basic-offset: 4 90 // c-comment-only-line-offset: 0 91 // c-file-offsets: ((defun-block-intro . +) (block-open . 0) (substatement-open . 0) (statement-cont . +) (statement-case-open . +4) (arglist-intro . +) (arglist-close . +) (inline-open . 0)) 92 // indent-tabs-mode: nil 93 // End: 94