예제 #1
0
	/**
	 * Convenience function.
	 */
	size_t read(uint8_t* data, size_t startPos, size_t size) {
		size_t oldReadPos = getReadPos();
		setReadPos(startPos);
		size_t ammountRead = read(data, size);
		setReadPos(oldReadPos);
		return ammountRead;
	}
예제 #2
0
bool LineSegment::readProperties(XmlReader& e)
      {
      const QStringRef& tag(e.name());
      if (tag == "subtype")
            setSubtype(SpannerSegmentType(e.readInt()));
      else if (tag == "off1")       // obsolete
            setUserOff(e.readPoint() * spatium());
      else if (tag == "off2")
            setUserOff2(e.readPoint() * spatium());
      else if (tag == "pos") {
            if (score()->mscVersion() > 114) {
                  qreal _spatium = spatium();
                  setUserOff(QPointF());
                  setReadPos(e.readPoint() * _spatium);
                  }
            else
                  e.readNext();
            }
#if 0
      else if (tag == "pos") {
            QPointF rp = e.readPoint() * spatium();
            if ((score()->mscVersion() <= 114) && (type() == VOLTA_SEGMENT)) {
                  rp.ry() -= spatium();
                  }
            setReadPos(rp);
            }
#endif
      else if (!Element::readProperties(e)) {
            e.unknown();
            return false;
            }
      return true;
      }
예제 #3
0
void Dynamic::layout()
      {
      if (!readPos().isNull()) {
            if (score()->mscVersion() < 118) {
                  setReadPos(QPointF());
                  // hack: 1.2 boundingBoxes are a bit wider which results
                  // in symbols moved right
                  setUserXoffset(userOff().x() - spatium() * .6);
                  }
            }
      Text::layout();

      Segment* s = segment();
      for (int voice = 0; voice < VOICES; ++voice) {
            int t = (track() & ~0x3) + voice;
            Chord* c = static_cast<Chord*>(s->element(t));
            if (!c)
                  continue;
            if (c->type() == CHORD) {
                  qreal noteHeadWidth = score()->noteHeadWidth() * c->mag();
                  if (c->stem() && !c->up())  // stem down
                        rxpos() += noteHeadWidth * .25;  // center on stem + optical correction
                  else
                        rxpos() += noteHeadWidth * .5;   // center on note head
                  }
            else
                  rxpos() += c->width() * .5;
            break;
            }
      }
예제 #4
0
/**
 * Create
 * Create and return a byte array of an HTTP request, built from the variables of this HTTPRequest
 *
 * @return Byte array of this HTTPRequest to be sent over the wire
 */
uint8_t* HTTPRequest::create() {
    // Clear the bytebuffer in the event this isn't the first call of create()
	clear();
    
    // Insert the initial line: <method> <path> <version>\r\n
    std::string mstr = "";
    mstr = methodIntToStr(method);
    if(mstr.empty()) {
        printf("Could not create HTTPRequest, unknown method id: %i\n", method);
        return NULL;
    }
    putLine(mstr + " " + requestUri + " " + version);
    
    // Put all headers
    putHeaders();
    
    // If theres body data, add it now
    if((data != NULL) && dataLen > 0) {
        putBytes(data, dataLen);
    }
    
    // Allocate space for the returned byte array and return it
	uint8_t* createRetData = new uint8_t[size()];
	setReadPos(0);
	getBytes(createRetData, size());
    
    return createRetData;
}
예제 #5
0
void Dynamic::layout()
      {
      if (!readPos().isNull()) {
            if (score()->mscVersion() < 118) {
                  setReadPos(QPointF());
                  // hack: 1.2 boundingBoxes are a bit wider which results
                  // in symbols moved right
                  setUserXoffset(userOff().x() - spatium() * .6);
                  }
            }
      Text::layout();
      }
예제 #6
0
/**
 * Get Line
 * Retrive the entire contents of a line: string from current position until CR or LF, whichever comes first, then increment the read position
 * until it's past the last CR or LF in the line
 *
 * @return Contents of the line in a string (without CR or LF)
 */
