annotate presetManager.h @ 4:7541aeaebcdc

presest store locally. bit crap still though.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 04 Dec 2012 18:36:00 +0000
parents 43df75088d85
children 5ee5ef99e117
rev   line source
rt300@0 1 //
rt300@0 2 // presetManager.h
rt300@0 3 // oscSenderExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 07/11/2012.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #ifndef __oscSenderExample__presetManager__
rt300@0 10 #define __oscSenderExample__presetManager__
rt300@0 11
rt300@0 12 #include <iostream>
rt300@0 13 #include "ofMain.h"
rt300@0 14 #include "ofxiPhone.h"
rt300@0 15 #include "ofxiPhoneExtras.h"
rt300@0 16 #include "2dvector.h"
rt300@3 17 #include "grid.h"
rt300@3 18
rt300@0 19
rt300@0 20 //---------------------------------------------------------------------------
rt300@0 21 class Preset{
rt300@3 22 public:
rt300@0 23
rt300@0 24 int presetID;
rt300@0 25 string name;
rt300@4 26 long long savetime;
rt300@4 27 double timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 28
rt300@0 29 TwoVector coordinates;
rt300@3 30
rt300@0 31 Preset(TwoVector acoord, string aname,int aID){
rt300@0 32 coordinates = acoord;
rt300@0 33 name = aname;
rt300@0 34 presetID = aID;
rt300@4 35
rt300@4 36 timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 37 savetime = (long long)(timemsd*1000);
rt300@3 38
rt300@3 39 };
rt300@3 40 Preset(int aID){
rt300@3 41 coordinates.setCoord(0.0,0.0);
rt300@3 42 name = "Blank";
rt300@3 43 presetID = aID;
rt300@4 44 timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@4 45 savetime = (long long)(timemsd*1000);
rt300@4 46
rt300@4 47 };
rt300@4 48
rt300@4 49 Preset(TwoVector acoord, string aname,int aID, long long stime){
rt300@4 50 coordinates = acoord;
rt300@4 51 name = aname;
rt300@4 52 presetID = aID;
rt300@4 53 savetime = stime;
rt300@0 54
rt300@0 55 };
rt300@3 56
rt300@0 57 };
rt300@3 58
rt300@3 59
rt300@3 60 //---------------------------------------------------------------------------
rt300@0 61 class PresetManager{
rt300@0 62 public:
rt300@0 63 int nextID;
rt300@3 64 int timesOpened;
rt300@0 65 // names values
rt300@0 66 // check if already there
rt300@0 67 // find and return all(?) presets within a certain coordinate range
rt300@0 68 vector<Preset *> thePresets; // we want vector ? or list? pointers using new?
rt300@0 69
rt300@0 70 int addPreset(TwoVector coord, string name); // returns id or negative error number
rt300@4 71 int loadPreset(const TwoVector coord, const string name, long long stime);
rt300@4 72
rt300@0 73 TwoVector recallPreset(int presetID); // by name ? id?
rt300@0 74 TwoVector recallPreset(string name); // by name ? id?
rt300@0 75 vector<TwoVector > getPresetsInRange(TwoVector min, TwoVector max);
rt300@4 76 void printAll();
rt300@0 77
rt300@0 78 void startupLoadAll(); // get stuff from XML
rt300@0 79 void exitAndSaveAll(); // save to XML, delete presets array (?)
rt300@4 80 void deleteAll();
rt300@0 81
rt300@0 82 PresetManager();
rt300@0 83 };
rt300@0 84
rt300@4 85
rt300@4 86 //---------------------------------------------------------------------------
rt300@4 87 inline ostream& operator<<(ostream & os, const Preset& p){
rt300@4 88 os.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 89 os.precision(1);
rt300@4 90
rt300@4 91 os << p.savetime << ',' << p.coordinates.x << ',' << p.coordinates.y << '\n';
rt300@4 92
rt300@4 93 return os;
rt300@4 94 }
rt300@4 95
rt300@4 96 //---------------------------------------------------------------------------
rt300@4 97 inline istream& operator>>(istream & is, PresetManager& p)
rt300@4 98 {
rt300@4 99 //um
rt300@4 100 string pname = "BLANK";
rt300@4 101 char delim;
rt300@4 102 double px, py;
rt300@4 103 long long stime;
rt300@4 104
rt300@4 105
rt300@4 106 is.setf(ios_base::fixed,ios_base::floatfield);
rt300@4 107 is.precision(1);
rt300@4 108
rt300@4 109 is >> stime >> delim >> px >> delim >> py;
rt300@4 110 if(!is){
rt300@4 111 cout << "problem reading preset file";
rt300@4 112 return(is);
rt300@4 113 }
rt300@4 114 TwoVector pcoord(px,py);
rt300@4 115 int n = p.loadPreset(pcoord, pname, stime);
rt300@4 116 cout << "read preset : " << n << '\n';
rt300@4 117 return(is);
rt300@4 118 }
rt300@4 119
rt300@0 120 #endif /* defined(__oscSenderExample__presetManager__) */