QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Committer:
dylanembed123
Date:
Sat Apr 26 04:03:20 2014 +0000
Revision:
48:dc9269ce9a79
Parent:
47:fd373c4ea831
Yet again trying to fix add;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dylanembed123 9:da906eeac51e 1 #include "dataLocation.h"
dylanembed123 7:c75d5e5e6bfc 2
dylanembed123 9:da906eeac51e 3 DataLocation* LocHolder::get(LHType type){
dylanembed123 9:da906eeac51e 4 if(type==LHType_locs){
dylanembed123 9:da906eeac51e 5 return locs;
dylanembed123 9:da906eeac51e 6 }else if(type==LHType_targ){
dylanembed123 9:da906eeac51e 7 return targ;
dylanembed123 9:da906eeac51e 8 }else if(type==LHType_base){
dylanembed123 9:da906eeac51e 9 return base;
dylanembed123 9:da906eeac51e 10 }
dylanembed123 7:c75d5e5e6bfc 11 return base;
dylanembed123 7:c75d5e5e6bfc 12 }
dylanembed123 7:c75d5e5e6bfc 13
dylanembed123 9:da906eeac51e 14 unsigned int LocHolder::getRealIndex(LHType type,int index,int offset,bool useSize){
dylanembed123 9:da906eeac51e 15 return (index+offset)%(useSize?getI(type,LHIType_size):MAXNUMLOCS);
dylanembed123 9:da906eeac51e 16 }
dylanembed123 9:da906eeac51e 17
dylanembed123 9:da906eeac51e 18 DataLocation& LocHolder::getC(LHType type,int offset){
dylanembed123 9:da906eeac51e 19 return get(type)[getRealIndex(type,offset)];
dylanembed123 7:c75d5e5e6bfc 20 }
dylanembed123 7:c75d5e5e6bfc 21
dylanembed123 9:da906eeac51e 22 unsigned int& LocHolder::getI(LHType type,LHIType indexType){
dylanembed123 9:da906eeac51e 23 if(indexType==LHIType_head){
dylanembed123 9:da906eeac51e 24 // Grab proper header
dylanembed123 9:da906eeac51e 25 if(type==LHType_locs){return headLocs;}else if(type==LHType_targ){return headTarg;}else if(type==LHType_base){return headBase;}
dylanembed123 9:da906eeac51e 26 }else if(indexType==LHIType_size){
dylanembed123 9:da906eeac51e 27 // Grab proper size
dylanembed123 9:da906eeac51e 28 if(type==LHType_locs){return sizeLocs;}else if(type==LHType_targ){return sizeTarg;}else if(type==LHType_base){return sizeBase;}
dylanembed123 9:da906eeac51e 29 }
dylanembed123 9:da906eeac51e 30 return headLocs;
dylanembed123 7:c75d5e5e6bfc 31 }
dylanembed123 9:da906eeac51e 32
dylanembed123 9:da906eeac51e 33 void LocHolder::inc(LHType type,int amount,bool abs){
dylanembed123 27:db73f8ac6c75 34 // Grab current index holder
dylanembed123 9:da906eeac51e 35 unsigned int& index=getI(type);
dylanembed123 27:db73f8ac6c75 36 // Set index and make sure the index is valid (not negative or greater than max)
dylanembed123 27:db73f8ac6c75 37 index=getRealIndex(type,(abs?0:index)+amount);
krobertson 32:9cb7bc3fc9e0 38 getI(type)=index;
dylanembed123 7:c75d5e5e6bfc 39 }
dylanembed123 9:da906eeac51e 40
dylanembed123 9:da906eeac51e 41 void LocHolder::add(LHType type,DataLocation newLoc){
dylanembed123 27:db73f8ac6c75 42 // Set the current index to the current size
dylanembed123 47:fd373c4ea831 43 //getI(type)=getI(type,LHIType_size);
dylanembed123 27:db73f8ac6c75 44 // Increment size
dylanembed123 47:fd373c4ea831 45 unsigned int newSize=getI(type,LHIType_size)+1;
dylanembed123 47:fd373c4ea831 46 getI(type,LHIType_size)=newSize>MAXNUMLOCS?MAXNUMLOCS:newSize;
dylanembed123 48:dc9269ce9a79 47 // Increment type using new size
dylanembed123 48:dc9269ce9a79 48 inc(type);
dylanembed123 27:db73f8ac6c75 49 // Assign current index
dylanembed123 40:7b4d6043f533 50 getC(type,getI(type))=newLoc;
dylanembed123 15:e3e03a9df89e 51 }
dylanembed123 15:e3e03a9df89e 52
dylanembed123 15:e3e03a9df89e 53 static LocHolder* mainLocHolder=NULL;
dylanembed123 15:e3e03a9df89e 54 LocHolder& DH::Locs(){if(mainLocHolder==NULL){mainLocHolder=new LocHolder();}return *mainLocHolder;}