InstructionBasic::InstructionBasic() { setOpcode(0); setLength(1); }
FrConstString::~FrConstString() { m_value = 0 ; setLength(0) ; return ; }
void Buffer::setData(const void *data, size_t len) { setLength(0); appendData(data, len); }
GfxFeatureMapRequestPacket::GfxFeatureMapRequestPacket( uint32 mapID, const UserUser* user, uint16 reqID, uint16 packetID, int32 upperLeftLat, int32 upperLeftLon, int32 lowerRightLat, int32 lowerRightLon, uint16 screenSizeX, uint16 screenSizeY, uint32 maxScaleLevel, uint32 minScaleLevel, uint32 filtScaleLevel, LangTypes::language_t language, const MapSettings* mapSettings, bool ignoreStartOffset, bool ignoreEndOffset, uint16 startOffset, uint16 endOffset, bool drawOverviewContents, bool extractForTileMaps ) : RequestPacket( MAX_PACKET_SIZE, GFXFEATUREMAP_REQUEST_PRIO, PACKETTYPE_GFXFEATUREMAPREQUEST, packetID, reqID, MAX_UINT32 ) { setMapID( mapID ); MC2_ASSERT(mapSettings != NULL); writeLong( upperLeftLat_POS, upperLeftLat ); writeLong( upperLeftLon_POS, upperLeftLon ); writeLong( lowerRightLat_POS, lowerRightLat ); writeLong( lowerRightLon_POS, lowerRightLon ); writeShort( screenSizeX_POS, screenSizeX ); writeShort( screenSizeY_POS, screenSizeY ); writeLong( maxScaleLevel_POS, maxScaleLevel ); writeLong( minScaleLevel_POS, minScaleLevel ); writeLong( filtScaleLevel_POS, filtScaleLevel ); writeLong( language_POS, language ); writeShort( startOffset_POS, startOffset ); writeShort( endOffset_POS, endOffset ); // Write some bits. setIgnoreStartOffset(ignoreStartOffset); setIgnoreEndOffset(ignoreEndOffset); setDrawOverviewContents(drawOverviewContents); writeBit(isStartAndEnd_POS, EXTRACT_FOR_TILEMAPS_BIT_POS, extractForTileMaps); writeByte( nbrReqPackets_POS, 0); // Nbr req packets writeShort( nbrNodeIDs_POS, 0 ); // Nbr node ids. int pos = endStatic_POS; mapSettings->saveToPacket( this, pos ); setLength( pos ); UserRightsMapInfo rights( mapID, user, ~MapRights() ); rights.save( this, pos ); // Save the real length of the mapSettings + userRights writeLong( mapSettingsLen_POS, pos - endStatic_POS ); setLength( pos ); }
LineRenderable::LineRenderable(const LineSymbol* symbol, const VirtualPath& virtual_path, bool closed) : Renderable(symbol->getColor()) , line_width(0.001f * symbol->getLineWidth()) { Q_ASSERT(virtual_path.size() >= 2); float half_line_width = (color_priority < 0) ? 0.0f : 0.5f * line_width; switch (symbol->getCapStyle()) { case LineSymbol::FlatCap: cap_style = Qt::FlatCap; break; case LineSymbol::RoundCap: cap_style = Qt::RoundCap; break; case LineSymbol::SquareCap: cap_style = Qt::SquareCap; break; case LineSymbol::PointedCap: cap_style = Qt::FlatCap; break; } switch (symbol->getJoinStyle()) { case LineSymbol::BevelJoin: join_style = Qt::BevelJoin; break; case LineSymbol::MiterJoin: join_style = Qt::MiterJoin; break; case LineSymbol::RoundJoin: join_style = Qt::RoundJoin; break; } auto& flags = virtual_path.coords.flags; auto& coords = virtual_path.coords; bool has_curve = false; bool hole = false; bool gap = false; QPainterPath first_subpath; auto i = virtual_path.first_index; path.moveTo(coords[i]); extent = QRectF(coords[i].x(), coords[i].y(), 0.0001f, 0.0001f); extentIncludeCap(i, half_line_width, false, symbol, virtual_path); for (++i; i <= virtual_path.last_index; ++i) { if (gap) { if (flags[i].isHolePoint()) { gap = false; hole = true; } else if (flags[i].isGapPoint()) { gap = false; if (first_subpath.isEmpty() && closed) { first_subpath = path; path = QPainterPath(); } path.moveTo(coords[i]); extentIncludeCap(i, half_line_width, false, symbol, virtual_path); } continue; } if (hole) { Q_ASSERT(!flags[i].isHolePoint() && "Two hole points in a row!"); if (first_subpath.isEmpty() && closed) { first_subpath = path; path = QPainterPath(); } path.moveTo(coords[i]); extentIncludeCap(i, half_line_width, false, symbol, virtual_path); hole = false; continue; } if (flags[i-1].isCurveStart()) { Q_ASSERT(i < virtual_path.last_index-1); has_curve = true; path.cubicTo(coords[i], coords[i+1], coords[i+2]); i += 2; } else path.lineTo(coords[i]); if (flags[i].isHolePoint()) hole = true; else if (flags[i].isGapPoint()) gap = true; if ((i < virtual_path.last_index && !hole && !gap) || (i == virtual_path.last_index && closed)) extentIncludeJoin(i, half_line_width, symbol, virtual_path); else extentIncludeCap(i, half_line_width, true, symbol, virtual_path); } if (closed) { if (first_subpath.isEmpty()) path.closeSubpath(); else path.connectPath(first_subpath); } // If we do not have the path coords, but there was a curve, calculate path coords. if (has_curve) { // This happens for point symbols with curved lines in them. const auto& path_coords = virtual_path.path_coords; Q_ASSERT(path_coords.front().param == 0.0); Q_ASSERT(path_coords.back().param == 0.0); for (auto i = path_coords.size()-1; i > 0; --i) { if (path_coords[i].param != 0.0) { const auto& pos = path_coords[i].pos; auto to_coord = pos - path_coords[i-1].pos; auto to_next = path_coords[i+1].pos - pos; to_coord.normalize(); to_next.normalize(); auto right = (to_coord + to_next).perpRight(); right.setLength(half_line_width); rectInclude(extent, pos + right); rectInclude(extent, pos - right); } } } Q_ASSERT(extent.right() < 999999); // assert if bogus values are returned }
void ByteArrayObject::set_length(uint32_t value) { setLength(value); }
blindComplexData::blindComplexData( const unsigned int cvNum ) : _length(0), _CVDataArrayPtr( NULL ) { setLength( cvNum ); }
void ODBCMetaColumn::init() { getDescription(); if (Utility::isError(Poco::Data::ODBC::SQLColAttribute(_rStmt, (SQLUSMALLINT) position() + 1, // ODBC columns are 1-based SQL_DESC_LENGTH, 0, 0, 0, &_dataLength))) { throw StatementException(_rStmt); } setName(std::string((char*) _columnDesc.name)); setLength(_columnDesc.size); setPrecision(_columnDesc.decimalDigits); setNullable(SQL_NULLABLE == _columnDesc.isNullable); switch(_columnDesc.dataType) { case SQL_BIT: setType(MetaColumn::FDT_BOOL); break; case SQL_CHAR: case SQL_VARCHAR: case SQL_LONGVARCHAR: case -9:// SQL Server NVARCHAR case -10:// PostgreSQL VARCHAR (without size specified) setType(MetaColumn::FDT_STRING); break; case SQL_TINYINT: setType(MetaColumn::FDT_INT8); break; case SQL_SMALLINT: setType(MetaColumn::FDT_INT16); break; case SQL_INTEGER: setType(MetaColumn::FDT_INT32); break; case SQL_BIGINT: setType(MetaColumn::FDT_INT64); break; case SQL_DOUBLE: case SQL_FLOAT: setType(MetaColumn::FDT_DOUBLE); break; case SQL_NUMERIC: case SQL_DECIMAL: if (0 == _columnDesc.decimalDigits) setType(MetaColumn::FDT_INT32); else setType(MetaColumn::FDT_DOUBLE); break; case SQL_REAL: setType(MetaColumn::FDT_FLOAT); break; case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: case -98:// IBM DB2 non-standard type setType(MetaColumn::FDT_BLOB); break; case SQL_TYPE_DATE: setType(MetaColumn::FDT_DATE); break; case SQL_TYPE_TIME: setType(MetaColumn::FDT_TIME); break; case SQL_TYPE_TIMESTAMP: setType(MetaColumn::FDT_TIMESTAMP); break; default: throw DataFormatException("Unsupported data type."); } }
Scrollbar::Scrollbar(Type type) : _type(type), _x(0.0), _y(0.0), _z(0.0) { _texture = TextureMan.get("gui_scrollbar"); setLength(16.0); }
int CIEC_DT_WSTRING::fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape) { int nSrcLen = pa_nLen >= 0 ? pa_nLen : (pa_bUnescape ? determineEscapedStringLength(pa_pacValue, '"') : (int)strlen(pa_pacValue)); int nSrcCappedLength = nSrcLen; if (0 <= nSrcLen) { if ((0 == pa_pacValue) || (pa_pacValue[0] == '\0') || (nSrcLen == 0)) { assign("", 0); return 0; } if (nSrcLen > static_cast<int>(scm_unMaxStringLen)) { // If we get a to large string we will truncate it // This is a conservative guess nSrcCappedLength = scm_unMaxStringLen; FZRTE_WARNING("Too large string, destination will be truncated!\n"); } // The needed space is surely not larger than original length - it can // only be smaller if there are chars outside the BMP reserve(static_cast<FzrteUInt16>(nSrcCappedLength)); if (0 == getGenData()) { return -1; } unsigned int nMaxWidth; int nLength = c_unicode_utils::checkUTF8((const char *)pa_pacValue, nSrcCappedLength, nMaxWidth); // Only accept if this is valid UTF-8, otherwise we can get major // problems when serializing if (nLength < 0) { FZRTE_WARNING("Invalid UTF-8 string given to fromString!\n"); *this = "***INVALID UTF-8***"; return -1; } else if (nMaxWidth > 16) { FZRTE_WARNING("UTF-8 string with characters outside of BMP given to fromString!\n"); } // If BMP, all is well - simply assign if (nMaxWidth <= 16) { assign(pa_pacValue, static_cast<FzrteUInt16>(nSrcCappedLength)); } else { FzrteUInt32 nCodepoint; const FzrteByte *pRunner = (const FzrteByte *)pa_pacValue; FzrteByte *pEncBuffer = (FzrteByte *)getValue(); FzrteByte *pEncRunner = pEncBuffer; while (*pRunner && (pRunner - (const FzrteByte *)pa_pacValue) < nSrcCappedLength) { int nRes; nRes = c_unicode_utils::parseUTF8Codepoint(pRunner, nCodepoint); pRunner += nRes; if (nCodepoint == c_unicode_utils::scm_uiBomMarker) continue; if (nCodepoint >= 0x10000) nCodepoint = '?'; nRes = c_unicode_utils::encodeUTF8Codepoint(pEncRunner, static_cast<unsigned int>(nSrcCappedLength - (pEncRunner - pEncBuffer)), nCodepoint); if (nRes < 1) break; pEncRunner += nRes; } *pEncRunner = '\0'; setLength(static_cast<FzrteUInt16>(pEncRunner - pEncBuffer)); } if (pa_bUnescape) { nLength = unescapeFromString(getValue(), '"'); if (-1 == nLength) { return -1; } } } return nSrcLen; }
bool CIEC_DT_WSTRING::fromUTF16(const FzrteByte *pa_pacBuffer, unsigned int pa_nBufferLen) { bool bLittleEndian = false; FzrteUInt32 nCodepoint; int nRes; unsigned int nRemLen = pa_nBufferLen; const FzrteByte *pacBuffer = pa_pacBuffer; if (pa_nBufferLen == 0) { assign("", 0); return true; } else if ((pa_nBufferLen & 1) == 1) { return false; } // Check the BOM, default to big endian nRes = c_unicode_utils::parseUTF16Codepoint(pa_pacBuffer, nCodepoint, false); if (nRes < 0) return false; if (nRes == 2) { if (nCodepoint == c_unicode_utils::scm_uiBomMarkerToSwap) { bLittleEndian = true; nRemLen -= 2; pacBuffer += 2; } else if (nCodepoint == c_unicode_utils::scm_uiBomMarker) { nRemLen -= 2; pacBuffer += 2; } } // Count the needed space const FzrteByte *pRunner = pacBuffer; unsigned int i = 0; unsigned int nNeededLength = 0; while (i < nRemLen) { nRes = c_unicode_utils::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian); if (nRes < 0 || nRes + i > nRemLen) return false; i += nRes; pRunner += nRes; nRes = c_unicode_utils::encodeUTF8Codepoint(0, 0, nCodepoint); if (nRes < 0) return false; nNeededLength += nRes; } if (nNeededLength > scm_unMaxStringLen) return false; // Reserve and encode reserve(static_cast<FzrteUInt16>(nNeededLength)); if (getGenData() == 0) return false; FzrteByte *pEncRunner = (FzrteByte *)getValue(); FzrteByte *pDataEnd = pEncRunner + nNeededLength; pRunner = pacBuffer; i = 0; while (i < nRemLen) { nRes = c_unicode_utils::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian); i += nRes; pRunner += nRes; nRes = c_unicode_utils::encodeUTF8Codepoint(pEncRunner, static_cast<unsigned int>(pDataEnd - pEncRunner), nCodepoint); pEncRunner += nRes; } setLength(static_cast<FzrteUInt16>(nNeededLength)); *pEncRunner = '\0'; return true; }
Box::Box() //Default constructor and sets the 3 parameters to 1. { setHeight(1.0); setWidth(1.0); setLength(1.0); }
Box::Box(double boxHeight, double boxWidth, double boxLength) //The three-parameter constructor that takes the parameters and sends it to the set methods. { setHeight(boxHeight); setWidth(boxWidth); setLength(boxLength); }
Metadata(std::size_t length) { setLength(length); setAllocated(false); }
void PipBoy::init() { if (_initialized) return; State::init(); setModal(true); setFullscreen(true); Game::getInstance()->mouse()->pushState(Input::Mouse::Cursor::BIG_ARROW); // Background auto background = new UI::Image("art/intrface/pip.frm"); Point backgroundPos = Point((Game::getInstance()->renderer()->size() - background->size()) / 2); int backgroundX = backgroundPos.x(); int backgroundY = backgroundPos.y(); background->setPosition(backgroundPos); // Buttons auto alarmButton = new UI::ImageButton(UI::ImageButton::Type::PIPBOY_ALARM_BUTTON, backgroundX+124, backgroundY+13); auto statusButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+340); auto automapsButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+394); auto archivesButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+423); auto closeButton = new UI::ImageButton(UI::ImageButton::Type::SMALL_RED_CIRCLE, backgroundX+53, backgroundY+448); closeButton->mouseClickHandler().add(std::bind(&PipBoy::onCloseButtonClick, this, std::placeholders::_1)); // Date and time // Date auto day = new UI::SmallCounter(backgroundPos + Point(21, 17)); day->setLength(2); day->setNumber(Game::getInstance()->gameTime()->day()); day->setColor(UI::SmallCounter::Color::WHITE); day->setType(UI::SmallCounter::Type::UNSIGNED); auto month = new UI::MonthCounter( static_cast<UI::MonthCounter::Month>(Game::getInstance()->gameTime()->month()), backgroundPos + Point(46, 18) ); auto year = new UI::SmallCounter(backgroundPos + Point(84, 17)); year->setLength(4); year->setNumber(Game::getInstance()->gameTime()->year()); year->setColor(UI::SmallCounter::Color::WHITE); year->setType(UI::SmallCounter::Type::UNSIGNED); // Time auto time = new UI::SmallCounter(backgroundPos + Point(160, 17)); time->setLength(4); time->setNumber((Game::getInstance()->gameTime()->hours() * 100) + Game::getInstance()->gameTime()->minutes()); time->setColor(UI::SmallCounter::Color::WHITE); time->setType(UI::SmallCounter::Type::UNSIGNED); addUI(background); addUI(alarmButton); addUI(statusButton); addUI(automapsButton); addUI(archivesButton); addUI(day); addUI(month); addUI(year); addUI(time); addUI(closeButton); }
bool IOBufferMemoryDescriptor::initWithPhysicalMask( task_t inTask, IOOptionBits options, mach_vm_size_t capacity, mach_vm_address_t alignment, mach_vm_address_t physicalMask) { kern_return_t kr; task_t mapTask = NULL; vm_map_t vmmap = NULL; mach_vm_address_t highestMask = 0; IOOptionBits iomdOptions = kIOMemoryTypeVirtual64 | kIOMemoryAsReference; IODMAMapSpecification mapSpec; bool mapped = false; bool needZero; if (!capacity) return false; _options = options; _capacity = capacity; _internalFlags = 0; _internalReserved = 0; _buffer = 0; _ranges.v64 = IONew(IOAddressRange, 1); if (!_ranges.v64) return (false); _ranges.v64->address = 0; _ranges.v64->length = 0; // make sure super::free doesn't dealloc _ranges before super::init _flags = kIOMemoryAsReference; // Grab IOMD bits from the Buffer MD options iomdOptions |= (options & kIOBufferDescriptorMemoryFlags); if (!(kIOMemoryMapperNone & options)) { IOMapper::checkForSystemMapper(); mapped = (0 != IOMapper::gSystem); } needZero = mapped; if (physicalMask && (alignment <= 1)) { alignment = ((physicalMask ^ (-1ULL)) & (physicalMask - 1)); highestMask = (physicalMask | alignment); alignment++; if (alignment < page_size) alignment = page_size; } if ((options & (kIOMemorySharingTypeMask | kIOMapCacheMask | kIOMemoryClearEncrypt)) && (alignment < page_size)) alignment = page_size; if (alignment >= page_size) capacity = round_page(capacity); if (alignment > page_size) options |= kIOMemoryPhysicallyContiguous; _alignment = alignment; if ((inTask != kernel_task) && !(options & kIOMemoryPageable)) return false; bzero(&mapSpec, sizeof(mapSpec)); mapSpec.alignment = _alignment; mapSpec.numAddressBits = 64; if (highestMask && mapped) { if (highestMask <= 0xFFFFFFFF) mapSpec.numAddressBits = (32 - __builtin_clz((unsigned int) highestMask)); else mapSpec.numAddressBits = (64 - __builtin_clz((unsigned int) (highestMask >> 32))); highestMask = 0; } // set flags for entry + object create vm_prot_t memEntryCacheMode = VM_PROT_READ | VM_PROT_WRITE; // set memory entry cache mode switch (options & kIOMapCacheMask) { case kIOMapInhibitCache: SET_MAP_MEM(MAP_MEM_IO, memEntryCacheMode); break; case kIOMapWriteThruCache: SET_MAP_MEM(MAP_MEM_WTHRU, memEntryCacheMode); break; case kIOMapWriteCombineCache: SET_MAP_MEM(MAP_MEM_WCOMB, memEntryCacheMode); break; case kIOMapCopybackCache: SET_MAP_MEM(MAP_MEM_COPYBACK, memEntryCacheMode); break; case kIOMapCopybackInnerCache: SET_MAP_MEM(MAP_MEM_INNERWBACK, memEntryCacheMode); break; case kIOMapDefaultCache: default: SET_MAP_MEM(MAP_MEM_NOOP, memEntryCacheMode); break; } if (options & kIOMemoryPageable) { iomdOptions |= kIOMemoryBufferPageable; // must create the entry before any pages are allocated // set flags for entry + object create memEntryCacheMode |= MAP_MEM_NAMED_CREATE; if (options & kIOMemoryPurgeable) memEntryCacheMode |= MAP_MEM_PURGABLE; } else { memEntryCacheMode |= MAP_MEM_NAMED_REUSE; vmmap = kernel_map; // Buffer shouldn't auto prepare they should be prepared explicitly // But it never was enforced so what are you going to do? iomdOptions |= kIOMemoryAutoPrepare; /* Allocate a wired-down buffer inside kernel space. */ bool contig = (0 != (options & kIOMemoryHostPhysicallyContiguous)); if (!contig && (0 != (options & kIOMemoryPhysicallyContiguous))) { contig |= (!mapped); contig |= (0 != (kIOMemoryMapperNone & options)); #if 0 // treat kIOMemoryPhysicallyContiguous as kIOMemoryHostPhysicallyContiguous for now contig |= true; #endif } if (contig || highestMask || (alignment > page_size)) { _internalFlags |= kInternalFlagPhysical; if (highestMask) { _internalFlags |= kInternalFlagPageSized; capacity = round_page(capacity); } _buffer = (void *) IOKernelAllocateWithPhysicalRestrict( capacity, highestMask, alignment, contig); } else if (needZero && ((capacity + alignment) <= (page_size - kIOPageAllocChunkBytes))) { _internalFlags |= kInternalFlagPageAllocated; needZero = false; _buffer = (void *) iopa_alloc(capacity, alignment); } else if (alignment > 1) { _buffer = IOMallocAligned(capacity, alignment); } else { _buffer = IOMalloc(capacity); } if (!_buffer) { return false; } if (needZero) bzero(_buffer, capacity); } if( (options & (kIOMemoryPageable | kIOMapCacheMask))) { ipc_port_t sharedMem; vm_size_t size = round_page(capacity); kr = mach_make_memory_entry(vmmap, &size, (vm_offset_t)_buffer, memEntryCacheMode, &sharedMem, NULL ); if( (KERN_SUCCESS == kr) && (size != round_page(capacity))) { ipc_port_release_send( sharedMem ); kr = kIOReturnVMError; } if( KERN_SUCCESS != kr) return( false ); _memEntry = (void *) sharedMem; if( options & kIOMemoryPageable) { #if IOALLOCDEBUG debug_iomallocpageable_size += size; #endif mapTask = inTask; if (NULL == inTask) inTask = kernel_task; } else if (options & kIOMapCacheMask) { // Prefetch each page to put entries into the pmap volatile UInt8 * startAddr = (UInt8 *)_buffer; volatile UInt8 * endAddr = (UInt8 *)_buffer + capacity; while (startAddr < endAddr) { *startAddr; startAddr += page_size; } } } _ranges.v64->address = (mach_vm_address_t) _buffer;; _ranges.v64->length = _capacity; if (!super::initWithOptions(_ranges.v64, 1, 0, inTask, iomdOptions, /* System mapper */ 0)) return false; // give any system mapper the allocation params if (kIOReturnSuccess != dmaCommandOperation(kIOMDAddDMAMapSpec, &mapSpec, sizeof(mapSpec))) return false; if (mapTask) { if (!reserved) { reserved = IONew( ExpansionData, 1 ); if( !reserved) return( false ); } reserved->map = createMappingInTask(mapTask, 0, kIOMapAnywhere | (options & kIOMapCacheMask), 0, 0); if (!reserved->map) { _buffer = 0; return( false ); } release(); // map took a retain on this reserved->map->retain(); removeMapping(reserved->map); mach_vm_address_t buffer = reserved->map->getAddress(); _buffer = (void *) buffer; if (kIOMemoryTypeVirtual64 == (kIOMemoryTypeMask & iomdOptions)) _ranges.v64->address = buffer; } setLength(_capacity); return true; }
RecordFrame::RecordFrame(size_t size_in_bytes ) { ASSERT_TRUE(ISALIGNED((&header_data), RECORD_FRAME_ALIGNMENT)); ASSERT_TRUE(header_data.plain_header == 0); setLength(size_in_bytes); // ASSERT: memory was prev. filled with 0s }
void write(PUP::dataType t,int n) { if (!bannerDisplayed) showBanner(); setMagic(pupMagic); type=t^typeMask; setLength(n); }
// SLOT FUNCTIONS //------------------------------------------------------------------------------ // setSlotLength() -- sets our tick mark length //------------------------------------------------------------------------------ bool DialTickMarks::setSlotLength(const Basic::Number* const newLength) { bool ok = true; if (newLength != nullptr) ok = setLength(newLength->getReal()); return ok; }
//default constructor, all dimensions are 1.0 Box::Box() { setHeight(1.0); setWidth(1.0); setLength(1.0); }
// // Assign facets // assign common facets // assign additional facet // void AbstractStringValidator::assignFacet(MemoryManager* const manager) { RefHashTableOf<KVStringPair>* facets = getFacets(); if (!facets) return; XMLCh* key; RefHashTableOfEnumerator<KVStringPair> e(facets, false, manager); while (e.hasMoreElements()) { KVStringPair pair = e.nextElement(); key = pair.getKey(); XMLCh* value = pair.getValue(); if (XMLString::equals(key, SchemaSymbols::fgELT_LENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_Len, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_Len, value, manager); setLength(val); setFacetsDefined(DatatypeValidator::FACET_LENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MINLENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_minLen, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_minLen, value, manager); setMinLength(val); setFacetsDefined(DatatypeValidator::FACET_MINLENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXLENGTH)) { int val; try { val = XMLString::parseInt(value, manager); } catch (NumberFormatException&) { ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_Invalid_maxLen, value, manager); } if ( val < 0 ) ThrowXMLwithMemMgr1(InvalidDatatypeFacetException, XMLExcepts::FACET_NonNeg_maxLen, value, manager); setMaxLength(val); setFacetsDefined(DatatypeValidator::FACET_MAXLENGTH); } else if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN)) { setPattern(value); if (getPattern()) setFacetsDefined(DatatypeValidator::FACET_PATTERN); // do not construct regex until needed } else if (XMLString::equals(key, SchemaSymbols::fgATT_FIXED)) { unsigned int val; bool retStatus; try { retStatus = XMLString::textToBin(value, val, fMemoryManager); } catch (RuntimeException&) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } if (!retStatus) { ThrowXMLwithMemMgr(InvalidDatatypeFacetException, XMLExcepts::FACET_internalError_fixed, manager); } setFixed(val); //no setFacetsDefined here } // // else if (XMLString::equals(key, SchemaSymbols::fgELT_SPECIAL_TOKEN)) // TODO // // Note: whitespace is taken care of by TraverseSchema. // else { assignAdditionalFacet(key, value, manager); } }//while }//end of assigneFacet()
//constructor Box::Box(double h, double w, double l) { setHeight(h); setWidth(w); setLength(l); }
HorizontalWall::HorizontalWall(float x1, float x2, float y) { _x1 = x1; _x2 = x2; _y1 = y; setLength(x2 - x1); }
// Overloaded constructor CRay::CRay(const CPos &origin, const CVector &dir, float len) { setOrigin(origin); setDir(dir); setLength(len); }
/** * Convenience function. */ void clear() { setLength(0); }
/// normalize to one bool Vector3d::normalize() { return setLength(1.0); }
void TestPreferences::testPreferences() { auto pref = SettingsObjectWrapper::instance(); pref->load(); auto cloud = pref->cloud_storage; cloud->setBackgroundSync(true); TEST(cloud->backgroundSync(), true); cloud->setBackgroundSync(false); TEST(cloud->backgroundSync(), false); cloud->setBaseUrl("test_one"); TEST(cloud->baseUrl(), QStringLiteral("test_one")); cloud->setBaseUrl("test_two"); TEST(cloud->baseUrl(), QStringLiteral("test_two")); cloud->setEmail("*****@*****.**"); TEST(cloud->email(), QStringLiteral("*****@*****.**")); cloud->setEmail("*****@*****.**"); TEST(cloud->email(), QStringLiteral("*****@*****.**")); cloud->setGitLocalOnly(true); TEST(cloud->gitLocalOnly(), true); cloud->setGitLocalOnly(false); TEST(cloud->gitLocalOnly(), false); // Why there's new password and password on the prefs? cloud->setNewPassword("ABCD"); TEST(cloud->newPassword(), QStringLiteral("ABCD")); cloud->setNewPassword("ABCDE"); TEST(cloud->newPassword(), QStringLiteral("ABCDE")); cloud->setPassword("ABCDE"); TEST(cloud->password(), QStringLiteral("ABCDE")); cloud->setPassword("ABCABC"); TEST(cloud->password(), QStringLiteral("ABCABC")); cloud->setSavePasswordLocal(true); TEST(cloud->savePasswordLocal(), true); cloud->setSavePasswordLocal(false); TEST(cloud->savePasswordLocal(), false); // Why this is short and not bool? cloud->setSaveUserIdLocal(1); TEST(cloud->saveUserIdLocal(), (short)1); cloud->setSaveUserIdLocal(0); TEST(cloud->saveUserIdLocal(), (short)0); cloud->setUserId("Tomaz"); TEST(cloud->userId(), QStringLiteral("Tomaz")); cloud->setUserId("Zamot"); TEST(cloud->userId(), QStringLiteral("Zamot")); cloud->setVerificationStatus(0); TEST(cloud->verificationStatus(), (short)0); cloud->setVerificationStatus(1); TEST(cloud->verificationStatus(), (short)1); auto tecDetails = pref->techDetails; tecDetails->setModp02(0.2); TEST(tecDetails->modp02(), 0.2); tecDetails->setModp02(1.0); TEST(tecDetails->modp02(), 1.0); tecDetails->setGflow(2); TEST(tecDetails->gflow(), 2); tecDetails->setGflow(3); TEST(tecDetails->gflow(), 3); tecDetails->setGfhigh(4); TEST(tecDetails->gfhigh(), 4); tecDetails->setGfhigh(5); TEST(tecDetails->gfhigh(), 5); tecDetails->setVpmbConservatism(5); TEST(tecDetails->vpmbConservatism(), (short)5); tecDetails->setVpmbConservatism(6); TEST(tecDetails->vpmbConservatism(), (short)6); tecDetails->setEad(true); TEST(tecDetails->ead(), true); tecDetails->setMod(true); TEST(tecDetails->mod(), true); tecDetails->setDCceiling(true); TEST(tecDetails->dcceiling(), true); tecDetails->setRedceiling(true); TEST(tecDetails->redceiling(), true); tecDetails->setCalcceiling(true); TEST(tecDetails->calcceiling(), true); tecDetails->setCalcceiling3m(true); TEST(tecDetails->calcceiling3m(), true); tecDetails->setCalcalltissues(true); TEST(tecDetails->calcalltissues(), true); tecDetails->setCalcndltts(true); TEST(tecDetails->calcndltts(), true); tecDetails->setBuehlmann(true); TEST(tecDetails->buehlmann(), true); tecDetails->setHRgraph(true); TEST(tecDetails->hrgraph(), true); tecDetails->setTankBar(true); TEST(tecDetails->tankBar(), true); tecDetails->setPercentageGraph(true); TEST(tecDetails->percentageGraph(), true); tecDetails->setRulerGraph(true); TEST(tecDetails->rulerGraph(), true); tecDetails->setShowCCRSetpoint(true); TEST(tecDetails->showCCRSetpoint(), true); tecDetails->setShowCCRSensors(true); TEST(tecDetails->showCCRSensors(), true); tecDetails->setZoomedPlot(true); TEST(tecDetails->zoomedPlot(), true); tecDetails->setShowSac(true); TEST(tecDetails->showSac(), true); tecDetails->setGfLowAtMaxDepth(true); TEST(tecDetails->gfLowAtMaxDepth(), true); tecDetails->setDisplayUnusedTanks(true); TEST(tecDetails->displayUnusedTanks(), true); tecDetails->setShowAverageDepth(true); TEST(tecDetails->showAverageDepth(), true); tecDetails->setShowPicturesInProfile(true); TEST(tecDetails->showPicturesInProfile(), true); tecDetails->setEad(false); TEST(tecDetails->ead(), false); tecDetails->setMod(false); TEST(tecDetails->mod(), false); tecDetails->setDCceiling(false); TEST(tecDetails->dcceiling(), false); tecDetails->setRedceiling(false); TEST(tecDetails->redceiling(), false); tecDetails->setCalcceiling(false); TEST(tecDetails->calcceiling(), false); tecDetails->setCalcceiling3m(false); TEST(tecDetails->calcceiling3m(), false); tecDetails->setCalcalltissues(false); TEST(tecDetails->calcalltissues(), false); tecDetails->setCalcndltts(false); TEST(tecDetails->calcndltts(), false); tecDetails->setBuehlmann(false); TEST(tecDetails->buehlmann(), false); tecDetails->setHRgraph(false); TEST(tecDetails->hrgraph(), false); tecDetails->setTankBar(false); TEST(tecDetails->tankBar(), false); tecDetails->setPercentageGraph(false); TEST(tecDetails->percentageGraph(), false); tecDetails->setRulerGraph(false); TEST(tecDetails->rulerGraph(), false); tecDetails->setShowCCRSetpoint(false); TEST(tecDetails->showCCRSetpoint(), false); tecDetails->setShowCCRSensors(false); TEST(tecDetails->showCCRSensors(), false); tecDetails->setZoomedPlot(false); TEST(tecDetails->zoomedPlot(), false); tecDetails->setShowSac(false); TEST(tecDetails->showSac(), false); tecDetails->setGfLowAtMaxDepth(false); TEST(tecDetails->gfLowAtMaxDepth(), false); tecDetails->setDisplayUnusedTanks(false); TEST(tecDetails->displayUnusedTanks(), false); tecDetails->setShowAverageDepth(false); TEST(tecDetails->showAverageDepth(), false); tecDetails->setShowPicturesInProfile(false); TEST(tecDetails->showPicturesInProfile(), false); auto pp = pref->pp_gas; pp->setShowPn2(false); pp->setShowPhe(false); pp->setShowPo2(false); pp->setPo2Threshold(1.0); pp->setPn2Threshold(2.0); pp->setPheThreshold(3.0); TEST(pp->showPn2(), (short) false); TEST(pp->showPhe(), (short) false); TEST(pp->showPo2(), (short) false); TEST(pp->pn2Threshold(), 2.0); TEST(pp->pheThreshold(), 3.0); TEST(pp->po2Threshold(), 1.0); pp->setShowPn2(true); pp->setShowPhe(true); pp->setShowPo2(true); pp->setPo2Threshold(4.0); pp->setPn2Threshold(5.0); pp->setPheThreshold(6.0); TEST(pp->showPn2(), (short) true); TEST(pp->showPhe(), (short) true); TEST(pp->showPo2(), (short) true); TEST(pp->pn2Threshold(), 5.0); TEST(pp->pheThreshold(), 6.0); TEST(pp->po2Threshold(), 4.0); auto fb = pref->facebook; fb->setAccessToken("rand-access-token"); fb->setUserId("tomaz-user-id"); fb->setAlbumId("album-id"); TEST(fb->accessToken(),QStringLiteral("rand-access-token")); TEST(fb->userId(), QStringLiteral("tomaz-user-id")); TEST(fb->albumId(), QStringLiteral("album-id")); fb->setAccessToken("rand-access-token-2"); fb->setUserId("tomaz-user-id-2"); fb->setAlbumId("album-id-2"); TEST(fb->accessToken(),QStringLiteral("rand-access-token-2")); TEST(fb->userId(), QStringLiteral("tomaz-user-id-2")); TEST(fb->albumId(), QStringLiteral("album-id-2")); auto geo = pref->geocoding; geo->setEnableGeocoding(true); geo->setParseDiveWithoutGps(true); geo->setTagExistingDives(true); TEST(geo->enableGeocoding(),true); TEST(geo->parseDiveWithoutGps(),true); TEST(geo->tagExistingDives(),true); geo->setFirstTaxonomyCategory(TC_NONE); geo->setSecondTaxonomyCategory(TC_OCEAN); geo->setThirdTaxonomyCategory(TC_COUNTRY); TEST(geo->firstTaxonomyCategory(), TC_NONE); TEST(geo->secondTaxonomyCategory(), TC_OCEAN); TEST(geo->thirdTaxonomyCategory(), TC_COUNTRY); geo->setEnableGeocoding(false); geo->setParseDiveWithoutGps(false); geo->setTagExistingDives(false); TEST(geo->enableGeocoding(),false); TEST(geo->parseDiveWithoutGps(),false); TEST(geo->tagExistingDives(),false); geo->setFirstTaxonomyCategory(TC_OCEAN); geo->setSecondTaxonomyCategory(TC_COUNTRY); geo->setThirdTaxonomyCategory(TC_NONE); TEST(geo->firstTaxonomyCategory(), TC_OCEAN); TEST(geo->secondTaxonomyCategory(), TC_COUNTRY); TEST(geo->thirdTaxonomyCategory(), TC_NONE); auto proxy = pref->proxy; proxy->setType(2); proxy->setPort(80); proxy->setAuth(true); proxy->setHost("localhost"); proxy->setUser("unknown"); proxy->setPass("secret"); TEST(proxy->type(),2); TEST(proxy->port(),80); TEST(proxy->auth(),true); TEST(proxy->host(),QStringLiteral("localhost")); TEST(proxy->user(),QStringLiteral("unknown")); TEST(proxy->pass(),QStringLiteral("secret")); proxy->setType(3); proxy->setPort(8080); proxy->setAuth(false); proxy->setHost("127.0.0.1"); proxy->setUser("unknown_1"); proxy->setPass("secret_1"); TEST(proxy->type(),3); TEST(proxy->port(),8080); TEST(proxy->auth(),false); TEST(proxy->host(),QStringLiteral("127.0.0.1")); TEST(proxy->user(),QStringLiteral("unknown_1")); TEST(proxy->pass(),QStringLiteral("secret_1")); auto planner = pref->planner_settings; planner->setLastStop(true); planner->setVerbatimPlan(true); planner->setDisplayRuntime(true); planner->setDisplayDuration(true); planner->setDisplayTransitions(true); planner->setDoo2breaks(true); planner->setDropStoneMode(true); planner->setSafetyStop(true); planner->setSwitchAtRequiredStop(true); planner->setAscrate75(1); planner->setAscrate50(2); planner->setAscratestops(3); planner->setAscratelast6m(4); planner->setDescrate(5); planner->setBottompo2(6); planner->setDecopo2(7); planner->setBestmixend(8); planner->setReserveGas(9); planner->setMinSwitchDuration(10); planner->setBottomSac(11); planner->setDecoSac(12); planner->setDecoMode(BUEHLMANN); TEST(planner->lastStop(),true); TEST(planner->verbatimPlan(),true); TEST(planner->displayRuntime(),true); TEST(planner->displayDuration(),true); TEST(planner->displayTransitions(),true); TEST(planner->doo2breaks(),true); TEST(planner->dropStoneMode(),true); TEST(planner->safetyStop(),true); TEST(planner->switchAtRequiredStop(),true); TEST(planner->ascrate75(),1); TEST(planner->ascrate50(),2); TEST(planner->ascratestops(),3); TEST(planner->ascratelast6m(),4); TEST(planner->descrate(),5); TEST(planner->bottompo2(),6); TEST(planner->decopo2(),7); TEST(planner->bestmixend(),8); TEST(planner->reserveGas(),9); TEST(planner->minSwitchDuration(),10); TEST(planner->bottomSac(),11); TEST(planner->decoSac(),12); TEST(planner->decoMode(),BUEHLMANN); planner->setLastStop(false); planner->setVerbatimPlan(false); planner->setDisplayRuntime(false); planner->setDisplayDuration(false); planner->setDisplayTransitions(false); planner->setDoo2breaks(false); planner->setDropStoneMode(false); planner->setSafetyStop(false); planner->setSwitchAtRequiredStop(false); planner->setAscrate75(11); planner->setAscrate50(12); planner->setAscratestops(13); planner->setAscratelast6m(14); planner->setDescrate(15); planner->setBottompo2(16); planner->setDecopo2(17); planner->setBestmixend(18); planner->setReserveGas(19); planner->setMinSwitchDuration(110); planner->setBottomSac(111); planner->setDecoSac(112); planner->setDecoMode(RECREATIONAL); TEST(planner->lastStop(),false); TEST(planner->verbatimPlan(),false); TEST(planner->displayRuntime(),false); TEST(planner->displayDuration(),false); TEST(planner->displayTransitions(),false); TEST(planner->doo2breaks(),false); TEST(planner->dropStoneMode(),false); TEST(planner->safetyStop(),false); TEST(planner->switchAtRequiredStop(),false); TEST(planner->ascrate75(),11); TEST(planner->ascrate50(),12); TEST(planner->ascratestops(),13); TEST(planner->ascratelast6m(),14); TEST(planner->descrate(),15); TEST(planner->bottompo2(),16); TEST(planner->decopo2(),17); TEST(planner->bestmixend(),18); TEST(planner->reserveGas(),19); TEST(planner->minSwitchDuration(),110); TEST(planner->bottomSac(),111); TEST(planner->decoSac(),112); TEST(planner->decoMode(),RECREATIONAL); auto units = pref->unit_settings; units->setLength(0); units->setPressure(0); units->setVolume(0); units->setTemperature(0); units->setWeight(0); units->setVerticalSpeedTime(0); units->setUnitSystem(QStringLiteral("metric")); units->setCoordinatesTraditional(false); TEST(units->length(),0); TEST(units->pressure(),0); TEST(units->volume(),0); TEST(units->temperature(),0); TEST(units->weight(),0); TEST(units->verticalSpeedTime(),0); TEST(units->unitSystem(),QStringLiteral("metric")); TEST(units->coordinatesTraditional(),false); units->setLength(1); units->setPressure(1); units->setVolume(1); units->setTemperature(1); units->setWeight(1); units->setVerticalSpeedTime(1); units->setUnitSystem(QStringLiteral("fake-metric-system")); units->setCoordinatesTraditional(true); TEST(units->length(),1); TEST(units->pressure(),1); TEST(units->volume(),1); TEST(units->temperature(),1); TEST(units->weight(),1); TEST(units->verticalSpeedTime(),1); TEST(units->unitSystem(),QStringLiteral("personalized")); TEST(units->coordinatesTraditional(),true); auto general = pref->general_settings; general->setDefaultFilename ("filename"); general->setDefaultCylinder ("cylinder_2"); //TODOl: Change this to a enum. // This is 'undefined', it will need to figure out later between no_file or use_deault file. general->setDefaultFileBehavior (0); general->setDefaultSetPoint (0); general->setO2Consumption (0); general->setPscrRatio (0); general->setUseDefaultFile (true); TEST(general->defaultFilename(), QStringLiteral("filename")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_2")); TEST(general->defaultFileBehavior(), (short) LOCAL_DEFAULT_FILE); // since we have a default file, here it returns TEST(general->defaultSetPoint(), 0); TEST(general->o2Consumption(), 0); TEST(general->pscrRatio(), 0); TEST(general->useDefaultFile(), true); general->setDefaultFilename ("no_file_name"); general->setDefaultCylinder ("cylinder_1"); //TODOl: Change this to a enum. general->setDefaultFileBehavior (CLOUD_DEFAULT_FILE); general->setDefaultSetPoint (1); general->setO2Consumption (1); general->setPscrRatio (1); general->setUseDefaultFile (false); TEST(general->defaultFilename(), QStringLiteral("no_file_name")); TEST(general->defaultCylinder(), QStringLiteral("cylinder_1")); TEST(general->defaultFileBehavior(), (short) CLOUD_DEFAULT_FILE); TEST(general->defaultSetPoint(), 1); TEST(general->o2Consumption(), 1); TEST(general->pscrRatio(), 1); TEST(general->useDefaultFile(), false); auto display = pref->display_settings; display->setDivelistFont("comic"); display->setFontSize(10.0); display->setDisplayInvalidDives(true); TEST(display->divelistFont(),QStringLiteral("comic")); TEST(display->fontSize(), 10.0); TEST(display->displayInvalidDives(),(short) true); //TODO: this is true / false. display->setDivelistFont("helvetica"); display->setFontSize(14.0); display->setDisplayInvalidDives(false); TEST(display->divelistFont(),QStringLiteral("helvetica")); TEST(display->fontSize(), 14.0); TEST(display->displayInvalidDives(),(short) false); auto language = pref->language_settings; language->setLangLocale ("en_US"); language->setLanguage ("en"); language->setTimeFormat ("hh:mm"); language->setDateFormat ("dd/mm/yy"); language->setDateFormatShort ("dd/mm"); language->setTimeFormatOverride (false); language->setDateFormatOverride (false); language->setUseSystemLanguage (false); TEST(language->langLocale(), QStringLiteral("en_US")); TEST(language->language(), QStringLiteral("en")); TEST(language->timeFormat(), QStringLiteral("hh:mm")); TEST(language->dateFormat(), QStringLiteral("dd/mm/yy")); TEST(language->dateFormatShort(), QStringLiteral("dd/mm")); TEST(language->timeFormatOverride(), false); TEST(language->dateFormatOverride(), false); TEST(language->useSystemLanguage(), false); language->setLangLocale ("en_EN"); language->setLanguage ("br"); language->setTimeFormat ("mm:hh"); language->setDateFormat ("yy/mm/dd"); language->setDateFormatShort ("dd/yy"); language->setTimeFormatOverride (true); language->setDateFormatOverride (true); language->setUseSystemLanguage (true); TEST(language->langLocale(), QStringLiteral("en_EN")); TEST(language->language(), QStringLiteral("br")); TEST(language->timeFormat(), QStringLiteral("mm:hh")); TEST(language->dateFormat(), QStringLiteral("yy/mm/dd")); TEST(language->dateFormatShort(), QStringLiteral("dd/yy")); TEST(language->timeFormatOverride(),true); TEST(language->dateFormatOverride(),true); TEST(language->useSystemLanguage(), true); pref->animation_settings->setAnimationSpeed(20); TEST(pref->animation_settings->animationSpeed(), 20); pref->animation_settings->setAnimationSpeed(30); TEST(pref->animation_settings->animationSpeed(), 30); auto location = pref->location_settings; location->setTimeThreshold(10); location->setDistanceThreshold(20); TEST(location->timeThreshold(), 10); TEST(location->distanceThreshold(), 20); location->setTimeThreshold(30); location->setDistanceThreshold(40); TEST(location->timeThreshold(), 30); TEST(location->distanceThreshold(), 40); auto update = pref->update_manager_settings; QDate date = QDate::currentDate(); update->setDontCheckForUpdates(true); update->setLastVersionUsed("tomaz-1"); update->setNextCheck(date); TEST(update->dontCheckForUpdates(), true); TEST(update->lastVersionUsed(), QStringLiteral("tomaz-1")); TEST(update->nextCheck(), date); date.addDays(3); update->setDontCheckForUpdates(false); update->setLastVersionUsed("tomaz-2"); update->setNextCheck(date); TEST(update->dontCheckForUpdates(), false); TEST(update->lastVersionUsed(), QStringLiteral("tomaz-2")); TEST(update->nextCheck(), date); auto dc = pref->dive_computer_settings; dc->setDevice("TomazComputer"); TEST(dc->dc_device(), QStringLiteral("TomazComputer")); dc->setDevice("Deepwater"); TEST(dc->dc_device(), QStringLiteral("Deepwater")); dc->setDownloadMode(0); TEST(dc->downloadMode(), 0); dc->setDownloadMode(1); TEST(dc->downloadMode(), 1); dc->setProduct("Thingy1"); TEST(dc->dc_product(), QStringLiteral("Thingy1")); dc->setProduct("Thingy2"); TEST(dc->dc_product(), QStringLiteral("Thingy2")); dc->setVendor("Sharewater"); TEST(dc->dc_vendor(), QStringLiteral("Sharewater")); dc->setVendor("OSTS"); TEST(dc->dc_vendor(), QStringLiteral("OSTS")); }
void pHorizontalScrollBar::constructor() { gtkWidget = gtk_hscrollbar_new(0); setLength(101); g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalScrollBar_change), (gpointer)&horizontalScrollBar); }
/*! \brief Constructor The range of the scale is initialized to [0, 100], The position is at (0, 0) with a length of 100. The orientation is QwtAbstractScaleDraw::Bottom. */ QwtScaleDraw::QwtScaleDraw() { d_data = new QwtScaleDraw::PrivateData; setLength( 100 ); }
void ZrtpPacketHello::configureHello(ZrtpConfigure* config) { // The NumSupported* data is in ZrtpTextData.h nHash = config->getNumConfiguredAlgos(HashAlgorithm); nCipher = config->getNumConfiguredAlgos(CipherAlgorithm); nPubkey = config->getNumConfiguredAlgos(PubKeyAlgorithm); nSas = config->getNumConfiguredAlgos(SasType); nAuth = config->getNumConfiguredAlgos(AuthLength); // length is fixed Header plus HMAC size (2*ZRTP_WORD_SIZE) int32_t length = sizeof(HelloPacket_t) + (2 * ZRTP_WORD_SIZE); length += nHash * ZRTP_WORD_SIZE; length += nCipher * ZRTP_WORD_SIZE; length += nPubkey * ZRTP_WORD_SIZE; length += nSas * ZRTP_WORD_SIZE; length += nAuth * ZRTP_WORD_SIZE; // Don't change order of this sequence oHash = sizeof(Hello_t); oCipher = oHash + (nHash * ZRTP_WORD_SIZE); oAuth = oCipher + (nCipher * ZRTP_WORD_SIZE); oPubkey = oAuth + (nAuth * ZRTP_WORD_SIZE); oSas = oPubkey + (nPubkey * ZRTP_WORD_SIZE); oHmac = oSas + (nSas * ZRTP_WORD_SIZE); // offset to HMAC void* allocated = &data; memset(allocated, 0, sizeof(data)); zrtpHeader = (zrtpPacketHeader_t *)&((HelloPacket_t *)allocated)->hdr; // the standard header helloHeader = (Hello_t *)&((HelloPacket_t *)allocated)->hello; setZrtpId(); // minus 1 for CRC size setLength(length / ZRTP_WORD_SIZE); setMessageType((uint8_t*)HelloMsg); setVersion((uint8_t*)zrtpVersion); uint32_t lenField = nHash << 16; for (int32_t i = 0; i < nHash; i++) { AlgorithmEnum& hash = config->getAlgoAt(HashAlgorithm, i); setHashType(i, (int8_t*)hash.getName()); } lenField |= nCipher << 12; for (int32_t i = 0; i < nCipher; i++) { AlgorithmEnum& cipher = config->getAlgoAt(CipherAlgorithm, i); setCipherType(i, (int8_t*)cipher.getName()); } lenField |= nAuth << 8; for (int32_t i = 0; i < nAuth; i++) { AlgorithmEnum& length = config->getAlgoAt(AuthLength, i); setAuthLen(i, (int8_t*)length.getName()); } lenField |= nPubkey << 4; for (int32_t i = 0; i < nPubkey; i++) { AlgorithmEnum& pubKey = config->getAlgoAt(PubKeyAlgorithm, i); setPubKeyType(i, (int8_t*)pubKey.getName()); } lenField |= nSas; for (int32_t i = 0; i < nSas; i++) { AlgorithmEnum& sas = config->getAlgoAt(SasType, i); setSasType(i, (int8_t*)sas.getName()); } *((uint32_t*)&helloHeader->flags) = htonl(lenField); }