QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

handle/dataLocation.cpp

Committer:
dylanembed123
Date:
2014-04-10
Revision:
15:e3e03a9df89e
Parent:
9:da906eeac51e
Child:
27:db73f8ac6c75

File content as of revision 15:e3e03a9df89e:

#include "dataLocation.h"

DataLocation* LocHolder::get(LHType type){
    if(type==LHType_locs){
        return locs;
    }else if(type==LHType_targ){
        return targ;
    }else if(type==LHType_base){
        return base;
    }
    return base;
}

unsigned int LocHolder::getRealIndex(LHType type,int index,int offset,bool useSize){
    return (index+offset)%(useSize?getI(type,LHIType_size):MAXNUMLOCS);
}

DataLocation& LocHolder::getC(LHType type,int offset){
    return get(type)[getRealIndex(type,offset)];
}

unsigned int& LocHolder::getI(LHType type,LHIType indexType){
    if(indexType==LHIType_head){
        // Grab proper header
        if(type==LHType_locs){return headLocs;}else if(type==LHType_targ){return headTarg;}else if(type==LHType_base){return headBase;}
    }else if(indexType==LHIType_size){
        // Grab proper size
        if(type==LHType_locs){return sizeLocs;}else if(type==LHType_targ){return sizeTarg;}else if(type==LHType_base){return sizeBase;}    
    }
    return headLocs;
}

void LocHolder::inc(LHType type,int amount,bool abs){
    unsigned int& index=getI(type);
    index=getRealIndex(type,(abs?0:index),amount);//((abs?0:index)+amount)%getI(type,LHIType_size);
    getI(type)=index;
}

void LocHolder::add(LHType type,DataLocation newLoc){
    getI(type)=getI(type,LHIType_size);
    getI(type,LHIType_size)++;
    getC(type)=newLoc;
}

static LocHolder* mainLocHolder=NULL;
LocHolder& DH::Locs(){if(mainLocHolder==NULL){mainLocHolder=new LocHolder();}return *mainLocHolder;}