DeviceOpener::~DeviceOpener() { if (fDevice >= 0) { RemoveCache(false); close(fDevice); } }
int ResetDNSCache(){ int iTemp; if (sDNSCache){ for (iTemp = 0; iTemp < iDNSCacheCount; iTemp++){ RemoveCache(iTemp, 0); } delete [] sDNSCache; sDNSCache = 0; } return 1; }
sDNS *AddDNSCache(char *szName, char *szIP){ int iEntry; if (!szName && !szIP){ return 0; } if (iDNSCacheCount < iDNSCacheLimit){ sDNS **sTemp; sDNS *sNewDNS; iEntry = iDNSCacheCount; if (sNewDNS = new sDNS){ sNewDNS->szIP = 0; sNewDNS->szName = 0; sNewDNS->lLastUse = 0; // Allocate room for the array and move it over if (sTemp = new sDNS* [iDNSCacheCount + 1]){ if (sDNSCache){ memcpy(sTemp, sDNSCache, sizeof(sDNS*) * iDNSCacheCount); delete [] sDNSCache; } sDNSCache = sTemp; sTemp = 0; sDNSCache[iDNSCacheCount] = sNewDNS; iDNSCacheCount++; } }else{ return 0; } }else{ int iTemp; if (! sDNSCache){ return 0; } iEntry = 0; // Let's find the oldest cache entry and replace it for (iTemp = 0; iTemp < iDNSCacheLimit; iTemp++){ if (sDNSCache[iTemp]->lLastUse < sDNSCache[iEntry]->lLastUse){ iEntry = iTemp; } } // Since we are going to simply replace the entry we will not force // the reallocation of the list's memory. RemoveCache(iEntry, 0); // Now we must allocate a new DNS memory block. if (sDNSCache[iEntry] = new sDNS){ sDNSCache[iEntry]->szIP = 0; sDNSCache[iEntry]->szName = 0; }else{ return 0; } } if (!sDNSCache[iEntry]){ return 0; } sDNSCache[iEntry]->szIP = DupString(szIP); sDNSCache[iEntry]->szName = DupString(szName); if (!szName){ sDNSCache[iEntry]->szName = 0; } if (!szIP){ sDNSCache[iEntry]->szIP = 0; } sDNSCache[iEntry]->lLastUse = lDNSCacheTime++; return sDNSCache[iEntry]; }
void Text::SetColor(const SDL_Color& color) { _color = color; RemoveCache(); }
void Text::SetTextAndColor(const std::string& text, const SDL_Color& color) { _color = color; _text = text; RemoveCache(); }
void Text::SetText(const std::string& text) { _text = text; RemoveCache(); }