string HTTPMessage::getLine() {
	string ret = "";
	int startPos = getReadPos();
	bool newLineReached = false;
	char c = 0;

	// Append characters to the return string until we hit the end of the buffer, a CR (13) or LF (10)
	for(unsigned int i = startPos; i < size(); i++) {
		// If the next byte is a \r or \n, we've reached the end of the line and should break out of the loop
		c = peek();
		if((c == 13) || (c == 10)) {
			newLineReached = true;
			break;
		}

		// Otherwise, append the next character to the string
		ret += getChar();
	}

	// If a line termination was never reached, discard the result and conclude there are no more lines to parse
	if(!newLineReached) {
		setReadPos(startPos); // Reset the position to before the last line read that we are now discarding
		ret = "";
		return ret;
	}

	// Increment the read position until the end of a CR or LF chain, so the read position will then point to the next line
	for(unsigned int i = getReadPos(); i < size(); i++) {
		c = getChar();
		if((c != 13) && (c != 10)) {
			// Set the Read position back one because the retrived character wasn't a LF or CR
			setReadPos(getReadPos()-1);
			break;
		}
	}

	return ret;
}
예제 #7
0
void Lyrics::layout()
      {
      // setPos(_textStyle.offset(spatium()));
      layout1();
      QPointF rp(readPos());
      if (!rp.isNull()) {
            if (score()->mscVersion() <= 114) {
                  rp.ry() += lineSpacing() + 2;
                  rp.rx() += bbox().width() * .5;
                  }
            setUserOff(rp - ipos());
            setReadPos(QPointF());
            }
      }
예제 #8
0
파일: repeat.cpp 프로젝트: aeliot/MuseScore
void Marker::adjustReadPos()
      {
      if (!readPos().isNull()) {
            QPointF uo;
            if (score()->mscVersion() <= 114) {
                  // rebase from Measure to Segment
                  uo = userOff();
                  uo.rx() -= segment()->pos().x();
                  // 1.2 is always HCENTER aligned
                  if ((align() & ALIGN_HMASK) == 0)    // ALIGN_LEFT
                        uo.rx() -= bbox().width() * .5;
                  }
            else
                  uo = readPos() - ipos();
            setUserOff(uo);
            setReadPos(QPointF());
            }
      }
예제 #9
0
byte* HttpResponse::create() {
    clear();

    std::stringstream sline;
    sline << version << " " << status << " " << reason;
    putLine(sline.str());

    putHeaders();

    if((data != NULL) && dataLen > 0) {
        putBytes(data, dataLen);
    }

    byte* createRetData = new byte[size()];
    setReadPos(0);
    getBytes(createRetData, size());

    return createRetData;
}
예제 #10
0
파일: line.cpp 프로젝트: guifre2/MuseScore
bool LineSegment::readProperties(const QDomElement& e)
      {
      const QString& tag(e.tagName());
      if (tag == "subtype")
            setSubtype(SpannerSegmentType(e.text().toInt()));
      else if (tag == "off1")       // obsolete
            setUserOff(readPoint(e) * spatium());
      else if (tag == "off2")
            setUserOff2(readPoint(e) * spatium());
      else if (tag == "pos") {
            if (score()->mscVersion() > 114) {
                  qreal _spatium = spatium();
                  setUserOff(QPointF());
                  setReadPos(readPoint(e) * _spatium);
                  }
            }
      else if (!Element::readProperties(e)) {
            domError(e);
            return false;
            }
      return true;
      }
예제 #11
0
/**
 * getStrElement
 * Get a token from the current buffer, stopping at the delimiter. Returns the token as a string
 *
 * @param delim The delimiter to stop at when retriving the element. By default, it's a space
 * @return Token found in the buffer. Empty if delimiter wasn't reached
 */
string HTTPMessage::getStrElement(char delim) {
    string ret = "";
    int startPos = getReadPos();
    unsigned int size = 0;
    int endPos = find(delim, startPos);

	// Calculate the size based on the found ending position
    size = (endPos+1) - startPos;

    if((endPos == -1) || (size <= 0))
        return "";
    
    // Grab the string from the byte buffer up to the delimiter
    char *str = new char[size];
    getBytes((byte*)str, size);
	str[size-1] = 0x00; // NULL termination
    ret.assign(str);
    
    // Increment the read position PAST the delimiter
    setReadPos(endPos+1);
    
    return ret;
}
예제 #12
0
파일: buffer.cpp 프로젝트: sitev/cjCore
	void Buffer::clear() {
		setPos(0);
		setReadPos(0);
	}