rt300@0: // rt300@0: // presetManager.h rt300@0: // oscSenderExample rt300@0: // rt300@0: // Created by Robert Tubb on 07/11/2012. rt300@0: // rt300@0: // rt300@0: rt300@0: #ifndef __oscSenderExample__presetManager__ rt300@0: #define __oscSenderExample__presetManager__ rt300@0: rt300@0: #include rt300@0: #include "ofMain.h" rt300@0: #include "ofxiPhone.h" rt300@0: #include "ofxiPhoneExtras.h" rt300@0: #include "2dvector.h" rt300@3: #include "grid.h" rt300@3: rt300@0: rt300@0: //--------------------------------------------------------------------------- rt300@0: class Preset{ rt300@3: public: rt300@0: rt300@0: int presetID; rt300@0: string name; rt300@4: long long savetime; rt300@4: double timemsd = [NSDate timeIntervalSinceReferenceDate]; rt300@4: rt300@0: TwoVector coordinates; rt300@3: rt300@0: Preset(TwoVector acoord, string aname,int aID){ rt300@0: coordinates = acoord; rt300@0: name = aname; rt300@0: presetID = aID; rt300@4: rt300@4: timemsd = [NSDate timeIntervalSinceReferenceDate]; rt300@4: savetime = (long long)(timemsd*1000); rt300@3: rt300@3: }; rt300@3: Preset(int aID){ rt300@3: coordinates.setCoord(0.0,0.0); rt300@3: name = "Blank"; rt300@3: presetID = aID; rt300@4: timemsd = [NSDate timeIntervalSinceReferenceDate]; rt300@4: savetime = (long long)(timemsd*1000); rt300@4: rt300@4: }; rt300@4: rt300@4: Preset(TwoVector acoord, string aname,int aID, long long stime){ rt300@4: coordinates = acoord; rt300@4: name = aname; rt300@4: presetID = aID; rt300@4: savetime = stime; rt300@0: rt300@0: }; rt300@3: rt300@0: }; rt300@3: rt300@3: rt300@3: //--------------------------------------------------------------------------- rt300@0: class PresetManager{ rt300@0: public: rt300@0: int nextID; rt300@3: int timesOpened; rt300@0: // names values rt300@0: // check if already there rt300@0: // find and return all(?) presets within a certain coordinate range rt300@0: vector thePresets; // we want vector ? or list? pointers using new? rt300@0: rt300@0: int addPreset(TwoVector coord, string name); // returns id or negative error number rt300@4: int loadPreset(const TwoVector coord, const string name, long long stime); rt300@4: rt300@0: TwoVector recallPreset(int presetID); // by name ? id? rt300@0: TwoVector recallPreset(string name); // by name ? id? rt300@0: vector getPresetsInRange(TwoVector min, TwoVector max); rt300@4: void printAll(); rt300@0: rt300@0: void startupLoadAll(); // get stuff from XML rt300@0: void exitAndSaveAll(); // save to XML, delete presets array (?) rt300@4: void deleteAll(); rt300@0: rt300@0: PresetManager(); rt300@0: }; rt300@0: rt300@4: rt300@4: //--------------------------------------------------------------------------- rt300@4: inline ostream& operator<<(ostream & os, const Preset& p){ rt300@4: os.setf(ios_base::fixed,ios_base::floatfield); rt300@4: os.precision(1); rt300@4: rt300@4: os << p.savetime << ',' << p.coordinates.x << ',' << p.coordinates.y << '\n'; rt300@4: rt300@4: return os; rt300@4: } rt300@4: rt300@4: //--------------------------------------------------------------------------- rt300@4: inline istream& operator>>(istream & is, PresetManager& p) rt300@4: { rt300@4: //um rt300@4: string pname = "BLANK"; rt300@4: char delim; rt300@4: double px, py; rt300@4: long long stime; rt300@4: rt300@4: rt300@4: is.setf(ios_base::fixed,ios_base::floatfield); rt300@4: is.precision(1); rt300@4: rt300@4: is >> stime >> delim >> px >> delim >> py; rt300@4: if(!is){ rt300@4: cout << "problem reading preset file"; rt300@4: return(is); rt300@4: } rt300@4: TwoVector pcoord(px,py); rt300@4: int n = p.loadPreset(pcoord, pname, stime); rt300@4: cout << "read preset : " << n << '\n'; rt300@4: return(is); rt300@4: } rt300@4: rt300@0: #endif /* defined(__oscSenderExample__presetManager__) */