TEST_F(NetworkTableTest, LeadingSlash) { auto nt = NetworkTable::GetTable("leadingslash"); auto nt2 = NetworkTable::GetTable("/leadingslash"); ASSERT_FALSE(nt->ContainsKey("testkey")); nt2->PutNumber("testkey", 5); ASSERT_TRUE(nt->ContainsKey("testkey")); }
TEST_F(NetworkTableTest, EmptyOrNoSlash) { auto inst = nt::NetworkTableInstance::Create(); auto nt = inst.GetTable("/"); auto nt2 = inst.GetTable(""); ASSERT_FALSE(nt->ContainsKey("testkey")); nt2->PutNumber("testkey", 5); ASSERT_TRUE(nt->ContainsKey("testkey")); ASSERT_TRUE(inst.GetEntry("/testkey").Exists()); }
TEST_F(NetworkTableTest, ContainsKey) { auto inst = nt::NetworkTableInstance::Create(); auto nt = inst.GetTable("containskey"); ASSERT_FALSE(nt->ContainsKey("testkey")); nt->PutNumber("testkey", 5); ASSERT_TRUE(nt->ContainsKey("testkey")); ASSERT_TRUE(inst.GetEntry("/containskey/testkey").Exists()); ASSERT_FALSE(inst.GetEntry("containskey/testkey").Exists()); }
bool Response::SendHeaders(Socket* aSocket) { string headers; headers.append("HTTP/1.1 "); headers.append(StatusCode(mode)); headers.append("\r\n"); headers.append("Connection: close\r\n"); headers.append(GetDate()); headers.append("\r\n"); headers.append("Server: HttpMediaServer/0.1\r\n"); if (ContainsKey(parser.GetParams(), "delay")) { const map<string,string> params = parser.GetParams(); string delayStr = params.find("delay")->second; double delay = atof(delayStr.c_str()); if (delay > 0.0) { Sleep((unsigned)(delay+0.5)); } } if (!parser.IsLive()) { if (mode == GET_ENTIRE_FILE) { headers.append("Accept-Ranges: bytes\r\n"); headers.append("Content-Length: "); headers.append(ToString(fileLength)); headers.append("\r\n"); } else if (mode == GET_FILE_RANGE) { headers.append("Accept-Ranges: bytes\r\n"); headers.append("Content-Length: "); headers.append(ToString(rangeEnd - rangeStart)); headers.append("\r\n"); headers.append("Content-Range: bytes "); headers.append(ToString(rangeStart)); headers.append("-"); headers.append(ToString(rangeEnd)); headers.append("/"); headers.append(ToString(fileLength)); headers.append("\r\n"); } } //headers.append("Last-Modified: Wed, 10 Nov 2009 04:58:08 GMT\r\n"); headers.append("Content-Type: "); if (parser.HasSpecifiedMimeType()) { headers.append(parser.GetSpecifiedMimeType()); } else { headers.append(ExtractContentType(path, mode)); } headers.append("\r\n\r\n"); cout << "Sending Headers " << parser.id << std::endl << headers; return aSocket->Send(headers.c_str(), (int)headers.size()) != -1; }
partition_id SpaceIDMap::SpaceIDFor(partition_id parentID, off_t spaceOffset) { BString key; key << parentID << ':' << (uint64)spaceOffset; if (ContainsKey(key.String())) return Get(key.String()); partition_id newID = fNextSpaceID--; Put(key.String(), newID); return newID; }
void IdentifierDatabase::ResultsForQueryAndType( const std::string &query, const std::string &filetype, std::vector< Result > &results, const size_t max_results ) const { FiletypeCandidateMap::const_iterator it; { std::lock_guard< std::mutex > locker( filetype_candidate_map_mutex_ ); it = filetype_candidate_map_.find( filetype ); if ( it == filetype_candidate_map_.end() ) { return; } } Bitset query_bitset = LetterBitsetFromString( query ); bool query_has_uppercase_letters = HasUppercase( query ); std::unordered_set< const Candidate * > seen_candidates; seen_candidates.reserve( candidate_repository_.NumStoredCandidates() ); { std::lock_guard< std::mutex > locker( filetype_candidate_map_mutex_ ); for ( const FilepathToCandidates::value_type & path_and_candidates : *it->second ) { for ( const Candidate * candidate : *path_and_candidates.second ) { if ( ContainsKey( seen_candidates, candidate ) ) { continue; } else { seen_candidates.insert( candidate ); } if ( candidate->Text().empty() || !candidate->MatchesQueryBitset( query_bitset ) ) { continue; } Result result = candidate->QueryMatchResult( query, query_has_uppercase_letters ); if ( result.IsSubsequence() ) { results.push_back( result ); } } } } PartialSort( results, max_results ); }
/** * Constructor for a Axis to load from Preferences * <p><b>Axis Preferences</b><br> * foo = channel. Either axis number, axis number, or pov direction (int)<br> * foo.js = joystick (int)<br> * </p> * @param axisConfig The configuration key for the axis */ Axis::Axis(std::string axisConfig) { auto pref = Preferences::GetInstance(); config = axisConfig; if (!pref->ContainsKey(axisConfig.c_str())) { DriverStation::ReportError("[Axis] Attempting to load config '" + axisConfig + "' and could not find it"); return; } else { axisChannel = pref->GetInt(axisConfig.c_str()); auto stickNum = pref->GetInt((axisConfig + ".js").c_str(), 0); // Default to joystick 0 stick = Joystick::GetStickForPort(stickNum); invert = pref->GetBoolean((axisConfig + ".invert").c_str(), false); deadband = pref->GetFloat((axisConfig + ".deadband").c_str()); } }
TEST_F(NetworkTableTest, ContainsKey) { auto nt = NetworkTable::GetTable("containskey"); ASSERT_FALSE(nt->ContainsKey("testkey")); nt->PutNumber("testkey", 5); ASSERT_TRUE(nt->ContainsKey("testkey")); }
// XXX this was (mostly, except for the type check) c&p from DependencyObjectCollection bool ResourceDictionary::AddedToCollection (Value *value, MoonError *error) { DependencyObject *obj = NULL; bool rv = false; if (value->Is(GetDeployment (), Type::DEPENDENCY_OBJECT)) { obj = value->AsDependencyObject (); // Call SetSurface() /before/ setting the logical parent // because Storyboard::SetSurface() needs to be able to // distinguish between the two cases. if (obj->GetParent () && !can_be_added_twice (GetDeployment (), value)) { MoonError::FillIn (error, MoonError::INVALID_OPERATION, g_strdup_printf ("Element is already a child of another element. %s", GetTypeName ())); return false; } obj->AddParent (this, error); if (error->number) return false; obj->SetIsAttached (IsAttached ()); obj->AddPropertyChangeListener (this); if (!from_resource_dictionary_api) { const char *key = obj->GetName(); if (!key) { MoonError::FillIn (error, MoonError::ARGUMENT_NULL, "key was null"); goto cleanup; } if (ContainsKey (key)) { MoonError::FillIn (error, MoonError::ARGUMENT, "An item with the same key has already been added"); goto cleanup; } } } rv = Collection::AddedToCollection (value, error); if (rv && !from_resource_dictionary_api && obj != NULL) { const char *key = obj->GetName(); Value *obj_value = new Value (obj); g_hash_table_insert (hash, g_strdup (key), obj_value); obj_value->Weaken (GetDeployment ()); EmitChanged (CollectionChangedActionAdd, obj_value, NULL, key); } cleanup: if (!rv) { if (obj) { /* If we set the parent, but the object wasn't added to the collection, make sure we clear the parent */ printf ("ResourceDictionary::AddedToCollection (): not added, clearing parent from %p\n", obj); obj->RemoveParent (this, NULL); } } return rv; }
bool Contains(block_run *run) { return ContainsKey((void *)run); }
// Returns true if we need to call again. bool Response::SendBody(Socket *aSocket) { if (mode == ERROR_FILE_NOT_EXIST) { cout << "Sent (empty) body (" << parser.id << ")" << std::endl; return false; } int len = 1024; unsigned wait = 0; string rateStr; if (ContainsKey(parser.GetParams(), "rate")) { const map<string,string> params = parser.GetParams(); rateStr = params.find("rate")->second; double rate = atof(rateStr.c_str()); const double period = 0.1; if (rate <= 0.0) { len = 1024; wait = 0; } else { len = (unsigned)(rate * 1024 * period); wait = (unsigned)(period * 1000.0); // ms } } if (mode == GET_ENTIRE_FILE) { if (!file) { if (fopen_s(&file, path.c_str(), "rb")) { file = 0; return false; } } if (feof(file)) { // Transmitted entire file! fclose(file); file = 0; return false; } int64_t tell = ftell64(file); // Transmit the next segment. char* buf = new char[len]; int x = (int)fread(buf, 1, len, file); int r = aSocket->Send(buf, x); delete buf; if (r < 0) { // Some kind of error. return false; } if (wait > 0) { Sleep(wait); } // Else we tranmitted that segment, we're ok. return true; } else if (mode == GET_FILE_RANGE) { if (!file) { if (fopen_s(&file, path.c_str(), "rb")) { file = 0; return false; } fseek64(file, rangeStart, SEEK_SET); offset = rangeStart; bytesRemaining = rangeEnd - rangeStart; } if (feof(file) || bytesRemaining == 0) { // Transmitted entire range. fclose(file); file = 0; return false; } // Transmit the next segment. char* buf = new char[len]; len = (unsigned)MIN(bytesRemaining, len); size_t bytesSent = fread(buf, 1, len, file); bytesRemaining -= bytesSent; int r = aSocket->Send(buf, (int)bytesSent); delete buf; if (r < 0) { // Some kind of error. return false; } offset += bytesSent; assert(ftell64(file) == offset); if (wait > 0) { Sleep(wait); } // Else we tranmitted that segment, we're ok. return true; } else if (mode == DIR_LIST) { std::stringstream response; PathEnumerator *enumerator = PathEnumerator::getEnumerator(path); if (enumerator) { response << "<!DOCTYPE html>\n<ul>"; string href; while (enumerator->next(href)) { if (href == "." || path == "." && href == "..") { continue; } response << "<li><a href=\"" << path + "/" + href; if (!rateStr.empty()) { response << "?rate=" + rateStr; } response << "\">" << href << "</a></li>"; } response << "</ul>"; delete enumerator; } string _r = response.str(); aSocket->Send(_r.c_str(), (int)_r.size()); return false; } return false; }