/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set the age in years as a double // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerStringAS::setDouble(const std::uint32_t index, const double value) { PUNTOEXE_FUNCTION_START(L"dataHandlerStringAS::setDouble"); if(value < 0) { setAge(index, 0, days); } if(value < 0.08) { setAge(index, (std::uint32_t)(value * 365), days); return; } if(value < 0.5) { setAge(index, (std::uint32_t)(value * 52.14), weeks); return; } if(value < 2) { setAge(index, (std::uint32_t)(value * 12), months); return; } setAge(index, (std::uint32_t)value, years); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Tells that no more transforms will be inserted in the // chain. // /////////////////////////////////////////////////////////// void transformsChain::endTransformsChain() { PUNTOEXE_FUNCTION_START(L"transformsChain::endTransformsChain"); // If this function has already been called, then return /////////////////////////////////////////////////////////// if(m_bEndTransformsChainCalled || m_transformsList.size() == 0) { return; } // Remember we was called /////////////////////////////////////////////////////////// m_bEndTransformsChainCalled = true; // Copy all the defined output images to the last transform // in the chain. /////////////////////////////////////////////////////////// for(long copyOutputImages = 0; ; ++copyOutputImages) { ptr<image> outputImage = getOutputImage(copyOutputImages); if(outputImage == 0) { break; } m_transformsList.back()->declareOutputImage(copyOutputImages, outputImage); } PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Initialize the charsetConversion object // /////////////////////////////////////////////////////////// void charsetConversion::initialize(const std::string& tableName) { PUNTOEXE_FUNCTION_START(L"charsetConversion::initialize"); // Find the table ID /////////////////////////////////////////////////////////// int requestedTable = findTable(tableName); if(requestedTable == -1) { close(); PUNTOEXE_THROW(charsetConversionExceptionNoTable, "The requested ISO table doesn't exist"); } // The specified table is already active. Simply return /////////////////////////////////////////////////////////// if(m_charsetTable[requestedTable].m_isoRegistration == m_isoCharset) { return; } // Close the active table /////////////////////////////////////////////////////////// close(); // Save the name of the active table /////////////////////////////////////////////////////////// m_isoCharset = m_charsetTable[requestedTable].m_isoRegistration; initialize(requestedTable); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Split several parts of a string // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerDateTimeBase::split(const std::wstring& timeString, const std::wstring& separators, std::vector<std::wstring> *pComponents) const { PUNTOEXE_FUNCTION_START(L"dataHandlerDateTimeBase::split"); if(timeString.empty()) { return; } for(size_t startPos(0), sepPos(timeString.find_first_of(separators)); /* empty */; sepPos = timeString.find_first_of(separators, startPos)) { if(sepPos == timeString.npos) { pComponents->push_back(timeString.substr(startPos)); break; } pComponents->push_back(timeString.substr(startPos, sepPos - startPos)); startPos = ++sepPos; if(startPos == timeString.size()) { pComponents->push_back(L""); break; } } PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Read an Huffman code // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// imbxUint32 huffmanTable::readHuffmanCode(streamReader* pStream) { PUNTOEXE_FUNCTION_START(L"huffmanTable::readHuffmanCode"); // Read initial number of bits imbxUint32 readBuffer(pStream->readBits(m_firstValidLength)); // Validate the current Huffman code. If it's OK, then // return the ordered value /////////////////////////////////////////////////////////// if(readBuffer<=m_maxValuePerLength[m_firstValidLength]) { return m_orderedValues[readBuffer - m_minValuePerLength[m_firstValidLength]]; } imbxUint32 orderedValue(m_valuesPerLength[m_firstValidLength]); // Scan all the codes sizes /////////////////////////////////////////////////////////// for(imbxUint8 scanSize(m_firstValidLength + 1), missingBits(0); scanSize != sizeof(m_valuesPerLength)/sizeof(m_valuesPerLength[0]); ++scanSize) { ++missingBits; // If the active length is empty, then continue the loop /////////////////////////////////////////////////////////// if(m_valuesPerLength[scanSize] == 0) { continue; } readBuffer <<= missingBits; if(missingBits == 1) { readBuffer |= pStream->readBit(); } else { readBuffer |= pStream->readBits(missingBits); } // Validate the current Huffman code. If it's OK, then // return the ordered value /////////////////////////////////////////////////////////// if(readBuffer<=m_maxValuePerLength[scanSize]) { return m_orderedValues[orderedValue + readBuffer - m_minValuePerLength[scanSize]]; } orderedValue += m_valuesPerLength[scanSize]; // Reset the number of bits to read in one go /////////////////////////////////////////////////////////// missingBits = 0; } PUNTOEXE_THROW(huffmanExceptionRead, "Invalid huffman code found while reading from a stream"); PUNTOEXE_FUNCTION_END(); }
void transactionsManager::addHandlerToTransaction(ptr<handlers::dataHandler> newHandler) { PUNTOEXE_FUNCTION_START(L"transactionsManager::addHandlerToTransaction"); // Retrieve the transactions manager and lock it /////////////////////////////////////////////////////////// transactionsManager* pManager = getTransactionsManager(); lockObject lockThis(pManager->m_lockObject.get()); // Find the thread's transactions stack /////////////////////////////////////////////////////////// std::thread::id threadId = std::this_thread::get_id(); tTransactionsMap::iterator findThread = pManager->m_transactions.find(threadId); if(findThread == pManager->m_transactions.end()) { return; } // Get the last transaction in the stack /////////////////////////////////////////////////////////// transaction* pLastTransaction = findThread->second.back(); // This throw if the stack is empty. It's OK pLastTransaction->addHandler(newHandler); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Buffer's constructor (on demand content) // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// buffer::buffer(ptr<baseObject> externalLock, std::string defaultType, ptr<baseStream> originalStream, imbxUint32 bufferPosition, imbxUint32 bufferLength, imbxUint32 wordLength, streamController::tByteOrdering endianType): baseObject(externalLock), m_originalStream(originalStream), m_originalBufferPosition(bufferPosition), m_originalBufferLength(bufferLength), m_originalWordLength(wordLength), m_originalEndianType(endianType), m_version(0) { PUNTOEXE_FUNCTION_START(L"buffer::buffer (on demand)"); // Set the buffer's type. // If the buffer's type is unspecified, then the buffer // type is set to OB /////////////////////////////////////////////////////////// if(defaultType.length()==2L) m_bufferType = defaultType; else m_bufferType = "OB"; PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get a string representation of the time // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// std::wstring dataHandlerTime::getUnicodeString(const imbxUint32 index) const { PUNTOEXE_FUNCTION_START(L"dataHandlerTime::getUnicodeString"); imbxInt32 year, month, day, hour, minutes, seconds, nanoseconds, offsetHours, offsetMinutes; getDate(index, &year, &month, &day, &hour, &minutes, &seconds, &nanoseconds, &offsetHours, &offsetMinutes); std::wostringstream convStream; convStream << std::setfill(L'0'); convStream << std::setw(2) << hour; convStream << std::setw(1) << L":"; convStream << std::setw(2) << minutes; convStream << std::setw(1) << L":"; convStream << std::setw(2) << seconds; convStream << std::setw(1) << L"."; convStream << std::setw(6) << nanoseconds; if(offsetHours != 0 && offsetMinutes != 0) { convStream << std::setw(1) << (offsetHours < 0 ? L"-" : L"+"); convStream << std::setw(2) << labs(offsetHours); convStream << std::setw(1) << L":"; convStream << std::setw(2) << labs(offsetMinutes); } return convStream.str(); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get a reading stream for the buffer // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// ptr<streamReader> buffer::getStreamReader() { PUNTOEXE_FUNCTION_START(L"buffer::getStreamReader"); // Lock the object /////////////////////////////////////////////////////////// lockObject lockAccess(this); // If the object must be loaded from the original stream, // then return the original stream /////////////////////////////////////////////////////////// if(m_originalStream != 0 && (m_memory == 0 || m_memory->empty()) ) { ptr<streamReader> reader(new streamReader(m_originalStream, m_originalBufferPosition, m_originalBufferLength)); return reader; } // Build a stream from the buffer's memory /////////////////////////////////////////////////////////// ptr<streamReader> reader; ptr<handlers::dataHandlerRaw> tempHandlerRaw = getDataHandlerRaw(false); if(tempHandlerRaw != 0) { ptr<baseStream> localStream(new bufferStream(tempHandlerRaw)); reader = ptr<streamReader>(new streamReader(localStream)); } return reader; PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Refill the data buffer // /////////////////////////////////////////////////////////// imbxUint32 streamReader::fillDataBuffer() { PUNTOEXE_FUNCTION_START(L"streamReader::fillDataBuffer"); imbxUint32 currentPosition = position(); imbxUint32 readLength = (imbxUint32)(m_pDataBufferMaxEnd - m_pDataBufferStart); if(m_virtualLength != 0) { if(currentPosition >= m_virtualLength) { m_dataBufferStreamPosition = m_virtualLength; m_pDataBufferCurrent = m_pDataBufferEnd = m_pDataBufferStart; return 0; } if(currentPosition + readLength > m_virtualLength) { readLength = m_virtualLength - currentPosition; } } imbxUint32 readBytes = m_pControlledStream->read(currentPosition + m_virtualStart, m_pDataBufferStart, readLength); m_dataBufferStreamPosition = currentPosition; m_pDataBufferEnd = m_pDataBufferStart + readBytes; m_pDataBufferCurrent = m_pDataBufferStart; return readBytes; PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Try to lock a critical section // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// bool criticalSection::tryLock() { #ifdef PUNTOEXE_WINDOWS // WINDOWS return TryEnterCriticalSection(&m_criticalSection) != 0; #else // POSIX PUNTOEXE_FUNCTION_START(L"criticalSection::tryLock"); int tryLockResult = pthread_mutex_trylock(&m_criticalSection); if(tryLockResult == 0) { return true; } if(tryLockResult == EBUSY) { return false; } PUNTOEXE_THROW(posixMutexException, "A mutex is in an error state"); PUNTOEXE_FUNCTION_END(); #endif }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // Return the buffer's size in bytes // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// imbxUint32 buffer::getBufferSizeBytes() { PUNTOEXE_FUNCTION_START(L"buffer::getBufferSizeBytes"); // Lock the object /////////////////////////////////////////////////////////// lockObject lockAccess(this); ptr<memory> localMemory(m_memory); // The buffer has not been loaded yet /////////////////////////////////////////////////////////// if(m_originalStream != 0 && (m_memory == 0 || m_memory->empty()) ) { return m_originalBufferLength; } // The buffer has no memory /////////////////////////////////////////////////////////// if(m_memory == 0) { return 0; } // Return the memory's size /////////////////////////////////////////////////////////// return m_memory->size(); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set the charset used in the tag // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerStringUnicode::setCharsetsList(charsetsList::tCharsetsList* pCharsetsList) { PUNTOEXE_FUNCTION_START(L"dataHandlerStringUnicode::setCharsetInfo"); // Copy the specified charsets into the tag /////////////////////////////////////////////////////////// m_charsetsList.clear(); charsetsList::updateCharsets(pCharsetsList, &m_charsetsList); // If no charset has been defined then we use the default // one /////////////////////////////////////////////////////////// if(m_charsetsList.empty()) { m_charsetsList.push_back(m_dicomCharsets[0].m_dicomName); } // Check for the dicom charset's name /////////////////////////////////////////////////////////// dicomCharsetInformation* pCharset = getCharsetInfo(m_charsetsList.front()); if(pCharset == 0 || pCharset->m_isoRegistration.empty()) { PUNTOEXE_THROW(dataHandlerStringUnicodeExceptionUnknownCharset, "Unknown charset"); } // Setup the conversion objects /////////////////////////////////////////////////////////// m_charsetConversion->initialize(pCharset->m_isoRegistration); m_localeCharsetConversion->initialize("LOCALE"); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Parse a date string // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerDateTimeBase::parseDate( std::wstring dateString, imbxInt32* pYear, imbxInt32* pMonth, imbxInt32* pDay) { PUNTOEXE_FUNCTION_START(L"dataHandlerDateTimeBase::parseDate"); if(dateString.size()<8) dateString.resize(8, L'0'); std::wstring dateYear=dateString.substr(0, 4); std::wstring dateMonth=dateString.substr(4, 2); std::wstring dateDay=dateString.substr(6, 2); std::wistringstream yearStream(dateYear); yearStream >> (*pYear); std::wistringstream monthStream(dateMonth); monthStream >> (*pMonth); std::wistringstream dayStream(dateDay); dayStream >> (*pDay); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get the size in strings // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// imbxUint32 dataHandlerString::getSize() const { PUNTOEXE_FUNCTION_START(L"dataHandlerString::getSize"); return (imbxUint32)m_strings.size(); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get the value as a signed long. // Overwritten to use getDouble() // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// std::int32_t dataHandlerStringDS::getSignedLong(const std::uint32_t index) const { PUNTOEXE_FUNCTION_START(L"dataHandlerStringDS::getSignedLong"); return (std::int32_t)getDouble(index); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Create a data handler and connect it to the buffer // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// ptr<handlers::dataHandler> buffer::getDataHandler(bool bWrite, imbxUint32 size) { PUNTOEXE_FUNCTION_START(L"buffer::getDataHandler"); return getDataHandler(bWrite, false, size); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Returns the number of bits stored // /////////////////////////////////////////////////////////// std::uint32_t waveform::getBitsStored() { PUNTOEXE_FUNCTION_START(L"waveform::getBitsStored"); return m_pDataSet->getUnsignedLong(0x003A, 0, 0x021A, 0); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Returns the number of allocated bits // /////////////////////////////////////////////////////////// std::uint32_t waveform::getBitsAllocated() { PUNTOEXE_FUNCTION_START(L"waveform::getBitsAllocated"); return m_pDataSet->getUnsignedLong(0x5400, 0, 0x1004, 0); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Returns the number of samples // /////////////////////////////////////////////////////////// std::uint32_t waveform::getSamples() { PUNTOEXE_FUNCTION_START(L"waveform::getSamples"); return m_pDataSet->getUnsignedLong(0x003A, 0, 0x0010, 0); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Returns the interpretation string // /////////////////////////////////////////////////////////// std::string waveform::getInterpretation() { PUNTOEXE_FUNCTION_START(L"waveform::getChannels"); return m_pDataSet->getString(0x5400, 0, 0x1006, 0); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set the date as a double (from time_t) // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerDateTimeBase::setDouble(double value) { PUNTOEXE_FUNCTION_START(L"dataHandlerDateTimeBase::setDouble"); setSignedLong((imbxInt32)value); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set the value as an unsigned long. // Overwritten to use setDouble() // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerStringDS::setUnsignedLong(const imbxUint32 index, const imbxUint32 value) { PUNTOEXE_FUNCTION_START(L"dataHandlerStringDS::setUnsignedLong"); setDouble(index, (double)value); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Returns the number of channels // /////////////////////////////////////////////////////////// imbxUint32 waveform::getChannels() { PUNTOEXE_FUNCTION_START(L"waveform::getChannels"); return m_pDataSet->getUnsignedLong(0x003A, 0, 0x0005, 0); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Retrieve the charsets used by the buffer // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void buffer::getCharsetsList(charsetsList::tCharsetsList* pCharsetsList) { PUNTOEXE_FUNCTION_START(L"buffer::getCharsetsList"); charsetsList::copyCharsets(&m_charsetsList, pCharsetsList); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set data element as a string // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerString::setString(const imbxUint32 index, const std::string& value) { PUNTOEXE_FUNCTION_START(L"dataHandlerString::setString"); setUnicodeString(index, convertToUnicode(value)); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Retrieve the dicom charsets used in the string // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerStringUnicode::getCharsetsList(charsetsList::tCharsetsList* pCharsetsList) const { PUNTOEXE_FUNCTION_START(L"dataHandlerStringUnicode::getCharsetList"); charsetsList::copyCharsets(&m_charsetsList, pCharsetsList); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Set the value as a signed long. // Overwritten to use setDouble() // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// void dataHandlerStringDS::setSignedLong(const std::uint32_t index, const std::int32_t value) { PUNTOEXE_FUNCTION_START(L"dataHandlerStringDS::setSignedLong"); setDouble(index, (double)value); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Get the value as a signed long. // Overwritten to use getDouble() // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// imbxInt32 dataHandlerStringDS::getSignedLong(const imbxUint32 index) const { PUNTOEXE_FUNCTION_START(L"dataHandlerStringDS::getSignedLong"); return (imbxInt32)getDouble(index); PUNTOEXE_FUNCTION_END(); }
/////////////////////////////////////////////////////////// // // Uninitialize the charsetConversion object // /////////////////////////////////////////////////////////// void charsetConversion::close() { PUNTOEXE_FUNCTION_START(L"charsetConversion::close"); m_isoCharset.clear(); PUNTOEXE_FUNCTION_END(); }