template<class VALUE> VALUE& ResizMemArena<VALUE>::allocate() { bool found = false; VALUE *result = nullptr; while( NOT found ) { bool inLastArray = currentArray == numArrays - 1; bool atLastIndex = currentIndex == currentArraySize -1; if(inLastArray && atLastIndex) resize(); else if(atLastIndex) { currentArray++; currentIndex = 0; currentArraySize = initSize * POWER_2(currentArray-1); } result = &(arrays[currentArray][currentIndex]); currentIndex++; found = NOT result->isClaimed(); } result->claim(); return *result; }
void Test1() { for(int i = 0; aSampleDigitals[i].str != NULL; i++) { TOKEN token; VALUE value; token.marker = aSampleDigitals[i].str; token.length = GXSTRLEN(aSampleDigitals[i].str); VALUE v; State state = v.set(token); clStringA str; if(v.rank == VALUE::Rank_Unsigned64) { str.Format("\"%s\" => %llu(Unsigned 64)\t\t%d|%d", aSampleDigitals[i].str, v.uValue64, aSampleDigitals[i].state, state); } else if(v.rank == VALUE::Rank_Signed64) { str.Format("\"%s\" => %lld(Signed 64)\t\t%d|%d", aSampleDigitals[i].str, v.nValue64, aSampleDigitals[i].state, state); } else if(v.rank == VALUE::Rank_Double) { str.Format("\"%s\" => %f(double)\t\t%d|%d", aSampleDigitals[i].str, v.fValue64, aSampleDigitals[i].state, state); } else if(state != VALUE::State_OK) { str.Format("\"%s\" => XXX(failed)\t\t%d|%d", aSampleDigitals[i].str, aSampleDigitals[i].state, state); } ASSERT(aSampleDigitals[i].state == state); TRACE(str.AppendFormat("%s\n", aSampleDigitals[i].state == state ? "" : " (X)")); } }
bool genius::parseArtist() { QJsonParseError jsonParseError; QJsonDocument jsonResponse = QJsonDocument::fromJson(static_cast<QString>(this->array).toUtf8(), &jsonParseError); if (jsonParseError.error != QJsonParseError::NoError) return false; if (!jsonResponse.isObject()) return false; qDebug()<<"parsing artist info1"; QJsonObject mainJsonObject(jsonResponse.object()); auto data = mainJsonObject.toVariantMap(); auto itemMap = data.value("response").toMap().value("artist").toMap(); qDebug()<<"parsing artist info2"; if(itemMap.isEmpty()) return false; VALUE contexts; qDebug()<<"parsing artist info3"; if(this->info == INFO::TAGS || this->info == INFO::ALL) { auto alias = itemMap.value("alternate_names").toStringList(); contexts.insert(CONTEXT::ARTIST_ALIAS, alias); auto followers = itemMap.value("followers_count").toString(); contexts.insert(CONTEXT::ARTIST_STAT, followers ); emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::TAGS, contexts)); if(this->info == INFO::TAGS ) return true; } if(this->info == INFO::WIKI || this->info == INFO::WIKI) { QString wikiData; for(auto wiki : itemMap.value("description").toMap().value("dom").toMap().value("children").toList()) { for(auto child : wiki.toMap().value("children").toStringList() ) wikiData = wikiData + child; } contexts.insert( CONTEXT::WIKI, wikiData); emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::WIKI, contexts)); if(!wikiData.isEmpty() && this->info == INFO::WIKI) return true; } if(this->info == INFO::ARTWORK || this->info == INFO::ALL) { auto artwork = itemMap.value("image_url").toString(); emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ARTIST, INFO::ARTWORK,CONTEXT::IMAGE,this->startConnection(artwork))); if(!artwork.isEmpty() && this->info == INFO::ARTWORK ) return true; } return false; }
virtual int Count() { int i = 1; VALUE list = this->Rest(); while (!list.IsEmpty()) { i++; list = list.GetList()->Rest(); } return i; }
bool genius::getAlbumInfo(const QByteArray &array) { QJsonParseError jsonParseError; QJsonDocument jsonResponse = QJsonDocument::fromJson(static_cast<QString>(array).toUtf8(), &jsonParseError); if (jsonParseError.error != QJsonParseError::NoError) return false; if (!jsonResponse.isObject()) return false; QJsonObject mainJsonObject(jsonResponse.object()); auto data = mainJsonObject.toVariantMap(); auto itemMap = data.value("response").toMap().value("album").toMap(); if(itemMap.isEmpty()) return false; if(this->info == INFO::TAGS || this->info == INFO::ALL) { VALUE tags; auto date = itemMap.value("release_date").toString(); tags.insert(CONTEXT::ALBUM_DATE, date); auto views = itemMap.value("song_pageviews").toString(); tags.insert(CONTEXT::ALBUM_STAT, views ); QStringList team; for(auto name : itemMap.value("song_performances").toList()) for(auto artist : name.toMap().value("artists").toList()) team<<artist.toMap().value("name").toString(); tags.insert(CONTEXT::ALBUM_TEAM, team); emit this->infoReady(this->track,this->packResponse(ONTOLOGY::ALBUM, INFO::TAGS, tags)); if(this->info == INFO::TAGS ) return true; } if(this->info == INFO::ARTWORK || this->info == INFO::ALL) { auto artwork = itemMap.value("cover_art_url").toString(); emit this->infoReady(this->track,this->packResponse(ONTOLOGY::TRACK, INFO::ARTWORK, CONTEXT::IMAGE,this->startConnection(artwork))); if(!artwork.isEmpty() && this->info == INFO::ARTWORK ) return true; } return false; }
template <class KEY, class VALUE, class CONTAINER> int ACE_Recyclable_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container, KEY *key, VALUE *) { VALUE value; if (container.unbind (*key, value) == -1) return -1; value.first ()->recycler (0, 0); value.first ()->close (); return 0; }
bool xRedisClient::smove(const RedisDBIdx& dbi, const KEY& srckey, const KEY& deskey, const VALUE& member) { if (0 == srckey.length()) { return false; } SETDEFAULTIOTYPE(MASTER); return command_bool(dbi, "SMOVE %s", srckey.c_str(), deskey.c_str(), member.c_str()); }
bool AttemptDirtyAdd( VALUE v ) { if (RefCount > 1 || !_rest.IsNil()) { return false; } LIST c; c.SetListPointer( (uintptr_t)Cons::Create( v, LIST() ) ); // c.MaterializeAsCons( v, NIL() ); SetRest(c); return true; }
VALUE *rd_define_class(const char *name, VALUE *super) { if(rd_find_constant(name)) { puts("Redefinition of class `%s' not allowed\n"); exit(1); } VALUE *val = new VALUE(); // Special base Class case. Super is self if(super == NULL) { val->super = val; } val->type = T_CLASS; val->name = name; val->define_method("new", return_new_value); val->define_method("to_s", default_to_s); ADD_CONST(val); return val; }
bool xRedisClient::smove(const RedisDBIdx& dbi, const KEY& srckey, const KEY& deskey, const VALUE& member) { return command_bool(dbi, "SMOVE %s", srckey.c_str(), deskey.c_str(), member.c_str()); }
bool xRedisClient::sismember(const RedisDBIdx& dbi, const KEY& key, const VALUE& member) { return command_bool(dbi, "SISMEMBER %s %s", key.c_str(), member.c_str()); }
bool genius::parseTrack() { QJsonParseError jsonParseError; QJsonDocument jsonResponse = QJsonDocument::fromJson(static_cast<QString>(this->array).toUtf8(), &jsonParseError); if (jsonParseError.error != QJsonParseError::NoError) return false; if (!jsonResponse.isObject()) return false; QJsonObject mainJsonObject(jsonResponse.object()); auto data = mainJsonObject.toVariantMap(); auto itemMap = data.value("response").toMap().value("song").toMap(); if(itemMap.isEmpty()) return false; auto albumMap = itemMap.value("album").toMap(); if(!albumMap.isEmpty()) { auto id = albumMap.value("api_path").toString(); qDebug()<<"TRACK ALBUM"<<this->API+id; auto album_array = this->startConnection(this->API+id, {{"Authorization", this->KEY}}); this->getAlbumInfo(album_array); } if(this->info == INFO::TAGS || this->info == INFO::ALL) { VALUE contexts; QStringList team; auto performances = itemMap.value("custom_performances").toList(); for(auto performance : performances) for(auto artist : performance.toMap().value("artists").toList()) team<< artist.toMap().value("name").toString(); qDebug()<<this->track[BAE::KEY::TITLE]<<"CUSTOM PERFORMANCES:"<<team; for(auto feature : itemMap.value("featured_artists").toList()) team<<feature.toMap().value("name").toString(); for(auto producer : itemMap.value("producer_artists").toList()) team<<producer.toMap().value("name").toString(); for(auto producer : itemMap.value("writer_artists").toList()) team<<producer.toMap().value("name").toString(); contexts.insert(CONTEXT::TRACK_TEAM, team); emit this->infoReady(this->track, this->packResponse(ONTOLOGY::TRACK, INFO::TAGS, contexts)); if(this->info == INFO::TAGS) return true; } if(this->info == INFO::WIKI || this->info == INFO::WIKI) { QString wikiData; for(auto wiki : itemMap.value("description").toMap().value("dom").toMap().value("children").toList()) for(auto child : wiki.toMap().value("children").toStringList() ) wikiData = wikiData + child; emit this->infoReady(this->track,this->packResponse(ONTOLOGY::TRACK, INFO::WIKI, CONTEXT::WIKI, wikiData)); if(wikiData.isEmpty() && this->info == INFO::WIKI) return false; } if(this->info == INFO::ARTWORK || this->info == INFO::ALL) { auto image = itemMap.value("header_image_url").toString(); emit this->infoReady(this->track, this->packResponse(ONTOLOGY::TRACK, INFO::ARTWORK, CONTEXT::IMAGE,this->startConnection(image))); if(image.isEmpty() && this->info == INFO::ARTWORK) return false; } if(this->info == INFO::LYRICS || this->info == INFO::ALL) { auto lyricsPath = itemMap.value("path").toString(); auto path = "https://genius.com"+lyricsPath; qDebug()<<"LYRICS PATH"<<path; auto lyricsArray = this->startConnection(path); bool lyrics = false; if(!lyricsArray.isEmpty()) lyrics = this->extractLyrics(lyricsArray); if(!lyrics && this->info == INFO::LYRICS) return false; } return false; }
void SetFirst( VALUE first ) { if (first.IsHeapObject()) { first.GetObject()->RefCount++; } _first = first; }
void SetRest( VALUE rest ) { if (rest.IsHeapObject()) { rest.GetObject()->RefCount++; } _rest = rest; }