bool getValid(TreeNode* root, long int minimum,long int maximum) { if(root == NULL) return true; if(!((root->val > minimum) && (root->val < maximum))) return false; return getValid(root->left,minimum,root->val) && getValid(root->right,root->val,maximum); }
/*** putEeprom ** ** Parameters: ** eeprom - pointer to a flash memory page acting as emulated EEPROM ** address - location to be written ** data - data to be written ** ** Return Value: ** Returns true if the operation was successful, false otherwise ** ** Errors: ** none ** ** Description: ** Searches through emulated EEPROM page for valid address then ** invalidates that location and writes the address and data ** to a new unused location. */ BOOL putEeprom(eeSeg * eeprom, uint32_t address, uint8_t data) { eeSeg tempSeg; int i; uint32_t nextAvalible; //Check if address exists for(i=0; i < _EEPROM_PAGE_SIZE; i++) { //Check if eeSeg is valid and address matches if(getValid(eeprom[i]) && !getTaken(eeprom[i]) && getAddress(eeprom[i]) == address) { //If data is same do nothing if(data == getData(eeprom[i])) { return fTrue; } //If data is different invalidate eeSeg else { tempSeg = eeprom[i]; tempSeg.temp.valid = 0; writeFlashWord((void*)&eeprom[i],tempSeg.data); // If data is 0xFF return //if(data == 0xFF) { // printf(" and data is 0xFF so done.\n\r"); // return fTrue; //} } } //If empty eeSeg found save location and break else if(getValid(eeprom[i]) && getTaken(eeprom[i])) { nextAvalible = i; break; } } //If I == max size no valid segments exist if(i == _EEPROM_PAGE_SIZE) { return fFalse; } //Pack address with data and write to flash tempSeg = pack(address,data); writeFlashWord((void*)&eeprom[i],tempSeg.data); return fTrue; }
void GHOST_WindowCarbon::setTitle(const STR_String& title) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setTitle(): window invalid") Str255 title255; gen2mac(title, title255); ::SetWTitle(m_windowRef, title255); }
void GHOST_WindowCarbon::getTitle(STR_String& title) const { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getTitle(): window invalid") Str255 title255; ::GetWTitle(m_windowRef, title255); mac2gen(title255, title); }
bool TOptIAPrefix::isValid() const { if (!Valid_ || (getValid() == 0)) { return false; } return this->getValid() >= this->getPref(); }
GHOST_TSuccess GHOST_WindowCarbon::setClientWidth(GHOST_TUns32 width) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientWidth(): window invalid") GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); if (((GHOST_TUns32)cBnds.getWidth()) != width) { ::SizeWindow(m_windowRef, width, cBnds.getHeight(), true); } return GHOST_kSuccess; }
void GHOST_WindowCarbon::getWindowBounds(GHOST_Rect& bounds) const { OSStatus success; Rect rect; GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getWindowBounds(): window invalid") success = ::GetWindowBounds(m_windowRef, kWindowStructureRgn, &rect); bounds.m_b = rect.bottom; bounds.m_l = rect.left; bounds.m_r = rect.right; bounds.m_t = rect.top; }
/*** getEeprom ** ** Parameters: ** eeprom - pointer to flash memory acting as emulated eeprom ** address - location to be read ** data - data to be read ** ** Return Value: ** Returns true or false wether the operation was successful ** or not. ** ** Errors: ** none ** ** Description: ** Searches through emulated eeprom for valid address and ** returns data. If no address can be found the funtion ** will return false and set data pointer to 0xFF */ BOOL getEeprom(eeSeg * eeprom, uint32_t address,uint8_t * data) { int i; //Check if address exists for(i=0; i < _EEPROM_PAGE_SIZE; i++) { //Check if eeSeg is valid and address matches if(getValid(eeprom[i]) && !getTaken(eeprom[i]) && getAddress(eeprom[i]) == address) { //Set data to pointer and return *data = getData(eeprom[i]); return fTrue; } else if(getValid(eeprom[i]) && getTaken(eeprom[i])) { break; } } //If address not found return 0xFF *data = 0xFF; return fFalse; }
void GHOST_WindowCarbon::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::clientToScreen(): window invalid") Point point; point.h = inX; point.v = inY; GrafPtr oldPort; ::GetPort(&oldPort); ::SetPort(m_grafPtr); ::LocalToGlobal(&point); ::SetPort(oldPort); outX = point.h; outY = point.v; }
GHOST_TWindowState GHOST_WindowCarbon::getState() const { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getState(): window invalid") GHOST_TWindowState state; if (::IsWindowVisible(m_windowRef) == false) { state = GHOST_kWindowStateMinimized; } else if (::IsWindowInStandardState(m_windowRef, nil, nil)) { state = GHOST_kWindowStateMaximized; } else { state = GHOST_kWindowStateNormal; } return state; }
void DatumTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) { const auto f = dynamic_cast<FloatDatum*>(d); const auto i = dynamic_cast<IntDatum*>(d); if (f && f->getValid() && (event->modifiers() & Qt::ShiftModifier)) { const double scale = fmax( 0.01, abs(PyFloat_AsDouble(f->getValue()) * 0.01)); const double dx = (event->screenPos() - event->lastScreenPos()).x(); f->dragValue(scale * dx); } else if (i && i->getValid() && (event->modifiers() & Qt::ShiftModifier)) { drag_accumulated += (event->screenPos() - event->lastScreenPos()).x() / 30.; int q = drag_accumulated; drag_accumulated -= q; i->dragValue(q); } else { QGraphicsTextItem::mouseMoveEvent(event); } }
static int applyToFeatures (FeatureFN fn, void *data) { const sensors_chip_name *chip; int i = 0, j, ret = 0, num = 0; while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) { for (j = 0; (ret == 0) && (j < numChipNames); ++ j) { if (sensors_match_chip (*chip, chipNames[j])) { int index0, subindex, chipindex = -1; for (index0 = 0; knownChips[index0]; ++ index0) for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex) if (!strcmp (chip->prefix, knownChips[index0]->names[subindex])) chipindex = index0; if (chipindex >= 0) { const ChipDescriptor *descriptor = knownChips[chipindex]; const FeatureDescriptor *features = descriptor->features; for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) { const FeatureDescriptor *feature = features + index0; int labelNumber = feature->dataNumbers[0]; const char *rawLabel = NULL; char *label = NULL; int valid = 0; if (getValid (*chip, labelNumber, &valid)) { sensorLog (LOG_ERR, "Error getting sensor validity: %s/#%d", chip->prefix, labelNumber); ret = -1; } else if (getRawLabel (*chip, labelNumber, &rawLabel)) { sensorLog (LOG_ERR, "Error getting raw sensor label: %s/#%d", chip->prefix, labelNumber); ret = -1; } else if (getLabel (*chip, labelNumber, &label)) { sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber); ret = -1; } else if (valid) { rrdCheckLabel (rawLabel, num); ret = fn (data, rrdLabels[num], label, feature); ++ num; } if (label) free (label); } } } } } return ret; }
GHOST_TSuccess GHOST_WindowCarbon::setClientHeight(GHOST_TUns32 height) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setClientHeight(): window invalid") GHOST_Rect cBnds, wBnds; getClientBounds(cBnds); #ifdef GHOST_DRAW_CARBON_GUTTER if (((GHOST_TUns32)cBnds.getHeight()) != height+s_sizeRectSize) { ::SizeWindow(m_windowRef, cBnds.getWidth(), height+s_sizeRectSize, true); } #else //GHOST_DRAW_CARBON_GUTTER if (((GHOST_TUns32)cBnds.getHeight()) != height) { ::SizeWindow(m_windowRef, cBnds.getWidth(), height, true); } #endif //GHOST_DRAW_CARBON_GUTTER return GHOST_kSuccess; }
void DrawableStatsAttachment::reset(void) { // Don't change it unless it's valid. // Needed to protect intermediate results if(!getValid()) return; setVertices (0); setPoints (0); setLines (0); setTriangles (0); setPatches (0); setProcessedAttributeBytes(0); setStoredAttributeBytes (0); setValid(false); }
/*** putBuffer ** ** Parameters: ** eeprom - pointer to flash memory acting as emulated eeprom ** buffer - pointer to buffer ** ** Return Value: ** Returns true or false wether the operation was successful ** or not. ** ** Errors: ** none ** ** Description: ** Searches through emulated eeprom for valid addresses ** then writes data to buffer using address as the index */ uint32_t putBuffer(eeSeg * eeprom, uint8_t * buffer) { uint16_t tempAddress; int i; //Initialize each byte in buffer to 0xFF for(i=0; i < _EEPROM_PAGE_SIZE; i++) { buffer[i] = 0xFF; } //Find all valid addresses and load them to buffer for(i=0; i < _EEPROM_PAGE_SIZE; i++) { if(getValid(eeprom[i]) && !getTaken(eeprom[i])) { tempAddress = getAddress(eeprom[i]); buffer[tempAddress] = getData(eeprom[i]); } } }
/*** putBuffer ** ** Parameters: ** eeprom - pointer to flash memory acting as emulated EEPROM ** buffer - pointer to buffer ** ** Return Value: ** Returns true if the operation was successful, false otherwise ** ** Errors: ** none ** ** Description: ** Searches through emulated EEPROM for valid addresses ** then writes data to buffer using address as the index ** buffer must be big enough to hold all addresses (even ** those that aren't used) i.e. MAX_ADDRESS_DEFAULT big. */ uint32_t putBuffer(uint8_t * buffer) { uint16_t tempAddress; int i, j; //Initialize each byte in buffer to 0xFF for(i=0; i < max_address; i++) { buffer[i] = 0xFF; } //Find all valid addresses and load them to buffer for(j=0; j < _EEPROM_PAGE_COUNT; j++) { for(i=0; i < _EEPROM_PAGE_SIZE; i++) { if(getValid((eeSeg)eedata_addr[j][i]) && !getTaken((eeSeg)eedata_addr[j][i])) { tempAddress = getAddress((eeSeg)eedata_addr[j][i]); buffer[tempAddress] = getData((eeSeg)eedata_addr[j][i]); } } } }
void GHOST_WindowCarbon::getClientBounds(GHOST_Rect& bounds) const { Rect rect; GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::getClientBounds(): window invalid") //::GetPortBounds(m_grafPtr, &rect); ::GetWindowBounds(m_windowRef, kWindowContentRgn, &rect); bounds.m_b = rect.bottom; bounds.m_l = rect.left; bounds.m_r = rect.right; bounds.m_t = rect.top; // Subtract gutter height from bottom #ifdef GHOST_DRAW_CARBON_GUTTER if ((bounds.m_b - bounds.m_t) > s_sizeRectSize) { bounds.m_b -= s_sizeRectSize; } else { bounds.m_t = bounds.m_b; } #endif //GHOST_DRAW_CARBON_GUTTER }
bool isValidBST(TreeNode *root) { return getValid(root,LONG_MIN,LONG_MAX); }
Point point; point.h = inX; point.v = inY; GrafPtr oldPort; ::GetPort(&oldPort); ::SetPort(m_grafPtr); ::LocalToGlobal(&point); ::SetPort(oldPort); outX = point.h; outY = point.v; } GHOST_TSuccess GHOST_WindowCarbon::setState(GHOST_TWindowState state) { GHOST_ASSERT(getValid(), "GHOST_WindowCarbon::setState(): window invalid") switch (state) { case GHOST_kWindowStateMinimized: ::HideWindow(m_windowRef); break; case GHOST_kWindowStateModified: SetWindowModified(m_windowRef, 1); break; case GHOST_kWindowStateUnModified: SetWindowModified(m_windowRef, 0); break; case GHOST_kWindowStateMaximized: case GHOST_kWindowStateNormal: default: ::ShowWindow(m_windowRef); break;
void DrawableStatsAttachment::validate(void) { commitChanges(); // Still valid? Do nothing. if(getValid()) return; AttachmentContainer *cont = dynamic_cast<AttachmentContainer *>(this->getParents(0)); // Called on a non-AttachmentContainer? if(cont == NULL) return; reset(); // Drawable? Drawable *g = dynamic_cast<Drawable *>(cont); if(g != NULL) { //calc(g); g->fill(this); } // Node? Node *n = dynamic_cast<Node *>(cont); if(n != NULL) { // Validate the core Drawable *g = dynamic_cast<Drawable *>(n->getCore()); if(g != NULL) { DrawableStatsAttachmentUnrecPtr s = get(g); if(s == NULL) { s = DrawableStatsAttachment::addTo(g); } s->validate(); *this += s; setValid(false); // Not done yet. } // Validate all the children for(UInt32 i = 0; i < n->getNChildren(); ++i) { Node *c = n->getChild(i); DrawableStatsAttachmentUnrecPtr s = get(c); if(s == NULL) { s = DrawableStatsAttachment::addTo(c); } s->validate(); *this += s; setValid(false); // Not done yet. } } setValid(true); // Done! }