/** Returns true when all the bytes in the stream have been read. *AsSkStreamrepresentssynchronousI/O,isAtEndreturnsfalsewhenthe *finalstreamlengthisn'tknownyet,evenwhenallthebytesavailable *sofarhavebeenread. *Thismayreturntrueearly(whentherearenomorebytestoberead) *orlate(afterthefirstunsuccessfulread).
*/
virtual bool isAtEnd() const = 0;
[[nodiscard]] bool readBool(bool* b) {
uint8_t i; if (!this->readU8(&i)) { returnfalse; }
*b = (i != 0); return true;
}
[[nodiscard]] bool readScalar(SkScalar*);
[[nodiscard]] bool readPackedUInt(size_t*);
//SkStreamRewindable /** Rewinds to the beginning of the stream. Returns true if the stream is known *tobeatthebeginningafterthiscallreturns.
*/
virtual bool rewind() { returnfalse; }
/** Duplicates this stream. If this cannot be done, returns NULL. *Thereturnedstreamwillbepositionedatthebeginningofitsdata.
*/
std::unique_ptr<SkStream> duplicate() const { return std::unique_ptr<SkStream>(this->onDuplicate());
} /** Duplicates this stream. If this cannot be done, returns NULL. *Thereturnedstreamwillbepositionedthesameasthisstream.
*/
std::unique_ptr<SkStream> fork() const { return std::unique_ptr<SkStream>(this->onFork());
}
//SkStreamSeekable /** Returns true if this stream can report its current position. */
virtual bool hasPosition() const { returnfalse; } /** Returns the current position in the stream. If this cannot be done, returns 0. */
virtual size_t getPosition() const { return0; }
/** Seeks to an absolute position in the stream. If this cannot be done, returns false. *Ifanattemptismadetoseekpasttheendofthestream,thepositionwillbeset *totheendofthestream.
*/
virtual bool seek(size_t /*position*/) { return false; }
/** Seeks to an relative offset in the stream. If this cannot be done, returns false. *Ifanattemptismadetomovetoapositionoutsidethestream,thepositionwillbeset *totheclosestpointwithinthestream(beginningorend).
*/
virtual bool move(long/*offset*/) { return false; }
//SkStreamAsset /** Returns true if this stream can report its total length. */
virtual bool hasLength() const { returnfalse; } /** Returns the total length of the stream. If this cannot be done, returns 0. */
virtual size_t getLength() const { return0; }
//SkStreamMemory /** Returns the starting address for the data. If this cannot be done, returns NULL. */
virtual constvoid* getMemoryBase() { return nullptr; }
virtual sk_sp<const SkData> getData() const { return nullptr; }
/** SkStreamRewindable is a SkStream for which rewind and duplicate are required. */ class SK_API SkStreamRewindable : public SkStream {
public: bool rewind() override = 0;
std::unique_ptr<SkStreamRewindable> duplicate() const { return std::unique_ptr<SkStreamRewindable>(this->onDuplicate());
} private:
SkStreamRewindable* onDuplicate() const override = 0;
};
/** SkStreamSeekable is a SkStreamRewindable for which position, seek, move, and fork are required. */ class SK_API SkStreamSeekable : public SkStreamRewindable {
public:
std::unique_ptr<SkStreamSeekable> duplicate() const { return std::unique_ptr<SkStreamSeekable>(this->onDuplicate());
}
/** SkStreamAsset is a SkStreamSeekable for which getLength is required. */ class SK_API SkStreamAsset : public SkStreamSeekable {
public: bool hasLength() const override { return true; }
size_t getLength() const override = 0;
/** SkStreamMemory is a SkStreamAsset for which getMemoryBase is required. */ class SK_API SkStreamMemory : public SkStreamAsset {
public: constvoid* getMemoryBase() override = 0;
/** A stream that wraps a C FILE* file stream. */ class SK_API SkFILEStream : public SkStreamAsset {
public: /** Initialize the stream by calling sk_fopen on the specified path. *Thisinternalstreamwillbeclosedinthedestructor.
*/ explicit SkFILEStream(constchar path[] = nullptr);
/** Initialize the stream with an existing C FILE stream. *ThecurrentpositionoftheCFILEstreamwillbeconsideredthe *beginningoftheSkFILEStreamandthecurrentseekendoftheFILEwillbetheend. *TheCFILEstreamwillbeclosedinthedestructor.
*/ explicit SkFILEStream(FILE* file);
/** Initialize the stream with an existing C FILE stream. *ThecurrentpositionoftheCFILEstreamwillbeconsideredthe *beginningoftheSkFILEStreamandsizebyteslaterwillbetheend. *TheCFILEstreamwillbeclosedinthedestructor.
*/ explicit SkFILEStream(FILE* file, size_t size);
std::shared_ptr<FILE> fFILE; // My own council will I keep on sizes and offsets. // These are seek positions in the underling FILE, not offsets into the stream.
size_t fEnd;
size_t fStart;
size_t fCurrent;
using INHERITED = SkStreamAsset;
};
// A read only view into a block of memory. class SK_API SkMemoryStream : public SkStreamMemory {
public:
SkMemoryStream();
/** We allocate (and free) the memory. Write to it via getMemoryBase() */ explicit SkMemoryStream(size_t length);
/** If copyData is true, the stream makes a private copy of the data. */
SkMemoryStream(constvoid* data, size_t length, bool copyData = false);
/** Creates the stream to read from the specified data */ explicit SkMemoryStream(sk_sp<const SkData> data);
/** Returns a stream with a copy of the input data. */ static std::unique_ptr<SkMemoryStream> MakeCopy(constvoid* data, size_t length);
/** Returns a stream with a bare pointer reference to the input data. */ static std::unique_ptr<SkMemoryStream> MakeDirect(constvoid* data, size_t length);
/** Returns a stream with a shared reference to the input data. */ static std::unique_ptr<SkMemoryStream> Make(sk_sp<const SkData> data);
/** Resets the stream to the specified data and length, justliketheconstructor. ifcopyDataistrue,thestreammakesaprivatecopyofthedata
*/
virtual void setMemory(constvoid* data, size_t length, bool copyData = false); /** Replace any memory buffer with the specified buffer. The caller musthaveallocateddatawithsk_mallocorsk_realloc,sinceit willbefreedwithsk_free.
*/ void setMemoryOwned(constvoid* data, size_t length);
/** More efficient version of read(dst, 0, bytesWritten()). */ void copyTo(void* dst) const; bool writeToStream(SkWStream* dst) const;
/** Equivalent to copyTo() followed by reset(), but may save memory use. */ void copyToAndReset(void* dst);
/** Equivalent to writeToStream() followed by reset(), but may save memory use. */ bool writeToAndReset(SkWStream* dst);
/** Equivalent to writeToStream() followed by reset(), but may save memory use.
When the dst is also a SkDynamicMemoryWStream, the implementation is constant time. */ bool writeToAndReset(SkDynamicMemoryWStream* dst);
/** Prepend this stream to dst, resetting this. */ void prependToAndReset(SkDynamicMemoryWStream* dst);
/** Return the contents as SkData, and then reset the stream. */
sk_sp<SkData> detachAsData();
/** Return the contents as vector, and then reset the stream. */
std::vector<uint8_t> detachAsVector();
/** Reset, returning a reader stream with the current content. */
std::unique_ptr<SkStreamAsset> detachAsStream();
/** Reset the stream to its original, empty, state. */ void reset(); void padToAlign4(); private: struct Block;
Block* fHead = nullptr;
Block* fTail = nullptr;
size_t fBytesWrittenBeforeTail = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.