THttpResponse TResponseBuilder::FormResponse() { Response.Headers.push_back(MakePair("Content-Length", TString(NStr::TStringBuilder() << Response.Body.size()))); Response.Headers.push_back(MakePair("Connection", "Closed")); Response.Headers.push_back(MakePair("Date", GetDateAndTime())); Response.Headers.push_back(MakePair("Server", "DnnServer")); Response.Headers.push_back(MakePair("LastModified", GetDateAndTime())); return Response; }
void TestPdfListTable::TestNonLists() { PdfListTable table; assertTest(table.OnListItem(L"CC") == MakePair(-1,-1)); assertTest(table.OnListItem(L"IV") == MakePair(-1,-1)); }
static void LibraryExportByName(FObject lib, FObject gl, FObject nam) { FAssert(LibraryP(lib)); FAssert(GlobalP(gl)); FAssert(SymbolP(nam)); FAssert(GlobalP(Assq(nam, AsLibrary(lib)->Exports)) == 0); // AsLibrary(lib)->Exports = MakePair(MakePair(nam, gl), AsLibrary(lib)->Exports); Modify(FLibrary, lib, Exports, MakePair(MakePair(nam, gl), AsLibrary(lib)->Exports)); }
static size_t onRead(char *buffer, size_t size, size_t nitems, void *instream) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(instream)); is_->state = HTTP_OPEN; if (is_->isAborted) { is_->state = HTTP_CLOSED; return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nitems); // Read as much as we can from the upload buffer queue. Deserializer* upload(dynamic_cast<Deserializer*>(is_->upload.Get())); size_t size_queued(upload->GetSize()); size_t size_left(real_size); if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then emit a "upload_chunk" event. if (size_left > 0) { VariantMap eventData; eventData.Insert(MakePair(StringHash("upload"), Variant(is_->upload))); eventData.Insert(MakePair(StringHash("size"), Variant((unsigned int)size_left))); is_->es.SendEvent("upload_chunk", eventData); } // Read as much as we can from the upload buffer queue (again). size_queued = upload->GetSize(); size_left = real_size; if ((size_left > 0) && (size_queued > 0)) { size_t read_size(std::min(size_queued, size_left)); upload->Read(buffer, (unsigned int)read_size); size_left -= read_size; } // If we still have bytes to fill, then something went wrong, so we should abort. if (size_left > 0) { is_->isAborted = true; return CURL_READFUNC_ABORT; } return real_size; }
void TestPdfListTable::TestMultiLevelHandling2() { PdfListTable table; assertTest(table.OnListItem(L"1.") == MakePair(1,0)); assertTest(table.OnListItem(L"2.").first == 1); assertTest(table.OnListItem(L"2.1.") == MakePair(1,1)); assertTest(table.OnListItem(L"2.1.").first == 2); // can't have same first stat - must be different list assertTest(table.OnListItem(L"2.2.").first == 2); assertTest(table.GetListCount() == 2); }
static size_t onHeader(char *ptr, size_t size, size_t nmemb, void *userdata) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(userdata)); if (is_->isAborted) { is_->state = HTTP_CLOSED; // This should probably be CURL_HEADERFUNC_ABORT, but that doesn't // exist. It probably would be the same numeric value, if it did. // The docs say that it just has to be a number of bytes that is // not "size * nmemb" to abort. return CURL_READFUNC_ABORT; } // Find the size in bytes. size_t real_size(size * nmemb); // Check for some known values. if (real_size == 2 && ptr[0] == '\r' && ptr[1] == '\n') { return real_size; } if (real_size > 5 && !strncmp(ptr, "HTTP/", 5)) { return real_size; } // Get the header key and value, and add them to the map. unsigned int key_end = 0; unsigned int value_begin = 2; while (value_begin < real_size) { if (ptr[key_end] == ':' && ptr[key_end + 1] == ' ') { break; } ++key_end; ++value_begin; } if (value_begin == real_size) { String key(ptr, (unsigned int)real_size); is_->responseHeaders.InsertNew(key.ToUpper(), MakePair(key, String())); } else { String key(ptr, (unsigned int)key_end); is_->responseHeaders.InsertNew(key.ToUpper(), MakePair(key, String(ptr + value_begin, (unsigned int)real_size - value_begin - 2))); } return real_size; }
static FObject MakeLibrary(FObject nam, FObject exports, FObject proc) { FAssert(sizeof(FLibrary) == sizeof(LibraryFieldsC) + sizeof(FRecord)); FLibrary * lib = (FLibrary *) MakeRecord(R.LibraryRecordType); lib->Name = nam; lib->Exports = exports; R.LoadedLibraries = MakePair(lib, R.LoadedLibraries); if (ProcedureP(proc)) R.LibraryStartupList = MakePair(List(proc), R.LibraryStartupList); return(lib); }
void RenderPathCommand::SetOutputName(unsigned index, const String& name) { if (index < outputs_.Size()) outputs_[index].first_ = name; else if (index == outputs_.Size() && index < MAX_RENDERTARGETS) outputs_.Push(MakePair(name, FACE_POSITIVE_X)); }
static FObject DoOnlyOrExcept(FObject env, FObject is, int_t cfif) { if (PairP(Rest(is)) == 0) return(NoValueObject); FObject ilst = DoImportSet(env, First(Rest(is)), is); FObject ids = Rest(Rest(is)); while (PairP(ids)) { if (IdentifierP(First(ids)) == 0 && SymbolP(First(ids)) == 0) return(NoValueObject); ids = Rest(ids); } if (ids != EmptyListObject) return(NoValueObject); FObject nlst = EmptyListObject; while (PairP(ilst)) { FAssert(GlobalP(First(ilst))); if (CheckForIdentifier(AsGlobal(First(ilst))->Name, Rest(Rest(is))) == cfif) nlst = MakePair(First(ilst), nlst); ilst = Rest(ilst); } FAssert(ilst == EmptyListObject); return(nlst); }
static void Visit(FObject key, FObject val, FObject ctx) { FAssert(GlobalP(val)); if (AsGlobal(val)->State == GlobalUndefined) UndefinedList = MakePair(AsGlobal(val)->Name, UndefinedList); }
void ShaderPrecache::StoreShaders(ShaderVariation* vs, ShaderVariation* ps) { if (!vs || !ps) return; // Check for duplicate using pointers first (fast) Pair<ShaderVariation*, ShaderVariation*> shaderPair = MakePair(vs, ps); if (usedPtrCombinations_.Contains(shaderPair)) return; usedPtrCombinations_.Insert(shaderPair); String vsName = vs->GetName(); String psName = ps->GetName(); const String& vsDefines = vs->GetDefines(); const String& psDefines = ps->GetDefines(); // Check for duplicate using strings (needed for combinations loaded from existing file) String newCombination = vsName + " " + vsDefines + " " + psName + " " + psDefines; if (usedCombinations_.Contains(newCombination)) return; usedCombinations_.Insert(newCombination); XMLElement shaderElem = xmlFile_.GetRoot().CreateChild("shader"); shaderElem.SetAttribute("vs", vsName); shaderElem.SetAttribute("vsdefines", vsDefines); shaderElem.SetAttribute("ps", psName); shaderElem.SetAttribute("psdefines", psDefines); }
void onEnd(int code) { VariantMap eventData; if (code != CURLE_OK) { state = HTTP_ERROR; eventData.Insert(MakePair(StringHash("error"), Variant(String(error, (unsigned int)strnlen(error, sizeof(error)))))); } else { state = HTTP_CLOSED; eventData.Insert(MakePair(StringHash("download"), Variant(download))); eventData.Insert(MakePair(StringHash("upload"), Variant(upload))); } es.SendEvent("complete", eventData); }
void RenderPathCommand::SetOutputFace(unsigned index, CubeMapFace face) { if (index < outputs_.Size()) outputs_[index].second_ = face; else if (index == outputs_.Size() && index < MAX_RENDERTARGETS) outputs_.Push(MakePair(String::EMPTY, face)); }
void Octree::CollectNodes(Vector<Pair<OctreeNode*, float> >& result, const Octant* octant, const Ray& ray, unsigned short nodeFlags, float maxDistance, unsigned layerMask) const { float octantDist = ray.HitDistance(octant->cullingBox); if (octantDist >= maxDistance) return; const Vector<OctreeNode*>& octantNodes = octant->nodes; for (auto it = octantNodes.Begin(); it != octantNodes.End(); ++it) { OctreeNode* node = *it; if ((node->Flags() & nodeFlags) == nodeFlags && (node->LayerMask() & layerMask)) { float distance = ray.HitDistance(node->WorldBoundingBox()); if (distance < maxDistance) result.Push(MakePair(node, distance)); } } for (size_t i = 0; i < NUM_OCTANTS; ++i) { if (octant->children[i]) CollectNodes(result, octant->children[i], ray, nodeFlags, maxDistance, layerMask); } }
// ------------------------------------------------------------------------------------------------ void GobBridge::RegisterProperty(const char* typeName, const char* propName, SetPropertyFncPtr set, GetPropertyFncPtr get) { ObjectTypeGUID tid = Hash32(typeName); ObjectPropertyUID pid = Hash32(propName); uint64_t tidpid = MakePair(tid, pid); assert(m_propertyFunctions.find(tidpid) == m_propertyFunctions.end()); // double registration. m_propertyFunctions[tidpid] = PropertyFunc(set, get); }
FObject CompileEval(FObject obj, FObject env) { FAssert(EnvironmentP(env)); FObject body = CompileEvalExpr(obj, env, EmptyListObject); body = ReverseListModify(body); if (R.LibraryStartupList != EmptyListObject) { body = MakePair(MakePair(BeginSyntax, ReverseListModify(R.LibraryStartupList)), body); R.LibraryStartupList = EmptyListObject; } else if (body == EmptyListObject) return(R.NoValuePrimitive); return(CompileLambda(env, NoValueObject, EmptyListObject, body)); }
void TestPdfListTable::TestBulletHandling() { CStdString sBullet1 = "a"; sBullet1[0] = -3913; CStdString sBullet2 = "a"; sBullet2[0] = -3929; PdfListTable table; assertTest(table.OnListItem(sBullet1) == MakePair(1,0)); assertTest(table.OnListItem(sBullet2) == MakePair(2,0)); assertTest(table.OnListItem(sBullet2) == MakePair(2,0)); assertTest(table.OnListItem(sBullet1) == MakePair(1,0)); }
// ------------------------------------------------------------------------------------------------ void GobBridge::RegisterChildList(const char* typeName, const char* listName, AddChildFncPtr add, RemoveChildFncPtr remove) { ObjectTypeGUID tid = Hash32(typeName); ObjectListUID lid = Hash32(listName); uint64_t tidlid = MakePair(tid, lid); assert(m_childListFunctions.find(tid) == m_childListFunctions.end()); // double registration. m_childListFunctions[tidlid] = ChildListFunc(add, remove); }
static void AddToLibraryPath(FChS * prog) { FChS * s = prog; FChS * pth = 0; while (*s) { if (PathChP(*s)) pth = s; s += 1; } if (pth != 0) R.LibraryPath = MakePair(MakeStringS(prog, pth - prog), R.LibraryPath); else R.LibraryPath = MakePair(MakeStringC("."), R.LibraryPath); }
void TestPdfListTable::TestMultiLevelHandling() { PdfListTable table; assertTest(table.OnListItem(L"1.") == MakePair(1,0)); assertTest(table.OnListItem(L"2.").first == 1); assertTest(table.OnListItem(L"3.").first == 1); assertTest(table.OnListItem(L"3.1.") == MakePair(1,1)); assertTest(table.OnListItem(L"3.2.").first == 1); assertTest(table.OnListItem(L"3.3.").first == 1); assertTest(table.OnListItem(L"3.3.1") == MakePair(1,2)); assertTest(table.OnListItem(L"3.4.") == MakePair(1,1)); assertTest(table.OnListItem(L"4.") == MakePair(1,0)); assertTest(table.GetListCount() == 1); }
void BufferedSoundStream::AddData(SharedArrayPtr<signed short> data, unsigned numBytes) { if (data && numBytes) { MutexLock lock(bufferMutex_); buffers_.Push(MakePair(ReinterpretCast<signed char>(data), numBytes)); } }
void BufferedSoundStream::AddData(SharedArrayPtr<signed char> data, unsigned numBytes) { if (data && numBytes) { MutexLock lock(bufferMutex_); buffers_.Push(MakePair(data, numBytes)); } }
FObject VectorToList(FObject vec) { FAssert(VectorP(vec)); FObject lst = EmptyListObject; for (int_t idx = (int_t) VectorLength(vec) - 1; idx >= 0; idx--) lst = MakePair(AsVector(vec)->Vector[idx], lst); return(lst); }
Pair<DrawResult, RefPtr<layers::Image>> RasterImage::GetCurrentImage(ImageContainer* aContainer, uint32_t aFlags) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aContainer); DrawResult drawResult; RefPtr<SourceSurface> surface; Tie(drawResult, surface) = GetFrameInternal(mSize, FRAME_CURRENT, aFlags | FLAG_ASYNC_NOTIFY); if (!surface) { // The OS threw out some or all of our buffer. We'll need to wait for the // redecode (which was automatically triggered by GetFrame) to complete. return MakePair(drawResult, RefPtr<layers::Image>()); } RefPtr<layers::Image> image = new layers::SourceSurfaceImage(surface); return MakePair(drawResult, Move(image)); }
static int onProgress(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) { WebRequestInternalState *is_(reinterpret_cast<WebRequestInternalState*>(clientp)); if (is_->isAborted) { // This should probably be CURL_XFERINFO_ABORT, but that doesn't // exist. It probably would be the same numeric value, if it did. // The docs say that it just has to be a nonzero to abort. return CURL_READFUNC_ABORT; } VariantMap eventData; eventData.Insert(MakePair(StringHash("down_total"), Variant((double)dltotal))); eventData.Insert(MakePair(StringHash("down_loaded"), Variant((double)dlnow))); eventData.Insert(MakePair(StringHash("up_total"), Variant((double)ultotal))); eventData.Insert(MakePair(StringHash("up_loaded"), Variant((double)ulnow))); is_->es.SendEvent("progress", eventData); return 0; }
void BufferedSoundStream::AddData(void* data, unsigned numBytes) { if (data && numBytes) { MutexLock lock(bufferMutex_); SharedArrayPtr<signed char> newBuffer(new signed char[numBytes]); memcpy(newBuffer.Get(), data, numBytes); buffers_.Push(MakePair(newBuffer, numBytes)); } }
// ------------------------------------------------------------------------------------------------ ObjectPropertyUID GobBridge::GetPropertyId(ObjectTypeGUID tid, const char* propName) { ObjectPropertyUID pid = Hash32(propName); uint64_t tidpid = MakePair(tid, pid); auto it = m_propertyFunctions.find(tidpid); if(it != m_propertyFunctions.end()) { return pid; } return 0; }
// ------------------------------------------------------------------------------------------------ ObjectListUID GobBridge::GetChildListId(ObjectTypeGUID tid, const char* listName) { ObjectListUID id = Hash32(listName); uint64_t pair = MakePair(tid, id); auto it = m_childListFunctions.find(pair); if(it != m_childListFunctions.end()) { return id; } return 0; }
static FObject MakeCommandLine(int_t argc, FChS * argv[]) { FObject cl = EmptyListObject; while (argc > 0) { argc -= 1; cl = MakePair(MakeStringS(argv[argc]), cl); } return(cl); }
ShaderVariation* Shader::GetVariation(ShaderType type, const char* defines) { StringHash definesHash(defines); if (type == VS) { HashMap<StringHash, SharedPtr<ShaderVariation> >::Iterator i = vsVariations_.Find(definesHash); if (i == vsVariations_.End()) { // If shader not found, normalize the defines (to prevent duplicates) and check again. In that case make an alias // so that further queries are faster String normalizedDefines = NormalizeDefines(defines); StringHash normalizedHash(normalizedDefines); i = vsVariations_.Find(normalizedHash); if (i != vsVariations_.End()) vsVariations_.Insert(MakePair(definesHash, i->second_)); else { // No shader variation found. Create new i = vsVariations_.Insert(MakePair(normalizedHash, SharedPtr<ShaderVariation>(new ShaderVariation(this, VS)))); if (definesHash != normalizedHash) vsVariations_.Insert(MakePair(definesHash, i->second_)); i->second_->SetName(GetFileName(GetName())); i->second_->SetDefines(normalizedDefines); ++numVariations_; RefreshMemoryUse(); } } return i->second_; } else { HashMap<StringHash, SharedPtr<ShaderVariation> >::Iterator i = psVariations_.Find(definesHash); if (i == psVariations_.End()) { String normalizedDefines = NormalizeDefines(defines); StringHash normalizedHash(normalizedDefines); i = psVariations_.Find(normalizedHash); if (i != psVariations_.End()) psVariations_.Insert(MakePair(definesHash, i->second_)); else { i = psVariations_.Insert(MakePair(normalizedHash, SharedPtr<ShaderVariation>(new ShaderVariation(this, PS)))); if (definesHash != normalizedHash) psVariations_.Insert(MakePair(definesHash, i->second_)); i->second_->SetName(GetFileName(GetName())); i->second_->SetDefines(normalizedDefines); ++numVariations_; RefreshMemoryUse(); } } return i->second_; } }