Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
stream_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <gsl/gsl>
11
12#include <istream>
13#include <streambuf>
14#include <string>
15
16namespace momentum {
17
22struct spanstreambuf : std::streambuf {
26 spanstreambuf(std::span<const std::byte> buffer = {});
27
29 ~spanstreambuf() override;
30
31 spanstreambuf(const spanstreambuf&) = delete;
35
36 protected:
42 std::streamsize xsputn(const char_type* s, std::streamsize n) override;
43
46 pos_type seekoff(
47 off_type off,
48 std::ios_base::seekdir way,
49 std::ios_base::openmode which = std::ios_base::in) override;
50
52 pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in) override;
53};
54
56struct ispanstream : std::istream {
60 explicit ispanstream(std::span<const std::byte> buffer);
61
63 ~ispanstream() override;
64
65 ispanstream(const ispanstream&) = delete;
69
70 private:
72 spanstreambuf sbuf_;
73};
74
83std::istream& GetLineCrossPlatform(std::istream& is, std::string& line);
84
85} // namespace momentum
std::istream & GetLineCrossPlatform(std::istream &is, std::string &line)
Reads a line from the input stream, handling line endings for different platforms.
ispanstream & operator=(const ispanstream &)=delete
ispanstream(const ispanstream &)=delete
ispanstream(ispanstream &&)=delete
~ispanstream() override
Destructor.
ispanstream & operator=(ispanstream &&)=delete
ispanstream(std::span< const std::byte > buffer)
Construct an ispanstream with a buffer.
Stream buffer based on a span.
std::streamsize xsputn(const char_type *s, std::streamsize n) override
Write a sequence of characters to the output buffer.
~spanstreambuf() override
Destructor.
spanstreambuf(std::span< const std::byte > buffer={})
Construct a spanstreambuf with an optional buffer.
pos_type seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which=std::ios_base::in) override
Seek to an offset relative to way (begin/cur/end).
spanstreambuf & operator=(spanstreambuf &&)=delete
pos_type seekpos(pos_type pos, std::ios_base::openmode which=std::ios_base::in) override
Seek to an absolute position from the start of the buffer.
spanstreambuf(spanstreambuf &&)=delete
spanstreambuf & operator=(const spanstreambuf &)=delete
spanstreambuf(const spanstreambuf &)=delete