SbBool SoTexture2::readInstance(SoInput *in, unsigned short flags) // //////////////////////////////////////////////////////////////////////// { // Detach filename sensor temporarily filenameSensor->detach(); // Read field info as usual. SbBool readOK = SoNode::readInstance(in, flags); if (readOK && !filename.isDefault()) { // See the comment in SoFile::readInstance for why we do this // and don't just let the FieldSensor take care of reading in // the image. setReadStatus(readOK); (*(filenameSensor->getFunction()))(filenameSensor->getData(), NULL); // Don't set readOK, because not being able to read the image // isn't a fatal error. But do issue a read error: if (getReadStatus() == FALSE) SoReadError::post(in, "Could not read texture file %s", filename.getValue().getString()); } // Reattach sensor filenameSensor->attach(&filename); return readOK; }
/** handles the current socket state. returns the state */ int ServerModule::run() { int result; switch(m_state) { case INIT: if(initSockets()) { m_state = READY_TO_LISTEN; } else { m_state = NET_ERROR; } break; case READY_TO_LISTEN: result = bind(m_socket, (sockaddr *) &m_address, sizeof(m_address)); if (result != SOCKET_ERROR) { m_state = CONNECTED; } else { setError(errCodes_bind, WSAGetLastError()); } break; case CONNECTED: result = listen(m_socket, /* size of connection queue */1); if (result != SOCKET_ERROR) { m_state = LISTENING; } else { setError(errCodes_listen, WSAGetLastError()); } break; case LISTENING: case PROCESSING: case READING_DATA: case SENDING_DATA: result = getReadStatus(); // TODO magic number... if(result == 1) { m_state = ESTABLISHING_CONNECTION; } else { m_state = LISTENING; } break; case ESTABLISHING_CONNECTION: addConnection(m_socket); m_state = LISTENING; break; case NET_ERROR: releaseSockets(); m_state = INIT; break; } manageClients(); return m_state; }
bool VcfGenotypeSample::read(IFILE filePtr, VcfGenotypeFormat& format) { static const char* GT_DELIM = "\n\t:|/."; static const int END_GT = 2; // Ends at index 2 or less static const int PHASED_CHAR_POS = 3; static const int UNPHASED_CHAR_POS = 4; static const int MISSING_GT_POS = 5; // Clear out any previously set values. reset(); myFormatPtr = &format; int gtIndex = format.getGTIndex(); // Read the subfields. SUBFIELD_READ_STATUS readStatus = MORE_SUBFIELDS; std::string* nextType = NULL; int subFieldIndex = 0; while(readStatus == MORE_SUBFIELDS) { // Get the field to write into. if(format.storeIndex(subFieldIndex)) { nextType = &(myGenotypeSubFields.getNextEmpty()); // Check if this is the GT field. if(subFieldIndex == gtIndex) { // There is a GT field, so set that all GT fields are there. // if any are missing it will be turned back to false. myHasAllGenotypeAlleles = true; // This is the GT field, so parse manually looking to see if it // is phased and store the genotypes. int stopChar = END_GT + 1; // Read until a new subfield is found. while(stopChar > END_GT) { // TODO have an option to autoparse the genotypes? // todo - store the previous nextType len in order to // do string conversion to ints... stopChar = filePtr->readTilChar(GT_DELIM, *nextType); if(stopChar == PHASED_CHAR_POS) { nextType->push_back('|'); myPhased = true; } else if(stopChar == UNPHASED_CHAR_POS) { nextType->push_back('/'); myUnphased = true; } else if(stopChar == MISSING_GT_POS) { nextType->push_back('.'); myHasAllGenotypeAlleles = false; } } // Check if this is the END_GT signal. readStatus = getReadStatus(stopChar); } else { // more subfields to read. readStatus = readGenotypeSubField(filePtr, nextType); } } else { readStatus = readGenotypeSubField(filePtr, NULL); } ++subFieldIndex; } // subFieldIndex contains the number of fields in this sample. if(subFieldIndex > format.getOrigNumFields()) { throw(std::runtime_error("VCF Number of Fields in a Sample does not match the Format.")); } else if(subFieldIndex < format.getOrigNumFields()) { // If there are no fields for this sample, enter the missing value. if(myGenotypeSubFields.size() == 0) { myGenotypeSubFields.getNextEmpty() = MISSING_FIELD; } } // Return true if there is a tab - it is just END_OF_FIELD. return(readStatus == END_OF_FIELD); }