Commit 5c217a8e authored by Benoit Rat's avatar Benoit Rat

all: improve recursivity of isValid() function

parent e3d669f5
......@@ -429,6 +429,24 @@ bool EWBField::sync(EWBSync::AMode amode)
return ret;
}
/**
* Return @true if this EWBField is valid.
*
* @note To be fully valid the EWBField must be connected to
* EWBBridge in order to sync with the device, you can use level
* to check if it is valid.
* EWBBride (0) < EWBBus (1) < EWBPeriph (2) < EWBReg (3) < EWBField (4)
*
*
* @param[in] level check the validity in each level.
* This check is stopped when it reaches 0 (never when staring at -1)
*/
bool EWBField::isValid(int level) const
{
if(level!=0) return (pReg && pReg->isValid(level-1));
else return pReg;
}
/**
* operator that print the data of the EWBField in a stream
*/
......
......@@ -89,8 +89,7 @@ public:
const EWBReg* getReg() const { return pReg; } //!< Get the linked register (RO)
EWBReg* getReg() { return pReg; } //!< Get the linked register
bool isOverflowPrevented() const { return checkOverflow; } //!< When true prevent overflow during FP conversion \ref regCvt(), \ ref convert()
bool isValid() const { return isValid(true); }
bool isValid(bool connected) const { return (pReg && pReg->isValid(connected)); }
bool isValid(int level=-1) const;
protected:
void getLimit(float &fmin, float &fmax);
......
......@@ -45,9 +45,9 @@ EWBParamStrCmd::~EWBParamStrCmd()
}
bool EWBParamStrCmd::isValid() const
bool EWBParamStrCmd::isValid(int level) const
{
return (pConsole && pConsole->isValid());
return (level!=0)?(pConsole && pConsole->isValid()):pConsole!=NULL;
}
......
......@@ -24,7 +24,7 @@ public:
virtual ~EWBParamStrCmd();
const std::string& getValue() const { return value; } //!< Get the name
bool sync(EWBSync::AMode mode);
bool isValid() const;
bool isValid(int level=-1) const;
protected:
......
......@@ -39,11 +39,11 @@ public:
// bool sync(uint32_t* pData32, uint32_t length, EWBSync::AMode amode, uint32_t doffset=0);
int getID() const { return this->ID; } //!< Get ID of WBPeriph
bool isValid(int level=-1) const { return (level!=0)?(bus && bus->isValid(level-1)):bus!=NULL; } //!< Return true when all pointers are defined
int getIndex() const { return this->index; } //!< Get unique index of WBPeriph
const std::string& getName() const { return this->name; } //!< Get the name
const char *getCName() const { return this->name.c_str(); } //!< Get the name in "C" format for printf function
const std::string& getDesc() const { return this->desc; } //!< Get the description
bool isValid(bool connected=true) const { return (bus && bus->isValid(connected)); } //!< Return true when all pointers are defined
const EWBBridge* getBridge() const { return (bus)?bus->getBridge():0; }
EWBBridge* getBridge() { return (bus)?bus->getBridge():0; }
......
......@@ -147,6 +147,24 @@ bool EWBReg::sync(EWBSync::AMode amode)
return ret;
}
/**
* Return @true if this EWBReg is valid.
*
* @note To be fully valid the register must be connected to
* EWBBridge in order to sync with the device, you can use level
* to check if it is valid.
* EWBBride (0) < EWBBus (1) < EWBPeriph (2) < EWBReg (3) < EWBField (4)
*
*
* @param[in] level check the validity in each level.
* This check is stopped when it reaches 0 (never when staring at -1)
*/
bool EWBReg::isValid(int level) const
{
if(level!=0) return (pPeriph && pPeriph->isValid(level-1));
else return pPeriph;
}
/**
* Return the offset of the register
......
......@@ -48,7 +48,7 @@ public:
const std::string& getName() const { return this->name; } //!< Get the name
const char *getCName() const { return this->name.c_str(); } //!< Get the name in "C" format for printf function
const std::string& getDesc() const { return this->desc; } //!< Get the description
bool isValid(bool connected=true) const { return (pPeriph && pPeriph->isValid(connected)); }
bool isValid(int level=-1) const;
protected:
EWBPeriph* getPeriph() { return pPeriph; }
......
......@@ -24,7 +24,7 @@ public:
virtual ~EWBSync() {};
virtual bool sync(EWBSync::AMode mode) = 0;
virtual bool isValid() const = 0;
virtual bool isValid(int level=-1) const = 0;
void setForceSync(bool val=true) { this->forceSync=val; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment