size_t HashStream::ReadLineToString(WHeapString& outString, bool includeNewLine/*=true*/)const { size_t oldPos = outString.Length(); size_t readCount = mSourceStream->ReadLineToString(outString, includeNewLine); RETURN_ZERO_IF_ZERO(readCount); mHasher->Process(outString.c_str() + oldPos, (outString.Length() - oldPos)*sizeof(wchar_t)); return readCount; }
size_t HashStream::ReadStringTo(HeapString& outString)const { size_t oldPos = outString.Length(); size_t readCount = mSourceStream->ReadStringTo(outString); RETURN_ZERO_IF_ZERO(readCount); mHasher->Process(outString.c_str() + oldPos, outString.Length() - oldPos); return readCount; }
int AndPredicate::Evaluate(void* p) const { RETURN_ZERO_IF_EMPTY(mItems); FOR_EACH_COLLECTION(i, mItems) { const IPredicate* item = *i; RETURN_ZERO_IF_ZERO(item->Evaluate(p)); } return 1; }
FormalConceptIntentBulkList addConceptToBulk(FormalConceptIntentBulkList root, const IncidenceCell* intent) { RETURN_ZERO_IF_ZERO(root); do { if (root->size == 0) { root->chunks[0] = newConceptChunk(root->attributes); root->size = 1; } int last_index; last_index = root->size - 1; if (root->chunks[last_index]->size == CHUNKSIZE) { if (root->size == BULKSIZE) { if (root->next == 0) { root->next = newConceptBulk(root->attributes); } root = root->next; continue; } else { last_index = root->size++; root->chunks[last_index] = newConceptChunk(root->attributes); } } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" memcpy( &(CELL(root->chunks[last_index]->size, root->chunks[last_index],0)), intent, sizeof(IncidenceCell) * root->attributes); #pragma GCC diagnostic pop root->chunks[last_index]->size++; break; } while (1); return root; }
/** * use this for bulks that are filled in order * * @param root * @return number of concepts in bulk */ int countConceptsInBulk(FormalConceptIntentBulkList root) { RETURN_ZERO_IF_ZERO(root); int count = 0; while (root != 0) { if (root->size > 0) { /* * count the full chunks */ count += CHUNKSIZE * (root->size - 1); /* * and the last chunk */ count += root->chunks[root->size - 1]->size; } root = root->next; } return count; }
uint IAudioSource::GetByteOffset() const { RETURN_ZERO_IF_ZERO(mSource); return AudioDevice::Instance().GetSourceIntegerProperty(mSource,AudioSourceIntegerProperty::ByteOffset); }
FormalContext newFormalContextFromFile(const char* filename) { char *line; size_t len; len = (INPUTBUFFERSIZE); line = malloc(sizeof(char) * len); FILE *file; if (strcmp(filename, "-") == 0) { file = stdin; } else { file = fopen(filename, "r"); RETURN_ZERO_IF_ZERO(file); } ssize_t read; int line_nbr; line_nbr = 0; int objects; int attributes; attributes = 0; objects = 0; myFormalContext *ctx; ctx = 0; while ((read = getline(&line, &len, file)) != -1) { /* * this should never happen, right? */ if (read == 0) break; line[read - 1] = 0; if (line_nbr == 0) { if (strcmp(line, "B")) { fprintf(stderr, "File '%s' is not a .cxt file\n", filename); goto grace; } } else if (line_nbr == 1) { //empty line } else if (line_nbr == 2) { objects = atoi(line); } else if (line_nbr == 3) { attributes = atoi(line); ctx = (myFormalContext *) newFormalContext(objects, attributes); } else if (line_nbr == 4) { //empty line } else if (line_nbr < objects + 5) { int i; i = line_nbr - 5; free(ctx->objectNames[i]); ctx->objectNames[i] = strdup(line); } else if (line_nbr < objects + attributes + 5) { int i; i = line_nbr - 5 - objects; free(ctx->attributeNames[i]); ctx->attributeNames[i] = strdup(line); } else if (line_nbr < objects * 2 + attributes + 5) { int i; i = line_nbr - 5 - objects - attributes; int width; width = MIN((signed)strlen(line),attributes); for (int var = 0; var < width; ++var) { if ((line[var] == 'x') || (line[var] == 'X') || (line[var] == '1')) { CROSS(CELL (i, ctx, var)); } } } else { /* * we read all data */ break; } line_nbr++; } /* * free memory and return */ grace: if (file != stdin) { fclose(file); } free(line); return (FormalContext) ctx; }